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

Commit 1add173d authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Store the existence of home and previous process

WindowProcessController can already know whether there is a home
or previous process. Though a refresh of the states require a
full oom-adj update, trimApplicationsLocked and appDiedLocked
should be frequently enough to update.

This removes potential lock contention when memFactor becomes
not ADJ_MEM_FACTOR_NORMAL when updating oom-adj. This also
reduces the dependency of internal interface across packages.

Bug: 159104503
Bug: 171989664
Test: Launch several apps and run memeater to trigger low mem.
      Check the output of "adb shell dumpsys activity processes"
      and set break point at AppProfiler to observe the values.
Change-Id: I2fe0eeccdde3ea687ce0d5d856beb3aee886c185
parent f2d1d264
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -247,6 +247,9 @@ public class AppProfiler {
    private int mMemWatchDumpUid;
    private boolean mMemWatchIsUserInitiated;

    boolean mHasHomeProcess;
    boolean mHasPreviousProcess;

    /**
     * Used to collect per-process CPU use for ANRs, battery stats, etc.
     * Must acquire this object's lock when accessing it.
@@ -961,8 +964,8 @@ public class AppProfiler {
            }
            int factor = numTrimming / 3;
            int minFactor = 2;
            if (mService.mAtmInternal.getHomeProcess() != null) minFactor++;
            if (mService.mAtmInternal.getPreviousProcess() != null) minFactor++;
            if (mHasHomeProcess) minFactor++;
            if (mHasPreviousProcess) minFactor++;
            if (factor < minFactor) factor = minFactor;
            int curLevel = ComponentCallbacks2.TRIM_MEMORY_COMPLETE;
            for (int i = 0; i < numOfLru; i++) {
+1 −0
Original line number Diff line number Diff line
@@ -500,6 +500,7 @@ public final class OomAdjuster {
        final ProcessRecord topApp = mService.getTopAppLocked();
        // Clear any pending ones because we are doing a full update now.
        mPendingProcessSet.clear();
        mService.mAppProfiler.mHasPreviousProcess = mService.mAppProfiler.mHasHomeProcess = false;
        updateOomAdjLockedInner(oomAdjReason, topApp , null, null, true, true);
    }

+12 −4
Original line number Diff line number Diff line
@@ -1875,16 +1875,24 @@ class ProcessRecord implements WindowProcessListener {

    boolean getCachedIsHomeProcess() {
        if (mCachedIsHomeProcess == VALUE_INVALID) {
            mCachedIsHomeProcess = getWindowProcessController().isHomeProcess()
                    ? VALUE_TRUE : VALUE_FALSE;
            if (getWindowProcessController().isHomeProcess()) {
                mCachedIsHomeProcess = VALUE_TRUE;
                mService.mAppProfiler.mHasHomeProcess = true;
            } else {
                mCachedIsHomeProcess = VALUE_FALSE;
            }
        }
        return mCachedIsHomeProcess == VALUE_TRUE;
    }

    boolean getCachedIsPreviousProcess() {
        if (mCachedIsPreviousProcess == VALUE_INVALID) {
            mCachedIsPreviousProcess = getWindowProcessController().isPreviousProcess()
                    ? VALUE_TRUE : VALUE_FALSE;
            if (getWindowProcessController().isPreviousProcess()) {
                mCachedIsPreviousProcess = VALUE_TRUE;
                mService.mAppProfiler.mHasPreviousProcess = true;
            } else {
                mCachedIsPreviousProcess = VALUE_FALSE;
            }
        }
        return mCachedIsPreviousProcess == VALUE_TRUE;
    }
+0 −3
Original line number Diff line number Diff line
@@ -533,9 +533,6 @@ public abstract class ActivityTaskManagerInternal {
    /** Flush recent tasks to disk. */
    public abstract void flushRecentTasks();

    public abstract WindowProcessController getHomeProcess();
    public abstract WindowProcessController getPreviousProcess();

    public abstract void clearLockedTasks(String reason);
    public abstract void updateUserConfiguration();
    public abstract boolean canShowErrorDialogs();
+0 −14
Original line number Diff line number Diff line
@@ -7361,20 +7361,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            mRecentTasks.flush();
        }

        @Override
        public WindowProcessController getHomeProcess() {
            synchronized (mGlobalLock) {
                return mHomeProcess;
            }
        }

        @Override
        public WindowProcessController getPreviousProcess() {
            synchronized (mGlobalLock) {
                return mPreviousProcess;
            }
        }

        @Override
        public void clearLockedTasks(String reason) {
            synchronized (mGlobalLock) {