Reconnect backup takes precedence

This commit is contained in:
M66B 2020-04-24 09:49:17 +02:00
parent 66ad968672
commit 4daba377a8
1 changed files with 58 additions and 47 deletions

View File

@ -818,7 +818,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (ago < RECONNECT_BACKOFF) if (ago < RECONNECT_BACKOFF)
try { try {
long backoff = RECONNECT_BACKOFF - ago; long backoff = RECONNECT_BACKOFF - ago;
EntityLog.log(ServiceSynchronize.this, account.name + " backoff=" + (backoff / 1000)); EntityLog.log(ServiceSynchronize.this, account.name + " reconnect backoff=" + (backoff / 1000));
state.acquire(backoff); state.acquire(backoff);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Log.w(account.name + " backoff " + ex.toString()); Log.w(account.name + " backoff " + ex.toString());
@ -1523,6 +1523,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (state.isRunning()) { if (state.isRunning()) {
int backoff = state.getBackoff(); int backoff = state.getBackoff();
long cbackoff = RECONNECT_BACKOFF - (new Date().getTime() - lastLost);
if (cbackoff > backoff) {
try {
EntityLog.log(this, account.name + " reconnect backoff=" + cbackoff);
state.acquire(cbackoff * 1000L);
} catch (InterruptedException ex) {
Log.w(account.name + " cbackoff " + ex.toString());
}
state.setBackoff(CONNECT_BACKOFF_START);
} else {
EntityLog.log(this, account.name + " backoff=" + backoff); EntityLog.log(this, account.name + " backoff=" + backoff);
if (backoff <= CONNECT_BACKOFF_MAX) { if (backoff <= CONNECT_BACKOFF_MAX) {
// Short back-off period, keep device awake // Short back-off period, keep device awake
@ -1579,6 +1589,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
else if (backoff < CONNECT_BACKOFF_AlARM_MAX * 60) else if (backoff < CONNECT_BACKOFF_AlARM_MAX * 60)
state.setBackoff(backoff * 2); state.setBackoff(backoff * 2);
} }
}
currentThread = Thread.currentThread().getId(); currentThread = Thread.currentThread().getId();
} }