Search in sources :

Example 91 with SyncAdapterType

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

the class AccountSyncPreferenceControllerTest method updateSummary_notSameAccountType_shouldNotCount.

@Test
public void updateSummary_notSameAccountType_shouldNotCount() {
    SyncAdapterType syncAdapterType = new SyncAdapterType("authority", /* authority */
    "type5", /* accountType */
    true, /* 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 92 with SyncAdapterType

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

the class AccountSyncPreferenceControllerTest method updateSummary_notSyncable_shouldNotCount.

@Test
public void updateSummary_notSyncable_shouldNotCount() {
    SyncAdapterType syncAdapterType = new SyncAdapterType("authority", /* authority */
    "type1", /* accountType */
    true, /* userVisible */
    true);
    SyncAdapterType[] syncAdapters = { syncAdapterType };
    ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
    ShadowContentResolver.setSyncable("authority", 0);
    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 93 with SyncAdapterType

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

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 94 with SyncAdapterType

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

the class AccountSyncPreferenceControllerTest method updateSummary_syncEnabled_shouldCount.

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

Example 95 with SyncAdapterType

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

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)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