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

Commit 0889f847 authored by Manish Singh's avatar Manish Singh
Browse files

Add flag guard and fix test

Bug: 317159160
Test: atest ApplicationsStateTest
Change-Id: If10300b88f9ef6c9f16d3dfdea870304327399a5
parent e2b1c973
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();
    }
}