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

Commit 2c20d387 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "ActivityManagerService: Penalise large apps going to background"

parents 8c4eb382 111968da
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -343,6 +343,16 @@ public final class ActivityManagerService extends ActivityManagerNative
    // devices.
    private boolean mShowDialogs = true;
    // Penalise Large applications going to background only for Low-RAM devices
    private boolean mPenaliseLargeApps = ActivityManager.isLowRamDeviceStatic();
    // ADJ to be set for new background app (if found to be large)
    private int mPenalisedAdj = SystemProperties.getInt("ro.am.penalise_large_apps.adj",
                                                   ProcessList.CACHED_APP_MAX_ADJ);
    // Threshold Pss to be compared against new background app's Pss
    private long mPenalisedThreshold;
    /**
     * Description of a request to start a new activity, which has been held
     * due to app switches being disabled.
@@ -1991,6 +2001,15 @@ public final class ActivityManagerService extends ActivityManagerNative
        mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
        if (mPenaliseLargeApps == true) {
            long cachedAppMaxMemLevel
                    = mProcessList.getMemLevel(ProcessList.CACHED_APP_MAX_ADJ)/1024;
            mPenalisedThreshold = SystemProperties.getLong(
                    "ro.am.penalise_large_apps.pss", cachedAppMaxMemLevel);
            Slog.i(TAG,"Large apps penalisation enabled. Threshold Pss = " + mPenalisedThreshold +
                        ", ADJ = " + mPenalisedAdj);
        }
        // User 0 is the first and only user that runs at boot.
        mStartedUsers.put(0, new UserStartedState(new UserHandle(0), true));
        mUserLru.add(Integer.valueOf(0));
@@ -15327,6 +15346,23 @@ public final class ActivityManagerService extends ActivityManagerNative
            app.setRawAdj = app.curRawAdj;
        }
        if ( (mPenaliseLargeApps == true) && ((app.curAdj == ProcessList.PREVIOUS_APP_ADJ)
                || ((app.curAdj >= ProcessList.CACHED_APP_MIN_ADJ)
                && (app.curAdj < ProcessList.CACHED_APP_MAX_ADJ))) ) {
            // Validate the PSS to be compared against for penalisation
            if (app.lastCachedPss == 0) {
                app.lastCachedPss = Debug.getPss(app.pid, null);
            }
            if (app.lastCachedPss > mPenalisedThreshold) {
                if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.i(
                    TAG,"New BG app : " + app.processName + " is heavy! (pss = " +
                    app.lastCachedPss + " kB). Forcing to ADJ " + mPenalisedAdj);
                app.curAdj = mPenalisedAdj;
            }
        }
        if (app.curAdj != app.setAdj) {
            if (Process.setOomAdj(app.pid, app.curAdj)) {
                if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(