Bug 715794 - Adjust syncResult delay to implement client-count-based sync interval. r=rnewman

This commit is contained in:
Marina Samuel 2012-04-03 16:43:07 -07:00
parent eda91a0a01
commit 026ab4e368

View File

@ -52,7 +52,8 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
private static final int SHARED_PREFERENCES_MODE = 0;
private static final int BACKOFF_PAD_SECONDS = 5;
private static final int MINIMUM_SYNC_INTERVAL_MILLISECONDS = 5 * 60 * 1000; // 5 minutes.
public static final int MULTI_DEVICE_INTERVAL_MILLISECONDS = 5 * 60 * 1000; // 5 minutes.
public static final int SINGLE_DEVICE_INTERVAL_MILLISECONDS = 24 * 60 * 60 * 1000; // 24 hours.
private final AccountManager mAccountManager;
private final Context mContext;
@ -172,7 +173,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
public Object syncMonitor = new Object();
private SyncResult syncResult;
private Account localAccount;
public Account localAccount;
/**
* Return the number of milliseconds until we're allowed to sync again,
@ -298,7 +299,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
Log.i(LOG_TAG, "Waiting on sync monitor.");
try {
syncMonitor.wait();
long next = System.currentTimeMillis() + MINIMUM_SYNC_INTERVAL_MILLISECONDS;
long next = System.currentTimeMillis() + getSyncInterval();
Log.i(LOG_TAG, "Setting minimum next sync time to " + next);
extendEarliestNextSync(next);
} catch (InterruptedException e) {
@ -310,6 +311,15 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
}
}
public int getSyncInterval() {
int clientsCount = this.getClientsCount();
if (clientsCount <= 1) {
return SINGLE_DEVICE_INTERVAL_MILLISECONDS;
}
return MULTI_DEVICE_INTERVAL_MILLISECONDS;
}
/**
* Now that we have a sync key and password, go ahead and do the work.