Wait longer only when max connections

pull/174/head
M66B 6 years ago
parent b73b26b44d
commit e0b6060252

@ -3311,6 +3311,7 @@ class Core {
private Semaphore semaphore = new Semaphore(0); private Semaphore semaphore = new Semaphore(0);
private boolean running = true; private boolean running = true;
private boolean recoverable = true; private boolean recoverable = true;
private boolean maxConnections = false;
private Long lastActivity = null; private Long lastActivity = null;
State(ConnectionHelper.NetworkState networkState) { State(ConnectionHelper.NetworkState networkState) {
@ -3373,8 +3374,17 @@ class Core {
yield(); yield();
} }
void setMaxConnections() {
maxConnections = true;
}
boolean getMaxConnections() {
return maxConnections;
}
void reset() { void reset() {
recoverable = true; recoverable = true;
maxConnections = false;
lastActivity = null; lastActivity = null;
} }

@ -819,7 +819,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
EntityLog.log(ServiceSynchronize.this, account.name + " alert: " + message); 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); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("alert:" + account.id, 1, nm.notify("alert:" + account.id, 1,
getNotificationAlert(account.name, message).build()); getNotificationAlert(account.name, message).build());
@ -849,7 +852,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
boolean ioError = false; boolean ioError = false;
Throwable c = ex; Throwable c = ex;
while (c != null) { 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; ioError = true;
break; break;
} }
@ -1456,8 +1462,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
// Short back-off period, keep device awake // Short back-off period, keep device awake
EntityLog.log(this, account.name + " backoff=" + backoff); EntityLog.log(this, account.name + " backoff=" + backoff);
try { try {
state.acquire(backoff * state.acquire(backoff * 1000L * (state.getMaxConnections() ? 2 : 1));
("imap.gmail.com".equalsIgnoreCase(account.host) ? 2000L : 1000L));
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Log.w(account.name + " backoff " + ex.toString()); Log.w(account.name + " backoff " + ex.toString());
} }

Loading…
Cancel
Save