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

Commit 2c09e8cd authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Fix issue #11157301: Bad process stats when apps are binding to...

Merge "Fix issue #11157301: Bad process stats when apps are binding to long-running services" into klp-dev
parents 6c906dc5 32366b29
Loading
Loading
Loading
Loading
+66 −24
Original line number Original line Diff line number Diff line
@@ -14267,6 +14267,8 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
            }
        }
        }
        boolean mayBeTop = false;
        for (int is = app.services.size()-1;
        for (int is = app.services.size()-1;
                is >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ
                is >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ
                        || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
                        || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
@@ -14427,19 +14429,28 @@ public final class ActivityManagerService extends ActivityManagerNative
                            if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
                            if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
                                schedGroup = Process.THREAD_GROUP_DEFAULT;
                                schedGroup = Process.THREAD_GROUP_DEFAULT;
                            }
                            }
                            if (clientProcState <=
                            if (clientProcState <= ActivityManager.PROCESS_STATE_TOP) {
                                    ActivityManager.PROCESS_STATE_PERSISTENT_UI &&
                                if (clientProcState == ActivityManager.PROCESS_STATE_TOP) {
                                    clientProcState >=
                                    // Special handling of clients who are in the top state.
                                            ActivityManager.PROCESS_STATE_PERSISTENT) {
                                    // We *may* want to consider this process to be in the
                                // Persistent processes don't allow us to become top.
                                    // top state as well, but only if there is not another
                                // However the top process DOES allow us to become top,
                                    // reason for it to be running.  Being on the top is a
                                // because in that case we are running because the current
                                    // special state, meaning you are specifically running
                                // top process wants us, so we should be counted as part
                                    // for the current top app.  If the process is already
                                // of the top set and not just running for some random
                                    // running in the background for some other reason, it
                                // unknown reason in the background.
                                    // is more important to continue considering it to be
                                    // in the background state.
                                    mayBeTop = true;
                                    clientProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
                                } else {
                                    // Special handling for above-top states (persistent
                                    // processes).  These should not bring the current process
                                    // into the top state, since they are not on top.  Instead
                                    // give them the best state after that.
                                    clientProcState =
                                    clientProcState =
                                            ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
                                            ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
                                }
                                }
                            }
                        } else {
                        } else {
                            if (clientProcState <
                            if (clientProcState <
                                    ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) {
                                    ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) {
@@ -14526,19 +14537,28 @@ public final class ActivityManagerService extends ActivityManagerNative
                    app.adjSourceOom = clientAdj;
                    app.adjSourceOom = clientAdj;
                    app.adjTarget = cpr.name;
                    app.adjTarget = cpr.name;
                }
                }
                if (clientProcState <=
                if (clientProcState <= ActivityManager.PROCESS_STATE_TOP) {
                        ActivityManager.PROCESS_STATE_PERSISTENT_UI &&
                    if (clientProcState == ActivityManager.PROCESS_STATE_TOP) {
                        clientProcState >=
                        // Special handling of clients who are in the top state.
                                ActivityManager.PROCESS_STATE_PERSISTENT) {
                        // We *may* want to consider this process to be in the
                    // Persistent processes don't allow us to become top.
                        // top state as well, but only if there is not another
                    // However the top process DOES allow us to become top,
                        // reason for it to be running.  Being on the top is a
                    // because in that case we are running because the current
                        // special state, meaning you are specifically running
                    // top process wants us, so we should be counted as part
                        // for the current top app.  If the process is already
                    // of the top set and not just running for some random
                        // running in the background for some other reason, it
                    // unknown reason in the background.
                        // is more important to continue considering it to be
                        // in the background state.
                        mayBeTop = true;
                        clientProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
                    } else {
                        // Special handling for above-top states (persistent
                        // processes).  These should not bring the current process
                        // into the top state, since they are not on top.  Instead
                        // give them the best state after that.
                        clientProcState =
                        clientProcState =
                                ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
                                ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
                    }
                    }
                }
                if (procState > clientProcState) {
                if (procState > clientProcState) {
                    procState = clientProcState;
                    procState = clientProcState;
                }
                }
@@ -14564,6 +14584,28 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
            }
        }
        }
        if (mayBeTop && procState > ActivityManager.PROCESS_STATE_TOP) {
            // A client of one of our services or providers is in the top state.  We
            // *may* want to be in the top state, but not if we are already running in
            // the background for some other reason.  For the decision here, we are going
            // to pick out a few specific states that we want to remain in when a client
            // is top (states that tend to be longer-term) and otherwise allow it to go
            // to the top state.
            switch (procState) {
                case ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND:
                case ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND:
                case ActivityManager.PROCESS_STATE_SERVICE:
                    // These all are longer-term states, so pull them up to the top
                    // of the background states, but not all the way to the top state.
                    procState = ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
                    break;
                default:
                    // Otherwise, top is a better choice, so take it.
                    procState = ActivityManager.PROCESS_STATE_TOP;
                    break;
            }
        }
        if (adj == ProcessList.SERVICE_ADJ) {
        if (adj == ProcessList.SERVICE_ADJ) {
            if (doingAll) {
            if (doingAll) {
                app.serviceb = mNewNumAServiceProcs > (mNumServiceProcs/3);
                app.serviceb = mNewNumAServiceProcs > (mNumServiceProcs/3);