am 09d8e3cf: am c68bb182: Merge "SyncManager now returns copy on getCurrentSyncs()" into klp-dev

* commit '09d8e3cf4e411b016ee65d8328dd7a443c9de0ff':
  SyncManager now returns copy on getCurrentSyncs()
This commit is contained in:
Matthew Williams
2013-11-14 09:27:26 -08:00
committed by Android Git Automerger
3 changed files with 38 additions and 10 deletions

View File

@@ -54,6 +54,14 @@ public class SyncInfo implements Parcelable {
this.startTime = startTime;
}
/** @hide */
public SyncInfo(SyncInfo other) {
this.authorityId = other.authorityId;
this.account = new Account(other.account.name, other.account.type);
this.authority = other.authority;
this.startTime = other.startTime;
}
/** @hide */
public int describeContents() {
return 0;

View File

@@ -660,7 +660,7 @@ public final class ContentService extends IContentService.Stub {
int userId = UserHandle.getCallingUserId();
long identityToken = clearCallingIdentity();
try {
return getSyncManager().getSyncStorageEngine().getCurrentSyncs(userId);
return getSyncManager().getSyncStorageEngine().getCurrentSyncsCopy(userId);
} finally {
restoreCallingIdentity(identityToken);
}

View File

@@ -1295,20 +1295,40 @@ public class SyncStorageEngine extends Handler {
}
/**
* Return a list of the currently active syncs. Note that the returned items are the
* real, live active sync objects, so be careful what you do with it.
* Return a list of the currently active syncs. Note that the returned
* items are the real, live active sync objects, so be careful what you do
* with it.
*/
public List<SyncInfo> getCurrentSyncs(int userId) {
private List<SyncInfo> getCurrentSyncs(int userId) {
synchronized (mAuthorities) {
ArrayList<SyncInfo> syncs = mCurrentSyncs.get(userId);
if (syncs == null) {
syncs = new ArrayList<SyncInfo>();
mCurrentSyncs.put(userId, syncs);
}
return syncs;
return getCurrentSyncsLocked(userId);
}
}
/**
* @return a copy of the current syncs data structure. Will not return
* null.
*/
public List<SyncInfo> getCurrentSyncsCopy(int userId) {
synchronized (mAuthorities) {
final List<SyncInfo> syncs = getCurrentSyncsLocked(userId);
final List<SyncInfo> syncsCopy = new ArrayList<SyncInfo>();
for (SyncInfo sync : syncs) {
syncsCopy.add(new SyncInfo(sync));
}
return syncsCopy;
}
}
private List<SyncInfo> getCurrentSyncsLocked(int userId) {
ArrayList<SyncInfo> syncs = mCurrentSyncs.get(userId);
if (syncs == null) {
syncs = new ArrayList<SyncInfo>();
mCurrentSyncs.put(userId, syncs);
}
return syncs;
}
/**
* Return an array of the current sync status for all authorities. Note
* that the objects inside the array are the real, live status objects,