diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 71e12ebb92..f203cd9e96 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -3311,6 +3311,7 @@ class Core { private Semaphore semaphore = new Semaphore(0); private boolean running = true; private boolean recoverable = true; + private boolean maxConnections = false; private Long lastActivity = null; State(ConnectionHelper.NetworkState networkState) { @@ -3373,8 +3374,17 @@ class Core { yield(); } + void setMaxConnections() { + maxConnections = true; + } + + boolean getMaxConnections() { + return maxConnections; + } + void reset() { recoverable = true; + maxConnections = false; lastActivity = null; } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 6ca97d0eef..ad9c335f97 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -819,7 +819,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences EntityLog.log(ServiceSynchronize.this, account.name + " alert: " + message); - if (!isMaxConnections(message) || state.getBackoff() > CONNECT_BACKOFF_MAX) { + boolean max = isMaxConnections(message); + if (max) + state.setMaxConnections(); + if (!max || state.getBackoff() > CONNECT_BACKOFF_MAX) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify("alert:" + account.id, 1, getNotificationAlert(account.name, message).build()); @@ -849,7 +852,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences boolean ioError = false; Throwable c = ex; while (c != null) { - if (c instanceof IOException || isMaxConnections(c.getMessage())) { + boolean max = isMaxConnections(c.getMessage()); + if (max) + state.setMaxConnections(); + if (c instanceof IOException || max) { ioError = true; break; } @@ -1456,8 +1462,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences // Short back-off period, keep device awake EntityLog.log(this, account.name + " backoff=" + backoff); try { - state.acquire(backoff * - ("imap.gmail.com".equalsIgnoreCase(account.host) ? 2000L : 1000L)); + state.acquire(backoff * 1000L * (state.getMaxConnections() ? 2 : 1)); } catch (InterruptedException ex) { Log.w(account.name + " backoff " + ex.toString()); }