From 026ab4e3683ba5f9f2550f6461cb27566a70abb0 Mon Sep 17 00:00:00 2001 From: Marina Samuel Date: Tue, 3 Apr 2012 16:43:07 -0700 Subject: [PATCH] Bug 715794 - Adjust syncResult delay to implement client-count-based sync interval. r=rnewman --- .../base/sync/syncadapter/SyncAdapter.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mobile/android/base/sync/syncadapter/SyncAdapter.java b/mobile/android/base/sync/syncadapter/SyncAdapter.java index bc0f49728fc..56cf87b94d2 100644 --- a/mobile/android/base/sync/syncadapter/SyncAdapter.java +++ b/mobile/android/base/sync/syncadapter/SyncAdapter.java @@ -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.