Skip to content

Commit 3fcf1c8

Browse files
Carlos ValdiviaAndroid (Google) Code Review
authored andcommitted
Merge "Fix a race condition with respect to clients of SyncStorageEngine." into jb-dev
2 parents 9ac663e + 3aca7d7 commit 3fcf1c8

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

core/java/android/content/SyncStorageEngine.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,29 @@ public static class AuthorityInfo {
197197
long delayUntil;
198198
final ArrayList<Pair<Bundle, Long>> periodicSyncs;
199199

200+
/**
201+
* Copy constructor for making deep-ish copies. Only the bundles stored
202+
* in periodic syncs can make unexpected changes.
203+
*
204+
* @param toCopy AuthorityInfo to be copied.
205+
*/
206+
AuthorityInfo(AuthorityInfo toCopy) {
207+
account = toCopy.account;
208+
userId = toCopy.userId;
209+
authority = toCopy.authority;
210+
ident = toCopy.ident;
211+
enabled = toCopy.enabled;
212+
syncable = toCopy.syncable;
213+
backoffTime = toCopy.backoffTime;
214+
backoffDelay = toCopy.backoffDelay;
215+
delayUntil = toCopy.delayUntil;
216+
periodicSyncs = new ArrayList<Pair<Bundle, Long>>();
217+
for (Pair<Bundle, Long> sync : toCopy.periodicSyncs) {
218+
// Still not a perfect copy, because we are just copying the mappings.
219+
periodicSyncs.add(Pair.create(new Bundle(sync.first), sync.second));
220+
}
221+
}
222+
200223
AuthorityInfo(Account account, int userId, String authority, int ident) {
201224
this.account = account;
202225
this.userId = userId;
@@ -1212,7 +1235,8 @@ public ArrayList<AuthorityInfo> getAuthorities() {
12121235
final int N = mAuthorities.size();
12131236
ArrayList<AuthorityInfo> infos = new ArrayList<AuthorityInfo>(N);
12141237
for (int i=0; i<N; i++) {
1215-
infos.add(mAuthorities.valueAt(i));
1238+
// Make deep copy because AuthorityInfo syncs are liable to change.
1239+
infos.add(new AuthorityInfo(mAuthorities.valueAt(i)));
12161240
}
12171241
return infos;
12181242
}

0 commit comments

Comments
 (0)