Loading src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java +3 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnDismissListener; import android.content.DialogInterface.OnShowListener; import android.content.Intent; import android.content.pm.UserInfo; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; Loading Loading @@ -168,7 +169,8 @@ public class ProfileSelectDialog extends DialogFragment implements UserAdapter.O } final UserManager userManager = UserManager.get(context); for (int i = userHandles.size() - 1; i >= 0; i--) { if (userManager.getUserInfo(userHandles.get(i).getIdentifier()) == null) { UserInfo userInfo = userManager.getUserInfo(userHandles.get(i).getIdentifier()); if (userInfo == null || userInfo.isCloneProfile()) { if (DEBUG) { Log.d(TAG, "Delete the user: " + userHandles.get(i).getIdentifier()); } Loading tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ public class ProfileSelectDialogTest { private static final UserHandle NORMAL_USER = new UserHandle(1111); private static final UserHandle REMOVED_USER = new UserHandle(2222); private static final UserHandle CLONE_USER = new UserHandle(3333); @Spy private Context mContext = ApplicationProvider.getApplicationContext(); Loading Loading @@ -101,6 +102,22 @@ public class ProfileSelectDialogTest { verify(mUserManager, times(2)).getUserInfo(REMOVED_USER.getIdentifier()); } @Test public void updateUserHandlesIfNeeded_removesCloneProfile() { final UserInfo userInfo = new UserInfo(CLONE_USER.getIdentifier(), "clone_user", null, UserInfo.FLAG_PROFILE, UserManager.USER_TYPE_PROFILE_CLONE); when(mUserManager.getUserInfo(CLONE_USER.getIdentifier())).thenReturn(userInfo); final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); tile.userHandle.add(CLONE_USER); tile.userHandle.add(NORMAL_USER); ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile); assertThat(tile.userHandle).hasSize(1); assertThat(tile.userHandle.get(0).getIdentifier()).isEqualTo(NORMAL_USER.getIdentifier()); verify(mUserManager, times(1)).getUserInfo(CLONE_USER.getIdentifier()); } @Test public void createDialog_showsCorrectTitle() { mContext.setTheme(R.style.Theme_AppCompat); Loading Loading
src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java +3 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnDismissListener; import android.content.DialogInterface.OnShowListener; import android.content.Intent; import android.content.pm.UserInfo; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; Loading Loading @@ -168,7 +169,8 @@ public class ProfileSelectDialog extends DialogFragment implements UserAdapter.O } final UserManager userManager = UserManager.get(context); for (int i = userHandles.size() - 1; i >= 0; i--) { if (userManager.getUserInfo(userHandles.get(i).getIdentifier()) == null) { UserInfo userInfo = userManager.getUserInfo(userHandles.get(i).getIdentifier()); if (userInfo == null || userInfo.isCloneProfile()) { if (DEBUG) { Log.d(TAG, "Delete the user: " + userHandles.get(i).getIdentifier()); } Loading
tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ public class ProfileSelectDialogTest { private static final UserHandle NORMAL_USER = new UserHandle(1111); private static final UserHandle REMOVED_USER = new UserHandle(2222); private static final UserHandle CLONE_USER = new UserHandle(3333); @Spy private Context mContext = ApplicationProvider.getApplicationContext(); Loading Loading @@ -101,6 +102,22 @@ public class ProfileSelectDialogTest { verify(mUserManager, times(2)).getUserInfo(REMOVED_USER.getIdentifier()); } @Test public void updateUserHandlesIfNeeded_removesCloneProfile() { final UserInfo userInfo = new UserInfo(CLONE_USER.getIdentifier(), "clone_user", null, UserInfo.FLAG_PROFILE, UserManager.USER_TYPE_PROFILE_CLONE); when(mUserManager.getUserInfo(CLONE_USER.getIdentifier())).thenReturn(userInfo); final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); tile.userHandle.add(CLONE_USER); tile.userHandle.add(NORMAL_USER); ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile); assertThat(tile.userHandle).hasSize(1); assertThat(tile.userHandle.get(0).getIdentifier()).isEqualTo(NORMAL_USER.getIdentifier()); verify(mUserManager, times(1)).getUserInfo(CLONE_USER.getIdentifier()); } @Test public void createDialog_showsCorrectTitle() { mContext.setTheme(R.style.Theme_AppCompat); Loading