Simplification

pull/169/head
M66B 6 years ago
parent 8a15321e83
commit a5ec0f9f0f

@ -1230,12 +1230,15 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
idlers.clear();
}
if (state.isRunning())
try {
if (state.isRunning()) {
if (backoff <= CONNECT_BACKOFF_MAX) {
// Short back-off period, keep device awake
EntityLog.log(this, account.name + " backoff=" + backoff);
try {
state.acquire(backoff * 1000L);
} catch (InterruptedException ex) {
Log.w(account.name + " backoff " + ex.toString());
}
} else {
// Long back-off period, let device sleep
EntityLog.log(this, account.name + " backoff alarm=" + CONNECT_BACKOFF_AlARM);
@ -1247,7 +1250,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}
};
String id = BuildConfig.APPLICATION_ID + ".BACKOFF." + account.id + "." + new Random().nextInt();
String id = BuildConfig.APPLICATION_ID + ".BACKOFF." + account.id;
PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(id), 0);
registerReceiver(alarm, new IntentFilter(id));
@ -1267,6 +1270,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
try {
wlAccount.release();
state.acquire(2 * CONNECT_BACKOFF_AlARM * 60 * 1000L);
} catch (InterruptedException ex) {
Log.w(account.name + " backoff " + ex.toString());
} finally {
wlAccount.acquire();
}
@ -1276,6 +1281,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
try {
unregisterReceiver(alarm);
} catch (IllegalArgumentException ex) {
// Should not happen, but does happen
Log.e(ex);
}
}
@ -1283,8 +1289,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (backoff <= CONNECT_BACKOFF_MAX)
backoff *= 2;
} catch (InterruptedException ex) {
Log.w(account.name + " backoff " + ex.toString());
}
}
} finally {

Loading…
Cancel
Save