summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Quintana <fredq@google.com>2010-03-30 15:16:21 -0700
committerFred Quintana <fredq@google.com>2010-03-30 17:31:52 -0700
commitd5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6b (patch)
tree368fa8665a93e3e524b0d020fe33f5febb58661d
parent8acdb911f4b9c38d1cafd3ab464d6bec54564c84 (diff)
downloadframeworks_base-d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6b.zip
frameworks_base-d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6b.tar.gz
frameworks_base-d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6b.tar.bz2
some changes due to an API review
- make EntityIterator extend Iterator and thus not throw a RemoteException, instead converting it into a RuntimeException. - rename ActiveSyncInfo to SyncInfo - change getActiveSync to getCurrentSync - remove the accessors in SyncInfo and instead make the final fields publicly accessible - made AbstractThreadedSyncAdapter.cancelSync not take a thread Change-Id: I99fde5585bc5f1e95f4873ffbba189074a8d6372 http://b/issue?id=2553539 http://b/issue?id=2553541 http://b/issue?id=2553550
-rw-r--r--api/current.xml115
-rw-r--r--core/java/android/content/AbstractThreadedSyncAdapter.java24
-rw-r--r--core/java/android/content/ContentResolver.java6
-rw-r--r--core/java/android/content/ContentService.java4
-rw-r--r--core/java/android/content/CursorEntityIterator.java20
-rw-r--r--core/java/android/content/EntityIterator.java34
-rw-r--r--core/java/android/content/IContentService.aidl4
-rw-r--r--core/java/android/content/SyncInfo.aidl (renamed from core/java/android/content/ActiveSyncInfo.aidl)2
-rw-r--r--core/java/android/content/SyncInfo.java (renamed from core/java/android/content/ActiveSyncInfo.java)49
-rw-r--r--core/java/android/content/SyncManager.java6
-rw-r--r--core/java/android/content/SyncStorageEngine.java16
-rw-r--r--core/java/android/pim/vcard/VCardComposer.java5
-rw-r--r--core/tests/coretests/src/android/pim/vcard/ExportTestResolver.java5
13 files changed, 122 insertions, 168 deletions
diff --git a/api/current.xml b/api/current.xml
index 016773e..8611d51 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -30012,48 +30012,6 @@
>
</field>
</class>
-<class name="ActiveSyncInfo"
- extends="java.lang.Object"
- abstract="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<method name="getAccount"
- return="android.accounts.Account"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
-<method name="getAuthority"
- return="java.lang.String"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
-<method name="getStartTime"
- return="long"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
-</class>
<class name="ActivityNotFoundException"
extends="java.lang.RuntimeException"
abstract="false"
@@ -32089,8 +32047,8 @@
<parameter name="selectionArgs" type="java.lang.String[]">
</parameter>
</method>
-<method name="getActiveSync"
- return="android.content.ActiveSyncInfo"
+<method name="getCurrentSync"
+ return="android.content.SyncInfo"
abstract="false"
native="false"
synchronized="false"
@@ -36131,6 +36089,8 @@
deprecated="not deprecated"
visibility="public"
>
+<implements name="java.util.Iterator">
+</implements>
<method name="close"
return="void"
abstract="true"
@@ -36142,32 +36102,6 @@
visibility="public"
>
</method>
-<method name="hasNext"
- return="boolean"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<exception name="RemoteException" type="android.os.RemoteException">
-</exception>
-</method>
-<method name="next"
- return="android.content.Entity"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<exception name="RemoteException" type="android.os.RemoteException">
-</exception>
-</method>
<method name="reset"
return="void"
abstract="true"
@@ -36178,8 +36112,6 @@
deprecated="not deprecated"
visibility="public"
>
-<exception name="RemoteException" type="android.os.RemoteException">
-</exception>
</method>
</interface>
<class name="Intent"
@@ -41612,6 +41544,45 @@
</parameter>
</method>
</class>
+<class name="SyncInfo"
+ extends="java.lang.Object"
+ abstract="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<field name="account"
+ type="android.accounts.Account"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="authority"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="startTime"
+ type="long"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+</class>
<class name="SyncResult"
extends="java.lang.Object"
abstract="false"
diff --git a/core/java/android/content/AbstractThreadedSyncAdapter.java b/core/java/android/content/AbstractThreadedSyncAdapter.java
index 14bc5dd..9dd7b9f 100644
--- a/core/java/android/content/AbstractThreadedSyncAdapter.java
+++ b/core/java/android/content/AbstractThreadedSyncAdapter.java
@@ -17,12 +17,10 @@
package android.content;
import android.accounts.Account;
-import android.net.TrafficStats;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
-import android.util.EventLog;
import java.util.concurrent.atomic.AtomicInteger;
@@ -113,12 +111,13 @@ public abstract class AbstractThreadedSyncAdapter {
public void cancelSync(ISyncContext syncContext) {
// synchronize to make sure that mSyncThread doesn't change between when we
// check it and when we use it
+ final SyncThread syncThread;
synchronized (mSyncThreadLock) {
- if (mSyncThread != null
- && mSyncThread.mSyncContext.getSyncContextBinder()
- == syncContext.asBinder()) {
- onSyncCanceled(mSyncThread);
- }
+ syncThread = mSyncThread;
+ }
+ if (syncThread != null
+ && syncThread.mSyncContext.getSyncContextBinder() == syncContext.asBinder()) {
+ onSyncCanceled();
}
}
@@ -213,9 +212,14 @@ public abstract class AbstractThreadedSyncAdapter {
* thread than the sync thread and so you must consider the multi-threaded implications
* of the work that you do in this method.
*
- * @param thread the thread that is running the sync operation to cancel
*/
- public void onSyncCanceled(Thread thread) {
- thread.interrupt();
+ public void onSyncCanceled() {
+ final SyncThread syncThread;
+ synchronized (mSyncThreadLock) {
+ syncThread = mSyncThread;
+ }
+ if (syncThread != null) {
+ syncThread.interrupt();
+ }
}
}
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java
index d3cc4df..1cb2353 100644
--- a/core/java/android/content/ContentResolver.java
+++ b/core/java/android/content/ContentResolver.java
@@ -1179,11 +1179,11 @@ public abstract class ContentResolver {
/**
* If a sync is active returns the information about it, otherwise returns false.
- * @return the ActiveSyncInfo for the currently active sync or null if one is not active.
+ * @return the SyncInfo for the currently active sync or null if one is not active.
*/
- public static ActiveSyncInfo getActiveSync() {
+ public static SyncInfo getCurrentSync() {
try {
- return getContentService().getActiveSync();
+ return getContentService().getCurrentSync();
} 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 0477d6d..377e383 100644
--- a/core/java/android/content/ContentService.java
+++ b/core/java/android/content/ContentService.java
@@ -386,14 +386,14 @@ public final class ContentService extends IContentService.Stub {
return false;
}
- public ActiveSyncInfo getActiveSync() {
+ public SyncInfo getCurrentSync() {
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().getActiveSync();
+ return syncManager.getSyncStorageEngine().getCurrentSync();
}
} finally {
restoreCallingIdentity(identityToken);
diff --git a/core/java/android/content/CursorEntityIterator.java b/core/java/android/content/CursorEntityIterator.java
index 54619a3..18437e5 100644
--- a/core/java/android/content/CursorEntityIterator.java
+++ b/core/java/android/content/CursorEntityIterator.java
@@ -53,9 +53,9 @@ public abstract class CursorEntityIterator implements EntityIterator {
* iterator is positioned in front of an element.
*
* @return {@code true} if there are more elements, {@code false} otherwise.
- * @see #next
+ * @see EntityIterator#next()
*/
- public final boolean hasNext() throws RemoteException {
+ public final boolean hasNext() {
if (mIsClosed) {
throw new IllegalStateException("calling hasNext() when the iterator is closed");
}
@@ -70,9 +70,9 @@ public abstract class CursorEntityIterator implements EntityIterator {
* @return the next object.
* @throws java.util.NoSuchElementException
* if there are no more elements.
- * @see #hasNext
+ * @see EntityIterator#hasNext()
*/
- public Entity next() throws RemoteException {
+ public Entity next() {
if (mIsClosed) {
throw new IllegalStateException("calling next() when the iterator is closed");
}
@@ -80,10 +80,18 @@ public abstract class CursorEntityIterator implements EntityIterator {
throw new IllegalStateException("you may only call next() if hasNext() is true");
}
- return getEntityAndIncrementCursor(mCursor);
+ try {
+ return getEntityAndIncrementCursor(mCursor);
+ } catch (RemoteException e) {
+ throw new RuntimeException("caught a remote exception, this process will die soon", e);
+ }
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException("remove not supported by EntityIterators");
}
- public final void reset() throws RemoteException {
+ public final void reset() {
if (mIsClosed) {
throw new IllegalStateException("calling reset() when the iterator is closed");
}
diff --git a/core/java/android/content/EntityIterator.java b/core/java/android/content/EntityIterator.java
index 3cc1040..55c47ba 100644
--- a/core/java/android/content/EntityIterator.java
+++ b/core/java/android/content/EntityIterator.java
@@ -16,32 +16,20 @@
package android.content;
-import android.os.RemoteException;
-
-public interface EntityIterator {
- /**
- * Returns whether there are more elements to iterate, i.e. whether the
- * iterator is positioned in front of an element.
- *
- * @return {@code true} if there are more elements, {@code false} otherwise.
- * @see #next
- * @since Android 1.0
- */
- public boolean hasNext() throws RemoteException;
+import java.util.Iterator;
+/**
+ * A specialization of {@link Iterator} that allows iterating over a collection of
+ * {@link Entity} objects. In addition to the iteration functionality it also allows
+ * resetting the iterator back to the beginning and provides for an explicit {@link #close()}
+ * method to indicate that the iterator is no longer needed and that its resources
+ * can be released.
+ */
+public interface EntityIterator extends Iterator<Entity> {
/**
- * Returns the next object in the iteration, i.e. returns the element in
- * front of the iterator and advances the iterator by one position.
- *
- * @return the next object.
- * @throws java.util.NoSuchElementException
- * if there are no more elements.
- * @see #hasNext
- * @since Android 1.0
+ * Reset the iterator back to the beginning.
*/
- public Entity next() throws RemoteException;
-
- public void reset() throws RemoteException;
+ public void reset();
/**
* Indicates that this iterator is no longer needed and that any associated resources
diff --git a/core/java/android/content/IContentService.aidl b/core/java/android/content/IContentService.aidl
index 2d906ed..a6368d5 100644
--- a/core/java/android/content/IContentService.aidl
+++ b/core/java/android/content/IContentService.aidl
@@ -17,7 +17,7 @@
package android.content;
import android.accounts.Account;
-import android.content.ActiveSyncInfo;
+import android.content.SyncInfo;
import android.content.ISyncStatusObserver;
import android.content.SyncAdapterType;
import android.content.SyncStatusInfo;
@@ -104,7 +104,7 @@ interface IContentService {
*/
boolean isSyncActive(in Account account, String authority);
- ActiveSyncInfo getActiveSync();
+ SyncInfo getCurrentSync();
/**
* Returns the types of the SyncAdapters that are registered with the system.
diff --git a/core/java/android/content/ActiveSyncInfo.aidl b/core/java/android/content/SyncInfo.aidl
index 1142206..0737429 100644
--- a/core/java/android/content/ActiveSyncInfo.aidl
+++ b/core/java/android/content/SyncInfo.aidl
@@ -16,4 +16,4 @@
package android.content;
-parcelable ActiveSyncInfo;
+parcelable SyncInfo;
diff --git a/core/java/android/content/ActiveSyncInfo.java b/core/java/android/content/SyncInfo.java
index b0c90a1..616b05f 100644
--- a/core/java/android/content/ActiveSyncInfo.java
+++ b/core/java/android/content/SyncInfo.java
@@ -23,44 +23,29 @@ import android.os.Parcelable.Creator;
/**
* Information about the sync operation that is currently underway.
*/
-public class ActiveSyncInfo {
- private final int authorityId;
- private final Account account;
- private final String authority;
- private final long startTime;
+public class SyncInfo {
+ /** @hide */
+ public final int authorityId;
/**
- * Get the {@link Account} that is currently being synced.
- * @return the account
+ * The {@link Account} that is currently being synced.
*/
- public Account getAccount() {
- return new Account(account.name, account.type);
- }
-
- /** @hide */
- public int getAuthorityId() {
- return authorityId;
- }
+ public final Account account;
/**
- * Get the authority of the provider that is currently being synced.
- * @return the authority
+ * The authority of the provider that is currently being synced.
*/
- public String getAuthority() {
- return authority;
- }
+ public final String authority;
/**
- * Get the start time of the current sync operation. This is represented in elapsed real time.
+ * The start time of the current sync operation in milliseconds since boot.
+ * This is represented in elapsed real time.
* See {@link android.os.SystemClock#elapsedRealtime()}.
- * @return the start time in milliseconds since boot
*/
- public long getStartTime() {
- return startTime;
- }
+ public final long startTime;
/** @hide */
- ActiveSyncInfo(int authorityId, Account account, String authority,
+ SyncInfo(int authorityId, Account account, String authority,
long startTime) {
this.authorityId = authorityId;
this.account = account;
@@ -82,7 +67,7 @@ public class ActiveSyncInfo {
}
/** @hide */
- ActiveSyncInfo(Parcel parcel) {
+ SyncInfo(Parcel parcel) {
authorityId = parcel.readInt();
account = new Account(parcel);
authority = parcel.readString();
@@ -90,13 +75,13 @@ public class ActiveSyncInfo {
}
/** @hide */
- public static final Creator<ActiveSyncInfo> CREATOR = new Creator<ActiveSyncInfo>() {
- public ActiveSyncInfo createFromParcel(Parcel in) {
- return new ActiveSyncInfo(in);
+ public static final Creator<SyncInfo> CREATOR = new Creator<SyncInfo>() {
+ public SyncInfo createFromParcel(Parcel in) {
+ return new SyncInfo(in);
}
- public ActiveSyncInfo[] newArray(int size) {
- return new ActiveSyncInfo[size];
+ public SyncInfo[] newArray(int size) {
+ return new SyncInfo[size];
}
};
}
diff --git a/core/java/android/content/SyncManager.java b/core/java/android/content/SyncManager.java
index 5c8ee18..13da1ea 100644
--- a/core/java/android/content/SyncManager.java
+++ b/core/java/android/content/SyncManager.java
@@ -1026,11 +1026,11 @@ public class SyncManager implements OnAccountsUpdateListener {
pw.println(sb.toString());
}
- ActiveSyncInfo active = mSyncStorageEngine.getActiveSync();
+ SyncInfo active = mSyncStorageEngine.getCurrentSync();
if (active != null) {
SyncStorageEngine.AuthorityInfo authority
- = mSyncStorageEngine.getAuthority(active.getAuthorityId());
- final long durationInSeconds = (now - active.getStartTime()) / 1000;
+ = mSyncStorageEngine.getAuthority(active.authorityId);
+ final long durationInSeconds = (now - active.startTime) / 1000;
pw.print("Active sync: ");
pw.print(authority != null ? authority.account : "<no account>");
pw.print(" ");
diff --git a/core/java/android/content/SyncStorageEngine.java b/core/java/android/content/SyncStorageEngine.java
index 6a959ae..c848a00 100644
--- a/core/java/android/content/SyncStorageEngine.java
+++ b/core/java/android/content/SyncStorageEngine.java
@@ -230,7 +230,7 @@ public class SyncStorageEngine extends Handler {
private final ArrayList<PendingOperation> mPendingOperations =
new ArrayList<PendingOperation>();
- private ActiveSyncInfo mActiveSync;
+ private SyncInfo mCurrentSync;
private final SparseArray<SyncStatusInfo> mSyncStatus =
new SparseArray<SyncStatusInfo>();
@@ -678,8 +678,8 @@ public class SyncStorageEngine extends Handler {
}
}
- if (mActiveSync != null) {
- AuthorityInfo ainfo = getAuthority(mActiveSync.getAuthorityId());
+ if (mCurrentSync != null) {
+ AuthorityInfo ainfo = getAuthority(mCurrentSync.authorityId);
if (ainfo != null && ainfo.account.equals(account)
&& ainfo.authority.equals(authority)) {
return true;
@@ -864,7 +864,7 @@ public class SyncStorageEngine extends Handler {
+ " auth=" + activeSyncContext.mSyncOperation.authority
+ " src=" + activeSyncContext.mSyncOperation.syncSource
+ " extras=" + activeSyncContext.mSyncOperation.extras);
- if (mActiveSync != null) {
+ if (mCurrentSync != null) {
Log.w(TAG, "setActiveSync called with existing active sync!");
}
AuthorityInfo authority = getAuthorityLocked(
@@ -874,12 +874,12 @@ public class SyncStorageEngine extends Handler {
if (authority == null) {
return;
}
- mActiveSync = new ActiveSyncInfo(authority.ident,
+ mCurrentSync = new SyncInfo(authority.ident,
authority.account, authority.authority,
activeSyncContext.mStartTime);
} else {
if (DEBUG) Log.v(TAG, "setActiveSync: null");
- mActiveSync = null;
+ mCurrentSync = null;
}
}
@@ -1063,9 +1063,9 @@ public class SyncStorageEngine extends Handler {
* active sync. Note that the returned object is the real, live active
* sync object, so be careful what you do with it.
*/
- public ActiveSyncInfo getActiveSync() {
+ public SyncInfo getCurrentSync() {
synchronized (mAuthorities) {
- return mActiveSync;
+ return mCurrentSync;
}
}
diff --git a/core/java/android/pim/vcard/VCardComposer.java b/core/java/android/pim/vcard/VCardComposer.java
index 194fe33..dc0d864 100644
--- a/core/java/android/pim/vcard/VCardComposer.java
+++ b/core/java/android/pim/vcard/VCardComposer.java
@@ -24,7 +24,6 @@ import android.content.Entity.NamedContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
-import android.os.RemoteException;
import android.pim.vcard.exception.VCardException;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
@@ -522,10 +521,6 @@ public class VCardComposer {
}
}
}
- } catch (RemoteException e) {
- Log.e(LOG_TAG, String.format("RemoteException at id %s (%s)",
- contactId, e.getMessage()));
- return "";
} finally {
if (entityIterator != null) {
entityIterator.close();
diff --git a/core/tests/coretests/src/android/pim/vcard/ExportTestResolver.java b/core/tests/coretests/src/android/pim/vcard/ExportTestResolver.java
index 1b3cdcc..5968e83 100644
--- a/core/tests/coretests/src/android/pim/vcard/ExportTestResolver.java
+++ b/core/tests/coretests/src/android/pim/vcard/ExportTestResolver.java
@@ -21,7 +21,6 @@ import android.content.Entity;
import android.content.EntityIterator;
import android.database.Cursor;
import android.net.Uri;
-import android.pim.vcard.VCardComposer;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
@@ -69,6 +68,10 @@ import java.util.List;
return mIterator.next();
}
+ public void remove() {
+ throw new UnsupportedOperationException("remove not supported");
+ }
+
public void reset() {
mIterator = mEntityList.iterator();
}