Browse Source

Increase daily job interval, schedule on boot/update only

main
M66B 6 years ago
parent
commit
420acdc1fe
3 changed files with 5 additions and 3 deletions
  1. +4
    -2
      app/src/main/java/eu/faircode/email/JobDaily.java
  2. +1
    -0
      app/src/main/java/eu/faircode/email/ReceiverAutostart.java
  3. +0
    -1
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java

+ 4
- 2
app/src/main/java/eu/faircode/email/JobDaily.java View File

@ -35,11 +35,13 @@ import java.util.concurrent.Executors;
public class JobDaily extends JobService { public class JobDaily extends JobService {
private ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory); private ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
private static final long CLEANUP_INTERVAL = 4 * 3600 * 1000L; // milliseconds
public static void schedule(Context context) { public static void schedule(Context context) {
Log.i(Helper.TAG, "Scheduling daily job"); Log.i(Helper.TAG, "Scheduling daily job");
JobInfo.Builder job = new JobInfo.Builder(Helper.JOB_DAILY, new ComponentName(context, JobDaily.class)) JobInfo.Builder job = new JobInfo.Builder(Helper.JOB_DAILY, new ComponentName(context, JobDaily.class))
.setPeriodic(24 * 3600 * 1000L)
.setPeriodic(CLEANUP_INTERVAL)
.setRequiresDeviceIdle(true); .setRequiresDeviceIdle(true);
JobScheduler scheduler = context.getSystemService(JobScheduler.class); JobScheduler scheduler = context.getSystemService(JobScheduler.class);
@ -47,7 +49,7 @@ public class JobDaily extends JobService {
if (scheduler.schedule(job.build()) == JobScheduler.RESULT_SUCCESS) if (scheduler.schedule(job.build()) == JobScheduler.RESULT_SUCCESS)
Log.i(Helper.TAG, "Scheduled daily job"); Log.i(Helper.TAG, "Scheduled daily job");
else else
Log.e(Helper.TAG, "Failed to schedule daily job");
Log.e(Helper.TAG, "Scheduling daily job failed");
} }
@Override @Override


+ 1
- 0
app/src/main/java/eu/faircode/email/ReceiverAutostart.java View File

@ -36,6 +36,7 @@ public class ReceiverAutostart extends BroadcastReceiver {
Log.i(Helper.TAG, "Synchronizing accounts=" + synchronizing); Log.i(Helper.TAG, "Synchronizing accounts=" + synchronizing);
if (synchronizing > 0) if (synchronizing > 0)
ServiceSynchronize.start(context); ServiceSynchronize.start(context);
JobDaily.schedule(context);
} }
}).start(); }).start();
} }


+ 0
- 1
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -2034,7 +2034,6 @@ public class ServiceSynchronize extends LifecycleService {
public static void start(Context context) { public static void start(Context context) {
ContextCompat.startForegroundService(context, new Intent(context, ServiceSynchronize.class)); ContextCompat.startForegroundService(context, new Intent(context, ServiceSynchronize.class));
JobDaily.schedule(context);
} }
public static void reload(Context context, String reason) { public static void reload(Context context, String reason) {


Loading…
Cancel
Save