From fe43910b936bcb43601cac1eff6bac8c5f9eb21d Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 6 Dec 2018 12:38:09 +0100 Subject: [PATCH] Small improvements --- .../eu/faircode/email/ServiceSynchronize.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 5fedcc0089..73e19e764e 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -2318,6 +2318,9 @@ public class ServiceSynchronize extends LifecycleService { private boolean started = false; private int queued = 0; private long lastLost = 0; + PowerManager pm = getSystemService(PowerManager.class); + PowerManager.WakeLock wl = pm.newWakeLock( + PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":manage"); private ExecutorService queue = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory); @Override @@ -2576,18 +2579,14 @@ public class ServiceSynchronize extends LifecycleService { queued++; queue.submit(new Runnable() { - PowerManager pm = getSystemService(PowerManager.class); - PowerManager.WakeLock wl = pm.newWakeLock( - PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":manage"); - @Override public void run() { - EntityLog.log(ServiceSynchronize.this, "Reload " + - " stop=" + doStop + " start=" + doStart + " queued=" + queued + " " + reason); - try { wl.acquire(); + EntityLog.log(ServiceSynchronize.this, "Reload " + + " stop=" + doStop + " start=" + doStart + " queued=" + queued + " " + reason); + if (doStop) stop(); @@ -2597,8 +2596,6 @@ public class ServiceSynchronize extends LifecycleService { } catch (Throwable ex) { Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); } finally { - wl.release(); - queued--; EntityLog.log(ServiceSynchronize.this, "Reload done queued=" + queued); @@ -2612,6 +2609,8 @@ public class ServiceSynchronize extends LifecycleService { stopSelf(); } } + + wl.release(); } } }); @@ -2635,7 +2634,6 @@ public class ServiceSynchronize extends LifecycleService { new Intent(context, ServiceSynchronize.class) .setAction("reload") .putExtra("reason", reason)); - JobDaily.schedule(context); } private class ServiceState {