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

Commit 30fc8e6e authored by Manish Singh's avatar Manish Singh Committed by Android (Google) Code Review
Browse files

Merge "Add flag guard and fix test" into main

parents 3fdca447 0889f847
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1702,7 +1702,8 @@ public class ApplicationsState {
        }

        public boolean isPrivateProfile() {
            return UserManager.USER_TYPE_PROFILE_PRIVATE.equals(mProfileType);
            return android.os.Flags.allowPrivateProfile()
                    && UserManager.USER_TYPE_PROFILE_PRIVATE.equals(mProfileType);
        }

        /**
+23 −2
Original line number Diff line number Diff line
@@ -22,21 +22,30 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.content.pm.ApplicationInfo;
import android.os.Flags;
import android.os.UserManager;
import android.platform.test.flag.junit.SetFlagsRule;

import androidx.test.core.app.ApplicationProvider;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class ApplicationsStateTest {
    private static final int APP_ENTRY_ID = 1;
    private ApplicationsState.AppEntry mEntry;
    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Before
    public void setUp() {
        mEntry = mock(ApplicationsState.AppEntry.class);
        mEntry.info = mock(ApplicationInfo.class);
        mEntry = new ApplicationsState.AppEntry(
                ApplicationProvider.getApplicationContext(),
                mock(ApplicationInfo.class),
                APP_ENTRY_ID);
    }

    @Test
@@ -310,6 +319,8 @@ public class ApplicationsStateTest {

    @Test
    public void testPrivateProfileFilterDisplaysCorrectApps() {
        mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);

        mEntry.showInPersonalTab = true;
        mEntry.mProfileType = UserManager.USER_TYPE_FULL_SYSTEM;
        assertThat(ApplicationsState.FILTER_PERSONAL.filterApp(mEntry)).isTrue();
@@ -320,4 +331,14 @@ public class ApplicationsStateTest {
        assertThat(ApplicationsState.FILTER_PERSONAL.filterApp(mEntry)).isFalse();
        assertThat(ApplicationsState.FILTER_PRIVATE_PROFILE.filterApp(mEntry)).isTrue();
    }

    @Test
    public void testPrivateProfileFilterDisplaysCorrectAppsWhenFlagDisabled() {
        mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);

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