From a7456e46f4cb64524386b22e2596ea93c244c16f Mon Sep 17 00:00:00 2001 From: Matthew Williams Date: Tue, 12 Nov 2013 14:41:02 -0800 Subject: SyncManager now returns copy on getCurrentSyncs() Bug:11559103 Added a new getCurrentSyncsCopy() that is public. The other version is needed for internal SSE calls. Change-Id: I0287f039a6f75abf04b65b85cb30f78353aeef4f --- .../com/android/server/content/ContentService.java | 2 +- .../android/server/content/SyncStorageEngine.java | 36 +++++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) (limited to 'services/java/com/android/server') diff --git a/services/java/com/android/server/content/ContentService.java b/services/java/com/android/server/content/ContentService.java index cb35ef1..023bf2b 100644 --- a/services/java/com/android/server/content/ContentService.java +++ b/services/java/com/android/server/content/ContentService.java @@ -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); } diff --git a/services/java/com/android/server/content/SyncStorageEngine.java b/services/java/com/android/server/content/SyncStorageEngine.java index 41ef229..5ebf9ea 100644 --- a/services/java/com/android/server/content/SyncStorageEngine.java +++ b/services/java/com/android/server/content/SyncStorageEngine.java @@ -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 getCurrentSyncs(int userId) { + private List getCurrentSyncs(int userId) { synchronized (mAuthorities) { - ArrayList syncs = mCurrentSyncs.get(userId); - if (syncs == null) { - syncs = new ArrayList(); - mCurrentSyncs.put(userId, syncs); + return getCurrentSyncsLocked(userId); + } + } + + /** + * @return a copy of the current syncs data structure. Will not return + * null. + */ + public List getCurrentSyncsCopy(int userId) { + synchronized (mAuthorities) { + final List syncs = getCurrentSyncsLocked(userId); + final List syncsCopy = new ArrayList(); + for (SyncInfo sync : syncs) { + syncsCopy.add(new SyncInfo(sync)); } - return syncs; + return syncsCopy; } } + private List getCurrentSyncsLocked(int userId) { + ArrayList syncs = mCurrentSyncs.get(userId); + if (syncs == null) { + syncs = new ArrayList(); + 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, -- cgit v1.1