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 AccountSyncSettings method updateAccountSwitches.
private void updateAccountSwitches() {
mInvisibleAdapters.clear();
SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(mUserHandle.getIdentifier());
ArrayList<SyncAdapterType> authorities = new ArrayList<>();
for (int i = 0, n = syncAdapters.length; i < n; i++) {
final SyncAdapterType sa = syncAdapters[i];
// Only keep track of sync adapters for this account
if (!sa.accountType.equals(mAccount.type))
continue;
if (sa.isUserVisible()) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "updateAccountSwitches: added authority " + sa.authority + " to accountType " + sa.accountType);
}
authorities.add(sa);
} else {
// keep track of invisible sync adapters, so sync now forces
// them to sync as well.
mInvisibleAdapters.add(sa);
}
}
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "looking for sync adapters that match account " + mAccount);
}
cacheRemoveAllPrefs(getPreferenceScreen());
for (int j = 0, m = authorities.size(); j < m; j++) {
final SyncAdapterType syncAdapter = authorities.get(j);
// We could check services here....
int syncState = ContentResolver.getIsSyncableAsUser(mAccount, syncAdapter.authority, mUserHandle.getIdentifier());
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, " found authority " + syncAdapter.authority + " " + syncState);
}
if (syncState > 0) {
final int uid;
try {
uid = getContext().getPackageManager().getPackageUidAsUser(syncAdapter.getPackageName(), mUserHandle.getIdentifier());
addSyncStateSwitch(mAccount, syncAdapter.authority, syncAdapter.getPackageName(), uid);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "No uid for package" + syncAdapter.getPackageName(), e);
}
}
}
removeCachedPrefs(getPreferenceScreen());
}
use of android.content.SyncAdapterType in project android_packages_apps_Settings by omnirom.
the class ChooseAccountActivity method getAuthoritiesForAccountType.
public ArrayList<String> getAuthoritiesForAccountType(String type) {
if (mAccountTypeToAuthorities == null) {
mAccountTypeToAuthorities = Maps.newHashMap();
SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(mUserHandle.getIdentifier());
for (int i = 0, n = syncAdapters.length; i < n; i++) {
final SyncAdapterType sa = syncAdapters[i];
ArrayList<String> authorities = mAccountTypeToAuthorities.get(sa.accountType);
if (authorities == null) {
authorities = new ArrayList<String>();
mAccountTypeToAuthorities.put(sa.accountType, authorities);
}
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.d(TAG, "added authority " + sa.authority + " to accountType " + sa.accountType);
}
authorities.add(sa.authority);
}
}
return mAccountTypeToAuthorities.get(type);
}
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(mContext.getString(R.string.account_sync_summary_all_off));
}
use of android.content.SyncAdapterType in project android_packages_apps_Settings by crdroidandroid.
the class AccountSyncPreferenceController method updateSummary.
@VisibleForTesting
void updateSummary(Preference preference) {
if (mAccount == null) {
return;
}
final int userId = mUserHandle.getIdentifier();
final SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(userId);
int total = 0;
int enabled = 0;
if (syncAdapters != null) {
for (int i = 0, n = syncAdapters.length; i < n; i++) {
final SyncAdapterType sa = syncAdapters[i];
if (!sa.accountType.equals(mAccount.type) || !sa.isUserVisible()) {
continue;
}
final int syncState = ContentResolver.getIsSyncableAsUser(mAccount, sa.authority, userId);
if (syncState > 0) {
total++;
final boolean syncEnabled = ContentResolver.getSyncAutomaticallyAsUser(mAccount, sa.authority, userId);
final boolean oneTimeSyncMode = !ContentResolver.getMasterSyncAutomaticallyAsUser(userId);
if (oneTimeSyncMode || syncEnabled) {
enabled++;
}
}
}
}
if (enabled == 0) {
preference.setSummary(R.string.account_sync_summary_all_off);
} else if (enabled == total) {
preference.setSummary(R.string.account_sync_summary_all_on);
} else {
preference.setSummary(mContext.getString(R.string.account_sync_summary_some_on, enabled, total));
}
}
Aggregations