From 15036ca521489531f89e9eae16fb87601c9f7ea2 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 31 May 2018 15:51:47 -0700 Subject: Update the task stack state when resizing the tasks after the PiP animation - When the animation into PiP ends, we clear the task stack state and request a layout prior to resizing the the stack to update the task bounds to the stack bounds. This triggers a relayout from the client, which fetches the new configuration prior to handling the PiP mode/config change scheduled as a part of the PiP mode change. We can instead update the task stack state when we resize the tasks to ensure that we don't relayout multiple times. Bug: 75995355 Test: atest CtsActivityManagerDeviceTestCases:ActivityManagerPinnedStackTests Change-Id: I58a6e30651f16b85ec160e977554b8d091b461ec --- .../java/com/android/server/am/ActivityStack.java | 5 ++++- .../android/server/am/ActivityStackSupervisor.java | 6 ++++++ .../android/server/wm/StackWindowController.java | 6 ++++++ .../core/java/com/android/server/wm/TaskStack.java | 22 ++++++++++++---------- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 3ad461f9b1b0..748eae951379 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -134,7 +134,6 @@ import android.os.Looper; import android.os.Message; import android.os.RemoteException; import android.os.SystemClock; -import android.os.Trace; import android.os.UserHandle; import android.service.voice.IVoiceInteractionSession; import android.util.ArraySet; @@ -4789,6 +4788,10 @@ class ActivityStack extends ConfigurationContai } } + void onPipAnimationEndResize() { + mWindowContainerController.onPipAnimationEndResize(); + } + /** * Adjust bounds to stay within stack bounds. diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 257d79d2c153..76cc3425d060 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -2968,6 +2968,12 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D insetBounds.right = tempPinnedTaskBounds.width(); insetBounds.bottom = tempPinnedTaskBounds.height(); } + if (pinnedBounds != null && tempPinnedTaskBounds == null) { + // We have finished the animation into PiP, and are resizing the tasks to match the + // stack bounds, while layouts are deferred, update any task state as a part of + // transitioning it from fullscreen into a floating state. + stack.onPipAnimationEndResize(); + } stack.resize(pinnedBounds, tempPinnedTaskBounds, insetBounds); stack.ensureVisibleActivitiesConfigurationLocked(r, false); } finally { diff --git a/services/core/java/com/android/server/wm/StackWindowController.java b/services/core/java/com/android/server/wm/StackWindowController.java index 653850aa288f..1fd2c0fd19c5 100644 --- a/services/core/java/com/android/server/wm/StackWindowController.java +++ b/services/core/java/com/android/server/wm/StackWindowController.java @@ -192,6 +192,12 @@ public class StackWindowController } } + public void onPipAnimationEndResize() { + synchronized (mService.mWindowMap) { + mContainer.onPipAnimationEndResize(); + } + } + /** * @see TaskStack.getStackDockedModeBoundsLocked(Rect, Rect, Rect, boolean) */ diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java index 2fbb84604598..c59540b3d088 100644 --- a/services/core/java/com/android/server/wm/TaskStack.java +++ b/services/core/java/com/android/server/wm/TaskStack.java @@ -1667,16 +1667,6 @@ public class TaskStack extends WindowContainer implements @Override // AnimatesBounds public void onAnimationEnd(boolean schedulePipModeChangedCallback, Rect finalStackSize, boolean moveToFullscreen) { - // Hold the lock since this is called from the BoundsAnimator running on the UiThread - synchronized (mService.mWindowMap) { - mBoundsAnimating = false; - for (int i = 0; i < mChildren.size(); i++) { - final Task t = mChildren.get(i); - t.clearPreserveNonFloatingState(); - } - mService.requestTraversal(); - } - if (inPinnedWindowingMode()) { // Update to the final bounds if requested. This is done here instead of in the bounds // animator to allow us to coordinate this after we notify the PiP mode changed @@ -1706,6 +1696,18 @@ public class TaskStack extends WindowContainer implements } } + /** + * Called immediately prior to resizing the tasks at the end of the pinned stack animation. + */ + public void onPipAnimationEndResize() { + mBoundsAnimating = false; + for (int i = 0; i < mChildren.size(); i++) { + final Task t = mChildren.get(i); + t.clearPreserveNonFloatingState(); + } + mService.requestTraversal(); + } + @Override public boolean shouldDeferStartOnMoveToFullscreen() { // Workaround for the recents animation -- normally we need to wait for the new activity to -- cgit v1.2.3-59-g8ed1b