changes from Sync Manager API Review: bug 2164262

This commit is contained in:
Fred Quintana
2009-10-06 17:05:58 -07:00
parent 460b60c9b0
commit f038004f4a
5 changed files with 511 additions and 64 deletions

View File

@ -27216,6 +27216,81 @@
</package> </package>
<package name="android.content" <package name="android.content"
> >
<class name="AbstractThreadedSyncAdapter"
extends="java.lang.Object"
abstract="true"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<constructor name="AbstractThreadedSyncAdapter"
type="android.content.AbstractThreadedSyncAdapter"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="context" type="android.content.Context">
</parameter>
<parameter name="autoInitialize" type="boolean">
</parameter>
</constructor>
<method name="getContext"
return="android.content.Context"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getSyncAdapterBinder"
return="android.os.IBinder"
abstract="false"
native="false"
synchronized="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="onPerformSync"
return="void"
abstract="true"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="account" type="android.accounts.Account">
</parameter>
<parameter name="extras" type="android.os.Bundle">
</parameter>
<parameter name="authority" type="java.lang.String">
</parameter>
<parameter name="provider" type="android.content.ContentProviderClient">
</parameter>
<parameter name="syncResult" type="android.content.SyncResult">
</parameter>
</method>
<field name="LOG_SYNC_DETAILS"
type="int"
transient="false"
volatile="false"
value="2743"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
</class>
<class name="ActivityNotFoundException" <class name="ActivityNotFoundException"
extends="java.lang.RuntimeException" extends="java.lang.RuntimeException"
abstract="false" abstract="false"
@ -38092,6 +38167,416 @@
> >
</field> </field>
</class> </class>
<class name="SyncContext"
extends="java.lang.Object"
abstract="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<method name="getSyncContextBinder"
return="android.os.IBinder"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="onFinished"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="result" type="android.content.SyncResult">
</parameter>
</method>
</class>
<class name="SyncResult"
extends="java.lang.Object"
abstract="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
<implements name="android.os.Parcelable">
</implements>
<constructor name="SyncResult"
type="android.content.SyncResult"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</constructor>
<method name="clear"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="describeContents"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="hasError"
return="boolean"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="hasHardError"
return="boolean"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="hasSoftError"
return="boolean"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="madeSomeProgress"
return="boolean"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="toDebugString"
return="java.lang.String"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="writeToParcel"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="parcel" type="android.os.Parcel">
</parameter>
<parameter name="flags" type="int">
</parameter>
</method>
<field name="ALREADY_IN_PROGRESS"
type="android.content.SyncResult"
transient="false"
volatile="false"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="CREATOR"
type="android.os.Parcelable.Creator"
transient="false"
volatile="false"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="databaseError"
type="boolean"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="fullSyncRequested"
type="boolean"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="moreRecordsToGet"
type="boolean"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="partialSyncUnavailable"
type="boolean"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="stats"
type="android.content.SyncStats"
transient="false"
volatile="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="syncAlreadyInProgress"
type="boolean"
transient="false"
volatile="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="tooManyDeletions"
type="boolean"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="tooManyRetries"
type="boolean"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
</class>
<class name="SyncStats"
extends="java.lang.Object"
abstract="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<implements name="android.os.Parcelable">
</implements>
<constructor name="SyncStats"
type="android.content.SyncStats"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</constructor>
<constructor name="SyncStats"
type="android.content.SyncStats"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="in" type="android.os.Parcel">
</parameter>
</constructor>
<method name="clear"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="describeContents"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="writeToParcel"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="dest" type="android.os.Parcel">
</parameter>
<parameter name="flags" type="int">
</parameter>
</method>
<field name="CREATOR"
type="android.os.Parcelable.Creator"
transient="false"
volatile="false"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="numAuthExceptions"
type="long"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="numConflictDetectedExceptions"
type="long"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="numDeletes"
type="long"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="numEntries"
type="long"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="numInserts"
type="long"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="numIoExceptions"
type="long"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="numParseExceptions"
type="long"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="numSkippedEntries"
type="long"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="numUpdates"
type="long"
transient="false"
volatile="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</field>
</class>
<interface name="SyncStatusObserver" <interface name="SyncStatusObserver"
abstract="true" abstract="true"
static="false" static="false"

View File

@ -20,6 +20,7 @@ import android.accounts.Account;
import android.os.Bundle; import android.os.Bundle;
import android.os.Process; import android.os.Process;
import android.os.NetStat; import android.os.NetStat;
import android.os.IBinder;
import android.util.EventLog; import android.util.EventLog;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -29,12 +30,10 @@ import java.util.concurrent.atomic.AtomicInteger;
* If a sync operation is already in progress when a startSync() request is received then an error * If a sync operation is already in progress when a startSync() request is received then an error
* will be returned to the new request and the existing request will be allowed to continue. * will be returned to the new request and the existing request will be allowed to continue.
* When a startSync() is received and there is no sync operation in progress then a thread * When a startSync() is received and there is no sync operation in progress then a thread
* will be started to run the operation and {@link #performSync} will be invoked on that thread. * will be started to run the operation and {@link #onPerformSync} will be invoked on that thread.
* If a cancelSync() is received that matches an existing sync operation then the thread * If a cancelSync() is received that matches an existing sync operation then the thread
* that is running that sync operation will be interrupted, which will indicate to the thread * that is running that sync operation will be interrupted, which will indicate to the thread
* that the sync has been canceled. * that the sync has been canceled.
*
* @hide
*/ */
public abstract class AbstractThreadedSyncAdapter { public abstract class AbstractThreadedSyncAdapter {
private final Context mContext; private final Context mContext;
@ -71,7 +70,7 @@ public abstract class AbstractThreadedSyncAdapter {
return mContext; return mContext;
} }
class ISyncAdapterImpl extends ISyncAdapter.Stub { private class ISyncAdapterImpl extends ISyncAdapter.Stub {
public void startSync(ISyncContext syncContext, String authority, Account account, public void startSync(ISyncContext syncContext, String authority, Account account,
Bundle extras) { Bundle extras) {
final SyncContext syncContextClient = new SyncContext(syncContext); final SyncContext syncContextClient = new SyncContext(syncContext);
@ -112,7 +111,7 @@ public abstract class AbstractThreadedSyncAdapter {
// check it and when we use it // check it and when we use it
synchronized (mSyncThreadLock) { synchronized (mSyncThreadLock) {
if (mSyncThread != null if (mSyncThread != null
&& mSyncThread.mSyncContext.getISyncContext().asBinder() && mSyncThread.mSyncContext.getSyncContextBinder()
== syncContext.asBinder()) { == syncContext.asBinder()) {
mSyncThread.interrupt(); mSyncThread.interrupt();
} }
@ -121,9 +120,9 @@ public abstract class AbstractThreadedSyncAdapter {
} }
/** /**
* The thread that invokes performSync(). It also acquires the provider for this sync * The thread that invokes {@link AbstractThreadedSyncAdapter#onPerformSync}. It also acquires
* before calling performSync and releases it afterwards. Cancel this thread in order to * the provider for this sync before calling onPerformSync and releases it afterwards. Cancel
* cancel the sync. * this thread in order to cancel the sync.
*/ */
private class SyncThread extends Thread { private class SyncThread extends Thread {
private final SyncContext mSyncContext; private final SyncContext mSyncContext;
@ -157,11 +156,10 @@ public abstract class AbstractThreadedSyncAdapter {
try { try {
provider = mContext.getContentResolver().acquireContentProviderClient(mAuthority); provider = mContext.getContentResolver().acquireContentProviderClient(mAuthority);
if (provider != null) { if (provider != null) {
AbstractThreadedSyncAdapter.this.performSync(mAccount, mExtras, AbstractThreadedSyncAdapter.this.onPerformSync(mAccount, mExtras,
mAuthority, provider, syncResult); mAuthority, provider, syncResult);
} else { } else {
// TODO(fredq) update the syncResults to indicate that we were unable to syncResult.databaseError = true;
// find the provider. maybe with a ProviderError?
} }
} finally { } finally {
if (provider != null) { if (provider != null) {
@ -170,7 +168,7 @@ public abstract class AbstractThreadedSyncAdapter {
if (!isCanceled()) { if (!isCanceled()) {
mSyncContext.onFinished(syncResult); mSyncContext.onFinished(syncResult);
} }
logSyncDetails(NetStat.getUidTxBytes(uid) - mInitialTxBytes, onLogSyncDetails(NetStat.getUidTxBytes(uid) - mInitialTxBytes,
NetStat.getUidRxBytes(uid) - mInitialRxBytes, syncResult); NetStat.getUidRxBytes(uid) - mInitialRxBytes, syncResult);
// synchronize so that the assignment will be seen by other threads // synchronize so that the assignment will be seen by other threads
// that also synchronize accesses to mSyncThread // that also synchronize accesses to mSyncThread
@ -186,10 +184,10 @@ public abstract class AbstractThreadedSyncAdapter {
} }
/** /**
* @return a reference to the ISyncAdapter interface into this SyncAdapter implementation. * @return a reference to the IBinder of the SyncAdapter service.
*/ */
public final ISyncAdapter getISyncAdapter() { public final IBinder getSyncAdapterBinder() {
return mISyncAdapterImpl; return mISyncAdapterImpl.asBinder();
} }
/** /**
@ -204,7 +202,7 @@ public abstract class AbstractThreadedSyncAdapter {
* authority * authority
* @param syncResult SyncAdapter-specific parameters * @param syncResult SyncAdapter-specific parameters
*/ */
public abstract void performSync(Account account, Bundle extras, public abstract void onPerformSync(Account account, Bundle extras,
String authority, ContentProviderClient provider, SyncResult syncResult); String authority, ContentProviderClient provider, SyncResult syncResult);
/** /**
@ -215,9 +213,9 @@ public abstract class AbstractThreadedSyncAdapter {
* @param bytesSent number of bytes the sync sent over the network * @param bytesSent number of bytes the sync sent over the network
* @param bytesReceived number of bytes the sync received over the network * @param bytesReceived number of bytes the sync received over the network
* @param result The SyncResult object holding info on the sync * @param result The SyncResult object holding info on the sync
* @hide
*/ */
protected void logSyncDetails(long bytesSent, long bytesReceived, SyncResult result) { protected void onLogSyncDetails(long bytesSent, long bytesReceived, SyncResult result) {
EventLog.writeEvent(SyncAdapter.LOG_SYNC_DETAILS, TAG, bytesSent, bytesReceived, ""); EventLog.writeEvent(SyncAdapter.LOG_SYNC_DETAILS, TAG, bytesSent, bytesReceived, "");
} }
}
}

View File

@ -18,16 +18,17 @@ package android.content;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.IBinder;
/**
* @hide
*/
public class SyncContext { public class SyncContext {
private ISyncContext mSyncContext; private ISyncContext mSyncContext;
private long mLastHeartbeatSendTime; private long mLastHeartbeatSendTime;
private static final long HEARTBEAT_SEND_INTERVAL_IN_MS = 1000; private static final long HEARTBEAT_SEND_INTERVAL_IN_MS = 1000;
/**
* @hide
*/
public SyncContext(ISyncContext syncContextInterface) { public SyncContext(ISyncContext syncContextInterface) {
mSyncContext = syncContextInterface; mSyncContext = syncContextInterface;
mLastHeartbeatSendTime = 0; mLastHeartbeatSendTime = 0;
@ -38,6 +39,8 @@ public class SyncContext {
* {@link #updateHeartbeat}, so it also takes the place of a call to that. * {@link #updateHeartbeat}, so it also takes the place of a call to that.
* *
* @param message the current status message for this sync * @param message the current status message for this sync
*
* @hide
*/ */
public void setStatusText(String message) { public void setStatusText(String message) {
updateHeartbeat(); updateHeartbeat();
@ -48,7 +51,7 @@ public class SyncContext {
* downloads or sends records to/from the server, this may be called after each record * downloads or sends records to/from the server, this may be called after each record
* is downloaded or uploaded. * is downloaded or uploaded.
*/ */
public void updateHeartbeat() { private void updateHeartbeat() {
final long now = SystemClock.elapsedRealtime(); final long now = SystemClock.elapsedRealtime();
if (now < mLastHeartbeatSendTime + HEARTBEAT_SEND_INTERVAL_IN_MS) return; if (now < mLastHeartbeatSendTime + HEARTBEAT_SEND_INTERVAL_IN_MS) return;
try { try {
@ -67,7 +70,7 @@ public class SyncContext {
} }
} }
public ISyncContext getISyncContext() { public IBinder getSyncContextBinder() {
return mSyncContext; return mSyncContext.asBinder();
} }
} }

View File

@ -5,8 +5,6 @@ import android.os.Parcelable;
/** /**
* This class is used to store information about the result of a sync * This class is used to store information about the result of a sync
*
* @hide
*/ */
public final class SyncResult implements Parcelable { public final class SyncResult implements Parcelable {
public final boolean syncAlreadyInProgress; public final boolean syncAlreadyInProgress;

View File

@ -1,37 +0,0 @@
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.content;
/**
* Class with callback methods for SyncAdapters and ContentProviders
* that are called in response to the calls on SyncContext. This class
* is really only meant to be used by the Sync UI activities.
*
* <p>All of the onXXX callback methods here are called from a handler
* on the thread this object was created in.
*
* <p>This interface is unused. It should be removed.
*
* @hide
*/
@Deprecated
public interface SyncUIContext {
void setStatusText(String text);
Context context();
}