public class SyncManager extends Object
scheduleSyncOperationH(SyncOperation, long)
. This function schedules a job
with JobScheduler with appropriate delay and constraints (according to backoffs and extras).
The scheduleSyncOperationH function also assigns a unique jobId to each
SyncOperation.
Periodic Syncs:
Each periodic sync is scheduled as a periodic job. If a periodic sync fails, we create a new
one off SyncOperation and set its SyncOperation.sourcePeriodicId
field to the jobId of the
periodic sync. We don't allow the periodic job to run while any job initiated by it is pending.
Backoffs:
Each SyncStorageEngine.EndPoint
has a backoff associated with it. When a SyncOperation fails, we increase
the backoff on the authority. Then we reschedule all syncs associated with that authority to
run at a later time. Similarly, when a sync succeeds, backoff is cleared and all associated syncs
are rescheduled. A rescheduled sync will get a new jobId.Modifier and Type | Field and Description |
---|---|
protected ArrayList<com.android.server.content.SyncManager.ActiveSyncContext> |
mActiveSyncContexts |
protected SyncAdaptersCache |
mSyncAdapters |
Constructor and Description |
---|
SyncManager(Context context,
boolean factoryTest)
Should only be created after
ContentService.systemReady() so that
PackageManager is ready to query. |
Modifier and Type | Method and Description |
---|---|
void |
cancelActiveSync(SyncStorageEngine.EndPoint info,
Bundle extras)
Cancel the active sync if it matches the target.
|
void |
cancelScheduledSyncOperation(SyncStorageEngine.EndPoint info,
Bundle extras)
Remove a specified sync, if it exists.
|
void |
clearScheduledSyncOperations(SyncStorageEngine.EndPoint info)
Remove scheduled sync operations.
|
int |
computeSyncable(Account account,
int userId,
String authority,
boolean checkAccountAccess) |
protected void |
dump(FileDescriptor fd,
PrintWriter pw) |
protected void |
dumpPendingSyncs(PrintWriter pw) |
protected void |
dumpPeriodicSyncs(PrintWriter pw) |
protected void |
dumpSyncHistory(PrintWriter pw) |
protected void |
dumpSyncState(PrintWriter pw) |
List<PeriodicSync> |
getPeriodicSyncs(SyncStorageEngine.EndPoint target)
Get a list of periodic syncs corresponding to the given target.
|
String[] |
getSyncAdapterPackagesForAuthorityAsUser(String authority,
int userId) |
SyncAdapterType[] |
getSyncAdapterTypes(int userId) |
SyncStorageEngine |
getSyncStorageEngine() |
void |
removePeriodicSync(SyncStorageEngine.EndPoint target,
Bundle extras)
Remove a specific periodic sync identified by its target and extras.
|
void |
scheduleLocalSync(Account account,
int userId,
int reason,
String authority)
Schedule sync based on local changes to a provider.
|
void |
scheduleSync(Account requestedAccount,
int userId,
int reason,
String requestedAuthority,
Bundle extras,
int targetSyncState)
Initiate a sync.
|
static boolean |
syncExtrasEquals(Bundle b1,
Bundle b2,
boolean includeSyncSettings)
Sync extra comparison function.
|
void |
updateOrAddPeriodicSync(SyncStorageEngine.EndPoint target,
long pollFrequency,
long flex,
Bundle extras)
Add a periodic sync.
|
protected final ArrayList<com.android.server.content.SyncManager.ActiveSyncContext> mActiveSyncContexts
protected SyncAdaptersCache mSyncAdapters
public SyncManager(Context context, boolean factoryTest)
ContentService.systemReady()
so that
PackageManager
is ready to query.public SyncStorageEngine getSyncStorageEngine()
public void scheduleSync(Account requestedAccount, int userId, int reason, String requestedAuthority, Bundle extras, int targetSyncState)
If the ContentResolver.SYNC_EXTRAS_UPLOAD boolean in extras is true then initiate a sync that just checks for local changes to send to the server, otherwise initiate a sync that first gets any changes from the server before sending local changes back to the server.
If a specific provider is being synced (the url is non-null) then the extras can contain SyncAdapter-specific information to control what gets synced (e.g. which specific feed to sync).
You'll start getting callbacks after this.
requestedAccount
- the account to sync, may be null to signify all accountsuserId
- the id of the user whose accounts are to be synced. If userId is USER_ALL,
then all users' accounts are considered.reason
- for sync request. If this is a positive integer, it is the Linux uid
assigned to the process that requested the sync. If it's negative, the sync was requested by
the SyncManager itself and could be one of the following:
SyncOperation.REASON_BACKGROUND_DATA_SETTINGS_CHANGED
SyncOperation.REASON_ACCOUNTS_UPDATED
SyncOperation.REASON_SERVICE_CHANGED
SyncOperation.REASON_PERIODIC
SyncOperation.REASON_IS_SYNCABLE
SyncOperation.REASON_SYNC_AUTO
SyncOperation.REASON_MASTER_SYNC_AUTO
SyncOperation.REASON_USER_START
requestedAuthority
- the authority to sync, may be null to indicate all authoritiesextras
- a Map of SyncAdapter-specific information to control
syncs of a specific provider. Can be null. Is ignored
if the url is null.targetSyncState
- Only sync authorities that have the specified sync state.
Use SyncStorageEngine.AuthorityInfo.UNDEFINED
to sync all authorities.public int computeSyncable(Account account, int userId, String authority, boolean checkAccountAccess)
public void removePeriodicSync(SyncStorageEngine.EndPoint target, Bundle extras)
public void updateOrAddPeriodicSync(SyncStorageEngine.EndPoint target, long pollFrequency, long flex, Bundle extras)
public List<PeriodicSync> getPeriodicSyncs(SyncStorageEngine.EndPoint target)
public void scheduleLocalSync(Account account, int userId, int reason, String authority)
public SyncAdapterType[] getSyncAdapterTypes(int userId)
public String[] getSyncAdapterPackagesForAuthorityAsUser(String authority, int userId)
public void cancelActiveSync(SyncStorageEngine.EndPoint info, Bundle extras)
info
- object containing info about which syncs to cancel. The target can
have null account/provider info to specify all accounts/providers.extras
- if non-null, specifies the exact sync to remove.public void clearScheduledSyncOperations(SyncStorageEngine.EndPoint info)
info
- limit the removals to operations that match this target. The target can
have null account/provider info to specify all accounts/providers.public void cancelScheduledSyncOperation(SyncStorageEngine.EndPoint info, Bundle extras)
info
- Authority for which the sync is to be removed.extras
- extras bundle to uniquely identify sync.protected void dump(FileDescriptor fd, PrintWriter pw)
protected void dumpPendingSyncs(PrintWriter pw)
protected void dumpPeriodicSyncs(PrintWriter pw)
protected void dumpSyncState(PrintWriter pw)
protected void dumpSyncHistory(PrintWriter pw)