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

Commit a1cc3f45 authored by David Stevens's avatar David Stevens Committed by Android (Google) Code Review
Browse files

Merge changes I01c1e0f2,I401661d4 into main

* changes:
  Remove unused field in ProcessStateRecord
  Clean up logic for killing bg restricted apps
parents 1e4f700a b2074751
Loading
Loading
Loading
Loading
+13 −17
Original line number Diff line number Diff line
@@ -2178,14 +2178,12 @@ public abstract class OomAdjuster {
                            + " target=" + state.getAdjTarget());
        }

        if (state.isCached() && !state.shouldNotKillOnBgRestrictedAndIdle()) {
            // It's eligible to get killed when in UID idle and bg restricted mode,
            // check if these states are just flipped.
            if (!state.isSetCached() || state.isSetNoKillOnBgRestrictedAndIdle()) {
                // Take the timestamp, we'd hold the killing for the background settle time
                // (for states debouncing to avoid from thrashing).
                state.setLastCanKillOnBgRestrictedAndIdleTime(nowElapsed);
                // Kick off the delayed checkup message if needed.
        if (state.isCached() && !state.isSetCached()) {
            // Cached procs are eligible to get killed when in an UID idle and bg restricted.
            // However, we want to debounce state changes to avoid thrashing. Mark down when this
            // process became eligible and then schedule a check for eligible processes after
            // a background settling time, if needed.
            state.setLastCachedTime(nowElapsed);
            if (mService.mDeterministicUidIdle
                    || !mService.mHandler.hasMessages(IDLE_UIDS_MSG)) {
                if (mLogger.shouldLog(app.uid)) {
@@ -2197,9 +2195,7 @@ public abstract class OomAdjuster {
                        mConstants.mKillBgRestrictedAndCachedIdleSettleTimeMs);
            }
        }
        }
        state.setSetCached(state.isCached());
        state.setSetNoKillOnBgRestrictedAndIdle(state.shouldNotKillOnBgRestrictedAndIdle());
        if (((oldProcState != state.getSetProcState()) || (oldOomAdj != state.getSetAdj()))
                && mLogger.shouldLog(app.uid)) {
            mLogger.logProcStateChanged(app.uid, app.getPid(),
+0 −1
Original line number Diff line number Diff line
@@ -1160,7 +1160,6 @@ public class OomAdjusterImpl extends OomAdjuster {
        state.setAdjSource(null);
        state.setAdjTarget(null);

        state.setNoKillOnBgRestrictedAndIdle(false);
        // If this UID is currently allowlisted, it should not be frozen.
        final UidRecord uidRec = app.getUidRecord();
        app.mOptRecord.setShouldNotFreeze(uidRec != null && uidRec.isCurAllowListed(),
+4 −4
Original line number Diff line number Diff line
@@ -5614,14 +5614,14 @@ public final class ProcessList {
    @GuardedBy("mService")
    long killAppIfBgRestrictedAndCachedIdleLocked(ProcessRecord app, long nowElapsed) {
        final UidRecord uidRec = app.getUidRecord();
        final long lastCanKillTime = app.mState.getLastCanKillOnBgRestrictedAndIdleTime();
        final long lastCachedTime = app.mState.getLastCachedTime();
        if (!mService.mConstants.mKillBgRestrictedAndCachedIdle
                || app.isKilled() || app.getThread() == null || uidRec == null || !uidRec.isIdle()
                || !app.isCached() || app.mState.shouldNotKillOnBgRestrictedAndIdle()
                || !app.mState.isBackgroundRestricted() || lastCanKillTime == 0) {
                || !app.isCached() || !app.mState.isBackgroundRestricted()
                || lastCachedTime == 0) {
            return 0;
        }
        final long future = lastCanKillTime
        final long future = lastCachedTime
                + mService.mConstants.mKillBgRestrictedAndCachedIdleSettleTimeMs;
        if (future <= nowElapsed) {
            app.killLocked("cached idle & background restricted",
+7 −58
Original line number Diff line number Diff line
@@ -267,12 +267,6 @@ final class ProcessStateRecord {
    @GuardedBy("mService")
    private int mCompletedAdjSeq;

    /**
     * Whether this app has encountered a cycle in the most recent update.
     */
    @GuardedBy("mService")
    private boolean mContainsCycle;

    /**
     * When (uptime) the process last became unimportant.
     */
@@ -378,13 +372,6 @@ final class ProcessStateRecord {
    @ElapsedRealtimeLong
    private long mLastInvisibleTime;

    /**
     * Whether or not this process could be killed when it's in background restricted mode
     * and cached &amp; idle state.
     */
    @GuardedBy("mService")
    private boolean mNoKillOnBgRestrictedAndIdle;

    /**
     * Last set value of {@link #isCached()}.
     */
@@ -392,19 +379,11 @@ final class ProcessStateRecord {
    private boolean mSetCached;

    /**
     * Last set value of {@link #mNoKillOnBgRestrictedAndIdle}.
     * When the proc became cached. Used to debounce killing bg restricted apps in
     * an idle UID.
     */
    @GuardedBy("mService")
    private boolean mSetNoKillOnBgRestrictedAndIdle;

    /**
     * The last time when the {@link #mNoKillOnBgRestrictedAndIdle} is false and the
     * {@link #isCached()} is true, and either the former state is flipping from true to false
     * when latter state is true, or the latter state is flipping from false to true when the
     * former state is false.
     */
    @GuardedBy("mService")
    private @ElapsedRealtimeLong long mLastCanKillOnBgRestrictedAndIdleTime;
    private @ElapsedRealtimeLong long mLastCachedTime;

    // Below are the cached task info for OomAdjuster only
    private static final int VALUE_INVALID = -1;
@@ -871,16 +850,6 @@ final class ProcessStateRecord {
        return mCompletedAdjSeq;
    }

    @GuardedBy("mService")
    void setContainsCycle(boolean containsCycle) {
        mContainsCycle = containsCycle;
    }

    @GuardedBy("mService")
    boolean containsCycle() {
        return mContainsCycle;
    }

    @GuardedBy({"mService", "mProcLock"})
    void setWhenUnimportant(long whenUnimportant) {
        mWhenUnimportant = whenUnimportant;
@@ -1271,16 +1240,6 @@ final class ProcessStateRecord {
        return mLastInvisibleTime;
    }

    @GuardedBy("mService")
    void setNoKillOnBgRestrictedAndIdle(boolean shouldNotKill) {
        mNoKillOnBgRestrictedAndIdle = shouldNotKill;
    }

    @GuardedBy("mService")
    boolean shouldNotKillOnBgRestrictedAndIdle() {
        return mNoKillOnBgRestrictedAndIdle;
    }

    @GuardedBy("mService")
    void setSetCached(boolean cached) {
        mSetCached = cached;
@@ -1292,24 +1251,14 @@ final class ProcessStateRecord {
    }

    @GuardedBy("mService")
    void setSetNoKillOnBgRestrictedAndIdle(boolean shouldNotKill) {
        mSetNoKillOnBgRestrictedAndIdle = shouldNotKill;
    }

    @GuardedBy("mService")
    boolean isSetNoKillOnBgRestrictedAndIdle() {
        return mSetNoKillOnBgRestrictedAndIdle;
    }

    @GuardedBy("mService")
    void setLastCanKillOnBgRestrictedAndIdleTime(@ElapsedRealtimeLong long now) {
        mLastCanKillOnBgRestrictedAndIdleTime = now;
    void setLastCachedTime(@ElapsedRealtimeLong long now) {
        mLastCachedTime = now;
    }

    @ElapsedRealtimeLong
    @GuardedBy("mService")
    long getLastCanKillOnBgRestrictedAndIdleTime() {
        return mLastCanKillOnBgRestrictedAndIdleTime;
    long getLastCachedTime() {
        return mLastCachedTime;
    }

    public void setCacheOomRankerRss(long rss, long rssTimeMs) {