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

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

Consider app switch state for real caller.

The app switch state was ignored for the real caller, which cause the
real caller check to return allow while the caller check blocked for the
same condition. This fix is neccessary to require creator opt in with a
consistent behavior.

Bug: 296478951
Test: atest BackgroundActivityLaunchTest
Change-Id: I7a093369f52bd9d99c51b9c2d7b5a244fb9d7bc5
parent 4dadb089
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.Preconditions;
import com.android.server.UiThread;
import com.android.server.am.PendingIntentRecord;
import com.android.window.flags.Flags;

import java.lang.annotation.Retention;
import java.util.HashMap;
@@ -807,6 +808,20 @@ public class BackgroundActivityStartController {
                    "realCallingUid has BAL permission.");
        }

        // Normal apps with visible app window will be allowed to start activity if app switching
        // is allowed, or apps like live wallpaper with non app visible window will be allowed.
        final boolean appSwitchAllowedOrFg = state.mAppSwitchState == APP_SWITCH_ALLOW
                || state.mAppSwitchState == APP_SWITCH_FG_ONLY;
        if (Flags.balImproveRealCallerVisibilityCheck()) {
            if (appSwitchAllowedOrFg && state.mRealCallingUidHasAnyVisibleWindow) {
                return new BalVerdict(BAL_ALLOW_PENDING_INTENT,
                        /*background*/ false, "realCallingUid has visible window");
            }
            if (mService.mActiveUids.hasNonAppVisibleWindow(state.mRealCallingUid)) {
                return new BalVerdict(BAL_ALLOW_PENDING_INTENT,
                        /*background*/ false, "realCallingUid has non-app visible window");
            }
        } else {
            // don't abort if the realCallingUid has a visible window
            // TODO(b/171459802): We should check appSwitchAllowed also
            if (state.mRealCallingUidHasAnyVisibleWindow) {
@@ -814,6 +829,8 @@ public class BackgroundActivityStartController {
                        /*background*/ false,
                        "realCallingUid has visible (non-toast) window.");
            }
        }

        // if the realCallingUid is a persistent system process, abort if the IntentSender
        // wasn't allowed to start an activity
        if (state.mForcedBalByPiSender.allowsBackgroundActivityStarts()