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

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

am: Make setAttachingProcessStatesLSP use internal class

This change migrates the `OomAdjuster.setAttachingProcessStatesLSP()` to
operate directly on `ProcessRecordInternal`. To achieve that, it adds
`getPid`, `useFifoUiScheduling`, and `NotifyTopProcChanged` to abstract
methods in `ProcessRecordInternal`.

Bug: 425766486
Test: m services.core
Test: atest MockingOomAdjusterTests OomAdjusterTests
Test: atest FrameworksServicesTestsRavenwood_ProcessStateController
Flag: EXEMPT pure refactor

Change-Id: I6835aaaa4a10d40e1dd134aac5bdca9ee3f04d3a
parent 3fd24c96
Loading
Loading
Loading
Loading
+18 −19
Original line number Diff line number Diff line
@@ -2215,7 +2215,7 @@ public abstract class OomAdjuster {
                if (curSchedGroup == SCHED_GROUP_TOP_APP) {
                    // do nothing if we already switched to RT
                    if (oldSchedGroup != SCHED_GROUP_TOP_APP) {
                        app.getWindowProcessController().onTopProcChanged();
                        app.notifyTopProcChanged();
                        if (app.useFifoUiScheduling()) {
                            // Switch UI pipeline for app to SCHED_FIFO
                            state.setSavedPriority(Process.getThreadPriority(app.getPid()));
@@ -2236,7 +2236,7 @@ public abstract class OomAdjuster {
                    }
                } else if (oldSchedGroup == SCHED_GROUP_TOP_APP
                        && curSchedGroup != SCHED_GROUP_TOP_APP) {
                    app.getWindowProcessController().onTopProcChanged();
                    app.notifyTopProcChanged();
                    if (app.useFifoUiScheduling()) {
                        // Reset UI pipeline to SCHED_OTHER
                        ActivityManagerService.setFifoPriority(app, false /* enable */);
@@ -2409,28 +2409,27 @@ public abstract class OomAdjuster {
    }

    @GuardedBy({"mService", "mProcLock"})
    void setAttachingProcessStatesLSP(ProcessRecord app) {
    void setAttachingProcessStatesLSP(ProcessRecordInternal app) {
        int initialSchedGroup = SCHED_GROUP_DEFAULT;
        int initialProcState = PROCESS_STATE_CACHED_EMPTY;
            // Avoid freezing a freshly attached process.
        int initialCapability = ALL_CPU_TIME_CAPABILITIES;
        final ProcessRecordInternal state = app;
        final int prevProcState = state.getCurProcState();
        final int prevAdj = state.getCurRawAdj();
        final int prevProcState = app.getCurProcState();
        final int prevAdj = app.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.getHasForegroundActivities()) {
        if (app.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
                // is not ready when attaching.
                app.getWindowProcessController().onTopProcChanged();
                app.notifyTopProcChanged();
                if (app.useFifoUiScheduling()) {
                    mService.scheduleAsFifoPriority(app.getPid(), true);
                } else {
                    mInjector.setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST);
                }
                if (isScreenOnOrAnimatingLocked(state)) {
                if (isScreenOnOrAnimatingLocked(app)) {
                    initialSchedGroup = SCHED_GROUP_TOP_APP;
                    initialProcState = PROCESS_STATE_TOP;
                }
@@ -2440,17 +2439,17 @@ public abstract class OomAdjuster {
            }
        }

        state.setCurrentSchedulingGroup(initialSchedGroup);
        state.setCurProcState(initialProcState);
        state.setCurRawProcState(initialProcState);
        state.setCurCapability(initialCapability);
        state.addCurCpuTimeReasons(CPU_TIME_REASON_OTHER);
        state.addCurImplicitCpuTimeReasons(IMPLICIT_CPU_TIME_REASON_OTHER);
        app.setCurrentSchedulingGroup(initialSchedGroup);
        app.setCurProcState(initialProcState);
        app.setCurRawProcState(initialProcState);
        app.setCurCapability(initialCapability);
        app.addCurCpuTimeReasons(CPU_TIME_REASON_OTHER);
        app.addCurImplicitCpuTimeReasons(IMPLICIT_CPU_TIME_REASON_OTHER);

        state.setCurAdj(ProcessList.FOREGROUND_APP_ADJ);
        state.setCurRawAdj(ProcessList.FOREGROUND_APP_ADJ);
        state.setForcingToImportant(null);
        state.setHasShownUi(false);
        app.setCurAdj(ProcessList.FOREGROUND_APP_ADJ);
        app.setCurRawAdj(ProcessList.FOREGROUND_APP_ADJ);
        app.setForcingToImportant(null);
        app.setHasShownUi(false);

        onProcessStateChanged(app, prevProcState);
        onProcessOomAdjChanged(app, prevAdj);
+11 −2
Original line number Diff line number Diff line
@@ -675,8 +675,9 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
        mPkgDeps = pkgDeps;
    }

    @Override
    @GuardedBy(anyOf = {"mService", "mProcLock"})
    int getPid() {
    public int getPid() {
        return mPid;
    }

@@ -733,13 +734,21 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
        mProfile.onProcessInactive(tracker);
    }

    @Override
    @GuardedBy(anyOf = {"mService", "mProcLock"})
    boolean useFifoUiScheduling() {
    public boolean useFifoUiScheduling() {
        // TODO: b/439611239 - Migrate control of mAllowSpecifiedFifoScheduling to
        //  ProcessStateController.
        return mService.mUseFifoUiScheduling
                || (mService.mAllowSpecifiedFifoScheduling
                        && mWindowProcessController.useFifoUiScheduling());
    }

    @Override
    public void notifyTopProcChanged() {
        mWindowProcessController.onTopProcChanged();
    }

    @GuardedBy("mService")
    int getDyingPid() {
        return mDyingPid;
+9 −0
Original line number Diff line number Diff line
@@ -225,6 +225,15 @@ public abstract class ProcessRecordInternal {
    /** Returns the internal broadcast receiver related record for this process. */
    public abstract ProcessReceiverRecordInternal getReceivers();

    /** Returns the process ID. */
    public abstract int getPid();

    /** Determines if UI scheduling for this process should use FIFO priority. */
    public abstract boolean useFifoUiScheduling();

    /** Notifies the window process controller about a change in top process status. */
    public abstract void notifyTopProcChanged();

    // Enable this to trace all OomAdjuster state transitions
    private static final boolean TRACE_OOM_ADJ = false;