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

Commit 8702e554 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Use top sched group for last non-top freeform app" into main

parents ca84c998 c525cc31
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1708,6 +1708,11 @@ public class OomAdjuster {
                // priority for this non-top split.
                schedGroup = SCHED_GROUP_TOP_APP;
                mAdjType = "resumed-split-screen-activity";
            } else if ((flags
                    & WindowProcessController.ACTIVITY_STATE_FLAG_PERCEPTIBLE_FREEFORM) != 0) {
                // The recently used non-top visible freeform app.
                schedGroup = SCHED_GROUP_TOP_APP;
                mAdjType = "perceptible-freeform-activity";
            }
            foregroundActivities = true;
            mHasVisibleActivities = true;
+22 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.wm;
import static android.app.ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.content.res.Configuration.ASSETS_SEQ_UNDEFINED;
import static android.os.Build.VERSION_CODES.Q;
@@ -73,6 +74,7 @@ import android.os.LocaleList;
import android.os.Message;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.Log;
@@ -112,6 +114,13 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE;
    private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION;

    /**
     * The max number of processes which can be top scheduling group if there are non-top visible
     * freeform activities run in the process.
     */
    private static final int MAX_NUM_PERCEPTIBLE_FREEFORM =
            SystemProperties.getInt("persist.wm.max_num_perceptible_freeform", 1);

    private static final int MAX_RAPID_ACTIVITY_LAUNCH_COUNT = 200;
    private static final long RAPID_ACTIVITY_LAUNCH_MS = 500;
    private static final long RESET_RAPID_ACTIVITY_LAUNCH_MS = 3 * RAPID_ACTIVITY_LAUNCH_MS;
@@ -318,6 +327,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    public static final int ACTIVITY_STATE_FLAG_HAS_RESUMED = 1 << 21;
    public static final int ACTIVITY_STATE_FLAG_HAS_ACTIVITY_IN_VISIBLE_TASK = 1 << 22;
    public static final int ACTIVITY_STATE_FLAG_RESUMED_SPLIT_SCREEN = 1 << 23;
    public static final int ACTIVITY_STATE_FLAG_PERCEPTIBLE_FREEFORM = 1 << 24;
    public static final int ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER = 0x0000ffff;

    /**
@@ -1229,6 +1239,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
        ActivityRecord.State bestInvisibleState = DESTROYED;
        boolean allStoppingFinishing = true;
        boolean visible = false;
        boolean hasResumedFreeform = false;
        int minTaskLayer = Integer.MAX_VALUE;
        int stateFlags = 0;
        final boolean wasResumed = hasResumedActivity();
@@ -1256,6 +1267,8 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
                                    .processPriorityPolicyForMultiWindowMode()
                            && task.getAdjacentTask() != null) {
                        stateFlags |= ACTIVITY_STATE_FLAG_RESUMED_SPLIT_SCREEN;
                    } else if (windowingMode == WINDOWING_MODE_FREEFORM) {
                        hasResumedFreeform = true;
                    }
                }
                if (minTaskLayer > 0) {
@@ -1289,6 +1302,12 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
            }
        }

        if (hasResumedFreeform
                && com.android.window.flags.Flags.processPriorityPolicyForMultiWindowMode()
                // Exclude task layer 1 because it is already the top most.
                && minTaskLayer > 1 && minTaskLayer <= 1 + MAX_NUM_PERCEPTIBLE_FREEFORM) {
            stateFlags |= ACTIVITY_STATE_FLAG_PERCEPTIBLE_FREEFORM;
        }
        stateFlags |= minTaskLayer & ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER;
        if (visible) {
            stateFlags |= ACTIVITY_STATE_FLAG_IS_VISIBLE;
@@ -2105,6 +2124,9 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
                    if ((stateFlags & ACTIVITY_STATE_FLAG_RESUMED_SPLIT_SCREEN) != 0) {
                        pw.print("RS|");
                    }
                    if ((stateFlags & ACTIVITY_STATE_FLAG_PERCEPTIBLE_FREEFORM) != 0) {
                        pw.print("PF|");
                    }
                }
            } else if ((stateFlags & ACTIVITY_STATE_FLAG_IS_PAUSING_OR_PAUSED) != 0) {
                pw.print("P|");
+7 −0
Original line number Diff line number Diff line
@@ -500,6 +500,13 @@ public class MockingOomAdjusterTests {
        updateOomAdj(app);
        assertProcStates(app, PROCESS_STATE_TOP, VISIBLE_APP_ADJ, SCHED_GROUP_TOP_APP);
        assertEquals("resumed-split-screen-activity", app.mState.getAdjType());

        doReturn(WindowProcessController.ACTIVITY_STATE_FLAG_IS_VISIBLE
                | WindowProcessController.ACTIVITY_STATE_FLAG_PERCEPTIBLE_FREEFORM)
                .when(wpc).getActivityStateFlags();
        updateOomAdj(app);
        assertProcStates(app, PROCESS_STATE_TOP, VISIBLE_APP_ADJ, SCHED_GROUP_TOP_APP);
        assertEquals("perceptible-freeform-activity", app.mState.getAdjType());
    }

    @SuppressWarnings("GuardedBy")