am d5e4fdc8: 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 a
Merge commit 'd5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6b' into froyo-plus-aosp * commit 'd5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6b': some changes due to an API review
This commit is contained in:
115
api/current.xml
115
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"
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 final void reset() throws RemoteException {
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("remove not supported by EntityIterators");
|
||||
}
|
||||
|
||||
public final void reset() {
|
||||
if (mIsClosed) {
|
||||
throw new IllegalStateException("calling reset() when the iterator is closed");
|
||||
}
|
||||
|
||||
@@ -16,32 +16,20 @@
|
||||
|
||||
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
|
||||
* {@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 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
|
||||
* Reset the iterator back to the beginning.
|
||||
*/
|
||||
public boolean hasNext() throws RemoteException;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -16,4 +16,4 @@
|
||||
|
||||
package android.content;
|
||||
|
||||
parcelable ActiveSyncInfo;
|
||||
parcelable SyncInfo;
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* Get the {@link Account} that is currently being synced.
|
||||
* @return the account
|
||||
*/
|
||||
public Account getAccount() {
|
||||
return new Account(account.name, account.type);
|
||||
}
|
||||
|
||||
public class SyncInfo {
|
||||
/** @hide */
|
||||
public int getAuthorityId() {
|
||||
return authorityId;
|
||||
}
|
||||
public final int authorityId;
|
||||
|
||||
/**
|
||||
* Get the authority of the provider that is currently being synced.
|
||||
* @return the authority
|
||||
* The {@link Account} that is currently being synced.
|
||||
*/
|
||||
public String getAuthority() {
|
||||
return authority;
|
||||
}
|
||||
public final Account account;
|
||||
|
||||
/**
|
||||
* 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()}.
|
||||
* @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];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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(" ");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user