From 12bc106a7569db1dc74f672a6d4f7e9db2415b48 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 10 Dec 2019 10:36:59 +0100 Subject: [PATCH] Fixed wakeup --- .../eu/faircode/email/ServiceSynchronize.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 7f256e8a66..b1098a6fdf 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -279,8 +279,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences } } else { TupleAccountNetworkState prev = accountStates.get(index); - accountStates.remove(index); - Core.State state = serviceStates.get(current); if (state != null) state.setNetworkState(current.networkState); @@ -294,11 +292,15 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences case "wakeup": if (state == null) Log.e("### wakeup without state"); - else + else { + Log.i("### waking up " + current); state.release(); + } continue; } + accountStates.remove(index); + // Some networks disallow email server connections: // - reload on network type change when disconnected if (reload || @@ -733,11 +735,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences try { wlAccount.acquire(); - PendingIntent piWakeup = PendingIntent.getService( - this, - PI_WAKEUP, - new Intent("wakeup:" + account.id), - PendingIntent.FLAG_UPDATE_CURRENT); + Intent wakeup = new Intent(ServiceSynchronize.this, ServiceSynchronize.class); + wakeup.setAction("wakeup:" + account.id); + PendingIntent piWakeup; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) + piWakeup = PendingIntent.getService(this, PI_WAKEUP, wakeup, PendingIntent.FLAG_UPDATE_CURRENT); + else + piWakeup = PendingIntent.getForegroundService(this, PI_WAKEUP, wakeup, PendingIntent.FLAG_UPDATE_CURRENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (account.notify) @@ -1201,6 +1205,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences try { wlAccount.release(); state.acquire(2 * duration); + Log.i("### " + account.name + " keeping alive"); } catch (InterruptedException ex) { EntityLog.log(this, account.name + " waited state=" + state); } finally { @@ -1286,6 +1291,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences try { wlAccount.release(); state.acquire(2 * duration); + Log.i("### " + account.name + " backoff done"); } catch (InterruptedException ex) { Log.w(account.name + " backoff " + ex.toString()); } finally {