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

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

Deprecate and remove ProcessStateRecord.mAllowStartFgsState field.

Its functionality can be fully covered by mCurProcState.

Also dump allowStartForeground in human-readable string.

Bug: NA.
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java
Change-Id: Ib76185f5a93ac37bd902a719ed7a347d85fecfde
parent 38b22faf
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -6621,8 +6621,8 @@ public final class ActiveServices {
            final Integer allowedType = mAm.mProcessList.searchEachLruProcessesLOSP(false, app -> {
                if (app.uid == callingUid) {
                    final ProcessStateRecord state = app.mState;
                    if (state.isAllowedStartFgsState()) {
                        return getReasonCodeFromProcState(state.getAllowStartFgsState());
                    if (state.isAllowedStartFgs()) {
                        return getReasonCodeFromProcState(state.getCurProcState());
                    } else {
                        final ActiveInstrumentation instr = app.getActiveInstrumentation();
                        if (instr != null
+0 −7
Original line number Diff line number Diff line
@@ -1478,7 +1478,6 @@ public class OomAdjuster {
        state.setAdjTarget(null);
        state.setEmpty(false);
        state.setCached(false);
        state.resetAllowStartFgsState();
        if (!cycleReEval) {
            // Don't reset this flag when doing cycles re-evaluation.
            state.setNoKillOnBgRestrictedAndIdle(false);
@@ -1537,7 +1536,6 @@ public class OomAdjuster {
            state.setCurRawProcState(state.getCurProcState());
            state.setCurAdj(state.getMaxAdj());
            state.setCompletedAdjSeq(state.getAdjSeq());
            state.bumpAllowStartFgsState(state.getCurProcState());
            // if curAdj is less than prevAppAdj, then this process was promoted
            return state.getCurAdj() < prevAppAdj || state.getCurProcState() < prevProcState;
        }
@@ -1563,7 +1561,6 @@ public class OomAdjuster {
            foregroundActivities = true;
            hasVisibleActivities = true;
            procState = PROCESS_STATE_CUR_TOP;
            state.bumpAllowStartFgsState(PROCESS_STATE_TOP);
            if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
                reportOomAdjMessageLocked(TAG_OOM_ADJ, "Making top: " + app);
            }
@@ -1661,7 +1658,6 @@ public class OomAdjuster {
                // The user is aware of this app, so make it visible.
                adj = ProcessList.PERCEPTIBLE_APP_ADJ;
                procState = PROCESS_STATE_FOREGROUND_SERVICE;
                state.bumpAllowStartFgsState(PROCESS_STATE_FOREGROUND_SERVICE);
                state.setAdjType("fg-service");
                state.setCached(false);
                schedGroup = ProcessList.SCHED_GROUP_DEFAULT;
@@ -2103,8 +2099,6 @@ public class OomAdjuster {
                                // give them the best bound state after that.
                                if (cr.hasFlag(Context.BIND_FOREGROUND_SERVICE)) {
                                    clientProcState = PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
                                    state.bumpAllowStartFgsState(
                                            PROCESS_STATE_BOUND_FOREGROUND_SERVICE);
                                } else if (mService.mWakefulness.get()
                                        == PowerManagerInternal.WAKEFULNESS_AWAKE
                                        && (cr.flags & Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE)
@@ -2118,7 +2112,6 @@ public class OomAdjuster {
                                // Go at most to BOUND_TOP, unless requested to elevate
                                // to client's state.
                                clientProcState = PROCESS_STATE_BOUND_TOP;
                                state.bumpAllowStartFgsState(PROCESS_STATE_BOUND_TOP);
                                final boolean enabled = cstate.getCachedCompatChange(
                                        CACHED_COMPAT_CHANGE_PROCESS_CAPABILITY);
                                if (enabled) {
+3 −30
Original line number Diff line number Diff line
@@ -295,13 +295,6 @@ final class ProcessStateRecord {
    @GuardedBy("mService")
    private boolean mSystemNoUi;

    /**
     * If the proc state is PROCESS_STATE_BOUND_FOREGROUND_SERVICE or above, it can start FGS.
     * It must obtain the proc state from a persistent/top process or FGS, not transitive.
     */
    @GuardedBy("mService")
    private int mAllowStartFgsState = PROCESS_STATE_NONEXISTENT;

    /**
     * Whether or not the app is background restricted (OP_RUN_ANY_IN_BACKGROUND is NOT allowed).
     */
@@ -1165,33 +1158,15 @@ final class ProcessStateRecord {
        mCurRawAdj = mSetRawAdj = mCurAdj = mSetAdj = mVerifiedAdj = ProcessList.INVALID_ADJ;
        mCurCapability = mSetCapability = PROCESS_CAPABILITY_NONE;
        mCurSchedGroup = mSetSchedGroup = ProcessList.SCHED_GROUP_BACKGROUND;
        mCurProcState = mCurRawProcState = mSetProcState = mAllowStartFgsState =
                PROCESS_STATE_NONEXISTENT;
        mCurProcState = mCurRawProcState = mSetProcState = PROCESS_STATE_NONEXISTENT;
        for (int i = 0; i < mCachedCompatChanges.length; i++) {
            mCachedCompatChanges[i] = VALUE_INVALID;
        }
    }

    @GuardedBy("mService")
    void resetAllowStartFgsState() {
        mAllowStartFgsState = PROCESS_STATE_NONEXISTENT;
    }

    @GuardedBy("mService")
    void bumpAllowStartFgsState(int newProcState) {
        if (newProcState < mAllowStartFgsState) {
            mAllowStartFgsState = newProcState;
        }
    }

    @GuardedBy("mService")
    int getAllowStartFgsState() {
        return mAllowStartFgsState;
    }

    @GuardedBy("mService")
    boolean isAllowedStartFgsState() {
        return mAllowStartFgsState <= PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
    boolean isAllowedStartFgs() {
        return mCurProcState <= PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
    }

    @GuardedBy("mService")
@@ -1331,8 +1306,6 @@ final class ProcessStateRecord {
        pw.print(" setCapability=");
        ActivityManager.printCapabilitiesFull(pw, mSetCapability);
        pw.println();
        pw.print(prefix); pw.print("allowStartFgsState=");
        pw.print(mAllowStartFgsState);
        if (mBackgroundRestricted) {
            pw.print(" backgroundRestricted=");
            pw.print(mBackgroundRestricted);
+1 −1
Original line number Diff line number Diff line
@@ -488,7 +488,7 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
        pw.print(prefix); pw.print("recentCallingUid=");
        pw.println(mRecentCallingUid);
        pw.print(prefix); pw.print("allowStartForeground=");
        pw.println(mAllowStartForeground);
        pw.println(PowerExemptionManager.reasonCodeToString(mAllowStartForeground));
        pw.print(prefix); pw.print("startForegroundCount=");
        pw.println(mStartForegroundCount);
        pw.print(prefix); pw.print("infoAllowStartForeground=");