use of android.content.SyncAdapterType in project android_packages_apps_Settings by omnirom.
the class AccountSyncSettings method requestOrCancelSyncForEnabledProviders.
private void requestOrCancelSyncForEnabledProviders(boolean startSync) {
// sync everything that the user has enabled
int count = getPreferenceScreen().getPreferenceCount();
for (int i = 0; i < count; i++) {
Preference pref = getPreferenceScreen().getPreference(i);
if (!(pref instanceof SyncStateSwitchPreference)) {
continue;
}
SyncStateSwitchPreference syncPref = (SyncStateSwitchPreference) pref;
if (!syncPref.isChecked()) {
continue;
}
requestOrCancelSync(syncPref.getAccount(), syncPref.getAuthority(), startSync);
}
// plus whatever the system needs to sync, e.g., invisible sync adapters
if (mAccount != null) {
for (SyncAdapterType syncAdapter : mInvisibleAdapters) {
requestOrCancelSync(mAccount, syncAdapter.authority, startSync);
}
}
}
use of android.content.SyncAdapterType in project android_packages_apps_Settings by omnirom.
the class AccountSyncPreferenceControllerTest method updateSummary_adapterInvisible_shouldNotCount.
@Test
public void updateSummary_adapterInvisible_shouldNotCount() {
SyncAdapterType syncAdapterType = new SyncAdapterType("authority", /* authority */
"type1", /* accountType */
false, /* userVisible */
true);
SyncAdapterType[] syncAdapters = { syncAdapterType };
ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
mController.updateSummary(mPreference);
assertThat(mPreference.getSummary()).isEqualTo(mActivity.getString(R.string.account_sync_summary_all_off));
}
use of android.content.SyncAdapterType in project platform_frameworks_base by android.
the class AccountSyncSettingsBackupHelper method serializeAccountSyncSettingsToJSON.
/**
* Fetch and serialize Account and authority information as a JSON Array.
*/
private JSONObject serializeAccountSyncSettingsToJSON() throws JSONException {
Account[] accounts = mAccountManager.getAccounts();
SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(mContext.getUserId());
// Create a map of Account types to authorities. Later this will make it easier for us to
// generate our JSON.
HashMap<String, List<String>> accountTypeToAuthorities = new HashMap<String, List<String>>();
for (SyncAdapterType syncAdapter : syncAdapters) {
// Skip adapters that aren’t visible to the user.
if (!syncAdapter.isUserVisible()) {
continue;
}
if (!accountTypeToAuthorities.containsKey(syncAdapter.accountType)) {
accountTypeToAuthorities.put(syncAdapter.accountType, new ArrayList<String>());
}
accountTypeToAuthorities.get(syncAdapter.accountType).add(syncAdapter.authority);
}
// Generate JSON.
JSONObject backupJSON = new JSONObject();
backupJSON.put(KEY_VERSION, JSON_FORMAT_VERSION);
backupJSON.put(KEY_MASTER_SYNC_ENABLED, ContentResolver.getMasterSyncAutomatically());
JSONArray accountJSONArray = new JSONArray();
for (Account account : accounts) {
List<String> authorities = accountTypeToAuthorities.get(account.type);
// settings for us to restore.
if (authorities == null || authorities.isEmpty()) {
continue;
}
JSONObject accountJSON = new JSONObject();
accountJSON.put(KEY_ACCOUNT_NAME, account.name);
accountJSON.put(KEY_ACCOUNT_TYPE, account.type);
// Add authorities for this Account type and check whether or not sync is enabled.
JSONArray authoritiesJSONArray = new JSONArray();
for (String authority : authorities) {
int syncState = ContentResolver.getIsSyncable(account, authority);
boolean syncEnabled = ContentResolver.getSyncAutomatically(account, authority);
JSONObject authorityJSON = new JSONObject();
authorityJSON.put(KEY_AUTHORITY_NAME, authority);
authorityJSON.put(KEY_AUTHORITY_SYNC_STATE, syncState);
authorityJSON.put(KEY_AUTHORITY_SYNC_ENABLED, syncEnabled);
authoritiesJSONArray.put(authorityJSON);
}
accountJSON.put(KEY_ACCOUNT_AUTHORITIES, authoritiesJSONArray);
accountJSONArray.put(accountJSON);
}
backupJSON.put(KEY_ACCOUNTS, accountJSONArray);
return backupJSON;
}
use of android.content.SyncAdapterType in project android_frameworks_base by ParanoidAndroid.
the class SyncManager method getIsSyncable.
public int getIsSyncable(Account account, int userId, String providerName) {
int isSyncable = mSyncStorageEngine.getIsSyncable(account, userId, providerName);
UserInfo userInfo = UserManager.get(mContext).getUserInfo(userId);
// If it's not a restricted user, return isSyncable
if (userInfo == null || !userInfo.isRestricted())
return isSyncable;
// Else check if the sync adapter has opted-in or not
RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo = mSyncAdapters.getServiceInfo(SyncAdapterType.newKey(providerName, account.type), userId);
if (syncAdapterInfo == null)
return isSyncable;
PackageInfo pInfo = null;
try {
pInfo = AppGlobals.getPackageManager().getPackageInfo(syncAdapterInfo.componentName.getPackageName(), 0, userId);
if (pInfo == null)
return isSyncable;
} catch (RemoteException re) {
// Shouldn't happen
return isSyncable;
}
if (pInfo.restrictedAccountType != null && pInfo.restrictedAccountType.equals(account.type)) {
return isSyncable;
} else {
return 0;
}
}
use of android.content.SyncAdapterType in project android_frameworks_base by ParanoidAndroid.
the class SyncManager method scheduleSync.
/**
* Initiate a sync. This can start a sync for all providers
* (pass null to url, set onlyTicklable to false), only those
* providers that are marked as ticklable (pass null to url,
* set onlyTicklable to true), or a specific provider (set url
* to the content url of the provider).
*
* <p>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.
*
* <p>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).
*
* <p>You'll start getting callbacks after this.
*
* @param requestedAccount the account to sync, may be null to signify all accounts
* @param userId the id of the user whose accounts are to be synced. If userId is USER_ALL,
* then all users' accounts are considered.
* @param 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:
* {@link SyncOperation#REASON_BACKGROUND_DATA_SETTINGS_CHANGED}
* {@link SyncOperation#REASON_ACCOUNTS_UPDATED}
* {@link SyncOperation#REASON_SERVICE_CHANGED}
* {@link SyncOperation#REASON_PERIODIC}
* {@link SyncOperation#REASON_IS_SYNCABLE}
* {@link SyncOperation#REASON_SYNC_AUTO}
* {@link SyncOperation#REASON_MASTER_SYNC_AUTO}
* {@link SyncOperation#REASON_USER_START}
* @param requestedAuthority the authority to sync, may be null to indicate all authorities
* @param extras a Map of SyncAdapter-specific information to control
* syncs of a specific provider. Can be null. Is ignored
* if the url is null.
* @param delay how many milliseconds in the future to wait before performing this
* @param onlyThoseWithUnkownSyncableState
*/
public void scheduleSync(Account requestedAccount, int userId, int reason, String requestedAuthority, Bundle extras, long delay, boolean onlyThoseWithUnkownSyncableState) {
boolean isLoggable = Log.isLoggable(TAG, Log.VERBOSE);
final boolean backgroundDataUsageAllowed = !mBootCompleted || getConnectivityManager().getBackgroundDataSetting();
if (extras == null)
extras = new Bundle();
Boolean expedited = extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false);
if (expedited) {
// this means schedule at the front of the queue
delay = -1;
}
AccountAndUser[] accounts;
if (requestedAccount != null && userId != UserHandle.USER_ALL) {
accounts = new AccountAndUser[] { new AccountAndUser(requestedAccount, userId) };
} else {
// if the accounts aren't configured yet then we can't support an account-less
// sync request
accounts = mRunningAccounts;
if (accounts.length == 0) {
if (isLoggable) {
Log.v(TAG, "scheduleSync: no accounts configured, dropping");
}
return;
}
}
final boolean uploadOnly = extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false);
final boolean manualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
if (manualSync) {
extras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, true);
extras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true);
}
final boolean ignoreSettings = extras.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, false);
int source;
if (uploadOnly) {
source = SyncStorageEngine.SOURCE_LOCAL;
} else if (manualSync) {
source = SyncStorageEngine.SOURCE_USER;
} else if (requestedAuthority == null) {
source = SyncStorageEngine.SOURCE_POLL;
} else {
// this isn't strictly server, since arbitrary callers can (and do) request
// a non-forced two-way sync on a specific url
source = SyncStorageEngine.SOURCE_SERVER;
}
for (AccountAndUser account : accounts) {
// Compile a list of authorities that have sync adapters.
// For each authority sync each account that matches a sync adapter.
final HashSet<String> syncableAuthorities = new HashSet<String>();
for (RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapter : mSyncAdapters.getAllServices(account.userId)) {
syncableAuthorities.add(syncAdapter.type.authority);
}
// syncable
if (requestedAuthority != null) {
final boolean hasSyncAdapter = syncableAuthorities.contains(requestedAuthority);
syncableAuthorities.clear();
if (hasSyncAdapter)
syncableAuthorities.add(requestedAuthority);
}
for (String authority : syncableAuthorities) {
int isSyncable = getIsSyncable(account.account, account.userId, authority);
if (isSyncable == 0) {
continue;
}
final RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo;
syncAdapterInfo = mSyncAdapters.getServiceInfo(SyncAdapterType.newKey(authority, account.account.type), account.userId);
if (syncAdapterInfo == null) {
continue;
}
final boolean allowParallelSyncs = syncAdapterInfo.type.allowParallelSyncs();
final boolean isAlwaysSyncable = syncAdapterInfo.type.isAlwaysSyncable();
if (isSyncable < 0 && isAlwaysSyncable) {
mSyncStorageEngine.setIsSyncable(account.account, account.userId, authority, 1);
isSyncable = 1;
}
if (onlyThoseWithUnkownSyncableState && isSyncable >= 0) {
continue;
}
if (!syncAdapterInfo.type.supportsUploading() && uploadOnly) {
continue;
}
// always allow if the isSyncable state is unknown
boolean syncAllowed = (isSyncable < 0) || ignoreSettings || (backgroundDataUsageAllowed && mSyncStorageEngine.getMasterSyncAutomatically(account.userId) && mSyncStorageEngine.getSyncAutomatically(account.account, account.userId, authority));
if (!syncAllowed) {
if (isLoggable) {
Log.d(TAG, "scheduleSync: sync of " + account + ", " + authority + " is not allowed, dropping request");
}
continue;
}
Pair<Long, Long> backoff = mSyncStorageEngine.getBackoff(account.account, account.userId, authority);
long delayUntil = mSyncStorageEngine.getDelayUntilTime(account.account, account.userId, authority);
final long backoffTime = backoff != null ? backoff.first : 0;
if (isSyncable < 0) {
Bundle newExtras = new Bundle();
newExtras.putBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, true);
if (isLoggable) {
Log.v(TAG, "scheduleSync:" + " delay " + delay + ", source " + source + ", account " + account + ", authority " + authority + ", extras " + newExtras);
}
scheduleSyncOperation(new SyncOperation(account.account, account.userId, reason, source, authority, newExtras, 0, backoffTime, delayUntil, allowParallelSyncs));
}
if (!onlyThoseWithUnkownSyncableState) {
if (isLoggable) {
Log.v(TAG, "scheduleSync:" + " delay " + delay + ", source " + source + ", account " + account + ", authority " + authority + ", extras " + extras);
}
scheduleSyncOperation(new SyncOperation(account.account, account.userId, reason, source, authority, extras, delay, backoffTime, delayUntil, allowParallelSyncs));
}
}
}
}
Aggregations