Search in sources :

Example 56 with SyncAdapterType

use of android.content.SyncAdapterType in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccountSyncPreferenceControllerTest method updateSummary_multipleSyncAdapters_shouldSetSummary.

@Test
public void updateSummary_multipleSyncAdapters_shouldSetSummary() {
    SyncAdapterType syncAdapterType1 = new SyncAdapterType("authority1", /* authority */
    "type1", /* accountType */
    true, /* userVisible */
    true);
    SyncAdapterType syncAdapterType2 = new SyncAdapterType("authority2", /* authority */
    "type1", /* accountType */
    true, /* userVisible */
    true);
    SyncAdapterType syncAdapterType3 = new SyncAdapterType("authority3", /* authority */
    "type1", /* accountType */
    true, /* userVisible */
    true);
    SyncAdapterType syncAdapterType4 = new SyncAdapterType("authority4", /* authority */
    "type1", /* accountType */
    true, /* userVisible */
    true);
    SyncAdapterType[] syncAdapters = { syncAdapterType1, syncAdapterType2, syncAdapterType3, syncAdapterType4 };
    ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
    ShadowContentResolver.setSyncAutomatically("authority4", false);
    mController.updateSummary(mPreference);
    assertThat(mPreference.getSummary()).isEqualTo(mActivity.getString(R.string.account_sync_summary_some_on, 3, 4));
}
Also used : SyncAdapterType(android.content.SyncAdapterType) Test(org.junit.Test)

Example 57 with SyncAdapterType

use of android.content.SyncAdapterType in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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

Example 58 with SyncAdapterType

use of android.content.SyncAdapterType in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ChooseAccountPreferenceControllerTest method updateAuthDescriptions_twoProvider_shouldAddTwoPreference.

@Test
public void updateAuthDescriptions_twoProvider_shouldAddTwoPreference() {
    final AuthenticatorDescription authDesc = new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.header_add_an_account, 0, 0, 0, false);
    final AuthenticatorDescription authDesc2 = new AuthenticatorDescription("com.acct2", "com.android.settings", R.string.header_add_an_account, 0, 0, 0, false);
    ShadowAccountManager.addAuthenticator(authDesc);
    ShadowAccountManager.addAuthenticator(authDesc2);
    final SyncAdapterType[] syncAdapters = { new SyncAdapterType("authority", /* authority */
    "com.acct1", /* accountType */
    false, /* userVisible */
    true), new SyncAdapterType("authority2", /* authority */
    "com.acct2", /* accountType */
    false, /* userVisible */
    true) };
    ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
    doReturn("label").when(mController).getLabelForType(anyString());
    doReturn("label2").when(mController).getLabelForType(anyString());
    doReturn(new ColorDrawable()).when(mController).getDrawableForType(anyString());
    doReturn(new ColorDrawable()).when(mController).getDrawableForType(anyString());
    mController.initialize(null, null, new UserHandle(3), mActivity);
    mController.displayPreference(mPreferenceScreen);
    assertThat(mPreferenceScreen.getPreferenceCount()).isEqualTo(2);
}
Also used : AuthenticatorDescription(android.accounts.AuthenticatorDescription) ColorDrawable(android.graphics.drawable.ColorDrawable) UserHandle(android.os.UserHandle) SyncAdapterType(android.content.SyncAdapterType) Test(org.junit.Test)

Example 59 with SyncAdapterType

use of android.content.SyncAdapterType in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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());
    getCachedPreference(EntityHeaderController.PREF_KEY_APP_HEADER);
    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 60 with SyncAdapterType

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());
    getCachedPreference(EntityHeaderController.PREF_KEY_APP_HEADER);
    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)

Aggregations

SyncAdapterType (android.content.SyncAdapterType)132 Test (org.junit.Test)50 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 UserHandle (android.os.UserHandle)13 ArrayList (java.util.ArrayList)13 AccountAndUser (android.accounts.AccountAndUser)12 RemoteException (android.os.RemoteException)11 AuthenticatorDescription (android.accounts.AuthenticatorDescription)9 Bundle (android.os.Bundle)8 HashSet (java.util.HashSet)8 SyncStatusInfo (android.content.SyncStatusInfo)7 Preference (android.support.v7.preference.Preference)7 PackageInfo (android.content.pm.PackageInfo)6 List (java.util.List)6 RemoteCallback (android.os.RemoteCallback)5 VisibleForTesting (android.support.annotation.VisibleForTesting)5