@ -133,6 +133,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private static final ExecutorService executorNotify =
Helper . getBackgroundExecutor ( 1 , "notify" ) ;
static final int DEFAULT_BACKOFF_POWER = 3 ; // 2^3=8 seconds (totally 8+2x20=48 seconds)
private static final long BACKUP_DELAY = 30 * 1000L ; // milliseconds
private static final long PURGE_DELAY = 30 * 1000L ; // milliseconds
private static final int QUIT_DELAY = 10 ; // seconds
@ -141,7 +143,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private static final int TUNE_KEEP_ALIVE_INTERVAL_STEP = 2 ; // minutes
private static final int OPTIMIZE_POLL_INTERVAL = 15 ; // minutes
private static final int CONNECT_BACKOFF_START = 8 ; // seconds
private static final int CONNECT_BACKOFF_MAX = 8 ; // seconds (totally 8+2x20=48 seconds)
private static final int CONNECT_BACKOFF_INTERMEDIATE = 5 ; // minutes
private static final int CONNECT_BACKOFF_ALARM_START = 15 ; // minutes
private static final int CONNECT_BACKOFF_ALARM_MAX = 60 ; // minutes
@ -2647,6 +2648,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if ( state . isRunning ( ) ) {
long now = new Date ( ) . getTime ( ) ;
boolean logarithmic_backoff = prefs . getBoolean ( "logarithmic_backoff" , true ) ;
int max_backoff_power = prefs . getInt ( "max_backoff_power" , DEFAULT_BACKOFF_POWER - 3 ) ;
int max_backoff = ( int ) Math . pow ( 2 , max_backoff_power + 3 ) ;
if ( logarithmic_backoff ) {
// Check for fast successive server, connectivity, etc failures
@ -2679,7 +2682,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
" avg=" + ( avg_fail / 1000L ) + "/" + ( fail_threshold / 1000L ) +
" missing=" + ( missing / 1000L ) +
" compensate=" + compensate +
" backoff=" + backoff +
" backoff=" + backoff + "/" + max_backoff +
" host=" + account . host +
" ex=" + Log . formatThrowable ( last_fail , false ) ;
if ( compensate > 2 )
@ -2700,14 +2703,14 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
int backoff = state . getBackoff ( ) ;
int recently = ( lastLost + LOST_RECENTLY < now ? 1 : 2 ) ;
EntityLog . log ( this , EntityLog . Type . Account , account ,
account . name + " backoff=" + backoff +
account . name + " backoff=" + backoff + "/" + max_backoff +
" recently=" + recently + "x" +
" logarithmic=" + logarithmic_backoff ) ;
if ( logarithmic_backoff ) {
if ( backoff < CONNECT_BACKOFF_MAX )
if ( backoff < max_backoff )
state . setBackoff ( backoff * 2 ) ;
else if ( backoff = = CONNECT_BACKOFF_MAX )
else if ( backoff = = max_backoff )
if ( AlarmManagerCompatEx . hasExactAlarms ( this ) )
state . setBackoff ( CONNECT_BACKOFF_INTERMEDIATE * 60 ) ;
else
@ -2731,11 +2734,12 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
Map < String , String > crumb = new HashMap < > ( ) ;
crumb . put ( "account" , account . name ) ;
crumb . put ( "backoff" , Integer . toString ( backoff ) ) ;
crumb . put ( "max_backoff" , Integer . toString ( max_backoff ) ) ;
crumb . put ( "recently" , Integer . toString ( recently ) ) ;
crumb . put ( "logarithmic" , Boolean . toString ( logarithmic_backoff ) ) ;
Log . breadcrumb ( "Backing off" , crumb ) ;
if ( backoff < = CONNECT_BACKOFF_MAX ) {
if ( backoff < = max_backoff ) {
// Short back-off period, keep device awake
try {
long interval = backoff * 1000L * recently ;