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

Commit 744c95c7 authored by Jeremy Sim's avatar Jeremy Sim Committed by Android (Google) Code Review
Browse files

Merge "Add StageOrderOperator to keep track of stages indicies" into main

parents ea2d2c08 eaf8dd7b
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -70,6 +70,8 @@ import com.android.internal.jank.InteractionJankMonitor
import com.android.internal.policy.ScreenDecorationsUtils
import com.android.internal.protolog.ProtoLog
import com.android.window.flags.Flags
import com.android.window.flags.Flags.enableMoveToNextDisplayShortcut
import com.android.wm.shell.Flags.enableFlexibleSplit
import com.android.wm.shell.R
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTaskOrganizer
@@ -102,6 +104,7 @@ import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus.DESKTOP_DENSITY_OVERRIDE
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus.useDesktopOverrideDensity
import com.android.wm.shell.shared.desktopmode.DesktopModeTransitionSource
import com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_INDEX_UNDEFINED
import com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT
import com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT
import com.android.wm.shell.splitscreen.SplitScreenController
@@ -1512,11 +1515,15 @@ class DesktopTasksController(
            WINDOWING_MODE_MULTI_WINDOW -> {
                val splitPosition = splitScreenController
                    .determineNewInstancePosition(callingTaskInfo)
                // TODO(b/349828130) currently pass in index_undefined until we can revisit these
                //  specific cases in the future.
                val splitIndex = if (enableFlexibleSplit())
                    splitScreenController.determineNewInstanceIndex(callingTaskInfo) else
                    SPLIT_INDEX_UNDEFINED
                splitScreenController.startIntent(
                    launchIntent, context.userId, fillIn, splitPosition,
                    options.toBundle(), null /* hideTaskToken */,
                    true /* forceLaunchNewTask */
                )
                    true /* forceLaunchNewTask */, splitIndex)
            }
            WINDOWING_MODE_FREEFORM -> {
                val wct = WindowContainerTransaction()
+27 −18
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ import static com.android.wm.shell.draganddrop.SplitDragPolicy.Target.TYPE_SPLIT
import static com.android.wm.shell.draganddrop.SplitDragPolicy.Target.TYPE_SPLIT_TOP;
import static com.android.wm.shell.shared.draganddrop.DragAndDropConstants.EXTRA_DISALLOW_HIT_REGION;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SNAP_TO_2_50_50;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_INDEX_0;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_INDEX_1;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_INDEX_UNDEFINED;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_UNDEFINED;
@@ -81,6 +84,7 @@ import com.android.wm.shell.draganddrop.anim.HoverAnimProps;
import com.android.wm.shell.draganddrop.anim.TwoFiftyFiftyTargetAnimator;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.shared.split.SplitScreenConstants;
import com.android.wm.shell.shared.split.SplitScreenConstants.SplitIndex;
import com.android.wm.shell.shared.split.SplitScreenConstants.SplitPosition;
import com.android.wm.shell.splitscreen.SplitScreenController;

@@ -219,8 +223,10 @@ public class SplitDragPolicy implements DropTarget {
                        displayRegion.splitHorizontally(startHitRegion, endHitRegion);
                    }

                    mTargets.add(new Target(TYPE_SPLIT_LEFT, startHitRegion, startBounds, -1));
                    mTargets.add(new Target(TYPE_SPLIT_RIGHT, endHitRegion, endBounds, -1));
                    mTargets.add(new Target(TYPE_SPLIT_LEFT, startHitRegion, startBounds,
                            SPLIT_INDEX_0));
                    mTargets.add(new Target(TYPE_SPLIT_RIGHT, endHitRegion, endBounds,
                            SPLIT_INDEX_1));
                } else {
                    // TODO(b/349828130), move this into init function and/or the insets updating
                    //  callback
@@ -287,9 +293,10 @@ public class SplitDragPolicy implements DropTarget {
                        displayRegion.splitVertically(leftHitRegion, rightHitRegion);
                    }

                    mTargets.add(new Target(TYPE_SPLIT_LEFT, leftHitRegion, topOrLeftBounds, -1));
                    mTargets.add(new Target(TYPE_SPLIT_LEFT, leftHitRegion, topOrLeftBounds,
                            SPLIT_INDEX_UNDEFINED));
                    mTargets.add(new Target(TYPE_SPLIT_RIGHT, rightHitRegion, bottomOrRightBounds,
                            -1));
                            SPLIT_INDEX_UNDEFINED));
                } else {
                    final Rect topHitRegion = new Rect();
                    final Rect bottomHitRegion = new Rect();
@@ -308,9 +315,10 @@ public class SplitDragPolicy implements DropTarget {
                        displayRegion.splitHorizontally(topHitRegion, bottomHitRegion);
                    }

                    mTargets.add(new Target(TYPE_SPLIT_TOP, topHitRegion, topOrLeftBounds, -1));
                    mTargets.add(new Target(TYPE_SPLIT_TOP, topHitRegion, topOrLeftBounds,
                            SPLIT_INDEX_UNDEFINED));
                    mTargets.add(new Target(TYPE_SPLIT_BOTTOM, bottomHitRegion, bottomOrRightBounds,
                            -1));
                            SPLIT_INDEX_UNDEFINED));
                }
            }
        } else {
@@ -378,9 +386,9 @@ public class SplitDragPolicy implements DropTarget {
                ? mFullscreenStarter
                : mSplitscreenStarter;
        if (mSession.appData != null) {
            launchApp(mSession, starter, position, hideTaskToken);
            launchApp(mSession, starter, position, hideTaskToken, target.index);
        } else {
            launchIntent(mSession, starter, position, hideTaskToken);
            launchIntent(mSession, starter, position, hideTaskToken, target.index);
        }

        if (enableFlexibleSplit()) {
@@ -392,9 +400,10 @@ public class SplitDragPolicy implements DropTarget {
     * Launches an app provided by SysUI.
     */
    private void launchApp(DragSession session, Starter starter, @SplitPosition int position,
            @Nullable WindowContainerToken hideTaskToken) {
        ProtoLog.v(ShellProtoLogGroup.WM_SHELL_DRAG_AND_DROP, "Launching app data at position=%d",
                position);
            @Nullable WindowContainerToken hideTaskToken, @SplitIndex int splitIndex) {
        ProtoLog.v(ShellProtoLogGroup.WM_SHELL_DRAG_AND_DROP,
                "Launching app data at position=%d index=%d",
                position, splitIndex);
        final ClipDescription description = session.getClipDescription();
        final boolean isTask = description.hasMimeType(MIMETYPE_APPLICATION_TASK);
        final boolean isShortcut = description.hasMimeType(MIMETYPE_APPLICATION_SHORTCUT);
@@ -429,7 +438,7 @@ public class SplitDragPolicy implements DropTarget {
                }
            }
            starter.startIntent(launchIntent, user.getIdentifier(), null /* fillIntent */,
                    position, opts, hideTaskToken);
                    position, opts, hideTaskToken, splitIndex);
        }
    }

@@ -437,7 +446,7 @@ public class SplitDragPolicy implements DropTarget {
     * Launches an intent sender provided by an application.
     */
    private void launchIntent(DragSession session, Starter starter, @SplitPosition int position,
            @Nullable WindowContainerToken hideTaskToken) {
            @Nullable WindowContainerToken hideTaskToken, @SplitIndex int index) {
        ProtoLog.v(ShellProtoLogGroup.WM_SHELL_DRAG_AND_DROP, "Launching intent at position=%d",
                position);
        final ActivityOptions baseActivityOpts = ActivityOptions.makeBasic();
@@ -452,7 +461,7 @@ public class SplitDragPolicy implements DropTarget {
        final Bundle opts = baseActivityOpts.toBundle();
        starter.startIntent(session.launchableIntent,
                session.launchableIntent.getCreatorUserHandle().getIdentifier(),
                null /* fillIntent */, position, opts, hideTaskToken);
                null /* fillIntent */, position, opts, hideTaskToken, index);
    }

    @Override
@@ -541,7 +550,7 @@ public class SplitDragPolicy implements DropTarget {
                @Nullable Bundle options, UserHandle user);
        void startIntent(PendingIntent intent, int userId, Intent fillInIntent,
                @SplitPosition int position, @Nullable Bundle options,
                @Nullable WindowContainerToken hideTaskToken);
                @Nullable WindowContainerToken hideTaskToken, @SplitIndex int index);
        void enterSplitScreen(int taskId, boolean leftOrTop);

        /**
@@ -592,7 +601,7 @@ public class SplitDragPolicy implements DropTarget {
        @Override
        public void startIntent(PendingIntent intent, int userId, @Nullable Intent fillInIntent,
                int position, @Nullable Bundle options,
                @Nullable WindowContainerToken hideTaskToken) {
                @Nullable WindowContainerToken hideTaskToken, @SplitIndex int index) {
            if (hideTaskToken != null) {
                ProtoLog.v(ShellProtoLogGroup.WM_SHELL_DRAG_AND_DROP,
                        "Default starter does not support hide task token");
@@ -641,13 +650,13 @@ public class SplitDragPolicy implements DropTarget {
        final Rect hitRegion;
        // The approximate visual region for where the task will start
        final Rect drawRegion;
        int index;
        @SplitIndex int index;

        /**
         * @param index 0-indexed, represents which position of drop target this object represents,
         *              0 to N for left to right, top to bottom
         */
        public Target(@Type int t, Rect hit, Rect draw, int index) {
        public Target(@Type int t, Rect hit, Rect draw, @SplitIndex int index) {
            type = t;
            hitRegion = hit;
            drawRegion = draw;
+8 −4
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@ import android.graphics.Rect
import com.android.wm.shell.R
import com.android.wm.shell.common.DisplayLayout
import com.android.wm.shell.draganddrop.SplitDragPolicy.Target
import com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_INDEX_0
import com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_INDEX_1
import com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_INDEX_2
import com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_INDEX_3

/**
 * Represents Drop Zone targets and animations for when the system is currently in a 2 app 50/50
@@ -98,7 +102,7 @@ class TwoFiftyFiftyTargetAnimator : DropTargetAnimSupplier {
                    farStartBounds.right + halfDividerWidth,
                    farStartBounds.bottom
                ),
                farStartBounds, 0
                farStartBounds, SPLIT_INDEX_0
            )
        )
        targets.add(
@@ -110,7 +114,7 @@ class TwoFiftyFiftyTargetAnimator : DropTargetAnimSupplier {
                    startBounds.right + halfDividerWidth,
                    startBounds.bottom
                ),
                startBounds, 1
                startBounds, SPLIT_INDEX_1
            )
        )
        targets.add(
@@ -120,7 +124,7 @@ class TwoFiftyFiftyTargetAnimator : DropTargetAnimSupplier {
                    endBounds.left - halfDividerWidth,
                    endBounds.top, endBounds.right, endBounds.bottom
                ),
                endBounds, 2
                endBounds, SPLIT_INDEX_2
            )
        )
        targets.add(
@@ -130,7 +134,7 @@ class TwoFiftyFiftyTargetAnimator : DropTargetAnimSupplier {
                    farEndBounds.left - halfDividerWidth,
                    farEndBounds.top, farEndBounds.right, farEndBounds.bottom
                ),
                farEndBounds, 3
                farEndBounds, SPLIT_INDEX_3
            )
        )

+21 −1
Original line number Diff line number Diff line
@@ -54,10 +54,27 @@ public interface SplitScreen {
     */
    int STAGE_TYPE_SIDE = 1;

    /**
     * Position independent stage identifier for a given Stage
     */
    int STAGE_TYPE_A = 2;
    /**
     * Position independent stage identifier for a given Stage
     */
    int STAGE_TYPE_B = 3;
    /**
     * Position independent stage identifier for a given Stage
     */
    int STAGE_TYPE_C = 4;

    @IntDef(prefix = { "STAGE_TYPE_" }, value = {
            STAGE_TYPE_UNDEFINED,
            STAGE_TYPE_MAIN,
            STAGE_TYPE_SIDE
            STAGE_TYPE_SIDE,
            // Used for flexible split
            STAGE_TYPE_A,
            STAGE_TYPE_B,
            STAGE_TYPE_C
    })
    @interface StageType {}

@@ -128,6 +145,9 @@ public interface SplitScreen {
            case STAGE_TYPE_UNDEFINED: return "UNDEFINED";
            case STAGE_TYPE_MAIN: return "MAIN";
            case STAGE_TYPE_SIDE: return "SIDE";
            case STAGE_TYPE_A: return "STAGE_A";
            case STAGE_TYPE_B: return "STAGE_B";
            case STAGE_TYPE_C: return "STAGE_C";
            default: return "UNKNOWN(" + stage + ")";
        }
    }
+36 −9
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NO_USER_ACTION;
import static android.view.Display.DEFAULT_DISPLAY;

import static com.android.wm.shell.Flags.enableFlexibleSplit;
import static com.android.wm.shell.common.MultiInstanceHelper.getComponent;
import static com.android.wm.shell.common.MultiInstanceHelper.getShortcutComponent;
import static com.android.wm.shell.common.MultiInstanceHelper.samePackage;
@@ -33,6 +34,9 @@ import static com.android.wm.shell.common.split.SplitScreenUtils.splitFailureMes
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_SPLIT_SCREEN;
import static com.android.wm.shell.shared.ShellSharedConstants.KEY_EXTRA_SHELL_SPLIT_SCREEN;
import static com.android.wm.shell.shared.split.SplitScreenConstants.KEY_EXTRA_WIDGET_INTENT;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_INDEX_0;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_INDEX_1;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_INDEX_UNDEFINED;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_UNDEFINED;
@@ -98,6 +102,7 @@ import com.android.wm.shell.recents.RecentTasksController;
import com.android.wm.shell.shared.TransactionPool;
import com.android.wm.shell.shared.annotations.ExternalThread;
import com.android.wm.shell.shared.split.SplitScreenConstants.PersistentSnapPosition;
import com.android.wm.shell.shared.split.SplitScreenConstants.SplitIndex;
import com.android.wm.shell.shared.split.SplitScreenConstants.SplitPosition;
import com.android.wm.shell.splitscreen.SplitScreen.StageType;
import com.android.wm.shell.sysui.KeyguardChangeListener;
@@ -325,7 +330,6 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
    /**
     * @return an Array of RunningTaskInfo's ordered by leftToRight or topTopBottom
     */
    @Nullable
    public ActivityManager.RunningTaskInfo[] getAllTaskInfos() {
        // TODO(b/349828130) Add the third stage task info and not rely on positions
        ActivityManager.RunningTaskInfo topLeftTask = getTaskInfo(SPLIT_POSITION_TOP_OR_LEFT);
@@ -335,7 +339,7 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
            return new ActivityManager.RunningTaskInfo[]{topLeftTask, bottomRightTask};
        }

        return null;
        return new ActivityManager.RunningTaskInfo[0];
    }

    /** Check task is under split or not by taskId. */
@@ -405,7 +409,7 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
    public void prepareEnterSplitScreen(WindowContainerTransaction wct,
            ActivityManager.RunningTaskInfo taskInfo, int startPosition) {
        mStageCoordinator.prepareEnterSplitScreen(wct, taskInfo, startPosition,
                false /* resizeAnim */);
                false /* resizeAnim */, SPLIT_INDEX_UNDEFINED);
    }

    /**
@@ -451,6 +455,24 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
        }
    }

    /**
     * Determines which split index a new instance of a task should take.
     * @param callingTask The task requesting a new instance.
     * @return the split index of the new instance
     */
    @SplitIndex
    public int determineNewInstanceIndex(@NonNull ActivityManager.RunningTaskInfo callingTask) {
        if (!enableFlexibleSplit()) {
            throw new IllegalStateException("Use determineNewInstancePosition");
        }
        if (callingTask.getWindowingMode() == WINDOWING_MODE_FULLSCREEN
                || getSplitPosition(callingTask.taskId) == SPLIT_POSITION_TOP_OR_LEFT) {
            return SPLIT_INDEX_1;
        } else {
            return SPLIT_INDEX_0;
        }
    }

    public void enterSplitScreen(int taskId, boolean leftOrTop) {
        enterSplitScreen(taskId, leftOrTop, new WindowContainerTransaction());
    }
@@ -685,7 +707,10 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
        ProtoLog.d(WM_SHELL_SPLIT_SCREEN, "startIntentWithInstanceId: reason=%d",
                ENTER_REASON_LAUNCHER);
        mStageCoordinator.getLogger().enterRequested(instanceId, ENTER_REASON_LAUNCHER);
        startIntent(intent, userId, fillInIntent, position, options, null /* hideTaskToken */);
        // TODO(b/349828130) currently pass in index_undefined until we can revisit these
        //  specific cases in the future. Only focusing on parity with starting intent/task
        startIntent(intent, userId, fillInIntent, position, options, null /* hideTaskToken */,
                SPLIT_INDEX_UNDEFINED);
    }

    private void startIntentAndTask(PendingIntent pendingIntent, int userId1,
@@ -775,9 +800,9 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
    @Override
    public void startIntent(PendingIntent intent, int userId1, @Nullable Intent fillInIntent,
            @SplitPosition int position, @Nullable Bundle options,
            @Nullable WindowContainerToken hideTaskToken) {
            @Nullable WindowContainerToken hideTaskToken, @SplitIndex int index) {
        startIntent(intent, userId1, fillInIntent, position, options, hideTaskToken,
                false /* forceLaunchNewTask */);
                false /* forceLaunchNewTask */, index);
    }

    /**
@@ -790,7 +815,8 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
     */
    public void startIntent(PendingIntent intent, int userId1, @Nullable Intent fillInIntent,
            @SplitPosition int position, @Nullable Bundle options,
            @Nullable WindowContainerToken hideTaskToken, boolean forceLaunchNewTask) {
            @Nullable WindowContainerToken hideTaskToken, boolean forceLaunchNewTask,
            @SplitIndex int index) {
        ProtoLog.v(ShellProtoLogGroup.WM_SHELL_SPLIT_SCREEN,
                "startIntent(): intent=%s user=%d fillInIntent=%s position=%d", intent, userId1,
                fillInIntent, position);
@@ -816,7 +842,7 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
        if (taskInfo != null) {
            ProtoLog.v(ShellProtoLogGroup.WM_SHELL_SPLIT_SCREEN,
                    "Found suitable background task=%s", taskInfo);
            mStageCoordinator.startTask(taskInfo.taskId, position, options, hideTaskToken);
            mStageCoordinator.startTask(taskInfo.taskId, position, options, hideTaskToken, index);

            ProtoLog.v(ShellProtoLogGroup.WM_SHELL_SPLIT_SCREEN, "Start task in background");
            return;
@@ -841,7 +867,8 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
            }
        }

        mStageCoordinator.startIntent(intent, fillInIntent, position, options, hideTaskToken);
        mStageCoordinator.startIntent(intent, fillInIntent, position, options, hideTaskToken,
                index);
    }

    /**
Loading