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

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

am: Make OomAdjuster.evaluateConnectionPrelude to use internal classes

This change migrates the OomAdjusterImpl.evaluateConnectionPrelude()
method to access ProcessRecordInternal. This is a pure refactor to
align with internal class migration efforts and improve modularity.

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

Change-Id: I4ca546c58de21b0f7212f5d7a57e0eb041ba9ea4
parent 99761ed6
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -2828,7 +2828,7 @@ public abstract class OomAdjuster {
     * connection.
     */
    @GuardedBy("mService")
    boolean evaluateServiceConnectionAdd(ProcessRecord client, ProcessRecord app,
    boolean evaluateServiceConnectionAdd(ProcessRecordInternal client, ProcessRecordInternal app,
            ConnectionRecord cr) {
        if (evaluateConnectionPrelude(client, app)) {
            return true;
@@ -2855,7 +2855,7 @@ public abstract class OomAdjuster {
        } else if (cr.hasFlag(Context.BIND_WAIVE_PRIORITY | Context.BIND_ALLOW_OOM_MANAGEMENT)) {
            // These bind flags can grant the shouldNotFreeze state to the service.
            needDryRun = true;
        } else if (client.mOptRecord.shouldNotFreeze() && !app.mOptRecord.shouldNotFreeze()) {
        } else if (client.shouldNotFreeze() && !app.shouldNotFreeze()) {
            // The shouldNotFreeze state can be propagated and needs to be checked.
            needDryRun = true;
        }
@@ -2870,8 +2870,8 @@ public abstract class OomAdjuster {
    }

    @GuardedBy("mService")
    boolean evaluateServiceConnectionRemoval(ProcessRecord client, ProcessRecord app,
            ConnectionRecord cr) {
    boolean evaluateServiceConnectionRemoval(ProcessRecordInternal client,
            ProcessRecordInternal app, ConnectionRecord cr) {
        if (evaluateConnectionPrelude(client, app)) {
            return true;
        }
@@ -2887,7 +2887,7 @@ public abstract class OomAdjuster {
            return true;
        } else if (cr.hasFlag(Context.BIND_WAIVE_PRIORITY | Context.BIND_ALLOW_OOM_MANAGEMENT)) {
            return true;
        } else if (app.mOptRecord.shouldNotFreeze() && client.mOptRecord.shouldNotFreeze()) {
        } else if (app.shouldNotFreeze() && client.shouldNotFreeze()) {
            // Process has shouldNotFreeze and it could have gotten it from the client.
            return true;
        } else if (Flags.cpuTimeCapabilityBasedFreezePolicy()
@@ -2899,7 +2899,7 @@ public abstract class OomAdjuster {
    }

    @GuardedBy("mService")
    boolean evaluateProviderConnectionAdd(ProcessRecord client, ProcessRecord app) {
    boolean evaluateProviderConnectionAdd(ProcessRecordInternal client, ProcessRecordInternal app) {
        if (evaluateConnectionPrelude(client, app)) {
            return true;
        }
@@ -2909,7 +2909,7 @@ public abstract class OomAdjuster {
            needDryRun = true;
        } else if (app.getSetProcState() > client.getSetProcState()) {
            needDryRun = true;
        } else if (client.mOptRecord.shouldNotFreeze() && !app.mOptRecord.shouldNotFreeze()) {
        } else if (client.shouldNotFreeze() && !app.shouldNotFreeze()) {
            needDryRun = true;
        } else if (Flags.cpuTimeCapabilityBasedFreezePolicy()
                && (client.getSetCapability() & ~app.getSetCapability()
@@ -2925,7 +2925,8 @@ public abstract class OomAdjuster {
    }

    @GuardedBy("mService")
    boolean evaluateProviderConnectionRemoval(ProcessRecord client, ProcessRecord app) {
    boolean evaluateProviderConnectionRemoval(ProcessRecordInternal client,
            ProcessRecordInternal app) {
        if (evaluateConnectionPrelude(client, app)) {
            return true;
        }
@@ -2934,7 +2935,7 @@ public abstract class OomAdjuster {
            return true;
        } else if (app.getSetProcState() >= client.getSetProcState()) {
            return true;
        } else if (app.mOptRecord.shouldNotFreeze() && client.mOptRecord.shouldNotFreeze()) {
        } else if (app.shouldNotFreeze() && client.shouldNotFreeze()) {
            // Process has shouldNotFreeze and it could have gotten it from the client.
            return true;
        } else if (Flags.cpuTimeCapabilityBasedFreezePolicy()
@@ -2946,7 +2947,8 @@ public abstract class OomAdjuster {
        return false;
    }

    private boolean evaluateConnectionPrelude(ProcessRecord client, ProcessRecord app) {
    private boolean evaluateConnectionPrelude(ProcessRecordInternal client,
            ProcessRecordInternal app) {
        if (client == null || app == null) {
            return true;
        }
+5 −21
Original line number Diff line number Diff line
@@ -278,12 +278,6 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
    @CompositeRWLock({"mService", "mProcLock"})
    private ActiveInstrumentation mInstr;

    /**
     * True when proc has been killed by activity manager, not for RAM.
     */
    @CompositeRWLock({"mService", "mProcLock"})
    private boolean mKilledByAm;

    /**
     * The timestamp in uptime when this process was killed.
     */
@@ -523,9 +517,9 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
        pw.print(prefix); pw.print("startSeq="); pw.println(mStartSeq);
        pw.print(prefix); pw.print("mountMode="); pw.println(
                DebugUtils.valueToString(Zygote.class, "MOUNT_EXTERNAL_", mMountMode));
        if (isKilled() || mKilledByAm || mWaitingToKill != null) {
        if (isKilled() || isKilledByAm() || mWaitingToKill != null) {
            pw.print(prefix); pw.print("killed="); pw.print(isKilled());
            pw.print(" killedByAm="); pw.print(mKilledByAm);
            pw.print(" killedByAm="); pw.print(isKilledByAm());
            pw.print(" waitingToKill="); pw.println(mWaitingToKill);
        }
        if (mIsolatedEntryPoint != null || mIsolatedEntryPointArgs != null) {
@@ -982,16 +976,6 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
        return mInstr != null;
    }

    @GuardedBy(anyOf = {"mService", "mProcLock"})
    boolean isKilledByAm() {
        return mKilledByAm;
    }

    @GuardedBy({"mService", "mProcLock"})
    void setKilledByAm(boolean killedByAm) {
        mKilledByAm = killedByAm;
    }

    @GuardedBy(anyOf = {"mService", "mProcLock"})
    long getKillTime() {
        return mKillTime;
@@ -1248,7 +1232,7 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
    void scheduleCrashLocked(String message, int exceptionTypeId, @Nullable Bundle extras) {
        // Checking killedbyAm should keep it from showing the crash dialog if the process
        // was already dead for a good / normal reason.
        if (!mKilledByAm) {
        if (!isKilledByAm()) {
            if (mThread != null) {
                if (mPid == Process.myPid()) {
                    Slog.w(TAG, "scheduleCrash: trying to crash system process!");
@@ -1300,7 +1284,7 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
    @GuardedBy("mService")
    void killLocked(String reason, String description, @Reason int reasonCode,
            @SubReason int subReason, boolean noisy, boolean asyncKPG) {
        if (!mKilledByAm) {
        if (!isKilledByAm()) {
            if (Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) {
                Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER,
                        "kill/" + processName + "/" + reasonCode + "/" + subReason);
@@ -1329,7 +1313,7 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
            if (!mPersistent) {
                synchronized (mProcLock) {
                    setKilled(true);
                    mKilledByAm = true;
                    setKilledByAm(true);
                    mKillTime = SystemClock.uptimeMillis();
                }
            }
+15 −0
Original line number Diff line number Diff line
@@ -265,6 +265,10 @@ public abstract class ProcessRecordInternal {
    @CompositeRWLock({"mService", "mProcLock"})
    private boolean mKilled;

    /** True when proc has been killed by activity manager, not for RAM. */
    @CompositeRWLock({"mService", "mProcLock"})
    private boolean mKilledByAm;

    /**
     * Maximum OOM adjustment for this process.
     */
@@ -721,6 +725,17 @@ public abstract class ProcessRecordInternal {
        mKilled = killed;
    }

    @GuardedBy(anyOf = {"mServiceLock", "mProcLock"})
    public boolean isKilledByAm() {
        return mKilledByAm;
    }

    @GuardedBy({"mServiceLock", "mProcLock"})
    public void setKilledByAm(boolean killedByAm) {
        mKilledByAm = killedByAm;
    }


    @GuardedBy("mServiceLock")
    public void setMaxAdj(int maxAdj) {
        mMaxAdj = maxAdj;