Loading src/com/android/settings/accounts/AccountPreferenceController.java +5 −0 Original line number Diff line number Diff line Loading @@ -299,6 +299,11 @@ public class AccountPreferenceController extends PreferenceController final ProfileData data = mProfiles.get(userInfo.id); if (data != null) { data.pendingRemoval = false; 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; Loading tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java +36 −0 Original line number Diff line number Diff line Loading @@ -491,6 +491,42 @@ public class AccountPreferenceControllerTest { verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct13"))); } @Test @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class}) 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(new PreferenceMatcher("Acct1"))); } @Test @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class}) public void onResume_oneAccountRemoved_shouldRemoveOneAccountPreference() { Loading Loading
src/com/android/settings/accounts/AccountPreferenceController.java +5 −0 Original line number Diff line number Diff line Loading @@ -299,6 +299,11 @@ public class AccountPreferenceController extends PreferenceController final ProfileData data = mProfiles.get(userInfo.id); if (data != null) { data.pendingRemoval = false; 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; Loading
tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java +36 −0 Original line number Diff line number Diff line Loading @@ -491,6 +491,42 @@ public class AccountPreferenceControllerTest { verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct13"))); } @Test @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class}) 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(new PreferenceMatcher("Acct1"))); } @Test @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class}) public void onResume_oneAccountRemoved_shouldRemoveOneAccountPreference() { Loading