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
This commit is contained in:
Fred Quintana
2010-03-30 15:16:21 -07:00
parent 8acdb911f4
commit d5e4fdc8a4
13 changed files with 124 additions and 170 deletions

View File

@@ -30012,48 +30012,6 @@
> >
</field> </field>
</class> </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" <class name="ActivityNotFoundException"
extends="java.lang.RuntimeException" extends="java.lang.RuntimeException"
abstract="false" abstract="false"
@@ -32089,8 +32047,8 @@
<parameter name="selectionArgs" type="java.lang.String[]"> <parameter name="selectionArgs" type="java.lang.String[]">
</parameter> </parameter>
</method> </method>
<method name="getActiveSync" <method name="getCurrentSync"
return="android.content.ActiveSyncInfo" return="android.content.SyncInfo"
abstract="false" abstract="false"
native="false" native="false"
synchronized="false" synchronized="false"
@@ -36131,6 +36089,8 @@
deprecated="not deprecated" deprecated="not deprecated"
visibility="public" visibility="public"
> >
<implements name="java.util.Iterator">
</implements>
<method name="close" <method name="close"
return="void" return="void"
abstract="true" abstract="true"
@@ -36142,32 +36102,6 @@
visibility="public" visibility="public"
> >
</method> </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" <method name="reset"
return="void" return="void"
abstract="true" abstract="true"
@@ -36178,8 +36112,6 @@
deprecated="not deprecated" deprecated="not deprecated"
visibility="public" visibility="public"
> >
<exception name="RemoteException" type="android.os.RemoteException">
</exception>
</method> </method>
</interface> </interface>
<class name="Intent" <class name="Intent"
@@ -41612,6 +41544,45 @@
</parameter> </parameter>
</method> </method>
</class> </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" <class name="SyncResult"
extends="java.lang.Object" extends="java.lang.Object"
abstract="false" abstract="false"

View File

@@ -17,12 +17,10 @@
package android.content; package android.content;
import android.accounts.Account; import android.accounts.Account;
import android.net.TrafficStats;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.Process; import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.EventLog;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@@ -113,12 +111,13 @@ public abstract class AbstractThreadedSyncAdapter {
public void cancelSync(ISyncContext syncContext) { public void cancelSync(ISyncContext syncContext) {
// synchronize to make sure that mSyncThread doesn't change between when we // synchronize to make sure that mSyncThread doesn't change between when we
// check it and when we use it // check it and when we use it
final SyncThread syncThread;
synchronized (mSyncThreadLock) { synchronized (mSyncThreadLock) {
if (mSyncThread != null syncThread = mSyncThread;
&& mSyncThread.mSyncContext.getSyncContextBinder()
== syncContext.asBinder()) {
onSyncCanceled(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 * thread than the sync thread and so you must consider the multi-threaded implications
* of the work that you do in this method. * 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) { public void onSyncCanceled() {
thread.interrupt(); final SyncThread syncThread;
synchronized (mSyncThreadLock) {
syncThread = mSyncThread;
}
if (syncThread != null) {
syncThread.interrupt();
}
} }
} }

View File

@@ -1179,11 +1179,11 @@ 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 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 { try {
return getContentService().getActiveSync(); return getContentService().getCurrentSync();
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("the ContentService should always be reachable", e); throw new RuntimeException("the ContentService should always be reachable", e);
} }

View File

@@ -386,14 +386,14 @@ public final class ContentService extends IContentService.Stub {
return false; return false;
} }
public ActiveSyncInfo getActiveSync() { public SyncInfo getCurrentSync() {
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS, mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS,
"no permission to read the sync stats"); "no permission to read the sync stats");
long identityToken = clearCallingIdentity(); long identityToken = clearCallingIdentity();
try { try {
SyncManager syncManager = getSyncManager(); SyncManager syncManager = getSyncManager();
if (syncManager != null) { if (syncManager != null) {
return syncManager.getSyncStorageEngine().getActiveSync(); return syncManager.getSyncStorageEngine().getCurrentSync();
} }
} finally { } finally {
restoreCallingIdentity(identityToken); restoreCallingIdentity(identityToken);

View File

@@ -53,9 +53,9 @@ public abstract class CursorEntityIterator implements EntityIterator {
* iterator is positioned in front of an element. * iterator is positioned in front of an element.
* *
* @return {@code true} if there are more elements, {@code false} otherwise. * @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) { if (mIsClosed) {
throw new IllegalStateException("calling hasNext() when the iterator is closed"); throw new IllegalStateException("calling hasNext() when the iterator is closed");
} }
@@ -70,9 +70,9 @@ public abstract class CursorEntityIterator implements EntityIterator {
* @return the next object. * @return the next object.
* @throws java.util.NoSuchElementException * @throws java.util.NoSuchElementException
* if there are no more elements. * if there are no more elements.
* @see #hasNext * @see EntityIterator#hasNext()
*/ */
public Entity next() throws RemoteException { public Entity next() {
if (mIsClosed) { if (mIsClosed) {
throw new IllegalStateException("calling next() when the iterator is closed"); 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"); throw new IllegalStateException("you may only call next() if hasNext() is true");
} }
try {
return getEntityAndIncrementCursor(mCursor); return getEntityAndIncrementCursor(mCursor);
} catch (RemoteException e) {
throw new RuntimeException("caught a remote exception, this process will die soon", e);
}
} }
public final void reset() throws RemoteException { public void remove() {
throw new UnsupportedOperationException("remove not supported by EntityIterators");
}
public final void reset() {
if (mIsClosed) { if (mIsClosed) {
throw new IllegalStateException("calling reset() when the iterator is closed"); throw new IllegalStateException("calling reset() when the iterator is closed");
} }

View File

@@ -16,32 +16,20 @@
package android.content; package android.content;
import android.os.RemoteException; import java.util.Iterator;
public interface EntityIterator { /**
/** * A specialization of {@link Iterator} that allows iterating over a collection of
* Returns whether there are more elements to iterate, i.e. whether the * {@link Entity} objects. In addition to the iteration functionality it also allows
* iterator is positioned in front of an element. * 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
* @return {@code true} if there are more elements, {@code false} otherwise. * can be released.
* @see #next
* @since Android 1.0
*/ */
public boolean hasNext() throws RemoteException; public interface EntityIterator extends Iterator<Entity> {
/** /**
* Returns the next object in the iteration, i.e. returns the element in * Reset the iterator back to the beginning.
* 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
*/ */
public Entity next() throws RemoteException; public void reset();
public void reset() throws RemoteException;
/** /**
* Indicates that this iterator is no longer needed and that any associated resources * Indicates that this iterator is no longer needed and that any associated resources

View File

@@ -17,7 +17,7 @@
package android.content; package android.content;
import android.accounts.Account; import android.accounts.Account;
import android.content.ActiveSyncInfo; import android.content.SyncInfo;
import android.content.ISyncStatusObserver; import android.content.ISyncStatusObserver;
import android.content.SyncAdapterType; import android.content.SyncAdapterType;
import android.content.SyncStatusInfo; import android.content.SyncStatusInfo;
@@ -104,7 +104,7 @@ interface IContentService {
*/ */
boolean isSyncActive(in Account account, String authority); boolean isSyncActive(in Account account, String authority);
ActiveSyncInfo getActiveSync(); SyncInfo getCurrentSync();
/** /**
* Returns the types of the SyncAdapters that are registered with the system. * Returns the types of the SyncAdapters that are registered with the system.

View File

@@ -16,4 +16,4 @@
package android.content; package android.content;
parcelable ActiveSyncInfo; parcelable SyncInfo;

View File

@@ -23,44 +23,29 @@ import android.os.Parcelable.Creator;
/** /**
* Information about the sync operation that is currently underway. * Information about the sync operation that is currently underway.
*/ */
public class ActiveSyncInfo { public class SyncInfo {
private final int authorityId;
private final Account account;
private final String authority;
private final long startTime;
/**
* Get the {@link Account} that is currently being synced.
* @return the account
*/
public Account getAccount() {
return new Account(account.name, account.type);
}
/** @hide */ /** @hide */
public int getAuthorityId() { public final int authorityId;
return authorityId;
}
/** /**
* Get the authority of the provider that is currently being synced. * The {@link Account} that is currently being synced.
* @return the authority
*/ */
public String getAuthority() { public final Account account;
return authority;
}
/** /**
* Get the start time of the current sync operation. This is represented in elapsed real time. * The authority of the provider that is currently being synced.
*/
public final String authority;
/**
* 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()}. * See {@link android.os.SystemClock#elapsedRealtime()}.
* @return the start time in milliseconds since boot
*/ */
public long getStartTime() { public final long startTime;
return startTime;
}
/** @hide */ /** @hide */
ActiveSyncInfo(int authorityId, Account account, String authority, SyncInfo(int authorityId, Account account, String authority,
long startTime) { long startTime) {
this.authorityId = authorityId; this.authorityId = authorityId;
this.account = account; this.account = account;
@@ -82,7 +67,7 @@ public class ActiveSyncInfo {
} }
/** @hide */ /** @hide */
ActiveSyncInfo(Parcel parcel) { SyncInfo(Parcel parcel) {
authorityId = parcel.readInt(); authorityId = parcel.readInt();
account = new Account(parcel); account = new Account(parcel);
authority = parcel.readString(); authority = parcel.readString();
@@ -90,13 +75,13 @@ public class ActiveSyncInfo {
} }
/** @hide */ /** @hide */
public static final Creator<ActiveSyncInfo> CREATOR = new Creator<ActiveSyncInfo>() { public static final Creator<SyncInfo> CREATOR = new Creator<SyncInfo>() {
public ActiveSyncInfo createFromParcel(Parcel in) { public SyncInfo createFromParcel(Parcel in) {
return new ActiveSyncInfo(in); return new SyncInfo(in);
} }
public ActiveSyncInfo[] newArray(int size) { public SyncInfo[] newArray(int size) {
return new ActiveSyncInfo[size]; return new SyncInfo[size];
} }
}; };
} }

View File

@@ -1026,11 +1026,11 @@ public class SyncManager implements OnAccountsUpdateListener {
pw.println(sb.toString()); pw.println(sb.toString());
} }
ActiveSyncInfo active = mSyncStorageEngine.getActiveSync(); SyncInfo active = mSyncStorageEngine.getCurrentSync();
if (active != null) { if (active != null) {
SyncStorageEngine.AuthorityInfo authority SyncStorageEngine.AuthorityInfo authority
= mSyncStorageEngine.getAuthority(active.getAuthorityId()); = mSyncStorageEngine.getAuthority(active.authorityId);
final long durationInSeconds = (now - active.getStartTime()) / 1000; final long durationInSeconds = (now - active.startTime) / 1000;
pw.print("Active sync: "); pw.print("Active sync: ");
pw.print(authority != null ? authority.account : "<no account>"); pw.print(authority != null ? authority.account : "<no account>");
pw.print(" "); pw.print(" ");

View File

@@ -230,7 +230,7 @@ public class SyncStorageEngine extends Handler {
private final ArrayList<PendingOperation> mPendingOperations = private final ArrayList<PendingOperation> mPendingOperations =
new ArrayList<PendingOperation>(); new ArrayList<PendingOperation>();
private ActiveSyncInfo mActiveSync; private SyncInfo mCurrentSync;
private final SparseArray<SyncStatusInfo> mSyncStatus = private final SparseArray<SyncStatusInfo> mSyncStatus =
new SparseArray<SyncStatusInfo>(); new SparseArray<SyncStatusInfo>();
@@ -678,8 +678,8 @@ public class SyncStorageEngine extends Handler {
} }
} }
if (mActiveSync != null) { if (mCurrentSync != null) {
AuthorityInfo ainfo = getAuthority(mActiveSync.getAuthorityId()); AuthorityInfo ainfo = getAuthority(mCurrentSync.authorityId);
if (ainfo != null && ainfo.account.equals(account) if (ainfo != null && ainfo.account.equals(account)
&& ainfo.authority.equals(authority)) { && ainfo.authority.equals(authority)) {
return true; return true;
@@ -864,7 +864,7 @@ public class SyncStorageEngine extends Handler {
+ " auth=" + activeSyncContext.mSyncOperation.authority + " auth=" + activeSyncContext.mSyncOperation.authority
+ " src=" + activeSyncContext.mSyncOperation.syncSource + " src=" + activeSyncContext.mSyncOperation.syncSource
+ " extras=" + activeSyncContext.mSyncOperation.extras); + " extras=" + activeSyncContext.mSyncOperation.extras);
if (mActiveSync != null) { if (mCurrentSync != null) {
Log.w(TAG, "setActiveSync called with existing active sync!"); Log.w(TAG, "setActiveSync called with existing active sync!");
} }
AuthorityInfo authority = getAuthorityLocked( AuthorityInfo authority = getAuthorityLocked(
@@ -874,12 +874,12 @@ public class SyncStorageEngine extends Handler {
if (authority == null) { if (authority == null) {
return; return;
} }
mActiveSync = new ActiveSyncInfo(authority.ident, mCurrentSync = new SyncInfo(authority.ident,
authority.account, authority.authority, authority.account, authority.authority,
activeSyncContext.mStartTime); activeSyncContext.mStartTime);
} else { } else {
if (DEBUG) Log.v(TAG, "setActiveSync: null"); 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 * active sync. Note that the returned object is the real, live active
* sync object, so be careful what you do with it. * sync object, so be careful what you do with it.
*/ */
public ActiveSyncInfo getActiveSync() { public SyncInfo getCurrentSync() {
synchronized (mAuthorities) { synchronized (mAuthorities) {
return mActiveSync; return mCurrentSync;
} }
} }

View File

@@ -24,7 +24,6 @@ import android.content.Entity.NamedContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteException;
import android.net.Uri; import android.net.Uri;
import android.os.RemoteException;
import android.pim.vcard.exception.VCardException; import android.pim.vcard.exception.VCardException;
import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data; 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 { } finally {
if (entityIterator != null) { if (entityIterator != null) {
entityIterator.close(); entityIterator.close();

View File

@@ -21,7 +21,6 @@ import android.content.Entity;
import android.content.EntityIterator; import android.content.EntityIterator;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.pim.vcard.VCardComposer;
import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data; import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts; import android.provider.ContactsContract.RawContacts;
@@ -69,6 +68,10 @@ import java.util.List;
return mIterator.next(); return mIterator.next();
} }
public void remove() {
throw new UnsupportedOperationException("remove not supported");
}
public void reset() { public void reset() {
mIterator = mEntityList.iterator(); mIterator = mEntityList.iterator();
} }