FileDocCategorySizeDatePackage
TempProviderSyncAdapter.javaAPI DocAndroid 1.5 API23947Wed May 06 22:41:54 BST 2009android.content

TempProviderSyncAdapter

public abstract class TempProviderSyncAdapter extends SyncAdapter
hide

Fields Summary
private static final String
TAG
private static final int
MAX_GET_SERVER_DIFFS_LOOP_COUNT
private static final int
MAX_UPLOAD_CHANGES_LOOP_COUNT
private static final int
NUM_ALLOWED_SIMULTANEOUS_DELETIONS
private static final long
PERCENT_ALLOWED_SIMULTANEOUS_DELETIONS
private volatile SyncableContentProvider
mProvider
private volatile SyncThread
mSyncThread
private volatile boolean
mProviderSyncStarted
private volatile boolean
mAdapterSyncStarted
private Context
mContext
Constructors Summary
public TempProviderSyncAdapter(SyncableContentProvider provider)

    
       
        super();
        mProvider = provider;
    
Methods Summary
public voidcancelSync()

        if (mSyncThread != null) {
            mSyncThread.cancelSync();
        }
    
protected java.lang.ObjectcreateSyncInfo()

        return null;
    
public final ContextgetContext()
Retrieve the Context this adapter is running in. Only available once onSyncStarting() is called (not available from constructor).

        return mContext;
    
public abstract voidgetServerDiffs(SyncContext context, android.content.TempProviderSyncAdapter$SyncData syncData, SyncableContentProvider tempProvider, android.os.Bundle extras, java.lang.Object syncInfo, SyncResult syncResult)
Get diffs from the server since the last completed sync and put them into a temporary provider.

param
context allows you to publish status and interact with the user during interactive syncs.
param
syncData used to track the progress this client has made in syncing data from the server
param
tempProvider this is where the diffs should be stored
param
extras any extra data describing the sync that is desired
param
syncInfo sync adapter-specific data that is used during a single sync operation
param
syncResult information to track what happened during this sync attempt

protected booleanhasTooManyDeletions(SyncStats stats)

        long numEntries = stats.numEntries;
        long numDeletedEntries = stats.numDeletes;

        long percentDeleted = (numDeletedEntries == 0)
                ? 0
                : (100 * numDeletedEntries /
                        (numEntries + numDeletedEntries));
        boolean tooManyDeletions =
                (numDeletedEntries > NUM_ALLOWED_SIMULTANEOUS_DELETIONS)
                && (percentDeleted > PERCENT_ALLOWED_SIMULTANEOUS_DELETIONS);
        return tooManyDeletions;
    
protected voidinitTempProvider(SyncableContentProvider cp)
Initializes the temporary content providers used during {@link TempProviderSyncAdapter#sendClientDiffs}. May copy relevant data from the underlying db into this provider so joins, etc., can work.

param
cp The ContentProvider to initialize.

public abstract booleanisReadOnly()
Implement this to return true if the data in your content provider is read only.

protected voidlogSyncDetails(long bytesSent, long bytesReceived, SyncResult result)
Logs details on the sync. Normally this will be overridden by a subclass that will provide provider-specific details.

param
bytesSent number of bytes the sync sent over the network
param
bytesReceived number of bytes the sync received over the network
param
result The SyncResult object holding info on the sync

        EventLog.writeEvent(SyncAdapter.LOG_SYNC_DETAILS, TAG, bytesSent, bytesReceived, "");
    
public android.content.TempProviderSyncAdapter$SyncDatanewSyncData()
Create and return a new, empty SyncData object

        return null;
    
public abstract voidonAccountsChanged(java.lang.String[] accounts)
Called when the accounts list possibly changed, to give the SyncAdapter a chance to do any necessary bookkeeping, e.g. to make sure that any required SubscribedFeeds subscriptions exist.

param
accounts the list of accounts

public abstract voidonSyncCanceled()
Indicate to the SyncAdapter that the last sync that was started has been cancelled.

public abstract voidonSyncEnding(SyncContext context, boolean success)
Called right after a sync is completed

param
context allows you to publish status and interact with the user during interactive syncs.
param
success true if the sync suceeded, false if an error occured

public abstract voidonSyncStarting(SyncContext context, java.lang.String account, boolean forced, SyncResult result)
Called right before a sync is started.

param
context allows you to publish status and interact with the
param
account the account to sync
param
forced if true then the sync was forced
param
result information to track what happened during this sync attempt
return
true, if the sync was successfully started. One reason it can fail to start is if there is no user configured on the device.

public android.content.TempProviderSyncAdapter$SyncDatareadSyncData(SyncableContentProvider contentProvider)
Reads the sync data from the ContentProvider

param
contentProvider the ContentProvider to read from
return
the SyncData for the provider. This may be null.

        return null;
    
public abstract voidsendClientDiffs(SyncContext context, SyncableContentProvider clientDiffs, SyncableContentProvider serverDiffs, SyncResult syncResult, boolean dontActuallySendDeletes)
Send client diffs to the server, optionally receiving more diffs from the server

param
context allows you to publish status and interact with the user during interactive syncs.
param
clientDiffs the diffs from the client
param
serverDiffs the SyncableContentProvider that should be populated with the entries that were returned in response to an insert/update/delete request to the server
param
syncResult information to track what happened during this sync attempt
param
dontActuallySendDeletes

public final voidsetContext(Context context)

        mContext = context;
    
public voidstartSync(SyncContext syncContext, java.lang.String account, android.os.Bundle extras)

        if (mSyncThread != null) {
            syncContext.onFinished(SyncResult.ALREADY_IN_PROGRESS);
            return;
        }

        mSyncThread = new SyncThread(syncContext, account, extras);
        mSyncThread.start();
    
public voidwriteSyncData(android.content.TempProviderSyncAdapter$SyncData syncData, SyncableContentProvider contentProvider)
Stores the sync data in the Sync Stats database, keying it by the account that was set in the last call to onSyncStarting()