From 999669918d5738029f21f041de6e7186d331fbc8 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 6 Jan 2020 12:28:15 +0100 Subject: [PATCH] Revert "Small improvement" This reverts commit 241448568928cd5f877da1aa363bbfa66b15b8e6. --- .../eu/faircode/email/ReceiverAutoStart.java | 2 +- .../java/eu/faircode/email/WorkerCleanup.java | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java b/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java index e72d9112f7..891847fa76 100644 --- a/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java +++ b/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java @@ -38,7 +38,7 @@ public class ReceiverAutoStart extends BroadcastReceiver { ServiceSynchronize.boot(context); ServiceSend.boot(context); - WorkerCleanup.queue(context); + WorkerCleanup.queueOnce(context); } } } diff --git a/app/src/main/java/eu/faircode/email/WorkerCleanup.java b/app/src/main/java/eu/faircode/email/WorkerCleanup.java index 30d5a2d1b7..9b23d0b2e9 100644 --- a/app/src/main/java/eu/faircode/email/WorkerCleanup.java +++ b/app/src/main/java/eu/faircode/email/WorkerCleanup.java @@ -24,7 +24,9 @@ import android.content.SharedPreferences; import androidx.annotation.NonNull; import androidx.preference.PreferenceManager; +import androidx.work.Data; import androidx.work.ExistingPeriodicWorkPolicy; +import androidx.work.OneTimeWorkRequest; import androidx.work.PeriodicWorkRequest; import androidx.work.WorkManager; import androidx.work.Worker; @@ -103,8 +105,6 @@ public class WorkerCleanup extends Worker { for (EntityMessage message : db.message().getSnoozed()) EntityMessage.snooze(context, message.id, message.ui_snoozed); - ServiceSynchronize.reschedule(context); - // Clear last search SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); prefs.edit() @@ -223,6 +223,24 @@ public class WorkerCleanup extends Worker { } } + static void queueOnce(Context context) { + try { + Log.i("Queuing " + getName() + " once"); + + Data data = new Data.Builder().putBoolean("manual", true).build(); + + OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(WorkerCleanup.class) + .setInputData(data) + .build(); + WorkManager.getInstance(context).enqueue(workRequest); + + Log.i("Queued " + getName() + " once"); + } catch (IllegalStateException ex) { + // https://issuetracker.google.com/issues/138465476 + Log.w(ex); + } + } + static void cancel(Context context) { try { Log.i("Cancelling " + getName());