From: Doris Ling Date: Wed, 17 May 2017 00:23:55 +0000 (-0700) Subject: Fix issue for new account not being shown in work profile. X-Git-Tag: android-x86-9.0-r1~1062^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=71090678c0038cc87db8132be4739ec0bc6279ac;p=android-x86%2Fpackages-apps-Settings.git Fix issue for new account not being shown in work profile. When refreshing the UI, we tried to only create profile data for new profile, and skip the initialization for existing profiles. However, the authentication helper will not get the updated account list, since the account update listener is being paused. Re-create the authentication helper to get the latest list of enabled accounts. Change-Id: Ie29699456e5b32747e8158d51382afaa2c0c5908 Fix: 38302246 Test: make RunSettingsRoboTests --- diff --git a/src/com/android/settings/accounts/AccountPreferenceController.java b/src/com/android/settings/accounts/AccountPreferenceController.java index 2801f045a1..fdb13a42e9 100644 --- a/src/com/android/settings/accounts/AccountPreferenceController.java +++ b/src/com/android/settings/accounts/AccountPreferenceController.java @@ -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; diff --git a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java index 8453da5c58..17f1ab48f4 100644 --- a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java @@ -448,6 +448,42 @@ public class AccountPreferenceControllerTest { @Test @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class}) + public void onResume_oneNewAccountType_shouldAddOneAccountPreference() { + final List 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() { final List infos = new ArrayList<>(); infos.add(new UserInfo(1, "user 1", 0));