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

Commit 2aea24c1 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Revert "Revert "Only promote remote animator to top sched group during...

Merge "Revert "Revert "Only promote remote animator to top sched group during animation""" into rvc-dev am: e0255882 am: c8639b4d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11932662

Change-Id: I4b472b65e7a15ec13b5c62a5f52f59d69350ad5e
parents 2f21ab3e c8639b4d
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -1671,6 +1671,12 @@ public class ActivityManagerService extends IActivityManager.Stub
     */
    @Nullable ContentCaptureManagerInternal mContentCaptureService;
    /**
     * Set of {@link ProcessRecord} that have either {@link ProcessRecord#hasTopUi()} or
     * {@link ProcessRecord#runningRemoteAnimation} set to {@code true}.
     */
    final ArraySet<ProcessRecord> mTopUiOrRunningRemoteAnimApps = new ArraySet<>();
    final class UiHandler extends Handler {
        public UiHandler() {
            super(com.android.server.UiThread.get().getLooper(), null, true);
@@ -14702,6 +14708,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mProcessesToGc.remove(app);
        mPendingPssProcesses.remove(app);
        mTopUiOrRunningRemoteAnimApps.remove(app);
        ProcessList.abortNextPssTime(app.procStateMemTracker);
        // Dismiss any open dialogs.
@@ -18502,6 +18509,22 @@ public class ActivityManagerService extends IActivityManager.Stub
        return proc;
    }
    /**
     * @return {@code true} if {@link #mTopUiOrRunningRemoteAnimApps} set contains {@code app} or when there are no apps
     *         in this list, an false otherwise.
     */
    boolean containsTopUiOrRunningRemoteAnimOrEmptyLocked(ProcessRecord app) {
        return mTopUiOrRunningRemoteAnimApps.isEmpty() || mTopUiOrRunningRemoteAnimApps.contains(app);
    }
    void addTopUiOrRunningRemoteAnim(ProcessRecord app) {
        mTopUiOrRunningRemoteAnimApps.add(app);
    }
    void removeTopUiOrRunningRemoteAnim(ProcessRecord app) {
        mTopUiOrRunningRemoteAnimApps.remove(app);
    }
    @Override
    public boolean dumpHeap(String process, int userId, boolean managed, boolean mallocInfo,
            boolean runGc, String path, ParcelFileDescriptor fd, RemoteCallback finishCallback) {
+24 −5
Original line number Diff line number Diff line
@@ -1151,8 +1151,17 @@ public final class OomAdjuster {
            // is currently showing UI.
            app.systemNoUi = true;
            if (app == topApp) {
                app.systemNoUi = false;
                // If specific system app has set ProcessRecord.mHasTopUi or is running a remote
                // animation (ProcessRecord.runningRemoteAnimation), this will prevent topApp
                // to use SCHED_GROUP_TOP_APP to ensure process with mHasTopUi will have exclusive
                // access to configured cores.
                if (mService.containsTopUiOrRunningRemoteAnimOrEmptyLocked(app)) {
                    app.setCurrentSchedulingGroup(ProcessList.SCHED_GROUP_TOP_APP);
                } else {
                    app.setCurrentSchedulingGroup(ProcessList.SCHED_GROUP_DEFAULT);
                }
                app.systemNoUi = false;

                app.adjType = "pers-top-activity";
            } else if (app.hasTopUi()) {
                // sched group/proc state adjustment is below
@@ -1193,10 +1202,20 @@ public final class OomAdjuster {

        boolean foregroundActivities = false;
        if (PROCESS_STATE_CUR_TOP == PROCESS_STATE_TOP && app == topApp) {
            // The last app on the list is the foreground app.

            // If specific system app has set ProcessRecord.mHasTopUi or is running a remote
            // animation (ProcessRecord.runningRemoteAnimation), this will prevent topApp
            // to use SCHED_GROUP_TOP_APP to ensure process with mHasTopUi will have exclusive
            // access to configured cores.
            if (mService.containsTopUiOrRunningRemoteAnimOrEmptyLocked(app)) {
                adj = ProcessList.FOREGROUND_APP_ADJ;
                schedGroup = ProcessList.SCHED_GROUP_TOP_APP;
                app.adjType = "top-activity";
            } else {
                adj = ProcessList.FOREGROUND_APP_ADJ;
                schedGroup = ProcessList.SCHED_GROUP_DEFAULT;
                app.adjType = "top-activity-behind-topui";
            }
            foregroundActivities = true;
            procState = PROCESS_STATE_CUR_TOP;
            if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
+10 −0
Original line number Diff line number Diff line
@@ -1268,6 +1268,7 @@ class ProcessRecord implements WindowProcessListener {
    void setHasTopUi(boolean hasTopUi) {
        mHasTopUi = hasTopUi;
        mWindowProcessController.setHasTopUi(hasTopUi);
        updateTopUiOrRunningRemoteAnim();
    }

    boolean hasTopUi() {
@@ -1518,10 +1519,19 @@ class ProcessRecord implements WindowProcessListener {
                Slog.i(TAG, "Setting runningRemoteAnimation=" + runningRemoteAnimation
                        + " for pid=" + pid);
            }
            updateTopUiOrRunningRemoteAnim();
            mService.updateOomAdjLocked(this, true, OomAdjuster.OOM_ADJ_REASON_UI_VISIBILITY);
        }
    }

    void updateTopUiOrRunningRemoteAnim() {
        if (runningRemoteAnimation || hasTopUi()) {
            mService.addTopUiOrRunningRemoteAnim(this);
        } else {
            mService.removeTopUiOrRunningRemoteAnim(this);
        }
    }

    public long getInputDispatchingTimeout() {
        return mWindowProcessController.getInputDispatchingTimeout();
    }
+17 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import static com.android.server.am.ProcessList.VISIBLE_APP_ADJ;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.AdditionalAnswers.answer;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyLong;
@@ -170,6 +171,7 @@ public class MockingOomAdjusterTests {
                mock(OomAdjProfiler.class));
        doReturn(new ActivityManagerService.ProcessChangeItem()).when(sService)
                .enqueueProcessChangeItemLocked(anyInt(), anyInt());
        doReturn(true).when(sService).containsTopUiOrRunningRemoteAnimOrEmptyLocked(any());
        sService.mOomAdjuster = new OomAdjuster(sService, sService.mProcessList,
                mock(ActiveUids.class));
        sService.mOomAdjuster.mAdjSeq = 10000;
@@ -264,6 +266,21 @@ public class MockingOomAdjusterTests {
        assertProcStates(app, PROCESS_STATE_TOP_SLEEPING, VISIBLE_APP_ADJ, SCHED_GROUP_TOP_APP);
    }

    @SuppressWarnings("GuardedBy")
    @Test
    public void testUpdateOomAdj_DoOne_TopApp_PreemptedByTopUi() {
        ProcessRecord app = spy(makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID,
                MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true));
        doReturn(PROCESS_STATE_TOP).when(sService.mAtmInternal).getTopProcessState();
        doReturn(app).when(sService).getTopAppLocked();
        doReturn(false).when(sService).containsTopUiOrRunningRemoteAnimOrEmptyLocked(eq(app));
        sService.mWakefulness = PowerManagerInternal.WAKEFULNESS_AWAKE;
        sService.mOomAdjuster.updateOomAdjLocked(app, false, OomAdjuster.OOM_ADJ_REASON_NONE);
        doReturn(null).when(sService).getTopAppLocked();

        assertProcStates(app, PROCESS_STATE_TOP, FOREGROUND_APP_ADJ, SCHED_GROUP_DEFAULT);
    }

    @SuppressWarnings("GuardedBy")
    @Test
    public void testUpdateOomAdj_DoOne_RunningInstrumentation() {