From 93049776741f7d5ea9d52c842a365dc73468a929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAnkita?= Date: Tue, 15 Nov 2022 05:47:08 +0000 Subject: [PATCH] Do not show Choose Profile dialog for clone user. Bug: 249194639 Test: make RunSettingsRoboTests -j64 Test: make RunSettingsRoboTests ROBOTEST_FILTER=ProfileSelectDialogTest Change-Id: I35279f643f8c562df7b407fdf2cbfd2ae5ee9890 --- .../profileselector/ProfileSelectDialog.java | 4 +++- .../ProfileSelectDialogTest.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java index f82694c5841..ef6ad832477 100644 --- a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java +++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java @@ -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; @@ -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()); } diff --git a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java index e1cf52b995b..4e81ceeb437 100644 --- a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java @@ -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(); @@ -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);