From 724a7b4a4e7c967f7913ecba0893a5bf2bf0ed21 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 20 Oct 2022 18:01:32 +0200 Subject: [PATCH] Log prematurely released operation wakelock --- .../java/eu/faircode/email/ServiceSynchronize.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 95bb095f70..01fe1da8a2 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -2082,6 +2082,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences @Override public void run() { super.run(); + + long start = new Date().getTime(); + long timeout = 0; try { List partition; synchronized (partitions) { @@ -2090,7 +2093,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences } // Estimate maximum execution duration - long timeout = 0; if (mapFolders.get(folder) == null) { // Connect, sync folder list -> 3 minutes timeout += WAKELOCK_ACCOUNT_MAX; @@ -2104,8 +2106,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences int hours = (folder.initialize == 0 ? 30 : folder.initialize) * 24; timeout += WAKELOCK_OPERATION_MAX * hours * MESSAGES_HOUR_AVG; } else { - long now = new Date().getTime(); - long hours = (now - folder.last_sync) / (3600 * 1000L) + 1; + long hours = (start - folder.last_sync) / (3600 * 1000L) + 1; // 10 messages/hour -> 100 seconds timeout += WAKELOCK_OPERATION_MAX * hours * MESSAGES_HOUR_AVG; } @@ -2253,6 +2254,12 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences else Log.e(ex); } finally { + if (!wlOperations.isHeld()) { + long elapsed = new Date().getTime() - start; + EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Debug, + key + " prematurely released" + + " elapsed=" + elapsed + " timeout=" + timeout); + } wlOperations.release(); } }