Bring back reconnect delay

pull/169/head
M66B 6 years ago
parent 250edd19eb
commit e016f99070

@ -89,6 +89,7 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
public class ServiceSynchronize extends ServiceBase implements SharedPreferences.OnSharedPreferenceChangeListener { public class ServiceSynchronize extends ServiceBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private Boolean lastSuitable = null; private Boolean lastSuitable = null;
private long lastLost = 0;
private int lastAccounts = 0; private int lastAccounts = 0;
private int lastOperations = 0; private int lastOperations = 0;
@ -100,6 +101,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private static final int CONNECT_BACKOFF_START = 8; // seconds private static final int CONNECT_BACKOFF_START = 8; // seconds
private static final int CONNECT_BACKOFF_MAX = 64; // seconds (totally 2 minutes) private static final int CONNECT_BACKOFF_MAX = 64; // seconds (totally 2 minutes)
private static final int CONNECT_BACKOFF_AlARM = 15; // minutes private static final int CONNECT_BACKOFF_AlARM = 15; // minutes
private static final long RECONNECT_BACKOFF = 90 * 1000L; // milliseconds
private static final int ACCOUNT_ERROR_AFTER = 60; // minutes private static final int ACCOUNT_ERROR_AFTER = 60; // minutes
private static final int BACKOFF_ERROR_AFTER = 16; // seconds private static final int BACKOFF_ERROR_AFTER = 16; // seconds
@ -280,6 +282,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
crumb.put("suitable", Boolean.toString(accountNetworkState.networkState.isSuitable())); crumb.put("suitable", Boolean.toString(accountNetworkState.networkState.isSuitable()));
crumb.put("unmetered", Boolean.toString(accountNetworkState.networkState.isUnmetered())); crumb.put("unmetered", Boolean.toString(accountNetworkState.networkState.isUnmetered()));
crumb.put("roaming", Boolean.toString(accountNetworkState.networkState.isRoaming())); crumb.put("roaming", Boolean.toString(accountNetworkState.networkState.isRoaming()));
crumb.put("lastLost", new Date(lastLost).toString());
Log.breadcrumb("start", crumb); Log.breadcrumb("start", crumb);
Log.i("### start=" + accountNetworkState); Log.i("### start=" + accountNetworkState);
@ -304,6 +307,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
crumb.put("suitable", Boolean.toString(accountNetworkState.networkState.isSuitable())); crumb.put("suitable", Boolean.toString(accountNetworkState.networkState.isSuitable()));
crumb.put("unmetered", Boolean.toString(accountNetworkState.networkState.isUnmetered())); crumb.put("unmetered", Boolean.toString(accountNetworkState.networkState.isUnmetered()));
crumb.put("roaming", Boolean.toString(accountNetworkState.networkState.isRoaming())); crumb.put("roaming", Boolean.toString(accountNetworkState.networkState.isRoaming()));
crumb.put("lastLost", new Date(lastLost).toString());
Log.breadcrumb("stop", crumb); Log.breadcrumb("stop", crumb);
Log.i("### stop=" + accountNetworkState); Log.i("### stop=" + accountNetworkState);
@ -584,6 +588,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} }
private void onReload(Intent intent) { private void onReload(Intent intent) {
lastLost = 0;
Bundle command = new Bundle(); Bundle command = new Bundle();
command.putString("name", "reload"); command.putString("name", "reload");
command.putLong("account", intent.getLongExtra("account", -1)); command.putLong("account", intent.getLongExtra("account", -1));
@ -712,6 +717,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
account.deleteNotificationChannel(ServiceSynchronize.this); account.deleteNotificationChannel(ServiceSynchronize.this);
} }
long ago = new Date().getTime() - lastLost;
if (ago < RECONNECT_BACKOFF)
try {
long backoff = RECONNECT_BACKOFF - ago;
EntityLog.log(ServiceSynchronize.this, account.name + " backoff=" + (backoff / 1000));
state.acquire(backoff);
} catch (InterruptedException ex) {
Log.w(account.name + " backoff " + ex.toString());
}
final DB db = DB.getInstance(this); final DB db = DB.getInstance(this);
state.setBackoff(CONNECT_BACKOFF_START); state.setBackoff(CONNECT_BACKOFF_START);
@ -1295,6 +1310,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo active = cm.getActiveNetworkInfo(); NetworkInfo active = cm.getActiveNetworkInfo();
EntityLog.log(ServiceSynchronize.this, "Lost network=" + network + " active=" + active); EntityLog.log(ServiceSynchronize.this, "Lost network=" + network + " active=" + active);
if (active == null)
lastLost = new Date().getTime();
updateState(); updateState();
} }
@ -1319,7 +1336,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) { if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
boolean on = intent.getBooleanExtra("state", false); boolean on = intent.getBooleanExtra("state", false);
if (!on) if (!on)
; lastLost = 0;
} }
networkCallback.onCapabilitiesChanged(null, null); networkCallback.onCapabilitiesChanged(null, null);

Loading…
Cancel
Save