From c0a6b79bb4aa95c2eb379da2fa39bc6b5a9dbefd Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 10 Aug 2020 16:45:36 +0200 Subject: [PATCH] Added account wakeup failsafe --- app/src/main/java/eu/faircode/email/Core.java | 6 +++++- .../main/java/eu/faircode/email/ServiceSynchronize.java | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index c704904a20..8ae310d603 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -4036,9 +4036,13 @@ class Core { thread.setPriority(THREAD_PRIORITY_BACKGROUND); } - void release() { + boolean release() { + if (!thread.isAlive()) + return false; + semaphore.release(); yield(); + return true; } boolean acquire(long milliseconds) throws InterruptedException { diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index bea6a7af96..1bcbf732dc 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -765,11 +765,18 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences String action = intent.getAction(); long account = Long.parseLong(action.split(":")[1]); Core.State state = coreStates.get(account); + + boolean ok = false; if (state == null) EntityLog.log(this, "### wakeup missing account=" + account); else { EntityLog.log(this, "### waking up account=" + account); - state.release(); + ok = state.release(); + } + + if (!ok) { + Log.e("Wakeup failed account=" + account); + reload(this, account, false, "wakeup failed"); } }