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

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

psc: Move hasAboveClient to ProcessRecordInternal

This change refactors `OomAdjuster.setIntermediateAdjLSP` to use
`ProcessRecordInternal` instead of `ProcessRecord`.

To support this, `hasAboveClient()` is introduced as an abstract
method in `ProcessRecordInternal`, with `ProcessRecord` overriding it
to delegate to `ProcessServiceRecord`'s `hasAboveClient()`.
This is a temporary measure for ongoing refactoring.

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

Change-Id: I1dc3353005776a36a341d0fb5384ffb31707df66
parent 1ccb65c2
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -1927,20 +1927,18 @@ public abstract class OomAdjuster {
     * @return The proposed change to the schedGroup.
     */
    @GuardedBy({"mService", "mProcLock"})
    protected int setIntermediateAdjLSP(ProcessRecord app, int adj, int schedGroup) {
        final ProcessRecordInternal state = app;
        state.setCurRawAdj(adj);
    protected int setIntermediateAdjLSP(ProcessRecordInternal app, int adj, int schedGroup) {
        app.setCurRawAdj(adj);

        adj = applyBindAboveClientToAdj(app.mServices.hasAboveClient(), adj);
        if (adj > state.getMaxAdj()) {
            adj = state.getMaxAdj();
        adj = applyBindAboveClientToAdj(app.hasAboveClient(), adj);
        if (adj > app.getMaxAdj()) {
            adj = app.getMaxAdj();
            if (adj <= PERCEPTIBLE_LOW_APP_ADJ) {
                schedGroup = SCHED_GROUP_DEFAULT;
            }
        }

        state.setCurAdj(adj);

        app.setCurAdj(adj);
        return schedGroup;
    }

+5 −0
Original line number Diff line number Diff line
@@ -1168,6 +1168,11 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
                false/* default */);
    }

    @Override
    public boolean hasAboveClient() {
        return mServices.hasAboveClient();
    }

    boolean hasActivitiesOrRecentTasks() {
        return mWindowProcessController.hasActivitiesOrRecentTasks();
    }
+7 −0
Original line number Diff line number Diff line
@@ -187,6 +187,13 @@ public abstract class ProcessRecordInternal {
     */
    public abstract boolean hasCompatChange(@CachedCompatChangeId int cachedCompatChangeId);

    /**
     * Returns whether this process has bound to a service with
     * {@link android.content.Context#BIND_ABOVE_CLIENT}.
     * TODO(b/425766486): Remove it once ProcessRecordInternal could access ProcessServiceRecord.
     */
    public abstract boolean hasAboveClient();

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