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

Commit ab07fda4 authored by Shuming Hao's avatar Shuming Hao Committed by Android (Google) Code Review
Browse files

Merge "Refactor StageCoordinator to use SplitMultiDisplayHelper" into main

parents b95b3b96 30c76b60
Loading
Loading
Loading
Loading
+100 −60
Original line number Diff line number Diff line
@@ -244,12 +244,6 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
    private final Rect mTempRect1 = new Rect();
    private final Rect mTempRect2 = new Rect();

    /**
     * A single-top root task which the split divider attached to.
     */
    @VisibleForTesting
    ActivityManager.RunningTaskInfo mRootTaskInfo;

    private SurfaceControl mRootTaskLeash;

    // Tracks whether we should update the recent tasks.  Only allow this to happen in between enter
@@ -278,7 +272,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
    // because we will be posting and removing it from the handler.
    private final Runnable mReEnableLaunchAdjacentOnRoot = () -> setLaunchAdjacentDisabled(false);

    private SplitMultiDisplayHelper mSplitMultiDisplayHelper;
    @VisibleForTesting
    SplitMultiDisplayHelper mSplitMultiDisplayHelper;

    /**
     * Since StageCoordinator only coordinates MainStage and SideStage, it shouldn't support
@@ -300,7 +295,9 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
    @Override
    public WindowContainerToken getDisplayRootForDisplayId(int displayId) {
        if (displayId == DEFAULT_DISPLAY) {
            return mRootTaskInfo != null ? mRootTaskInfo.token : null;
            ActivityManager.RunningTaskInfo rootTaskInfo =
                    mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
            return rootTaskInfo != null ? rootTaskInfo.token : null;
        }

        // TODO(b/393217881): support different root task on external displays.
@@ -364,9 +361,11 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                    SurfaceControl bottomRightLeash =
                            mSideStagePosition == SPLIT_POSITION_BOTTOM_OR_RIGHT
                                    ? mSideStage.mRootLeash : mMainStage.mRootLeash;
                    ActivityManager.RunningTaskInfo rootTaskInfo =
                            mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
                    touchZone.inflate(
                            mContext.createConfigurationContext(mRootTaskInfo.configuration),
                            mRootTaskInfo.configuration, mSyncQueue,
                            mContext.createConfigurationContext(rootTaskInfo.configuration),
                            rootTaskInfo.configuration, mSyncQueue,
                            touchZone.isTopLeft() ? topLeftLeash : bottomRightLeash);
                }
            };
@@ -491,6 +490,9 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        mFoldLockSettingsObserver =
                new FoldLockSettingsObserver(context.getMainThreadHandler(), context);
        mFoldLockSettingsObserver.register();
        DisplayManager displayManager = context.getSystemService(DisplayManager.class);
        mSplitMultiDisplayHelper = new SplitMultiDisplayHelper(
                Objects.requireNonNull(displayManager));
    }

    public void setMixedHandler(DefaultMixedHandler mixedHandler) {
@@ -637,7 +639,9 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
    }

    boolean isRootOrStageRoot(int taskId) {
        if (mRootTaskInfo != null && mRootTaskInfo.taskId == taskId) {
        ActivityManager.RunningTaskInfo rootTaskInfo =
                mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
        if (rootTaskInfo != null && rootTaskInfo.taskId == taskId) {
            return true;
        }
        if (enableFlexibleSplit()) {
@@ -870,7 +874,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                    && getStageOfTask(taskId2) != STAGE_TYPE_UNDEFINED
                    && taskInfo1.displayId != DEFAULT_DISPLAY
                    && taskInfo1.displayId == taskInfo2.displayId) {
                wct.reparent(mRootTaskInfo.token, displayAreaInfo.token, true);
                wct.reparent(mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY).token,
                        displayAreaInfo.token, true);
                mTaskOrganizer.applyTransaction(wct);
                return;
            }
@@ -1031,8 +1036,10 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        }
        mSplitLayout.setDivideRatio(snapPosition);
        updateWindowBounds(mSplitLayout, wct);
        wct.reorder(mRootTaskInfo.token, true);
        wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
        ActivityManager.RunningTaskInfo rootTaskInfo =
                mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
        wct.reorder(rootTaskInfo.token, true);
        wct.setReparentLeafTaskIfRelaunch(rootTaskInfo.token,
                false /* reparentLeafTaskIfRelaunch */);
        setRootForceTranslucent(false, wct);
        // All callers of this method set the correct activity options on mSideStage,
@@ -1111,8 +1118,10 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        setSideStagePosition(splitPosition, wct);
        mSplitLayout.setDivideRatio(snapPosition);
        updateWindowBounds(mSplitLayout, wct);
        wct.reorder(mRootTaskInfo.token, true);
        wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
        ActivityManager.RunningTaskInfo rootTaskInfo =
                mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
        wct.reorder(rootTaskInfo.token, true);
        wct.setReparentLeafTaskIfRelaunch(rootTaskInfo.token,
                false /* reparentLeafTaskIfRelaunch */);
        setRootForceTranslucent(false, wct);

@@ -1156,14 +1165,16 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
    public void setExcludeImeInsets(boolean exclude) {
        if (android.view.inputmethod.Flags.refactorInsetsController()) {
            final WindowContainerTransaction wct = new WindowContainerTransaction();
            if (mRootTaskInfo == null) {
                ProtoLog.e(WM_SHELL_SPLIT_SCREEN, "setExcludeImeInsets: mRootTaskInfo is null");
            ActivityManager.RunningTaskInfo rootTaskInfo =
                    mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
            if (rootTaskInfo == null) {
                ProtoLog.e(WM_SHELL_SPLIT_SCREEN, "setExcludeImeInsets: rootTaskInfo is null");
                return;
            }
            ProtoLog.d(WM_SHELL_SPLIT_SCREEN,
                    "setExcludeImeInsets: root taskId=%s exclude=%s",
                    mRootTaskInfo.taskId, exclude);
            wct.setExcludeImeInsets(mRootTaskInfo.token, exclude);
                    rootTaskInfo.taskId, exclude);
            wct.setExcludeImeInsets(rootTaskInfo.token, exclude);
            mTaskOrganizer.applyTransaction(wct);
        }
    }
@@ -1354,7 +1365,9 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        // while it is moving across the screen, because granting focus also recalculates the
        // layering order, which is in delicate balance during this animation.
        WindowContainerTransaction noFocus = new WindowContainerTransaction();
        noFocus.setFocusable(mRootTaskInfo.token, false);
        ActivityManager.RunningTaskInfo rootTaskInfo =
                mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
        noFocus.setFocusable(rootTaskInfo.token, false);
        mSyncQueue.queue(noFocus);
        // Remove touch layers, since offscreen apps coming onscreen will not need their touch
        // layers anymore. populateTouchZones() is called in the end callback to inflate new touch
@@ -1370,7 +1383,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                    WindowContainerTransaction wct = new WindowContainerTransaction();

                    // Restore focus-ability to the windows and divider
                    wct.setFocusable(mRootTaskInfo.token, true);
                    wct.setFocusable(rootTaskInfo.token, true);

                    if (enableFlexibleSplit()) {
                        mStageOrderOperator.onDoubleTappedDivider();
@@ -1543,10 +1556,12 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        mSplitRequest = null;

        mSplitLayout.getInvisibleBounds(mTempRect1);
        ActivityManager.RunningTaskInfo rootTaskInfo =
                mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
        if (childrenToTop == null || childrenToTop.getTopVisibleChildTaskId() == INVALID_TASK_ID) {
            mSideStage.removeAllTasks(wct, false /* toTop */);
            deactivateSplit(wct, STAGE_TYPE_UNDEFINED);
            wct.reorder(mRootTaskInfo.token, false /* onTop */);
            wct.reorder(rootTaskInfo.token, false /* onTop */);
            setRootForceTranslucent(true, wct);
            wct.setBounds(mSideStage.mRootTaskInfo.token, mTempRect1);
            onTransitionAnimationComplete();
@@ -1557,7 +1572,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
            childrenToTop.resetBounds(wct);
            wct.reorder(childrenToTop.mRootTaskInfo.token, true);
        }
        wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
        wct.setReparentLeafTaskIfRelaunch(rootTaskInfo.token,
                false /* reparentLeafTaskIfRelaunch */);
        mSyncQueue.queue(wct);
        mSyncQueue.runInSync(t -> {
@@ -1576,7 +1591,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                    mIsExiting = false;
                    deactivateSplit(finishedWCT, childrenToTop.getId());
                    mSideStage.removeAllTasks(finishedWCT, childrenToTop == mSideStage /* toTop */);
                    finishedWCT.reorder(mRootTaskInfo.token, false /* toTop */);
                    finishedWCT.reorder(rootTaskInfo.token, false /* toTop */);
                    setRootForceTranslucent(true, finishedWCT);
                    finishedWCT.setBounds(mSideStage.mRootTaskInfo.token, mTempRect1);
                    mSyncQueue.queue(finishedWCT);
@@ -1759,10 +1774,12 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
            });
        }
        // Reparent root task to default display if non default display split is enabled.
        if (enableNonDefaultDisplaySplit() && mRootTaskInfo.displayId != DEFAULT_DISPLAY) {
        ActivityManager.RunningTaskInfo rootTaskInfo =
                mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
        if (enableNonDefaultDisplaySplit() && rootTaskInfo.displayId != DEFAULT_DISPLAY) {
            DisplayAreaInfo displayAreaInfo = mRootTDAOrganizer.getDisplayAreaInfo(DEFAULT_DISPLAY);
            if (displayAreaInfo != null) {
                wct.reparent(mRootTaskInfo.token, displayAreaInfo.token, false /* onTop */);
                wct.reparent(rootTaskInfo.token, displayAreaInfo.token, false /* onTop */);
            }
        }
        deactivateSplit(wct, stageToTop);
@@ -1788,7 +1805,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        // Preemptively reset the reparenting behavior if we know that we are entering, as starting
        // split tasks with activity trampolines can inadvertently trigger the task to be
        // reparented out of the split root mid-launch
        wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
        wct.setReparentLeafTaskIfRelaunch(mSplitMultiDisplayHelper
                        .getDisplayRootTaskInfo(DEFAULT_DISPLAY).token,
                false /* setReparentLeafTaskIfRelaunch */);
        if (isSplitActive()) {
            prepareBringSplit(wct, taskInfo, startPosition, resizeAnim);
@@ -1859,7 +1877,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
            mSplitLayout.getInvisibleBounds(mTempRect1);
            mSplitLayout.setTaskBounds(wct, mSideStage.mRootTaskInfo, mTempRect1);
        }
        wct.reorder(mRootTaskInfo.token, true);
        wct.reorder(mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY).token, true);
        setRootForceTranslucent(false, wct);
    }

@@ -2154,18 +2172,20 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
    @Override
    @CallSuper
    public void onTaskAppeared(ActivityManager.RunningTaskInfo taskInfo, SurfaceControl leash) {
        if (mRootTaskInfo != null || taskInfo.hasParentTask()) {
        if (mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY) != null
                || taskInfo.hasParentTask()) {
            throw new IllegalArgumentException(this + "\n Unknown task appeared: " + taskInfo);
        }

        ProtoLog.d(WM_SHELL_SPLIT_SCREEN, "onTaskAppeared: task=%s", taskInfo);
        mRootTaskInfo = taskInfo;

        mSplitMultiDisplayHelper.setDisplayRootTaskInfo(DEFAULT_DISPLAY, taskInfo);
        mRootTaskLeash = leash;

        if (mSplitLayout == null) {
            int parallaxType = enableFlexibleTwoAppSplit() ? PARALLAX_FLEX : PARALLAX_ALIGN_CENTER;
            mSplitLayout = new SplitLayout(TAG + "SplitDivider", mContext,
                    mRootTaskInfo.configuration, this, mParentContainerCallbacks,
                    taskInfo.configuration, this, mParentContainerCallbacks,
                    mDisplayController, mDisplayImeController, mTaskOrganizer, parallaxType,
                    mSplitState, mMainHandler);
            mDisplayInsetsController.addInsetsChangedListener(mDisplayId, mSplitLayout);
@@ -2177,12 +2197,16 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
    @Override
    @CallSuper
    public void onTaskInfoChanged(ActivityManager.RunningTaskInfo taskInfo) {
        if (mRootTaskInfo == null || mRootTaskInfo.taskId != taskInfo.taskId) {
        ActivityManager.RunningTaskInfo rootTaskInfo =
                mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
        if (rootTaskInfo == null || rootTaskInfo.taskId != taskInfo.taskId) {
            throw new IllegalArgumentException(this + "\n Unknown task info changed: " + taskInfo);
        }
        mRootTaskInfo = taskInfo;

        mSplitMultiDisplayHelper.setDisplayRootTaskInfo(DEFAULT_DISPLAY, taskInfo);

        if (mSplitLayout != null
                && mSplitLayout.updateConfiguration(mRootTaskInfo.configuration)
                && mSplitLayout.updateConfiguration(taskInfo.configuration)
                && isSplitActive()) {
            ProtoLog.d(WM_SHELL_SPLIT_SCREEN, "onTaskInfoChanged: task=%d updating",
                    taskInfo.taskId);
@@ -2199,7 +2223,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
    @CallSuper
    public void onTaskVanished(ActivityManager.RunningTaskInfo taskInfo) {
        ProtoLog.d(WM_SHELL_SPLIT_SCREEN, "onTaskVanished: task=%s", taskInfo);
        if (mRootTaskInfo == null) {
        if (mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY) == null) {
            throw new IllegalArgumentException(this + "\n Unknown task vanished: " + taskInfo);
        }

@@ -2210,7 +2234,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
            mSplitLayout = null;
        }

        mRootTaskInfo = null;
        mSplitMultiDisplayHelper.setDisplayRootTaskInfo(DEFAULT_DISPLAY, null);
        mRootTaskLeash = null;
        mIsRootTranslucent = false;
    }
@@ -2219,9 +2243,11 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
    @VisibleForTesting
    @Override
    public void onRootTaskAppeared() {
        ActivityManager.RunningTaskInfo rootTaskInfo =
                mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
        if (enableFlexibleSplit()) {
            ProtoLog.d(WM_SHELL_SPLIT_SCREEN, "onRootTaskAppeared: rootTask=%s",
                mRootTaskInfo);
                    rootTaskInfo);
            mStageOrderOperator.getAllStages().forEach(stage -> {
                ProtoLog.d(WM_SHELL_SPLIT_SCREEN,
                        "    onRootStageAppeared stageId=%s hasRoot=%b",
@@ -2230,7 +2256,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        } else {
            ProtoLog.d(WM_SHELL_SPLIT_SCREEN,
                    "onRootTaskAppeared: rootTask=%s mainRoot=%b sideRoot=%b",
                    mRootTaskInfo, mMainStage.mHasRootTask, mSideStage.mHasRootTask);
                    rootTaskInfo, mMainStage.mHasRootTask, mSideStage.mHasRootTask);
        }
        boolean notAllStagesHaveRootTask;
        if (enableFlexibleSplit()) {
@@ -2241,17 +2267,17 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                    || !mSideStage.mHasRootTask;
        }
        // Wait unit all root tasks appeared.
        if (mRootTaskInfo == null || notAllStagesHaveRootTask) {
        if (rootTaskInfo == null || notAllStagesHaveRootTask) {
            return;
        }

        final WindowContainerTransaction wct = new WindowContainerTransaction();
        if (enableFlexibleSplit()) {
            mStageOrderOperator.getAllStages().forEach(stage ->
                    wct.reparent(stage.mRootTaskInfo.token, mRootTaskInfo.token, true));
                    wct.reparent(stage.mRootTaskInfo.token, rootTaskInfo.token, true));
        } else {
            wct.reparent(mMainStage.mRootTaskInfo.token, mRootTaskInfo.token, true);
            wct.reparent(mSideStage.mRootTaskInfo.token, mRootTaskInfo.token, true);
            wct.reparent(mMainStage.mRootTaskInfo.token, rootTaskInfo.token, true);
            wct.reparent(mSideStage.mRootTaskInfo.token, rootTaskInfo.token, true);
        }

        setRootForceTranslucent(true, wct);
@@ -2287,7 +2313,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        if (mIsRootTranslucent == translucent) return;

        mIsRootTranslucent = translucent;
        wct.setForceTranslucent(mRootTaskInfo.token, translucent);
        wct.setForceTranslucent(mSplitMultiDisplayHelper
                .getDisplayRootTaskInfo(DEFAULT_DISPLAY).token, translucent);
    }

    /** Callback when split roots visiblility changed.
@@ -2317,14 +2344,16 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        }

        final WindowContainerTransaction wct = new WindowContainerTransaction();
        ActivityManager.RunningTaskInfo rootTaskInfo =
                mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
        if (!mainStageVisible) {
            // Split entering background.
            wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
            wct.setReparentLeafTaskIfRelaunch(rootTaskInfo.token,
                    true /* setReparentLeafTaskIfRelaunch */);
            setRootForceTranslucent(true, wct);
        } else {
            clearRequestIfPresented();
            wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
            wct.setReparentLeafTaskIfRelaunch(rootTaskInfo.token,
                    false /* setReparentLeafTaskIfRelaunch */);
            setRootForceTranslucent(false, wct);
        }
@@ -2480,8 +2509,10 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        toTopStage.resetBounds(wct);
        prepareExitSplitScreen(dismissTop, wct, EXIT_REASON_DRAG_DIVIDER);
        if (mRootTaskInfo != null) {
            wct.setDoNotPip(mRootTaskInfo.token);
        ActivityManager.RunningTaskInfo rootTaskInfo =
                mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
        if (rootTaskInfo != null) {
            wct.setDoNotPip(rootTaskInfo.token);
        }

        mSplitTransitions.startDismissTransition(wct, this, dismissTop, EXIT_REASON_DRAG_DIVIDER);
@@ -3136,7 +3167,9 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,

                final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
                if (taskInfo == null) continue;
                if (taskInfo.token.equals(mRootTaskInfo.token)) {
                ActivityManager.RunningTaskInfo rootTaskInfo =
                        mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY);
                if (taskInfo.token.equals(rootTaskInfo.token)) {
                    if (isOpeningType(change.getMode())) {
                        // Split is opened by someone so set it as visible.
                        setSplitsVisible(true);
@@ -3144,7 +3177,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                        //  This is setting the flag to a task and not interfering with the
                        //  transition.
                        final WindowContainerTransaction wct = new WindowContainerTransaction();
                        wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
                        wct.setReparentLeafTaskIfRelaunch(rootTaskInfo.token,
                                false /* reparentLeafTaskIfRelaunch */);
                        mTaskOrganizer.applyTransaction(wct);
                    } else if (isClosingType(change.getMode())) {
@@ -3154,7 +3187,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                        //  This is setting the flag to a task and not interfering with the
                        //  transition.
                        final WindowContainerTransaction wct = new WindowContainerTransaction();
                        wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
                        wct.setReparentLeafTaskIfRelaunch(rootTaskInfo.token,
                                true /* reparentLeafTaskIfRelaunch */);
                        mTaskOrganizer.applyTransaction(wct);
                    }
@@ -3365,7 +3398,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
    private void setLaunchAdjacentDisabled(boolean disabled) {
        ProtoLog.d(WM_SHELL_SPLIT_SCREEN, "setLaunchAdjacentDisabled: disabled=%b", disabled);
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        wct.setDisableLaunchAdjacent(mRootTaskInfo.token, disabled);
        wct.setDisableLaunchAdjacent(mSplitMultiDisplayHelper
                .getDisplayRootTaskInfo(DEFAULT_DISPLAY).token, disabled);
        mTaskOrganizer.applyTransaction(wct);
    }

@@ -3404,7 +3438,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                }
                mSplitTransitions.playDragDismissAnimation(transition, info, startTransaction,
                        finishTransaction, finishCallback, toTopStage.mRootTaskInfo.token,
                        toTopStage.getSplitDecorManager(), mRootTaskInfo.token);
                        toTopStage.getSplitDecorManager(), mSplitMultiDisplayHelper
                                .getDisplayRootTaskInfo(DEFAULT_DISPLAY).token);
                return true;
            }
        } else if (mSplitTransitions.isPendingResize(transition)) {
@@ -3436,7 +3471,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        }
        mSplitTransitions.playAnimation(transition, info, startTransaction, finishTransaction,
                finishCallback, mainToken, sideToken,
                mRootTaskInfo.token);
                mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY).token);
        return true;
    }

@@ -3585,7 +3620,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                mShowDecorImmediately = true;
                mSplitLayout.flingDividerToCenter(this::notifySplitAnimationFinished);
            }
            callbackWct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token, false);
            callbackWct.setReparentLeafTaskIfRelaunch(mSplitMultiDisplayHelper
                    .getDisplayRootTaskInfo(DEFAULT_DISPLAY).token, false);
            mWindowDecorViewModel.ifPresent(viewModel -> {
                if (finalMainChild != null) {
                    viewModel.onTaskInfoChanged(finalMainChild.getTaskInfo());
@@ -3837,7 +3873,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                mMainStage.getSplitDecorManager().release(callbackT);
                mSideStage.getSplitDecorManager().release(callbackT);
            }
            callbackWct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token, false);
            callbackWct.setReparentLeafTaskIfRelaunch(mSplitMultiDisplayHelper
                    .getDisplayRootTaskInfo(DEFAULT_DISPLAY).token, false);
        });
        return true;
    }
@@ -3879,7 +3916,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        setSplitsVisible(false);

        final WindowContainerTransaction wct = new WindowContainerTransaction();
        wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
        wct.setReparentLeafTaskIfRelaunch(mSplitMultiDisplayHelper
                        .getDisplayRootTaskInfo(DEFAULT_DISPLAY).token,
                true /* reparentLeafTaskIfRelaunch */);
        mTaskOrganizer.applyTransaction(wct);
    }
@@ -3937,7 +3975,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        }

        setSplitsVisible(false);
        finishWct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
        finishWct.setReparentLeafTaskIfRelaunch(mSplitMultiDisplayHelper
                        .getDisplayRootTaskInfo(DEFAULT_DISPLAY).token,
                true /* reparentLeafTaskIfRelaunch */);
    }

@@ -3985,7 +4024,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,

        final TransitionInfo.Change barChange = new TransitionInfo.Change(null /* token */, leash);
        mSplitLayout.getRefDividerBounds(mTempRect1);
        barChange.setParent(mRootTaskInfo.token);
        barChange.setParent(mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY).token);
        barChange.setStartAbsBounds(mTempRect1);
        barChange.setEndAbsBounds(mTempRect1);
        barChange.setMode(show ? TRANSIT_TO_FRONT : TRANSIT_TO_BACK);
@@ -4026,7 +4065,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        } else {
            final TransitionInfo.Change change =
                    new TransitionInfo.Change(null /* token */, dimLayer);
            change.setParent(mRootTaskInfo.token);
            change.setParent(mSplitMultiDisplayHelper.getDisplayRootTaskInfo(DEFAULT_DISPLAY)
                    .token);
            change.setStartAbsBounds(bounds);
            change.setEndAbsBounds(bounds);
            change.setMode(show ? TRANSIT_TO_FRONT : TRANSIT_TO_BACK);
+12 −4
Original line number Diff line number Diff line
@@ -16,14 +16,16 @@

package com.android.wm.shell.splitscreen;

import static android.view.Display.DEFAULT_DISPLAY;

import static com.android.wm.shell.shared.split.SplitScreenConstants.SNAP_TO_2_50_50;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.view.SurfaceControl;

@@ -45,6 +47,7 @@ import com.android.wm.shell.shared.TransactionPool;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.windowdecor.WindowDecorViewModel;

import java.util.Objects;
import java.util.Optional;

public class SplitTestUtils {
@@ -75,8 +78,8 @@ public class SplitTestUtils {
    }

    static class TestStageCoordinator extends StageCoordinator {
        final ActivityManager.RunningTaskInfo mRootTask;
        final SurfaceControl mRootLeash;
        final SplitMultiDisplayHelper mMultiDisplayHelper;

        TestStageCoordinator(Context context, int displayId, SyncTransactionQueue syncQueue,
                ShellTaskOrganizer taskOrganizer, StageTaskListener mainStage,
@@ -96,9 +99,14 @@ public class SplitTestUtils {
                    desktopTasksController, rootTDAOrganizer);

            // Prepare root task for testing.
            mRootTask = new TestRunningTaskInfoBuilder().build();
            mRootLeash = new SurfaceControl.Builder().setName("test").build();
            onTaskAppeared(mRootTask, mRootLeash);
            DisplayManager displayManager = context.getSystemService(DisplayManager.class);
            mMultiDisplayHelper = new SplitMultiDisplayHelper(
                    Objects.requireNonNull(displayManager));
            mMultiDisplayHelper.setDisplayRootTaskInfo(
                    DEFAULT_DISPLAY, new TestRunningTaskInfoBuilder().build());
            onTaskAppeared(mMultiDisplayHelper.getDisplayRootTaskInfo(
                    DEFAULT_DISPLAY), mRootLeash);
        }
    }
}
+2 −1

File changed.

Preview size limit exceeded, changes collapsed.

+22 −10

File changed.

Preview size limit exceeded, changes collapsed.