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

Commit e2b1c973 authored by Manish Singh's avatar Manish Singh
Browse files

Add a filter to filter out private profile apps

This is needed for filtering out apps belonging to the private
profile user when showing in the Apps storage Settings page.

Bug: 317159160
Test: atest ApplicationsStateTest
Change-Id: I3ee3e7c02f6063beca12074b902c6bd497ea1761
parent b640ff83
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -1621,6 +1621,7 @@ public class ApplicationsState {
    }

    public static class AppEntry extends SizeInfo {
        @VisibleForTesting String mProfileType;
        @Nullable public final File apkFile;
        public final long id;
        public String label;
@@ -1647,11 +1648,6 @@ 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;
@@ -1692,11 +1688,21 @@ public class ApplicationsState {
                        () -> this.ensureLabelDescriptionLocked(context));
            }
            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();
            mProfileType = userInfo.userType;
            this.showInPersonalTab = shouldShowInPersonalTab(um, info.uid);
        }

        public boolean isClonedProfile() {
            return UserManager.USER_TYPE_PROFILE_CLONE.equals(mProfileType);
        }

        public boolean isManagedProfile() {
            return UserManager.USER_TYPE_PROFILE_MANAGED.equals(mProfileType);
        }

        public boolean isPrivateProfile() {
            return UserManager.USER_TYPE_PROFILE_PRIVATE.equals(mProfileType);
        }

        /**
@@ -1890,16 +1896,24 @@ public class ApplicationsState {
    };

    public static final AppFilter FILTER_WORK = new AppFilter() {
        private int mCurrentUser;

        @Override
        public void init() {
            mCurrentUser = ActivityManager.getCurrentUser();
        public void init() {}

        @Override
        public boolean filterApp(AppEntry entry) {
            return !entry.showInPersonalTab && entry.isManagedProfile();
        }
    };

    public static final AppFilter FILTER_PRIVATE_PROFILE = new AppFilter() {

        @Override
        public void init() {}

        @Override
        public boolean filterApp(AppEntry entry) {
            return !entry.showInPersonalTab;
            return !entry.showInPersonalTab && entry.isPrivateProfile();
        }
    };

+16 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.content.pm.ApplicationInfo;
import android.os.UserManager;

import org.junit.Before;
import org.junit.Test;
@@ -297,11 +298,26 @@ public class ApplicationsStateTest {
    @Test
    public void testPersonalAndWorkFiltersDisplaysCorrectApps() {
        mEntry.showInPersonalTab = true;
        mEntry.mProfileType = UserManager.USER_TYPE_FULL_SYSTEM;
        assertThat(ApplicationsState.FILTER_PERSONAL.filterApp(mEntry)).isTrue();
        assertThat(ApplicationsState.FILTER_WORK.filterApp(mEntry)).isFalse();

        mEntry.showInPersonalTab = false;
        mEntry.mProfileType = UserManager.USER_TYPE_PROFILE_MANAGED;
        assertThat(ApplicationsState.FILTER_PERSONAL.filterApp(mEntry)).isFalse();
        assertThat(ApplicationsState.FILTER_WORK.filterApp(mEntry)).isTrue();
    }

    @Test
    public void testPrivateProfileFilterDisplaysCorrectApps() {
        mEntry.showInPersonalTab = true;
        mEntry.mProfileType = UserManager.USER_TYPE_FULL_SYSTEM;
        assertThat(ApplicationsState.FILTER_PERSONAL.filterApp(mEntry)).isTrue();
        assertThat(ApplicationsState.FILTER_PRIVATE_PROFILE.filterApp(mEntry)).isFalse();

        mEntry.showInPersonalTab = false;
        mEntry.mProfileType = UserManager.USER_TYPE_PROFILE_PRIVATE;
        assertThat(ApplicationsState.FILTER_PERSONAL.filterApp(mEntry)).isFalse();
        assertThat(ApplicationsState.FILTER_PRIVATE_PROFILE.filterApp(mEntry)).isTrue();
    }
}