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

Commit d066266e authored by Achim Thesmann's avatar Achim Thesmann
Browse files

Update tests to check start mode

Test: atest BackgroundActivityLaunchTest BackgroundActivityStartContriller*Test
Flag: com.android.window.flags.bal_additional_start_modes
Bug: 352182359
Change-Id: I4ec980b098c227b8a72c184d0c95feb19220b6ea
parent b2f054ae
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.server.wm;

import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED;
import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS;

import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_ALLOW;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_ALLOWLISTED_COMPONENT;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_FOREGROUND;
@@ -23,7 +26,6 @@ import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_SAW_PERMISSION;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_VISIBLE_WINDOW;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import static org.mockito.ArgumentMatchers.anyInt;
@@ -58,7 +60,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.quality.Strictness;

import java.lang.reflect.Field;
@@ -134,9 +135,8 @@ public class BackgroundActivityStartControllerExemptionTests {

    ActivityOptions mCheckedOptions = ActivityOptions.makeBasic()
            .setPendingIntentCreatorBackgroundActivityStartMode(
                    ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED)
            .setPendingIntentBackgroundActivityStartMode(
                    ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED);
                    MODE_BACKGROUND_ACTIVITY_START_ALLOWED)
            .setPendingIntentBackgroundActivityStartMode(MODE_BACKGROUND_ACTIVITY_START_ALLOWED);

    class TestableBackgroundActivityStartController extends BackgroundActivityStartController {
        private Set<Pair<Integer, Integer>> mBalPermissionUidPidPairs = new HashSet<>();
@@ -175,7 +175,6 @@ public class BackgroundActivityStartControllerExemptionTests {
        when(mService.getAppOpsManager()).thenReturn(mAppOpsManager);
        setViaReflection(mService, "mProcessMap", mProcessMap);

        //Mockito.when(mSupervisor.getBackgroundActivityLaunchController()).thenReturn(mController);
        setViaReflection(mSupervisor, "mRecentTasks", mRecentTasks);

        mController = new TestableBackgroundActivityStartController(mService, mSupervisor);
@@ -397,7 +396,7 @@ public class BackgroundActivityStartControllerExemptionTests {

        // setup state
        WindowProcessControllerMap mProcessMap = new WindowProcessControllerMap();
        WindowProcessController otherProcess = Mockito.mock(WindowProcessController.class);
        WindowProcessController otherProcess = mock(WindowProcessController.class);
        mProcessMap.put(callingPid, mCallerApp);
        mProcessMap.put(REGULAR_PID_1_1, otherProcess);
        setViaReflection(mService, "mProcessMap", mProcessMap);
@@ -516,14 +515,13 @@ public class BackgroundActivityStartControllerExemptionTests {
        BackgroundStartPrivileges forcedBalByPiSender = BackgroundStartPrivileges.NONE;
        Intent intent = TEST_INTENT;
        ActivityOptions checkedOptions = mCheckedOptions;
        checkedOptions.setPendingIntentBackgroundActivityLaunchAllowedByPermission(true);
        checkedOptions.setPendingIntentBackgroundActivityStartMode(
                MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS);
        BackgroundActivityStartController.BalState balState = mController.new BalState(callingUid,
                callingPid, callingPackage, realCallingUid, realCallingPid, null,
                originatingPendingIntent, forcedBalByPiSender, mResultRecord, intent,
                checkedOptions);

        assertThat(balState.isPendingIntentBalAllowedByPermission()).isTrue();

        // call
        BalVerdict realCallerVerdict = mController.checkBackgroundActivityStartAllowedBySender(
                balState);
+4 −2
Original line number Diff line number Diff line
@@ -547,7 +547,7 @@ public class BackgroundActivityStartControllerTests {
        assertThat(balState.callerExplicitOptInOrOut()).isFalse();
        assertThat(balState.realCallerExplicitOptInOrAutoOptIn()).isTrue();
        assertThat(balState.realCallerExplicitOptInOrOut()).isFalse();
        assertThat(balState.toString()).contains(
        assertThat(balState.toString()).startsWith(
                "[callingPackage: package.app1; "
                        + "callingPackageTargetSdk: -1; "
                        + "callingUid: 10001; "
@@ -563,6 +563,7 @@ public class BackgroundActivityStartControllerTests {
                        + "balAllowedByPiCreator: BSP.ALLOW_BAL; "
                        + "balAllowedByPiCreatorWithHardening: BSP.ALLOW_BAL; "
                        + "resultIfPiCreatorAllowsBal: null; "
                        + "callerStartMode: MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED; "
                        + "hasRealCaller: true; "
                        + "isCallForResult: false; "
                        + "isPendingIntent: false; "
@@ -646,7 +647,7 @@ public class BackgroundActivityStartControllerTests {
        assertThat(balState.callerExplicitOptInOrOut()).isFalse();
        assertThat(balState.realCallerExplicitOptInOrAutoOptIn()).isFalse();
        assertThat(balState.realCallerExplicitOptInOrOut()).isFalse();
        assertThat(balState.toString()).contains(
        assertThat(balState.toString()).startsWith(
                "[callingPackage: package.app1; "
                        + "callingPackageTargetSdk: -1; "
                        + "callingUid: 10001; "
@@ -662,6 +663,7 @@ public class BackgroundActivityStartControllerTests {
                        + "balAllowedByPiCreator: BSP.NONE; "
                        + "balAllowedByPiCreatorWithHardening: BSP.NONE; "
                        + "resultIfPiCreatorAllowsBal: null; "
                        + "callerStartMode: MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED; "
                        + "hasRealCaller: true; "
                        + "isCallForResult: false; "
                        + "isPendingIntent: true; "