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

Commit add81472 authored by Nan Wu's avatar Nan Wu
Browse files

Prevent BAL when app switch state is BAL disallow

This specifically fix when the PI sender binds to PI caller and PI
sender is visible and opt in. However, if the app switch state is BAL
disallow, we should still stop BAL.

Test: manual test. BackgroundActivityLaunchTest
Bug: 283801068
Change-Id: Iaeb4bc849e221aa997cae2126e81b34a58acbc5e
parent 4de6bb88
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -41,3 +41,10 @@ flag {
    description: "Prevent a task to restart based on a visible window during task switch."
    bug: "171459802"
}

flag {
    name: "bal_respect_app_switch_state_when_check_bound_by_foreground_uid"
    namespace: "responsible_apis"
    description: "Prevent BAL based on it is bound by foreground Uid but the app switch is stopped."
    bug: "171459802"
}
+9 −4
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.ActivityTaskManagerService.ACTIVITY_BG_START_GRACE_PERIOD_MS;
import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_ALLOW;
import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_FG_ONLY;
import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_DISALLOW;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_FOREGROUND;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_GRACE_PERIOD;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_PERMISSION;
@@ -49,6 +49,7 @@ import android.util.Slog;

import com.android.internal.annotations.GuardedBy;
import com.android.server.wm.BackgroundActivityStartController.BalVerdict;
import com.android.window.flags.Flags;

import java.io.PrintWriter;
import java.util.ArrayList;
@@ -113,13 +114,17 @@ class BackgroundLaunchProcessController {
                    "process allowed by token");
        }
        // Allow if the caller is bound by a UID that's currently foreground.
        if (isBoundByForegroundUid()) {
        // But still respect the appSwitchState.
        boolean allowBoundByForegroundUid =
                Flags.balRespectAppSwitchStateWhenCheckBoundByForegroundUid()
                ? appSwitchState != APP_SWITCH_DISALLOW && isBoundByForegroundUid()
                : isBoundByForegroundUid();
        if (allowBoundByForegroundUid) {
            return new BalVerdict(BAL_ALLOW_VISIBLE_WINDOW, /*background*/ false,
                    "process bound by foreground uid");
        }
        // Allow if the caller has an activity in any foreground task.
        if (hasActivityInVisibleTask
                && (appSwitchState == APP_SWITCH_ALLOW || appSwitchState == APP_SWITCH_FG_ONLY)) {
        if (hasActivityInVisibleTask && appSwitchState != APP_SWITCH_DISALLOW) {
            return new BalVerdict(BAL_ALLOW_FOREGROUND, /*background*/ false,
                    "process has activity in foreground task");
        }