From c6a69559cb62bd20166c0c9684e64c60d779da38 Mon Sep 17 00:00:00 2001 From: Fred Quintana Date: Mon, 27 Sep 2010 17:05:04 -0700 Subject: [PATCH] Add getCurrentSyncs() to the SDK, which replaces the deprecated getCurrentSync(). Change-Id: I1112df41e48ed93ff4c0c5af4825dbdce0c4cccc --- api/current.xml | 41 ++++++++++++++++++- .../java/android/content/ContentResolver.java | 28 ++++++++++++- core/java/android/content/ContentService.java | 8 +--- .../java/android/content/IContentService.aidl | 2 +- core/java/android/content/SyncInfo.java | 3 +- .../android/content/SyncStorageEngine.java | 17 -------- 6 files changed, 71 insertions(+), 28 deletions(-) diff --git a/api/current.xml b/api/current.xml index b0f0b1428ffbf..dde924ae48c9a 100644 --- a/api/current.xml +++ b/api/current.xml @@ -44007,6 +44007,17 @@ synchronized="false" static="true" final="false" + deprecated="deprecated" + visibility="public" +> + + @@ -54150,6 +54161,34 @@ deprecated="not deprecated" visibility="public" > + + + + + + + + + + - + diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java index 3289120885ab8..da1aac4bc00dd 100644 --- a/core/java/android/content/ContentResolver.java +++ b/core/java/android/content/ContentResolver.java @@ -1319,12 +1319,36 @@ public abstract class ContentResolver { } /** - * If a sync is active returns the information about it, otherwise returns false. + * If a sync is active returns the information about it, otherwise returns null. + *

* @return the SyncInfo for the currently active sync or null if one is not active. + * @deprecated + * Since multiple concurrent syncs are now supported you should use + * {@link #getCurrentSyncs()} to get the accurate list of current syncs. + * This method returns the first item from the list of current syncs + * or null if there are none. */ + @Deprecated public static SyncInfo getCurrentSync() { try { - return getContentService().getCurrentSync(); + final List syncs = getContentService().getCurrentSyncs(); + if (syncs.isEmpty()) { + return null; + } + return syncs.get(0); + } catch (RemoteException e) { + throw new RuntimeException("the ContentService should always be reachable", e); + } + } + + /** + * Returns a list with information about all the active syncs. This list will be empty + * if there are no active syncs. + * @return a List of SyncInfo objects for the currently active syncs. + */ + public static List getCurrentSyncs() { + try { + return getContentService().getCurrentSyncs(); } catch (RemoteException e) { throw new RuntimeException("the ContentService should always be reachable", e); } diff --git a/core/java/android/content/ContentService.java b/core/java/android/content/ContentService.java index fc2dfc07b0e17..afe8483c21b96 100644 --- a/core/java/android/content/ContentService.java +++ b/core/java/android/content/ContentService.java @@ -386,19 +386,15 @@ public final class ContentService extends IContentService.Stub { return false; } - public SyncInfo getCurrentSync() { + public List getCurrentSyncs() { mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS, "no permission to read the sync stats"); long identityToken = clearCallingIdentity(); try { - SyncManager syncManager = getSyncManager(); - if (syncManager != null) { - return syncManager.getSyncStorageEngine().getCurrentSync(); - } + return getSyncManager().getSyncStorageEngine().getCurrentSyncs(); } finally { restoreCallingIdentity(identityToken); } - return null; } public SyncStatusInfo getSyncStatus(Account account, String authority) { diff --git a/core/java/android/content/IContentService.aidl b/core/java/android/content/IContentService.aidl index a6368d53a4a85..86a93925de3bb 100644 --- a/core/java/android/content/IContentService.aidl +++ b/core/java/android/content/IContentService.aidl @@ -104,7 +104,7 @@ interface IContentService { */ boolean isSyncActive(in Account account, String authority); - SyncInfo getCurrentSync(); + List getCurrentSyncs(); /** * Returns the types of the SyncAdapters that are registered with the system. diff --git a/core/java/android/content/SyncInfo.java b/core/java/android/content/SyncInfo.java index 616b05fb38eb6..abfe964fa44c1 100644 --- a/core/java/android/content/SyncInfo.java +++ b/core/java/android/content/SyncInfo.java @@ -18,12 +18,13 @@ package android.content; import android.accounts.Account; import android.os.Parcel; +import android.os.Parcelable; import android.os.Parcelable.Creator; /** * Information about the sync operation that is currently underway. */ -public class SyncInfo { +public class SyncInfo implements Parcelable { /** @hide */ public final int authorityId; diff --git a/core/java/android/content/SyncStorageEngine.java b/core/java/android/content/SyncStorageEngine.java index 487f6ced42a97..17d85faf8a6a3 100644 --- a/core/java/android/content/SyncStorageEngine.java +++ b/core/java/android/content/SyncStorageEngine.java @@ -1087,23 +1087,6 @@ public class SyncStorageEngine extends Handler { reportChange(ContentResolver.SYNC_OBSERVER_TYPE_STATUS); } - /** - * Return the currently active sync information, or null if there is no - * active sync. Note that the returned object is the real, live active - * sync object, so be careful what you do with it. - *

- * Since multiple concurrent syncs are now supported you should use - * {@link #getCurrentSyncs()} to get the accurate list of current syncs. - * This method returns the first item from the list of current syncs - * or null if there are none. - * @deprecated use {@link #getCurrentSyncs()} - */ - public SyncInfo getCurrentSync() { - synchronized (mAuthorities) { - return !mCurrentSyncs.isEmpty() ? mCurrentSyncs.get(0) : null; - } - } - /** * 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.