Attempt to fix workers

This commit is contained in:
M66B 2019-05-29 10:02:10 +02:00
parent 822515623c
commit 0d2bd37772
3 changed files with 3 additions and 12 deletions

View File

@ -21,11 +21,9 @@ package eu.faircode.email;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import androidx.work.Constraints;
import androidx.work.ExistingPeriodicWorkPolicy;
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;
@ -157,17 +155,11 @@ public class WorkerCleanup extends Worker {
static void queue(Context context) {
Log.i("Queuing " + getName() + " every " + CLEANUP_INTERVAL + " hours");
Constraints.Builder constraints = new Constraints.Builder();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
constraints.setRequiresDeviceIdle(true);
PeriodicWorkRequest workRequest =
new PeriodicWorkRequest.Builder(WorkerCleanup.class, CLEANUP_INTERVAL, TimeUnit.HOURS)
.setInitialDelay(CLEANUP_INTERVAL, TimeUnit.HOURS)
.setConstraints(constraints.build())
.build();
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.KEEP, workRequest);
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.REPLACE, workRequest);
Log.i("Queued " + getName());
}

View File

@ -52,9 +52,9 @@ public class WorkerPoll extends Worker {
int pollInterval = prefs.getInt("poll_interval", 0);
if (enabled && pollInterval > 0) {
Log.i("Queuing " + getName() + " every " + pollInterval + " minutes");
PeriodicWorkRequest workRequest =
new PeriodicWorkRequest.Builder(WorkerPoll.class, pollInterval, TimeUnit.MINUTES)
.setInitialDelay(pollInterval, TimeUnit.MINUTES)
.build();
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.REPLACE, workRequest);

View File

@ -56,10 +56,9 @@ public class WorkerWatchdog extends Worker {
PeriodicWorkRequest workRequest =
new PeriodicWorkRequest.Builder(WorkerWatchdog.class, WATCHDOG_INTERVAL, TimeUnit.MINUTES)
.setInitialDelay(WATCHDOG_INTERVAL, TimeUnit.MINUTES)
.build();
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.KEEP, workRequest);
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.REPLACE, workRequest);
Log.i("Queued " + getName());
} else {