From b670ad2cf9c0312680ee2bc280be5905dc3eb8a1 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Mon, 10 Jan 2022 16:14:18 +0800 Subject: [PATCH] Collect dismissPip change before start transition Followup to ag/16568759. Bug: 213300721 Test: pass existing Change-Id: I1afbdbcaf6d108276325a1dc2b9855fb636fb97c --- .../server/wm/RootWindowContainer.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index 3f2e975057654..b91d3a8525e56 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -2052,24 +2052,29 @@ class RootWindowContainer extends WindowContainer try { final Task task = r.getTask(); - // If the activity in current PIP task needs to be moved back to the parent Task of next - // PIP activity, we can't use that parent Task as the next PIP Task. - // Because we need to start the Shell transition from the root Task, we delay to dismiss - // the current PIP task until root Task is ready. - boolean origPipWillBeMovedToTask = false; + // Create a transition now to collect the current pinned Task dismiss. Only do the + // create here as the Task (trigger) to enter PIP is not ready yet. + final TransitionController transitionController = task.mTransitionController; + Transition newTransition = null; + if (transitionController.isCollecting()) { + transitionController.setReady(task, false /* ready */); + } else if (transitionController.getTransitionPlayer() != null) { + newTransition = transitionController.createTransition(TRANSIT_PIP); + } + + // This will change the root pinned task's windowing mode to its original mode, ensuring + // we only have one root task that is in pinned mode. final Task rootPinnedTask = taskDisplayArea.getRootPinnedTask(); if (rootPinnedTask != null) { - final ActivityRecord topPipActivity = rootPinnedTask.getTopMostActivity(); - if (topPipActivity != null && topPipActivity.getLastParentBeforePip() == task) { - origPipWillBeMovedToTask = true; - } + transitionController.collect(rootPinnedTask); + rootPinnedTask.dismissPip(); } // Set a transition to ensure that we don't immediately try and update the visibility // of the activity entering PIP r.getDisplayContent().prepareAppTransition(TRANSIT_NONE); - final boolean singleActivity = task.getChildCount() == 1 && !origPipWillBeMovedToTask; + final boolean singleActivity = task.getChildCount() == 1; final Task rootTask; if (singleActivity) { rootTask = task; @@ -2123,7 +2128,7 @@ class RootWindowContainer extends WindowContainer final ActivityRecord oldTopActivity = task.getTopMostActivity(); if (oldTopActivity != null && oldTopActivity.isState(STOPPED) && task.getDisplayContent().mAppTransition.containsTransitRequest( - TRANSIT_TO_BACK) && !origPipWillBeMovedToTask) { + TRANSIT_TO_BACK)) { task.getDisplayContent().mClosingApps.add(oldTopActivity); oldTopActivity.mRequestForceTransition = true; } @@ -2137,14 +2142,13 @@ class RootWindowContainer extends WindowContainer // display area, so reparent. rootTask.reparent(taskDisplayArea, true /* onTop */); } - rootTask.mTransitionController.requestTransitionIfNeeded(TRANSIT_PIP, rootTask); - // This will change the root pinned task's windowing mode to its original mode, ensuring - // we only have one root task that is in pinned mode. - if (rootPinnedTask != null) { - rootTask.mTransitionController.collect(rootPinnedTask); - rootPinnedTask.dismissPip(); + // The new PIP Task is ready, start the transition before updating the windowing mode. + if (newTransition != null) { + transitionController.requestStartTransition(newTransition, rootTask, + null /* remoteTransition */, null /* displayChange */); } + transitionController.collect(rootTask); // Defer the windowing mode change until after the transition to prevent the activity // from doing work and changing the activity visuals while animating