From 420acdc1fedadd7fd9b16c31c7760338abb82174 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 22 Sep 2018 07:42:02 +0000 Subject: [PATCH] Increase daily job interval, schedule on boot/update only --- app/src/main/java/eu/faircode/email/JobDaily.java | 6 ++++-- app/src/main/java/eu/faircode/email/ReceiverAutostart.java | 1 + app/src/main/java/eu/faircode/email/ServiceSynchronize.java | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/JobDaily.java b/app/src/main/java/eu/faircode/email/JobDaily.java index 0d5c774a6e..c16fad7cf5 100644 --- a/app/src/main/java/eu/faircode/email/JobDaily.java +++ b/app/src/main/java/eu/faircode/email/JobDaily.java @@ -35,11 +35,13 @@ import java.util.concurrent.Executors; public class JobDaily extends JobService { private ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory); + private static final long CLEANUP_INTERVAL = 4 * 3600 * 1000L; // milliseconds + public static void schedule(Context context) { Log.i(Helper.TAG, "Scheduling daily job"); JobInfo.Builder job = new JobInfo.Builder(Helper.JOB_DAILY, new ComponentName(context, JobDaily.class)) - .setPeriodic(24 * 3600 * 1000L) + .setPeriodic(CLEANUP_INTERVAL) .setRequiresDeviceIdle(true); JobScheduler scheduler = context.getSystemService(JobScheduler.class); @@ -47,7 +49,7 @@ public class JobDaily extends JobService { if (scheduler.schedule(job.build()) == JobScheduler.RESULT_SUCCESS) Log.i(Helper.TAG, "Scheduled daily job"); else - Log.e(Helper.TAG, "Failed to schedule daily job"); + Log.e(Helper.TAG, "Scheduling daily job failed"); } @Override diff --git a/app/src/main/java/eu/faircode/email/ReceiverAutostart.java b/app/src/main/java/eu/faircode/email/ReceiverAutostart.java index eea1f42331..00670f0e88 100644 --- a/app/src/main/java/eu/faircode/email/ReceiverAutostart.java +++ b/app/src/main/java/eu/faircode/email/ReceiverAutostart.java @@ -36,6 +36,7 @@ public class ReceiverAutostart extends BroadcastReceiver { Log.i(Helper.TAG, "Synchronizing accounts=" + synchronizing); if (synchronizing > 0) ServiceSynchronize.start(context); + JobDaily.schedule(context); } }).start(); } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index bf07d880a9..116943ccfa 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -2034,7 +2034,6 @@ public class ServiceSynchronize extends LifecycleService { public static void start(Context context) { ContextCompat.startForegroundService(context, new Intent(context, ServiceSynchronize.class)); - JobDaily.schedule(context); } public static void reload(Context context, String reason) {