use of com.android.settings.AccessiblePreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AccountPreferenceControllerTest method onResume_oneProfile_shouldSetAccountTitleWithUserName.
@Test
public void onResume_oneProfile_shouldSetAccountTitleWithUserName() {
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", 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(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
mController.onResume();
verify(preferenceGroup).setTitle(mContext.getString(R.string.account_for_section_header, "user 1"));
}
use of com.android.settings.AccessiblePreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
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")));
}
use of com.android.settings.AccessiblePreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
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.isRestrictedProfile()).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("Account11", "com.acct1"), 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));
}
use of com.android.settings.AccessiblePreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AccountPreferenceControllerTest method onResume_noAccountChange_shouldNotAddAccountPreference.
@Test
public void onResume_noAccountChange_shouldNotAddAccountPreference() {
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);
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();
mController.onResume();
// each account should be added only once
verify(preferenceGroup).addPreference(argThat(titleMatches("Acct11")));
verify(preferenceGroup).addPreference(argThat(titleMatches("Acct12")));
}
use of com.android.settings.AccessiblePreferenceCategory in project android_packages_apps_Settings by omnirom.
the class AccountPreferenceController method updateProfileUi.
private void updateProfileUi(final UserInfo userInfo) {
if (mFragment.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(mFragment.getPreferenceManager().getContext());
preferenceGroup.setOrder(mAccountProfileOrder++);
// default title; may be modified below
preferenceGroup.setTitle(R.string.account_settings);
if (isSingleProfile()) {
final String title = context.getString(R.string.account_for_section_header, BidiFormatter.getInstance().unicodeWrap(userInfo.name));
preferenceGroup.setTitle(title);
preferenceGroup.setContentDescription(title);
} else if (userInfo.isManagedProfile()) {
if (mType == ProfileSelectFragment.ProfileType.ALL) {
preferenceGroup.setTitle(R.string.category_work);
final 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 {
if (mType == ProfileSelectFragment.ProfileType.ALL) {
preferenceGroup.setTitle(R.string.category_personal);
preferenceGroup.setContentDescription(mContext.getString(R.string.accessibility_category_personal));
}
}
final PreferenceScreen screen = mFragment.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);
}
Aggregations