Merge "Add isCloned variable in AppEntry"

This commit is contained in:
Ankita Vyas
2022-11-28 15:41:37 +00:00
committed by Android (Google) Code Review
2 changed files with 20 additions and 9 deletions

View File

@@ -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.

View File

@@ -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();
}
}