Search in sources :

Example 31 with SyncAdapterType

use of android.content.SyncAdapterType in project android_packages_apps_Settings by crdroidandroid.

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());
}
Also used : PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) SyncAdapterType(android.content.SyncAdapterType)

Example 32 with SyncAdapterType

use of android.content.SyncAdapterType in project android_packages_apps_Settings by crdroidandroid.

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);
        }
    }
}
Also used : Preference(android.support.v7.preference.Preference) SyncAdapterType(android.content.SyncAdapterType)

Example 33 with SyncAdapterType

use of android.content.SyncAdapterType in project android_packages_apps_Settings by crdroidandroid.

the class AccountSyncPreferenceControllerTest method updateSummary_syncDisabled_shouldNotCount.

@Test
public void updateSummary_syncDisabled_shouldNotCount() {
    SyncAdapterType syncAdapterType = new SyncAdapterType("authority", /* authority */
    "type1", /* accountType */
    true, /* userVisible */
    true);
    SyncAdapterType[] syncAdapters = { syncAdapterType };
    ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
    ShadowContentResolver.setSyncAutomatically("authority", false);
    ShadowContentResolver.setMasterSyncAutomatically(3, true);
    mController.updateSummary(mPreference);
    assertThat(mPreference.getSummary()).isEqualTo(mContext.getString(R.string.account_sync_summary_all_off));
}
Also used : SyncAdapterType(android.content.SyncAdapterType) Test(org.junit.Test)

Example 34 with SyncAdapterType

use of android.content.SyncAdapterType in project android_packages_apps_Settings by crdroidandroid.

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));
}
Also used : SyncAdapterType(android.content.SyncAdapterType) Test(org.junit.Test)

Example 35 with SyncAdapterType

use of android.content.SyncAdapterType in project android_packages_apps_Settings by SudaMod.

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));
    }
}
Also used : SyncAdapterType(android.content.SyncAdapterType) VisibleForTesting(android.support.annotation.VisibleForTesting)

Aggregations

SyncAdapterType (android.content.SyncAdapterType)127 Test (org.junit.Test)46 RegisteredServicesCache (android.content.pm.RegisteredServicesCache)33 EndPoint (com.android.server.content.SyncStorageEngine.EndPoint)30 UserInfo (android.content.pm.UserInfo)17 Account (android.accounts.Account)13 PackageManager (android.content.pm.PackageManager)13 ArrayList (java.util.ArrayList)13 AccountAndUser (android.accounts.AccountAndUser)12 RemoteException (android.os.RemoteException)11 UserHandle (android.os.UserHandle)9 Bundle (android.os.Bundle)8 Preference (android.support.v7.preference.Preference)8 HashSet (java.util.HashSet)8 SyncStatusInfo (android.content.SyncStatusInfo)7 PackageInfo (android.content.pm.PackageInfo)6 VisibleForTesting (android.support.annotation.VisibleForTesting)6 List (java.util.List)6 AuthenticatorDescription (android.accounts.AuthenticatorDescription)5 RemoteCallback (android.os.RemoteCallback)5