Search in sources :

Example 61 with AccessiblePreferenceCategory

use of com.android.settings.AccessiblePreferenceCategory in project platform_packages_apps_Settings by BlissRoms.

the class AccountPreferenceControllerTest method onResume_oneNewAccount_shouldAddOneAccountPreference.

@Test
public void onResume_oneNewAccount_shouldAddOneAccountPreference() {
    final List<UserInfo> infos = new ArrayList<>();
    infos.add(new UserInfo(1, "user 1", 0));
    when(mUserManager.isManagedProfile()).thenReturn(false);
    when(mUserManager.isLinkedUser()).thenReturn(false);
    when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
    Account[] accounts = { new Account("Acct1", "com.acct1") };
    when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts);
    Account[] accountType1 = new Account[2];
    accountType1[0] = new Account("Acct11", "com.acct1");
    accountType1[1] = new Account("Acct12", "com.acct1");
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
    AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false) };
    when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
    AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
    when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
    mController.onResume();
    // add a new account
    accountType1 = new Account[3];
    accountType1[0] = new Account("Acct11", "com.acct1");
    accountType1[1] = new Account("Acct12", "com.acct1");
    accountType1[2] = new Account("Acct13", "com.acct1");
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
    mController.onResume();
    // each account should be added only once
    verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct11")));
    verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct12")));
    verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct13")));
}
Also used : Context(android.content.Context) Account(android.accounts.Account) AuthenticatorDescription(android.accounts.AuthenticatorDescription) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory) PreferenceManager(android.support.v7.preference.PreferenceManager) Test(org.junit.Test)

Example 62 with AccessiblePreferenceCategory

use of com.android.settings.AccessiblePreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccountPreferenceControllerTest method onResume_noPreferenceScreen_shouldNotCrash.

@Test
public void onResume_noPreferenceScreen_shouldNotCrash() {
    final List<UserInfo> infos = new ArrayList<>();
    infos.add(new UserInfo(1, "user 1", 0));
    when(mUserManager.isManagedProfile()).thenReturn(false);
    when(mUserManager.isRestrictedProfile()).thenReturn(false);
    when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
    AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
    when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
    mController.onResume();
// Should not crash
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory) Test(org.junit.Test)

Example 63 with AccessiblePreferenceCategory

use of com.android.settings.AccessiblePreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccountPreferenceControllerTest method onResume_twoAccountsOfSameName_shouldAddFivePreferences.

@Test
@Config(shadows = { ShadowAccountManager.class, ShadowContentResolver.class })
public void onResume_twoAccountsOfSameName_shouldAddFivePreferences() {
    final List<UserInfo> infos = new ArrayList<>();
    infos.add(new UserInfo(1, "user 1", 0));
    when(mUserManager.isManagedProfile()).thenReturn(false);
    when(mUserManager.isRestrictedProfile()).thenReturn(false);
    when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
    final Account[] accountType1 = new Account[2];
    accountType1[0] = new Account("Account1", "com.acct1");
    accountType1[1] = new Account("Account2", "com.acct1");
    final Account[] accountType2 = new Account[2];
    accountType2[0] = new Account("Account1", "com.acct2");
    accountType2[1] = new Account("Account2", "com.acct2");
    final Account[] allAccounts = new Account[4];
    allAccounts[0] = accountType1[0];
    allAccounts[1] = accountType1[1];
    allAccounts[2] = accountType2[0];
    allAccounts[3] = accountType2[1];
    final AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false), new AuthenticatorDescription("com.acct2", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false) };
    when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(allAccounts);
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct2"), any(UserHandle.class))).thenReturn(accountType2);
    when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
    AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
    when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
    mController.onResume();
    // should add 4 individual account and the Add account preference
    verify(preferenceGroup, times(5)).addPreference(any(Preference.class));
}
Also used : Context(android.content.Context) Account(android.accounts.Account) AuthenticatorDescription(android.accounts.AuthenticatorDescription) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 64 with AccessiblePreferenceCategory

use of com.android.settings.AccessiblePreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccountPreferenceControllerTest method onResume_userReEnabled_shouldAddOneAccountPreference.

@Test
public void onResume_userReEnabled_shouldAddOneAccountPreference() {
    final List<UserInfo> infos = new ArrayList<>();
    infos.add(new UserInfo(1, "user 1", UserInfo.FLAG_DISABLED));
    when(mUserManager.isManagedProfile()).thenReturn(false);
    when(mUserManager.isRestrictedProfile()).thenReturn(false);
    when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
    Account[] accounts = { new Account("Acct1", "com.acct1") };
    when(mAccountManager.getAccountsAsUser(1)).thenReturn(accounts);
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accounts);
    AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, /* iconId */
    0, /* smallIconId */
    0, /* prefId */
    false) };
    when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
    AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
    when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
    // First time resume will build the UI with no account
    mController.onResume();
    verify(preferenceGroup, never()).addPreference(argThat(titleMatches("Acct1")));
    // Enable the user
    infos.remove(0);
    infos.add(new UserInfo(1, "user 1", 0));
    // Resume should show the account for the user
    mController.onResume();
    verify(preferenceGroup).addPreference(argThat(titleMatches("Acct1")));
}
Also used : Context(android.content.Context) Account(android.accounts.Account) AuthenticatorDescription(android.accounts.AuthenticatorDescription) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 65 with AccessiblePreferenceCategory

use of com.android.settings.AccessiblePreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccountPreferenceController method updateProfileUi.

private void updateProfileUi(final UserInfo userInfo) {
    if (mParent.getPreferenceManager() == null) {
        return;
    }
    final ProfileData data = mProfiles.get(userInfo.id);
    if (data != null) {
        data.pendingRemoval = false;
        data.userInfo = userInfo;
        if (userInfo.isEnabled()) {
            // recreate the authentication helper to refresh the list of enabled accounts
            data.authenticatorHelper = new AuthenticatorHelper(mContext, userInfo.getUserHandle(), this);
        }
        return;
    }
    final Context context = mContext;
    final ProfileData profileData = new ProfileData();
    profileData.userInfo = userInfo;
    AccessiblePreferenceCategory preferenceGroup = mHelper.createAccessiblePreferenceCategory(mParent.getPreferenceManager().getContext());
    preferenceGroup.setOrder(mAccountProfileOrder++);
    if (isSingleProfile()) {
        preferenceGroup.setTitle(context.getString(R.string.account_for_section_header, BidiFormatter.getInstance().unicodeWrap(userInfo.name)));
        preferenceGroup.setContentDescription(mContext.getString(R.string.account_settings));
    } else if (userInfo.isManagedProfile()) {
        preferenceGroup.setTitle(R.string.category_work);
        String workGroupSummary = getWorkGroupSummary(context, userInfo);
        preferenceGroup.setSummary(workGroupSummary);
        preferenceGroup.setContentDescription(mContext.getString(R.string.accessibility_category_work, workGroupSummary));
        profileData.removeWorkProfilePreference = newRemoveWorkProfilePreference();
        mHelper.enforceRestrictionOnPreference(profileData.removeWorkProfilePreference, DISALLOW_REMOVE_MANAGED_PROFILE, UserHandle.myUserId());
        profileData.managedProfilePreference = newManagedProfileSettings();
    } else {
        preferenceGroup.setTitle(R.string.category_personal);
        preferenceGroup.setContentDescription(mContext.getString(R.string.accessibility_category_personal));
    }
    final PreferenceScreen screen = mParent.getPreferenceScreen();
    if (screen != null) {
        screen.addPreference(preferenceGroup);
    }
    profileData.preferenceGroup = preferenceGroup;
    if (userInfo.isEnabled()) {
        profileData.authenticatorHelper = new AuthenticatorHelper(context, userInfo.getUserHandle(), this);
        profileData.addAccountPreference = newAddAccountPreference();
        mHelper.enforceRestrictionOnPreference(profileData.addAccountPreference, DISALLOW_MODIFY_ACCOUNTS, userInfo.id);
    }
    mProfiles.put(userInfo.id, profileData);
}
Also used : Context(android.content.Context) AuthenticatorHelper(com.android.settingslib.accounts.AuthenticatorHelper) PreferenceScreen(androidx.preference.PreferenceScreen) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory)

Aggregations

Context (android.content.Context)65 AccessiblePreferenceCategory (com.android.settings.AccessiblePreferenceCategory)65 UserInfo (android.content.pm.UserInfo)57 ArrayList (java.util.ArrayList)57 Test (org.junit.Test)57 Account (android.accounts.Account)43 AuthenticatorDescription (android.accounts.AuthenticatorDescription)43 UserHandle (android.os.UserHandle)43 PreferenceManager (android.support.v7.preference.PreferenceManager)36 Preference (android.support.v7.preference.Preference)12 AuthenticatorHelper (com.android.settingslib.accounts.AuthenticatorHelper)8 PreferenceManager (androidx.preference.PreferenceManager)7 Config (org.robolectric.annotation.Config)7 PreferenceScreen (android.support.v7.preference.PreferenceScreen)6 TestConfig (com.android.settings.TestConfig)6 SearchFeatureProviderImpl (com.android.settings.search.SearchFeatureProviderImpl)6 Preference (androidx.preference.Preference)2 PreferenceScreen (androidx.preference.PreferenceScreen)1