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

Commit e00160af authored by Chih-Yu Huang's avatar Chih-Yu Huang
Browse files

ProcessStateRecord: Publicize and document API

Publicized methods in ProcessStateRecord and added Javadoc for
non-trivial public APIs. This is the preparation for moving the class
into psc package.

Bug: 425766486
Test: m services.core
Test: atest MockingOomAdjusterTests OomAdjusterTests
Test: atest FrameworksServicesTestsRavenwood_ProcessStateController
Test: prebuilts/checkstyle/checkstyle.py --file ProcessStateRecord.java
Flag: EXEMPT pure refactor

Change-Id: Ia6aeeec93725a1cf49d4e225ef122a3cf51a4428
parent 2167e20c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8835,7 +8835,7 @@ public final class ActiveServices {
                    if (uidRecord != null) {
                        for (int i = uidRecord.getNumOfProcs() - 1; i >= 0; i--) {
                            final ProcessRecord pr = uidRecord.getProcessRecordByIndex(i);
                            if (pr != null && pr.mState.hasOverlayUi()) {
                            if (pr != null && pr.mState.getHasOverlayUi()) {
                                ret = REASON_SYSTEM_ALERT_WINDOW_PERMISSION;
                                break;
                            }
+4 −3
Original line number Diff line number Diff line
@@ -6696,7 +6696,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                        // that here (pre-V versions will be checked in the conditional below)
                        // Starting Android V, only allow the app to schedule a user-initiated job
                        // if it's granted the permission and currently showing an overlay window
                        if (pr != null && pr.mState.hasOverlayUi()) {
                        if (pr != null && pr.mState.getHasOverlayUi()) {
                            return true;
                        }
                    }
@@ -16792,7 +16792,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                            continue;
                        }
                        if (app.isRemoved()
                                || (app.userId == userId && app.mState.hasForegroundActivities())) {
                                || (app.userId == userId
                                        && app.mState.getHasForegroundActivities())) {
                            procs.add(app);
                        }
                    }
@@ -17098,7 +17099,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                    final ProcessRecord pr = (ProcessRecord) wpc.mOwner;
                    if (ActivityManager.isProcStateBackground(pr.mState.getSetProcState())
                            && !pr.mReceivers.isReceivingBroadcast()
                            && !pr.mState.hasStartedServices()) {
                            && !pr.mState.getHasStartedServices()) {
                        pr.killLocked("remove task", ApplicationExitInfo.REASON_USER_REQUESTED,
                                ApplicationExitInfo.SUBREASON_REMOVE_TASK, true);
                    } else {
+2 −2
Original line number Diff line number Diff line
@@ -1402,8 +1402,8 @@ public class AppProfiler {
                    final ProcessProfileRecord profile = app.mProfile;
                    final IApplicationThread thread;
                    final ProcessStateRecord state = app.mState;
                    if (state.hasProcStateChanged()) {
                        state.setProcStateChanged(false);
                    if (state.getHasProcStateChanged()) {
                        state.setHasProcStateChanged(false);
                    }
                    int procState = app.mState.getCurProcState();
                    if (((procState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
+13 −13
Original line number Diff line number Diff line
@@ -970,14 +970,14 @@ public abstract class OomAdjuster {
                    state.setCurAdj(nextPreviousAppAdj);
                    nextPreviousAppAdj = Math.min(nextPreviousAppAdj + 1, PREVIOUS_APP_MAX_ADJ);
                } else if (!app.isKilledByAm() && app.getThread() != null && (curAdj >= UNKNOWN_ADJ
                            || (state.hasShownUi() && curAdj >= CACHED_APP_MIN_ADJ))) {
                            || (state.getHasShownUi() && curAdj >= CACHED_APP_MIN_ADJ))) {
                    final ProcessServiceRecord psr = app.mServices;
                    int targetAdj = CACHED_APP_MIN_ADJ;

                    if (opt != null && opt.isFreezeExempt()) {
                        // BIND_WAIVE_PRIORITY and the like get oom_adj 900
                        targetAdj += 0;
                    } else if (state.hasShownUi() && uiTargetAdj < uiTierMaxAdj) {
                    } else if (state.getHasShownUi() && uiTargetAdj < uiTierMaxAdj) {
                        // The most recent UI-showing apps get [910, 910 + ui tier size).
                        targetAdj += uiTargetAdj++;
                    } else if ((state.getSetAdj() >= CACHED_APP_MIN_ADJ)
@@ -1886,7 +1886,7 @@ public abstract class OomAdjuster {
        // restrictions on screen off
        if (state.getCurProcState() >= PROCESS_STATE_BOUND_FOREGROUND_SERVICE
                && !isDeviceFullyAwake()
                && !state.shouldScheduleLikeTopApp()) {
                && !state.getScheduleLikeTopApp()) {
            if (schedGroup > SCHED_GROUP_RESTRICTED) {
                schedGroup = SCHED_GROUP_RESTRICTED;
            }
@@ -2105,7 +2105,7 @@ public abstract class OomAdjuster {
        final int curSchedGroup = state.getCurrentSchedulingGroup();
        if (app.getWaitingToKill() != null && !app.mReceivers.isReceivingBroadcast()
                && ActivityManager.isProcStateBackground(state.getCurProcState())
                && !state.hasStartedServices()) {
                && !state.getHasStartedServices()) {
            app.killLocked(app.getWaitingToKill(), ApplicationExitInfo.REASON_USER_REQUESTED,
                    ApplicationExitInfo.SUBREASON_REMOVE_TASK, true);
            success = false;
@@ -2183,8 +2183,8 @@ public abstract class OomAdjuster {
                }
            }
        }
        if (state.hasRepForegroundActivities() != state.hasForegroundActivities()) {
            state.setRepForegroundActivities(state.hasForegroundActivities());
        if (state.getHasRepForegroundActivities() != state.getHasForegroundActivities()) {
            state.setRepForegroundActivities(state.getHasForegroundActivities());
            changes |= ActivityManagerService.ProcessChangeItem.CHANGE_ACTIVITIES;
        }

@@ -2252,9 +2252,9 @@ public abstract class OomAdjuster {
                            mService.mProcessStats.getMemFactorLocked());
                }
            } else {
                state.setProcStateChanged(true);
                state.setHasProcStateChanged(true);
            }
        } else if (state.hasReportedInteraction()) {
        } else if (state.getHasReportedInteraction()) {
            final boolean fgsInteractionChangeEnabled = state.getCachedCompatChange(
                    CACHED_COMPAT_CHANGE_USE_SHORT_FGS_USAGE_INTERACTION_TIME);
            final long interactionThreshold = fgsInteractionChangeEnabled
@@ -2298,11 +2298,11 @@ public abstract class OomAdjuster {
            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG_PROCESS_OBSERVERS,
                    "Changes in " + app + ": " + changes);
            mProcessList.enqueueProcessChangeItemLocked(app.getPid(), app.info.uid,
                    changes, state.hasRepForegroundActivities());
                    changes, state.getHasRepForegroundActivities());
            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG_PROCESS_OBSERVERS,
                    "Enqueued process change item for "
                            + app.toShortString() + ": changes=" + changes
                            + " foreground=" + state.hasRepForegroundActivities()
                            + " foreground=" + state.getHasRepForegroundActivities()
                            + " type=" + state.getAdjType() + " source=" + state.getAdjSource()
                            + " target=" + state.getAdjTarget());
        }
@@ -2346,7 +2346,7 @@ public abstract class OomAdjuster {
        final int prevAdj = state.getCurRawAdj();
        // If the process has been marked as foreground, it is starting as the top app (with
        // Zygote#START_AS_TOP_APP_ARG), so boost the thread priority of its default UI thread.
        if (state.hasForegroundActivities()) {
        if (state.getHasForegroundActivities()) {
            try {
                // The priority must be the same as how does {@link #applyOomAdjLSP} set for
                // {@link SCHED_GROUP_TOP_APP}. We don't check render thread because it
@@ -2430,7 +2430,7 @@ public abstract class OomAdjuster {
                ? mConstants.USAGE_STATS_INTERACTION_INTERVAL_POST_S
                : mConstants.USAGE_STATS_INTERACTION_INTERVAL_PRE_S;
        if (isInteraction
                && (!state.hasReportedInteraction()
                && (!state.getHasReportedInteraction()
                    || (nowElapsed - state.getInteractionEventTime()) > interactionThreshold)) {
            state.setInteractionEventTime(nowElapsed);
            String[] packages = app.getPackageList();
@@ -2441,7 +2441,7 @@ public abstract class OomAdjuster {
                }
            }
        }
        state.setReportedInteraction(isInteraction);
        state.setHasReportedInteraction(isInteraction);
        if (!isInteraction) {
            state.setInteractionEventTime(0);
        }
+7 −7
Original line number Diff line number Diff line
@@ -1046,7 +1046,7 @@ public class OomAdjusterImpl extends OomAdjuster {
        // Need to check shouldScheduleLikeTopApp otherwise, there will be too many recompute which
        // leads to OOM.
        return !(cr.hasFlag(Context.BIND_SCHEDULE_LIKE_TOP_APP)
                && !host.mState.shouldScheduleLikeTopApp());
                && !host.mState.getScheduleLikeTopApp());
    }

    private static boolean isSandboxAttributedConnection(ConnectionRecord cr, ProcessRecord host) {
@@ -1222,7 +1222,7 @@ public class OomAdjusterImpl extends OomAdjuster {
                state.setSystemNoUi(false);
                state.setCurrentSchedulingGroup(SCHED_GROUP_TOP_APP);
                state.setAdjType("pers-top-activity");
            } else if (state.hasTopUi()) {
            } else if (state.getHasTopUi()) {
                // sched group/proc state adjustment is below
                state.setSystemNoUi(false);
                state.setAdjType("pers-top-ui");
@@ -1401,7 +1401,7 @@ public class OomAdjusterImpl extends OomAdjuster {
                // short-fgs can't start FGS from the background.
                newProcState = PROCESS_STATE_FOREGROUND_SERVICE;

            } else if (state.hasOverlayUi()) {
            } else if (state.getHasOverlayUi()) {
                adjType = "has-overlay-ui";
                newAdj = PERCEPTIBLE_APP_ADJ;
                newProcState = PROCESS_STATE_IMPORTANT_FOREGROUND;
@@ -1610,7 +1610,7 @@ public class OomAdjusterImpl extends OomAdjuster {
                                "Raise procstate to started service: " + app);
                    }
                }
                if (!s.mKeepWarming && state.hasShownUi() && !isHomeProcess(app)) {
                if (!s.mKeepWarming && state.getHasShownUi() && !isHomeProcess(app)) {
                    // If this process has shown some UI, let it immediately
                    // go to the LRU list because it may be pretty heavy with
                    // UI stuff.  We'll tag it with a label just to help
@@ -1952,7 +1952,7 @@ public class OomAdjusterImpl extends OomAdjuster {
                }
                // Not doing bind OOM management, so treat
                // this guy more like a started service.
                if (state.hasShownUi() && !isHomeProcess(app)) {
                if (state.getHasShownUi() && !isHomeProcess(app)) {
                    // If this process has shown some UI, let it immediately
                    // go to the LRU list because it may be pretty heavy with
                    // UI stuff.  We'll tag it with a label just to help
@@ -1988,7 +1988,7 @@ public class OomAdjusterImpl extends OomAdjuster {
                // is less important than a state that can be actively running, then we don't
                // care about the binding as much as we care about letting this process get into
                // the LRU list to be killed and restarted if needed for memory.
                if (state.hasShownUi() && !isHomeProcess(app)
                if (state.getHasShownUi() && !isHomeProcess(app)
                        && clientAdj > CACHING_UI_SERVICE_CLIENT_ADJ_THRESHOLD) {
                    if (adj >= CACHED_APP_MIN_ADJ) {
                        adjType = "cch-bound-ui-services";
@@ -2352,7 +2352,7 @@ public class OomAdjusterImpl extends OomAdjuster {

        String adjType = null;
        if (adj > clientAdj) {
            if (state.hasShownUi() && !isHomeProcess(app)
            if (state.getHasShownUi() && !isHomeProcess(app)
                    && clientAdj > PERCEPTIBLE_APP_ADJ) {
                adjType = "cch-ui-provider";
            } else {
Loading