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

Commit 3f38fcd6 authored by Wale Ogunwale's avatar Wale Ogunwale Committed by Android (Google) Code Review
Browse files

Merge changes I0f643038,I28b0be47

* changes:
  Delay sending configuraton changes to cached processes.
  Add setter for cached state within ProcessRecord.
parents 8c4aae3e 15192d37
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -4866,7 +4866,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        updateProcessForegroundLocked(app, false, 0, false);
        app.hasShownUi = false;
        app.setDebugging(false);
        app.cached = false;
        app.setCached(false);
        app.killedByAm = false;
        app.killed = false;
@@ -12154,7 +12154,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                        r.lastSwapPss*1024, new StringBuilder()));
                proto.write(ProcessOomProto.Detail.LAST_CACHED_PSS, DebugUtils.sizeValueToString(
                        r.lastCachedPss*1024, new StringBuilder()));
                proto.write(ProcessOomProto.Detail.CACHED, r.cached);
                proto.write(ProcessOomProto.Detail.CACHED, r.isCached());
                proto.write(ProcessOomProto.Detail.EMPTY, r.empty);
                proto.write(ProcessOomProto.Detail.HAS_ABOVE_CLIENT, r.hasAboveClient);
@@ -12281,7 +12281,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                pw.println();
                pw.print(prefix);
                pw.print("    ");
                pw.print("cached="); pw.print(r.cached);
                pw.print("cached="); pw.print(r.isCached());
                pw.print(" empty="); pw.print(r.empty);
                pw.print(" hasAboveClient="); pw.println(r.hasAboveClient);
+24 −24
Original line number Diff line number Diff line
@@ -261,7 +261,7 @@ public final class OomAdjuster {
            return updateOomAdjLocked(app, oomAdjReason);
        }
        final ProcessRecord TOP_APP = mService.getTopAppLocked();
        final boolean wasCached = app.cached;
        final boolean wasCached = app.isCached();

        mAdjSeq++;

@@ -274,7 +274,7 @@ public final class OomAdjuster {
        boolean success = updateOomAdjLocked(app, cachedAdj, TOP_APP, false,
                SystemClock.uptimeMillis());
        if (oomAdjAll
                && (wasCached != app.cached || app.getCurRawAdj() == ProcessList.UNKNOWN_ADJ)) {
                && (wasCached != app.isCached() || app.getCurRawAdj() == ProcessList.UNKNOWN_ADJ)) {
            // Changed to/from cached state, so apps after it in the LRU
            // list may also be changed.
            updateOomAdjLocked(oomAdjReason);
@@ -350,7 +350,7 @@ public final class OomAdjuster {
        mAdjSeq++;

        // Firstly, try to see if the importance of itself gets changed
        final boolean wasCached = app.cached;
        final boolean wasCached = app.isCached();
        final int oldAdj = app.getCurRawAdj();
        final int cachedAdj = oldAdj >= ProcessList.CACHED_APP_MIN_ADJ
                ? oldAdj : ProcessList.UNKNOWN_ADJ;
@@ -360,7 +360,7 @@ public final class OomAdjuster {
        app.resetCachedInfo();
        boolean success = updateOomAdjLocked(app, cachedAdj, topApp, false,
                SystemClock.uptimeMillis());
        if (!success || (wasCached == app.cached && oldAdj != ProcessList.INVALID_ADJ
        if (!success || (wasCached == app.isCached() && oldAdj != ProcessList.INVALID_ADJ
                && wasBackground == ActivityManager.isProcStateBackground(app.setProcState))) {
            // Okay, it's unchanged, it won't impact any service it binds to, we're done here.
            if (DEBUG_OOM_ADJ) {
@@ -978,7 +978,7 @@ public final class OomAdjuster {
            if (schedGroup < ProcessList.SCHED_GROUP_DEFAULT) {
                schedGroup = ProcessList.SCHED_GROUP_DEFAULT;
            }
            app.cached = false;
            app.setCached(false);
            app.empty = false;
            foregroundActivities = true;
        }
@@ -1003,7 +1003,7 @@ public final class OomAdjuster {
            if (schedGroup < ProcessList.SCHED_GROUP_DEFAULT) {
                schedGroup = ProcessList.SCHED_GROUP_DEFAULT;
            }
            app.cached = false;
            app.setCached(false);
            app.empty = false;
            foregroundActivities = true;
        }
@@ -1035,7 +1035,7 @@ public final class OomAdjuster {
                    }
                }
            }
            app.cached = false;
            app.setCached(false);
            app.empty = false;
            foregroundActivities = true;
        }
@@ -1084,7 +1084,7 @@ public final class OomAdjuster {
        app.adjSource = null;
        app.adjTarget = null;
        app.empty = false;
        app.cached = false;
        app.setCached(false);

        final int appUid = app.info.uid;
        final int logUid = mService.mCurOomAdjUid;
@@ -1220,7 +1220,7 @@ public final class OomAdjuster {
            // value that the caller wants us to.
            adj = cachedAdj;
            procState = PROCESS_STATE_CACHED_EMPTY;
            app.cached = true;
            app.setCached(true);
            app.empty = true;
            app.adjType = "cch-empty";
            if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
@@ -1255,7 +1255,7 @@ public final class OomAdjuster {
                adj = ProcessList.PERCEPTIBLE_APP_ADJ;
                procState = PROCESS_STATE_FOREGROUND_SERVICE;
                app.adjType = "fg-service";
                app.cached = false;
                app.setCached(false);
                schedGroup = ProcessList.SCHED_GROUP_DEFAULT;
                if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
                    reportOomAdjMessageLocked(TAG_OOM_ADJ, "Raise to " + app.adjType + ": "
@@ -1265,7 +1265,7 @@ public final class OomAdjuster {
                // The process is display an overlay UI.
                adj = ProcessList.PERCEPTIBLE_APP_ADJ;
                procState = PROCESS_STATE_IMPORTANT_FOREGROUND;
                app.cached = false;
                app.setCached(false);
                app.adjType = "has-overlay-ui";
                schedGroup = ProcessList.SCHED_GROUP_DEFAULT;
                if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
@@ -1295,7 +1295,7 @@ public final class OomAdjuster {
                // thus out of background check), so we yes the best background level we can.
                adj = ProcessList.PERCEPTIBLE_APP_ADJ;
                procState = PROCESS_STATE_TRANSIENT_BACKGROUND;
                app.cached = false;
                app.setCached(false);
                app.adjType = "force-imp";
                app.adjSource = app.forcingToImportant;
                schedGroup = ProcessList.SCHED_GROUP_DEFAULT;
@@ -1310,7 +1310,7 @@ public final class OomAdjuster {
                // We don't want to kill the current heavy-weight process.
                adj = ProcessList.HEAVY_WEIGHT_APP_ADJ;
                schedGroup = ProcessList.SCHED_GROUP_BACKGROUND;
                app.cached = false;
                app.setCached(false);
                app.adjType = "heavy";
                if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
                    reportOomAdjMessageLocked(TAG_OOM_ADJ, "Raise adj to heavy: " + app);
@@ -1331,7 +1331,7 @@ public final class OomAdjuster {
                // home app, so we don't want to let it go into the background.
                adj = ProcessList.HOME_APP_ADJ;
                schedGroup = ProcessList.SCHED_GROUP_BACKGROUND;
                app.cached = false;
                app.setCached(false);
                app.adjType = "home";
                if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
                    reportOomAdjMessageLocked(TAG_OOM_ADJ, "Raise adj to home: " + app);
@@ -1353,7 +1353,7 @@ public final class OomAdjuster {
                // a good experience around switching between two apps.
                adj = ProcessList.PREVIOUS_APP_ADJ;
                schedGroup = ProcessList.SCHED_GROUP_BACKGROUND;
                app.cached = false;
                app.setCached(false);
                app.adjType = "previous";
                if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
                    reportOomAdjMessageLocked(TAG_OOM_ADJ, "Raise adj to prev: " + app);
@@ -1400,7 +1400,7 @@ public final class OomAdjuster {
                if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
                    reportOomAdjMessageLocked(TAG_OOM_ADJ, "Raise adj to backup: " + app);
                }
                app.cached = false;
                app.setCached(false);
            }
            if (procState > ActivityManager.PROCESS_STATE_BACKUP) {
                procState = ActivityManager.PROCESS_STATE_BACKUP;
@@ -1448,7 +1448,7 @@ public final class OomAdjuster {
                                reportOomAdjMessageLocked(TAG_OOM_ADJ,
                                        "Raise adj to started service: " + app);
                            }
                            app.cached = false;
                            app.setCached(false);
                        }
                    }
                    // If we have let the service slide into the background
@@ -1538,7 +1538,7 @@ public final class OomAdjuster {
                                if (adj > clientAdj) {
                                    adjType = "cch-bound-ui-services";
                                }
                                app.cached = false;
                                app.setCached(false);
                                clientAdj = adj;
                                clientProcState = procState;
                            } else {
@@ -1601,8 +1601,8 @@ public final class OomAdjuster {
                                        newAdj = adj;
                                    }
                                }
                                if (!client.cached) {
                                    app.cached = false;
                                if (!client.isCached()) {
                                    app.setCached(false);
                                }
                                if (adj >  newAdj) {
                                    adj = newAdj;
@@ -1726,7 +1726,7 @@ public final class OomAdjuster {
                                    schedGroup = ProcessList.SCHED_GROUP_DEFAULT;
                                }
                            }
                            app.cached = false;
                            app.setCached(false);
                            app.adjType = "service";
                            app.adjTypeCode = ActivityManager.RunningAppProcessInfo
                                    .REASON_SERVICE_IN_USE;
@@ -1791,7 +1791,7 @@ public final class OomAdjuster {
                        app.setCurRawAdj(adj);
                        adjType = "provider";
                    }
                    app.cached &= client.cached;
                    app.setCached(app.isCached() & client.isCached());
                }

                if (clientProcState <= PROCESS_STATE_FOREGROUND_SERVICE) {
@@ -1836,7 +1836,7 @@ public final class OomAdjuster {
                    adj = ProcessList.FOREGROUND_APP_ADJ;
                    app.setCurRawAdj(adj);
                    schedGroup = ProcessList.SCHED_GROUP_DEFAULT;
                    app.cached = false;
                    app.setCached(false);
                    app.adjType = "ext-provider";
                    app.adjTarget = cpr.name;
                    if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
@@ -1860,7 +1860,7 @@ public final class OomAdjuster {
            if (adj > ProcessList.PREVIOUS_APP_ADJ) {
                adj = ProcessList.PREVIOUS_APP_ADJ;
                schedGroup = ProcessList.SCHED_GROUP_BACKGROUND;
                app.cached = false;
                app.setCached(false);
                app.adjType = "recent-provider";
                if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
                    reportOomAdjMessageLocked(TAG_OOM_ADJ,
+14 −2
Original line number Diff line number Diff line
@@ -237,7 +237,7 @@ class ProcessRecord implements WindowProcessListener {
    long lastTopTime;           // The last time the process was in the TOP state or greater.
    boolean reportLowMemory;    // Set to true when waiting to report low mem
    boolean empty;              // Is this an empty background process?
    boolean cached;             // Is this a cached process?
    private volatile boolean mCached;    // Is this a cached process?
    String adjType;             // Debugging: primary thing impacting oom_adj.
    int adjTypeCode;            // Debugging: adj code to report to app.
    Object adjSource;           // Debugging: option dependent object.
@@ -410,7 +410,7 @@ class ProcessRecord implements WindowProcessListener {
                pw.println();
        pw.print(prefix); pw.print("procStateMemTracker: ");
        procStateMemTracker.dumpLine(pw);
        pw.print(prefix); pw.print("cached="); pw.print(cached);
        pw.print(prefix); pw.print("cached="); pw.print(mCached);
                pw.print(" empty="); pw.println(empty);
        if (serviceb) {
            pw.print(prefix); pw.print("serviceb="); pw.print(serviceb);
@@ -689,6 +689,18 @@ class ProcessRecord implements WindowProcessListener {
        }
    }

    void setCached(boolean cached) {
        if (mCached != cached) {
            mCached = cached;
            mWindowProcessController.onProcCachedStateChanged(cached);
        }
    }

    @Override
    public boolean isCached() {
        return mCached;
    }

    boolean hasActivities() {
        return mWindowProcessController.hasActivities();
    }
+45 −14
Original line number Diff line number Diff line
@@ -179,6 +179,8 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio

    // Last configuration that was reported to the process.
    private final Configuration mLastReportedConfiguration;
    // Configuration that is waiting to be dispatched to the process.
    private Configuration mPendingConfiguration;
    private final Configuration mNewOverrideConfig = new Configuration();
    // Registered display id as a listener to override config change
    private int mDisplayId;
@@ -1073,7 +1075,21 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
            return;
        }

        try {
        if (mListener.isCached()) {
            // This process is in a cached state. We will delay delivering the config change to the
            // process until the process is no longer cached.
            if (mPendingConfiguration == null) {
                mPendingConfiguration = new Configuration(config);
            } else {
                mPendingConfiguration.setTo(config);
            }
            return;
        }

        dispatchConfigurationChange(config);
    }

    private void dispatchConfigurationChange(Configuration config) {
        if (mThread == null) {
            if (Build.IS_DEBUGGABLE && mIsImeProcess) {
                // TODO (b/135719017): Temporary log for debugging IME service.
@@ -1083,14 +1099,14 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
            return;
        }
        if (DEBUG_CONFIGURATION) {
                Slog.v(TAG_CONFIGURATION, "Sending to proc " + mName
                        + " new config " + config);
            Slog.v(TAG_CONFIGURATION, "Sending to proc " + mName + " new config " + config);
        }
        if (Build.IS_DEBUGGABLE && mIsImeProcess) {
            // TODO (b/135719017): Temporary log for debugging IME service.
                Slog.v(TAG_CONFIGURATION, "Sending to IME proc " + mName
                        + " new config " + config);
            Slog.v(TAG_CONFIGURATION, "Sending to IME proc " + mName + " new config " + config);
        }

        try {
            config.seq = mAtm.increaseConfigurationSeqLocked();
            mAtm.getLifecycleManager().scheduleTransaction(mThread,
                    ConfigurationChangeItem.obtain(config));
@@ -1190,6 +1206,21 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
        return false;
    }

    /**
     * Called to notify WindowProcessController of a change in the process's cached state.
     *
     * @param isCached whether or not the process is cached.
     */
    public void onProcCachedStateChanged(boolean isCached) {
        synchronized (mAtm.mGlobalLock) {
            if (!isCached && mPendingConfiguration != null) {
                final Configuration config = mPendingConfiguration;
                mPendingConfiguration = null;
                dispatchConfigurationChange(config);
            }
        }
    }

    @HotPath(caller = HotPath.OOM_ADJUSTMENT)
    public void onTopProcChanged() {
        synchronized (mAtm.mGlobalLockWithoutBoost) {
+5 −0
Original line number Diff line number Diff line
@@ -51,6 +51,11 @@ public interface WindowProcessListener {
     */
    boolean isRemoved();

    /**
     * Returns true if the process is in a cached state.
     */
    boolean isCached();

    /** Returns the total time (in milliseconds) spent executing in both user and system code. */
    long getCpuTime();

Loading