Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ae8fc3e authored by Ankita Vyas's avatar Ankita Vyas Committed by Android (Google) Code Review
Browse files

Merge "Add isCloned variable in AppEntry"

parents d39c54a1 f45e7009
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -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.
+8 −6
Original line number Diff line number Diff line
@@ -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();
    }
}