diff options
author | Carlos Valdivia <carlosvaldivia@google.com> | 2012-05-08 15:27:03 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-05-08 15:27:03 -0700 |
commit | 3fcf1c85873008df43ee80f896216fb39e4c630e (patch) | |
tree | 8ea400cf967eea8770f54cdfb4ec03facbe738bd | |
parent | 9ac663ef9ab6ec455403d1e71bf897c34d3b311e (diff) | |
parent | 3aca7d7bec4b48bc68480b9d6b0ccdabf6903dfb (diff) | |
download | frameworks_base-3fcf1c85873008df43ee80f896216fb39e4c630e.zip frameworks_base-3fcf1c85873008df43ee80f896216fb39e4c630e.tar.gz frameworks_base-3fcf1c85873008df43ee80f896216fb39e4c630e.tar.bz2 |
Merge "Fix a race condition with respect to clients of SyncStorageEngine." into jb-dev
-rw-r--r-- | core/java/android/content/SyncStorageEngine.java | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/core/java/android/content/SyncStorageEngine.java b/core/java/android/content/SyncStorageEngine.java index 6c7e940..226e107 100644 --- a/core/java/android/content/SyncStorageEngine.java +++ b/core/java/android/content/SyncStorageEngine.java @@ -197,6 +197,29 @@ public class SyncStorageEngine extends Handler { long delayUntil; final ArrayList<Pair<Bundle, Long>> periodicSyncs; + /** + * Copy constructor for making deep-ish copies. Only the bundles stored + * in periodic syncs can make unexpected changes. + * + * @param toCopy AuthorityInfo to be copied. + */ + AuthorityInfo(AuthorityInfo toCopy) { + account = toCopy.account; + userId = toCopy.userId; + authority = toCopy.authority; + ident = toCopy.ident; + enabled = toCopy.enabled; + syncable = toCopy.syncable; + backoffTime = toCopy.backoffTime; + backoffDelay = toCopy.backoffDelay; + delayUntil = toCopy.delayUntil; + periodicSyncs = new ArrayList<Pair<Bundle, Long>>(); + for (Pair<Bundle, Long> sync : toCopy.periodicSyncs) { + // Still not a perfect copy, because we are just copying the mappings. + periodicSyncs.add(Pair.create(new Bundle(sync.first), sync.second)); + } + } + AuthorityInfo(Account account, int userId, String authority, int ident) { this.account = account; this.userId = userId; @@ -1212,7 +1235,8 @@ public class SyncStorageEngine extends Handler { final int N = mAuthorities.size(); ArrayList<AuthorityInfo> infos = new ArrayList<AuthorityInfo>(N); for (int i=0; i<N; i++) { - infos.add(mAuthorities.valueAt(i)); + // Make deep copy because AuthorityInfo syncs are liable to change. + infos.add(new AuthorityInfo(mAuthorities.valueAt(i))); } return infos; } |