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

Commit ca7b4a14 authored by Hui Yu's avatar Hui Yu
Browse files

Add param isCheckingForFgsStart to areBackgroundActivityStartsAllowed().

If isCheckingForFgsStart is true, this checking is for FGS start, it
won't invoke the mBackgroundActivityStartCallback.

Bug: 177642703
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java
Change-Id: Ie6d58b8886e8477a9dbc524d43ccda930139a460
parent a6480854
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5373,7 +5373,7 @@ public final class ActiveServices {
            for (int i = mAm.mProcessList.mLruProcesses.size() - 1; i >= 0; i--) {
                final ProcessRecord pr = mAm.mProcessList.mLruProcesses.get(i);
                if (pr.uid == callingUid) {
                    if (pr.getWindowProcessController().areBackgroundActivityStartsAllowed()) {
                    if (pr.getWindowProcessController().areBackgroundFgsStartsAllowed()) {
                        ret = FGS_FEATURE_ALLOWED_BY_ACTIVITY_STARTER;
                        break;
                    }
+21 −6
Original line number Diff line number Diff line
@@ -519,13 +519,21 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
        }
    }

    public boolean areBackgroundActivityStartsAllowed() {
    /**
     * Is this WindowProcessController in the state of allowing background FGS start?
     */
    public boolean areBackgroundFgsStartsAllowed() {
        synchronized (mAtm.mGlobalLock) {
            return areBackgroundActivityStartsAllowed(mAtm.getBalAppSwitchesAllowed());
            return areBackgroundActivityStartsAllowed(mAtm.getBalAppSwitchesAllowed(), true);
        }
    }

    boolean areBackgroundActivityStartsAllowed(boolean appSwitchAllowed) {
        return areBackgroundActivityStartsAllowed(appSwitchAllowed, false);
    }

    boolean areBackgroundActivityStartsAllowed(boolean appSwitchAllowed,
            boolean isCheckingForFgsStart) {
        // If app switching is not allowed, we ignore all the start activity grace period
        // exception so apps cannot start itself in onPause() after pressing home button.
        if (appSwitchAllowed) {
@@ -579,7 +587,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
            return true;
        }
        // allow if the flag was explicitly set
        if (isBackgroundStartAllowedByToken()) {
        if (isBackgroundStartAllowedByToken(isCheckingForFgsStart)) {
            if (DEBUG_ACTIVITY_STARTS) {
                Slog.d(TAG, "[WindowProcessController(" + mPid
                        + ")] Activity start allowed: process allowed by token");
@@ -590,13 +598,20 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    }

    /**
     * If there are no tokens, we don't allow *by token*. If there are tokens, we ask the callback
     * if the start is allowed for these tokens, otherwise if there is no callback we allow.
     * If there are no tokens, we don't allow *by token*. If there are tokens and
     * isCheckingForFgsStart is false, we ask the callback if the start is allowed for these tokens,
     * otherwise if there is no callback we allow.
     */
    private boolean isBackgroundStartAllowedByToken() {
    private boolean isBackgroundStartAllowedByToken(boolean isCheckingForFgsStart) {
        if (mBackgroundActivityStartTokens.isEmpty()) {
            return false;
        }

        if (isCheckingForFgsStart) {
            /// The checking is for BG-FGS-start.
            return true;
        }

        if (mBackgroundActivityStartCallback == null) {
            // We have tokens but no callback to decide => allow
            return true;