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

Commit cf02b08d authored by Tony Huang's avatar Tony Huang Committed by Android (Google) Code Review
Browse files

Merge "Fix accident evict if drag same app to same position." into udc-dev

parents 8fd01cb7 ee5e5562
Loading
Loading
Loading
Loading
+34 −16
Original line number Original line Diff line number Diff line
@@ -482,8 +482,6 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        }
        }


        final WindowContainerTransaction wct = new WindowContainerTransaction();
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        final WindowContainerTransaction evictWct = new WindowContainerTransaction();
        prepareEvictChildTasks(position, evictWct);


        options = resolveStartStage(STAGE_TYPE_UNDEFINED, position, options, null /* wct */);
        options = resolveStartStage(STAGE_TYPE_UNDEFINED, position, options, null /* wct */);
        wct.sendPendingIntent(intent, fillInIntent, options);
        wct.sendPendingIntent(intent, fillInIntent, options);
@@ -494,12 +492,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        prepareEnterSplitScreen(wct, null /* taskInfo */, position);
        prepareEnterSplitScreen(wct, null /* taskInfo */, position);


        mSplitTransitions.startEnterTransition(TRANSIT_TO_FRONT, wct, null, this,
        mSplitTransitions.startEnterTransition(TRANSIT_TO_FRONT, wct, null, this,
                null /* consumedCallback */,
                null /* consumedCallback */, null /* finishedCallback */, extraTransitType);
                (finishWct, finishT) -> {
                    if (!evictWct.isEmpty()) {
                        finishWct.merge(evictWct, true);
                    }
                } /* finishedCallback */, extraTransitType);
    }
    }


    /** Launches an activity into split by legacy transition. */
    /** Launches an activity into split by legacy transition. */
@@ -1511,7 +1504,6 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        if (taskInfo != null) {
        if (taskInfo != null) {
            wct.startTask(taskInfo.taskId,
            wct.startTask(taskInfo.taskId,
                    resolveStartStage(STAGE_TYPE_UNDEFINED, startPosition, null, wct));
                    resolveStartStage(STAGE_TYPE_UNDEFINED, startPosition, null, wct));
            targetStage.evictAllChildren(wct);
        }
        }
        // If running background, we need to reparent current top visible task to another stage
        // If running background, we need to reparent current top visible task to another stage
        // and evict all tasks current under its.
        // and evict all tasks current under its.
@@ -1521,7 +1513,6 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
            updateWindowBounds(mSplitLayout, wct);
            updateWindowBounds(mSplitLayout, wct);
            final StageTaskListener anotherStage = targetStage == mMainStage
            final StageTaskListener anotherStage = targetStage == mMainStage
                    ? mSideStage : mMainStage;
                    ? mSideStage : mMainStage;
            anotherStage.evictAllChildren(wct);
            anotherStage.reparentTopTask(wct);
            anotherStage.reparentTopTask(wct);
            wct.reorder(mRootTaskInfo.token, true);
            wct.reorder(mRootTaskInfo.token, true);
            setRootForceTranslucent(false, wct);
            setRootForceTranslucent(false, wct);
@@ -1540,6 +1531,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
            mSideStage.addTask(taskInfo, wct);
            mSideStage.addTask(taskInfo, wct);
        }
        }
        mMainStage.activate(wct, true /* includingTopTask */);
        mMainStage.activate(wct, true /* includingTopTask */);
        mSplitLayout.resetDividerPosition();
        updateWindowBounds(mSplitLayout, wct);
        updateWindowBounds(mSplitLayout, wct);
        wct.reorder(mRootTaskInfo.token, true);
        wct.reorder(mRootTaskInfo.token, true);
        setRootForceTranslucent(false, wct);
        setRootForceTranslucent(false, wct);
@@ -1778,7 +1770,10 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        });
        });
    }
    }


    void onChildTaskAppeared(StageListenerImpl stageListener, int taskId) {
    /** Callback when split roots have child task appeared under it, this is a little different from
     * #onStageHasChildrenChanged because this would be called every time child task appeared.
     * NOTICE: This only be called on legacy transition. */
    private void onChildTaskAppeared(StageListenerImpl stageListener, int taskId) {
        // Handle entering split screen while there is a split pair running in the background.
        // Handle entering split screen while there is a split pair running in the background.
        if (stageListener == mSideStageListener && !isSplitScreenVisible() && isSplitActive()
        if (stageListener == mSideStageListener && !isSplitScreenVisible() && isSplitActive()
                && mSplitRequest == null) {
                && mSplitRequest == null) {
@@ -1824,6 +1819,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        wct.setForceTranslucent(mRootTaskInfo.token, translucent);
        wct.setForceTranslucent(mRootTaskInfo.token, translucent);
    }
    }


    /** Callback when split roots visiblility changed.
     * NOTICE: This only be called on legacy transition. */
    private void onStageVisibilityChanged(StageListenerImpl stageListener) {
    private void onStageVisibilityChanged(StageListenerImpl stageListener) {
        // If split didn't active, just ignore this callback because we should already did these
        // If split didn't active, just ignore this callback because we should already did these
        // on #applyExitSplitScreen.
        // on #applyExitSplitScreen.
@@ -1965,6 +1962,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        }
        }
    }
    }


    /** Callback when split roots have child or haven't under it.
     * NOTICE: This only be called on legacy transition. */
    private void onStageHasChildrenChanged(StageListenerImpl stageListener) {
    private void onStageHasChildrenChanged(StageListenerImpl stageListener) {
        final boolean hasChildren = stageListener.mHasChildren;
        final boolean hasChildren = stageListener.mHasChildren;
        final boolean isSideStage = stageListener == mSideStageListener;
        final boolean isSideStage = stageListener == mSideStageListener;
@@ -2555,7 +2554,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        boolean shouldAnimate = true;
        boolean shouldAnimate = true;
        if (mSplitTransitions.isPendingEnter(transition)) {
        if (mSplitTransitions.isPendingEnter(transition)) {
            shouldAnimate = startPendingEnterAnimation(
            shouldAnimate = startPendingEnterAnimation(
                    transition, info, startTransaction, finishTransaction);
                    mSplitTransitions.mPendingEnter, info, startTransaction, finishTransaction);
        } else if (mSplitTransitions.isPendingDismiss(transition)) {
        } else if (mSplitTransitions.isPendingDismiss(transition)) {
            shouldAnimate = startPendingDismissAnimation(
            shouldAnimate = startPendingDismissAnimation(
                    mSplitTransitions.mPendingDismiss, info, startTransaction, finishTransaction);
                    mSplitTransitions.mPendingDismiss, info, startTransaction, finishTransaction);
@@ -2591,7 +2590,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        }
        }
    }
    }


    private boolean startPendingEnterAnimation(@NonNull IBinder transition,
    private boolean startPendingEnterAnimation(
            @NonNull SplitScreenTransitions.TransitSession enterTransition,
            @NonNull TransitionInfo info, @NonNull SurfaceControl.Transaction t,
            @NonNull TransitionInfo info, @NonNull SurfaceControl.Transaction t,
            @NonNull SurfaceControl.Transaction finishT) {
            @NonNull SurfaceControl.Transaction finishT) {
        // First, verify that we actually have opened apps in both splits.
        // First, verify that we actually have opened apps in both splits.
@@ -2602,9 +2602,11 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
            final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
            final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
            if (taskInfo == null || !taskInfo.hasParentTask()) continue;
            if (taskInfo == null || !taskInfo.hasParentTask()) continue;
            final @StageType int stageType = getStageType(getStageOfTask(taskInfo));
            final @StageType int stageType = getStageType(getStageOfTask(taskInfo));
            if (stageType == STAGE_TYPE_MAIN) {
            if (stageType == STAGE_TYPE_MAIN
                    && (isOpeningType(change.getMode()) || change.getMode() == TRANSIT_CHANGE)) {
                // Includes TRANSIT_CHANGE to cover reparenting top-most task to split.
                mainChild = change;
                mainChild = change;
            } else if (stageType == STAGE_TYPE_SIDE) {
            } else if (stageType == STAGE_TYPE_SIDE && isOpeningType(change.getMode())) {
                sideChild = change;
                sideChild = change;
            }
            }
        }
        }
@@ -2623,7 +2625,10 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                final int dismissTop = mainChild != null ? STAGE_TYPE_MAIN :
                final int dismissTop = mainChild != null ? STAGE_TYPE_MAIN :
                        (sideChild != null ? STAGE_TYPE_SIDE : STAGE_TYPE_UNDEFINED);
                        (sideChild != null ? STAGE_TYPE_SIDE : STAGE_TYPE_UNDEFINED);
                mSplitTransitions.mPendingEnter.cancel(
                mSplitTransitions.mPendingEnter.cancel(
                        (cancelWct, cancelT) -> prepareExitSplitScreen(dismissTop, cancelWct));
                        (cancelWct, cancelT) -> {
                            mSideStage.removeAllTasks(cancelWct, dismissTop == STAGE_TYPE_SIDE);
                            mMainStage.deactivate(cancelWct, dismissTop == STAGE_TYPE_MAIN);
                        });
                return true;
                return true;
            }
            }
        }
        }
@@ -2645,6 +2650,17 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                    + " before startAnimation().");
                    + " before startAnimation().");
        }
        }


        final TransitionInfo.Change finalMainChild = mainChild;
        final TransitionInfo.Change finalSideChild = sideChild;
        enterTransition.setFinishedCallback((callbackWct, callbackT) -> {
            if (finalMainChild != null) {
                mMainStage.evictOtherChildren(callbackWct, finalMainChild.getTaskInfo().taskId);
            }
            if (finalSideChild != null) {
                mSideStage.evictOtherChildren(callbackWct, finalSideChild.getTaskInfo().taskId);
            }
        });

        finishEnterSplitScreen(finishT);
        finishEnterSplitScreen(finishT);
        addDividerBarToTransition(info, true /* show */);
        addDividerBarToTransition(info, true /* show */);
        return true;
        return true;
@@ -2911,6 +2927,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        }
        }
        if (!isSplitScreenVisible()) {
        if (!isSplitScreenVisible()) {
            // If split running background, exit split first.
            // If split running background, exit split first.
            // TODO(b/280392203) : skip doing this on shell transition once this bug is fixed.
            exitSplitScreen(null /* childrenToTop */, EXIT_REASON_RECREATE_SPLIT);
            exitSplitScreen(null /* childrenToTop */, EXIT_REASON_RECREATE_SPLIT);
        }
        }
        mLogger.enterRequestedByDrag(position, dragSessionId);
        mLogger.enterRequestedByDrag(position, dragSessionId);
@@ -2922,6 +2939,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler,
    public void onRequestToSplit(InstanceId sessionId, int enterReason) {
    public void onRequestToSplit(InstanceId sessionId, int enterReason) {
        if (!isSplitScreenVisible()) {
        if (!isSplitScreenVisible()) {
            // If split running background, exit split first.
            // If split running background, exit split first.
            // TODO(b/280392203) : skip doing this on shell transition once this bug is fixed.
            exitSplitScreen(null /* childrenToTop */, EXIT_REASON_RECREATE_SPLIT);
            exitSplitScreen(null /* childrenToTop */, EXIT_REASON_RECREATE_SPLIT);
        }
        }
        mLogger.enterRequested(sessionId, enterReason);
        mLogger.enterRequested(sessionId, enterReason);
+0 −3
Original line number Original line Diff line number Diff line
@@ -158,8 +158,6 @@ public class StageCoordinatorTests extends ShellTestCase {
        verify(mStageCoordinator).prepareEnterSplitScreen(eq(wct), eq(task),
        verify(mStageCoordinator).prepareEnterSplitScreen(eq(wct), eq(task),
                eq(SPLIT_POSITION_BOTTOM_OR_RIGHT));
                eq(SPLIT_POSITION_BOTTOM_OR_RIGHT));
        verify(mMainStage).reparentTopTask(eq(wct));
        verify(mMainStage).reparentTopTask(eq(wct));
        verify(mMainStage).evictAllChildren(eq(wct));
        verify(mSideStage).evictAllChildren(eq(wct));
        verify(mSplitLayout).resetDividerPosition();
        verify(mSplitLayout).resetDividerPosition();
        assertEquals(SPLIT_POSITION_BOTTOM_OR_RIGHT, mStageCoordinator.getSideStagePosition());
        assertEquals(SPLIT_POSITION_BOTTOM_OR_RIGHT, mStageCoordinator.getSideStagePosition());
        assertEquals(SPLIT_POSITION_TOP_OR_LEFT, mStageCoordinator.getMainStagePosition());
        assertEquals(SPLIT_POSITION_TOP_OR_LEFT, mStageCoordinator.getMainStagePosition());
@@ -178,7 +176,6 @@ public class StageCoordinatorTests extends ShellTestCase {
        mStageCoordinator.moveToStage(task, SPLIT_POSITION_BOTTOM_OR_RIGHT, wct);
        mStageCoordinator.moveToStage(task, SPLIT_POSITION_BOTTOM_OR_RIGHT, wct);
        verify(mStageCoordinator).prepareEnterSplitScreen(eq(wct), eq(task),
        verify(mStageCoordinator).prepareEnterSplitScreen(eq(wct), eq(task),
                eq(SPLIT_POSITION_BOTTOM_OR_RIGHT));
                eq(SPLIT_POSITION_BOTTOM_OR_RIGHT));
        verify(mMainStage).evictAllChildren(eq(wct));
        assertEquals(SPLIT_POSITION_BOTTOM_OR_RIGHT, mStageCoordinator.getMainStagePosition());
        assertEquals(SPLIT_POSITION_BOTTOM_OR_RIGHT, mStageCoordinator.getMainStagePosition());
        assertEquals(SPLIT_POSITION_TOP_OR_LEFT, mStageCoordinator.getSideStagePosition());
        assertEquals(SPLIT_POSITION_TOP_OR_LEFT, mStageCoordinator.getSideStagePosition());
    }
    }