Search in sources :

Example 36 with AccessiblePreferenceCategory

use of com.android.settings.AccessiblePreferenceCategory in project android_packages_apps_Settings by omnirom.

the class AccountPreferenceControllerTest method onResume_oneNewAccountType_shouldAddOneAccountPreference.

@Test
public void onResume_oneNewAccountType_shouldAddOneAccountPreference() {
    final List<UserInfo> infos = new ArrayList<>();
    infos.add(new UserInfo(1, "user 1", 0));
    infos.add(new UserInfo(2, "user 2", UserInfo.FLAG_MANAGED_PROFILE));
    when(mUserManager.isManagedProfile()).thenReturn(false);
    when(mUserManager.isRestrictedProfile()).thenReturn(false);
    when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
    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();
    // Add new account
    Account[] accounts = { new Account("Acct1", "com.acct1") };
    when(mAccountManager.getAccountsAsUser(2)).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, 0, 0, false) };
    when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
    // Resume should show the newly added account
    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 37 with AccessiblePreferenceCategory

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

the class AccountSettings method updateProfileUi.

private void updateProfileUi(final UserInfo userInfo, boolean addCategory, PreferenceScreen parent) {
    final Context context = getActivity();
    final ProfileData profileData = new ProfileData();
    profileData.userInfo = userInfo;
    if (addCategory) {
        profileData.preferenceGroup = new AccessiblePreferenceCategory(getPrefContext());
        if (userInfo.isManagedProfile()) {
            profileData.preferenceGroup.setLayoutResource(R.layout.work_profile_category);
            profileData.preferenceGroup.setTitle(R.string.category_work);
            String workGroupSummary = getWorkGroupSummary(context, userInfo);
            profileData.preferenceGroup.setSummary(workGroupSummary);
            ((AccessiblePreferenceCategory) profileData.preferenceGroup).setContentDescription(getString(R.string.accessibility_category_work, workGroupSummary));
            profileData.removeWorkProfilePreference = newRemoveWorkProfilePreference(context);
            profileData.managedProfilePreference = newManagedProfileSettings();
        } else {
            profileData.preferenceGroup.setTitle(R.string.category_personal);
            ((AccessiblePreferenceCategory) profileData.preferenceGroup).setContentDescription(getString(R.string.accessibility_category_personal));
        }
        parent.addPreference(profileData.preferenceGroup);
    } else {
        profileData.preferenceGroup = parent;
    }
    if (userInfo.isEnabled()) {
        profileData.authenticatorHelper = new AuthenticatorHelper(context, userInfo.getUserHandle(), this);
        profileData.addAccountPreference = newAddAccountPreference(context);
        if (RestrictedLockUtils.hasBaseUserRestriction(context, UserManager.DISALLOW_MODIFY_ACCOUNTS, userInfo.id)) {
            profileData.addAccountPreference.setEnabled(false);
        } else {
            profileData.addAccountPreference.checkRestrictionAndSetDisabled(DISALLOW_MODIFY_ACCOUNTS, userInfo.id);
        }
    }
    mProfiles.put(userInfo.id, profileData);
    Index.getInstance(getActivity()).updateFromClassNameResource(AccountSettings.class.getName(), true, true);
}
Also used : Context(android.content.Context) AuthenticatorHelper(com.android.settingslib.accounts.AuthenticatorHelper) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory)

Example 38 with AccessiblePreferenceCategory

use of com.android.settings.AccessiblePreferenceCategory in project android_packages_apps_Settings by LineageOS.

the class AccountPreferenceControllerTest method onResume_oneNewAccountType_shouldAddOneAccountPreference.

@Test
public void onResume_oneNewAccountType_shouldAddOneAccountPreference() {
    final List<UserInfo> infos = new ArrayList<>();
    infos.add(new UserInfo(1, "user 1", 0));
    infos.add(new UserInfo(2, "user 2", UserInfo.FLAG_MANAGED_PROFILE));
    when(mUserManager.isManagedProfile()).thenReturn(false);
    when(mUserManager.isLinkedUser()).thenReturn(false);
    when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
    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();
    // Add new account
    Account[] accounts = { new Account("Acct1", "com.acct1") };
    when(mAccountManager.getAccountsAsUser(2)).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, 0, 0, false) };
    when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
    // Resume should show the newly added account
    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(android.support.v7.preference.PreferenceManager) Test(org.junit.Test)

Example 39 with AccessiblePreferenceCategory

use of com.android.settings.AccessiblePreferenceCategory in project android_packages_apps_Settings by LineageOS.

the class AccountPreferenceControllerTest method onResume_twoAccountsOfSameType_shouldAddThreePreferences.

@Test
public void onResume_twoAccountsOfSameType_shouldAddThreePreferences() {
    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("Account1", "com.acct1") };
    when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts);
    Account[] accountType1 = new Account[2];
    accountType1[0] = new Account("Account11", "com.acct1");
    accountType1[1] = new Account("Account12", "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();
    // should add 2 individual account and the Add account preference
    verify(preferenceGroup, times(3)).addPreference(any(Preference.class));
}
Also used : Context(android.content.Context) Account(android.accounts.Account) AuthenticatorDescription(android.accounts.AuthenticatorDescription) Preference(android.support.v7.preference.Preference) 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 40 with AccessiblePreferenceCategory

use of com.android.settings.AccessiblePreferenceCategory in project android_packages_apps_Settings by LineageOS.

the class AccountPreferenceControllerTest method onResume_oneAccountRemoved_shouldRemoveOneAccountPreference.

@Test
public void onResume_oneAccountRemoved_shouldRemoveOneAccountPreference() {
    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();
    // remove an account
    accountType1 = new Account[1];
    accountType1[0] = new Account("Acct11", "com.acct1");
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
    mController.onResume();
    verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct11")));
    verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct12")));
    verify(preferenceGroup, times(1)).removePreference(argThat(titleMatches("Acct12")));
}
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)

Aggregations

Context (android.content.Context)66 AccessiblePreferenceCategory (com.android.settings.AccessiblePreferenceCategory)66 UserInfo (android.content.pm.UserInfo)58 ArrayList (java.util.ArrayList)58 Test (org.junit.Test)58 Account (android.accounts.Account)44 AuthenticatorDescription (android.accounts.AuthenticatorDescription)44 UserHandle (android.os.UserHandle)44 PreferenceManager (android.support.v7.preference.PreferenceManager)30 PreferenceManager (androidx.preference.PreferenceManager)14 Preference (android.support.v7.preference.Preference)10 AuthenticatorHelper (com.android.settingslib.accounts.AuthenticatorHelper)8 Config (org.robolectric.annotation.Config)7 PreferenceScreen (android.support.v7.preference.PreferenceScreen)5 TestConfig (com.android.settings.TestConfig)5 SearchFeatureProviderImpl (com.android.settings.search.SearchFeatureProviderImpl)5 Preference (androidx.preference.Preference)4 PreferenceScreen (androidx.preference.PreferenceScreen)2