From 6275d4900727415807455af400083a7cf75f8edd Mon Sep 17 00:00:00 2001 From: Shreyas Basarge Date: Fri, 12 Feb 2016 20:27:49 +0000 Subject: [PATCH] Add defaultPeriodic to every authority Adds a default periodic sync to every authority on boot so that subscribedfeeds adapter gets back its periodic sync if lost. This change will bereverted in the next droidfood build. Change-Id: Icae76c2baafb471ad69d01a4c65023dc6f6525c0 --- .../android/server/content/SyncManager.java | 38 +++++++++++++++++++ .../server/content/SyncStorageEngine.java | 12 +++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/content/SyncManager.java b/services/core/java/com/android/server/content/SyncManager.java index 218e529d53669..231962b1e2a84 100644 --- a/services/core/java/com/android/server/content/SyncManager.java +++ b/services/core/java/com/android/server/content/SyncManager.java @@ -451,10 +451,48 @@ public class SyncManager { } } } + ensureDefaultPeriodicSyncsH(); } }); } + private void ensureDefaultPeriodicSyncsH() { + + long defaultPeriod = SyncStorageEngine.DEFAULT_POLL_FREQUENCY_SECONDS; + long defaultFlex = SyncStorageEngine.calculateDefaultFlexTime(defaultPeriod); + + List authorities = mSyncStorageEngine.getAllAuthorities(); + List syncs = getAllPendingSyncsFromCache(); + for (AuthorityInfo authority: authorities) { + boolean foundPeriodicSync = false; + for (SyncOperation op: syncs) { + if (op.isPeriodic && authority.target.matchesSpec(op.target)) { + foundPeriodicSync = true; + break; + } + } + if (!foundPeriodicSync) { + EndPoint target = authority.target; + final RegisteredServicesCache.ServiceInfo + syncAdapterInfo = mSyncAdapters.getServiceInfo( + SyncAdapterType.newKey( + target.provider, target.account.type), + target.userId); + if (syncAdapterInfo == null) { + continue; + } + scheduleSyncOperationH( + new SyncOperation(target, syncAdapterInfo.uid, + syncAdapterInfo.componentName.getPackageName(), + SyncOperation.REASON_PERIODIC, SyncStorageEngine.SOURCE_PERIODIC, + new Bundle(), syncAdapterInfo.type.allowParallelSyncs(), + true /* periodic */, SyncOperation.NO_JOB_ID, defaultPeriod * 1000L, + defaultFlex * 1000L) + ); + } + } + } + private synchronized void verifyJobScheduler() { if (mJobScheduler != null) { return; diff --git a/services/core/java/com/android/server/content/SyncStorageEngine.java b/services/core/java/com/android/server/content/SyncStorageEngine.java index 965054fc057e1..cefaa8ddd8318 100644 --- a/services/core/java/com/android/server/content/SyncStorageEngine.java +++ b/services/core/java/com/android/server/content/SyncStorageEngine.java @@ -80,7 +80,7 @@ public class SyncStorageEngine extends Handler { private static final String XML_TAG_LISTEN_FOR_TICKLES = "listenForTickles"; /** Default time for a periodic sync. */ - private static final long DEFAULT_POLL_FREQUENCY_SECONDS = 60 * 60 * 24; // One day + static final long DEFAULT_POLL_FREQUENCY_SECONDS = 60 * 60 * 24; // One day /** Percentage of period that is flex by default, if no flexMillis is set. */ private static final double DEFAULT_FLEX_PERCENT_SYNC = 0.04; @@ -857,6 +857,16 @@ public class SyncStorageEngine extends Handler { } } + List getAllAuthorities() { + List authorities = new ArrayList(); + synchronized (mAuthorities) { + for (int i = 0; i < mAuthorities.size(); i++) { + authorities.add(mAuthorities.valueAt(i)); + } + } + return authorities; + } + /** * Returns true if there is currently a sync operation being actively processed for the given * target.