From f45e70094b997e0d399a4454b97795d853a2c700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAnkita?= Date: Sun, 20 Nov 2022 08:41:30 +0000 Subject: [PATCH] Add isCloned variable in AppEntry Bug: 259021576 Test: robo test Change-Id: I15629045f19a7221280b04e720dbdc6501d4dd04 --- .../applications/ApplicationsState.java | 15 ++++++++++++--- .../applications/ApplicationsStateRoboTest.java | 14 ++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java index 65c94cec60092..ca5f57d3d6973 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java @@ -1598,6 +1598,11 @@ public class ApplicationsState { */ public boolean isHomeApp; + /** + * Whether or not it's a cloned app . + */ + public boolean isCloned; + public String getNormalizedLabel() { if (normalizedLabel != null) { return normalizedLabel; @@ -1637,7 +1642,12 @@ public class ApplicationsState { ThreadUtils.postOnBackgroundThread( () -> this.ensureLabelDescriptionLocked(context)); } - this.showInPersonalTab = shouldShowInPersonalTab(context, info.uid); + UserManager um = UserManager.get(context); + this.showInPersonalTab = shouldShowInPersonalTab(um, info.uid); + UserInfo userInfo = um.getUserInfo(UserHandle.getUserId(info.uid)); + if (userInfo != null) { + this.isCloned = userInfo.isCloneProfile(); + } } /** @@ -1645,8 +1655,7 @@ public class ApplicationsState { * {@link UserProperties#SHOW_IN_SETTINGS_WITH_PARENT} set. */ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) - boolean shouldShowInPersonalTab(Context context, int uid) { - UserManager userManager = UserManager.get(context); + boolean shouldShowInPersonalTab(UserManager userManager, int uid) { int userId = UserHandle.getUserId(uid); // Regardless of apk version, if the app belongs to the current user then return true. diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/ApplicationsStateRoboTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/ApplicationsStateRoboTest.java index 39875f7950e4d..96e64ea1de71f 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/ApplicationsStateRoboTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/ApplicationsStateRoboTest.java @@ -755,28 +755,30 @@ public class ApplicationsStateRoboTest { @Test public void shouldShowInPersonalTab_forCurrentUser_returnsTrue() { + UserManager um = RuntimeEnvironment.application.getSystemService(UserManager.class); ApplicationInfo appInfo = createApplicationInfo(PKG_1); AppEntry primaryUserApp = createAppEntry(appInfo, 1); - assertThat(primaryUserApp.shouldShowInPersonalTab(mContext, appInfo.uid)).isTrue(); + assertThat(primaryUserApp.shouldShowInPersonalTab(um, appInfo.uid)).isTrue(); } @Test public void shouldShowInPersonalTab_userProfilePreU_returnsFalse() { + UserManager um = RuntimeEnvironment.application.getSystemService(UserManager.class); ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.TIRAMISU); // Create an app (and subsequent AppEntry) in a non-primary user profile. ApplicationInfo appInfo1 = createApplicationInfo(PKG_1, PROFILE_UID_1); AppEntry nonPrimaryUserApp = createAppEntry(appInfo1, 1); - assertThat(nonPrimaryUserApp.shouldShowInPersonalTab(mContext, appInfo1.uid)).isFalse(); + assertThat(nonPrimaryUserApp.shouldShowInPersonalTab(um, appInfo1.uid)).isFalse(); } @Test public void shouldShowInPersonalTab_currentUserIsParent_returnsAsPerUserPropertyOfProfile1() { // Mark system user as parent for both profile users. - ShadowUserManager shadowUserManager = Shadow - .extract(RuntimeEnvironment.application.getSystemService(UserManager.class)); + UserManager um = RuntimeEnvironment.application.getSystemService(UserManager.class); + ShadowUserManager shadowUserManager = Shadow.extract(um); shadowUserManager.addProfile(USER_SYSTEM, PROFILE_USERID, CLONE_USER, 0); shadowUserManager.addProfile(USER_SYSTEM, PROFILE_USERID2, @@ -796,7 +798,7 @@ public class ApplicationsStateRoboTest { AppEntry nonPrimaryUserApp1 = createAppEntry(appInfo1, 1); AppEntry nonPrimaryUserApp2 = createAppEntry(appInfo2, 2); - assertThat(nonPrimaryUserApp1.shouldShowInPersonalTab(mContext, appInfo1.uid)).isTrue(); - assertThat(nonPrimaryUserApp2.shouldShowInPersonalTab(mContext, appInfo2.uid)).isFalse(); + assertThat(nonPrimaryUserApp1.shouldShowInPersonalTab(um, appInfo1.uid)).isTrue(); + assertThat(nonPrimaryUserApp2.shouldShowInPersonalTab(um, appInfo2.uid)).isFalse(); } }