From 63cd654af21539f0b59ebbc4785d2f64e79c4f94 Mon Sep 17 00:00:00 2001 From: Robert Horvath Date: Tue, 31 May 2022 14:20:47 +0200 Subject: [PATCH] Only restash TV PiP if necessary on immediate placement Restricted keep clear area do not immediately move the TV PiP window, but movements are debounced. But other changes, such as changes to unrestricted keep clear areas, do cause the PiP to move immediately. When doing immediate movements, the PiP could stash even though Placement#triggerStash was not set. This changes unifies the logic between regular deferred placement and immediate placement. Bug: 234421149 Test: atest TvPipBoundsControllerTest Change-Id: I8cac0ba600f52ff9d72743af2a09eacea4cde629 --- .../shell/pip/tv/TvPipBoundsController.java | 29 +++++++++---------- .../shell/pip/tv/TvPipBoundsControllerTest.kt | 10 +++++++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsController.java index 3a6ce81821eca..b212ea9a71562 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipBoundsController.java @@ -122,9 +122,9 @@ public class TvPipBoundsController { cancelScheduledPlacement(); applyPlacementBounds(placement.getUnstashedBounds(), animationDuration); } else if (immediate) { + boolean shouldStash = mUnstashRunnable != null || placement.getTriggerStash(); cancelScheduledPlacement(); - applyPlacementBounds(placement.getBounds(), animationDuration); - scheduleUnstashIfNeeded(placement); + applyPlacement(placement, shouldStash, animationDuration); } else { applyPlacementBounds(mCurrentPlacementBounds, animationDuration); schedulePinnedStackPlacement(placement, animationDuration); @@ -176,22 +176,21 @@ public class TvPipBoundsController { "%s: applyPendingPlacement()", TAG); } if (mPendingPlacement != null) { - if (mPendingStash) { - mPendingStash = false; - scheduleUnstashIfNeeded(mPendingPlacement); - } + applyPlacement(mPendingPlacement, mPendingStash, mPendingPlacementAnimationDuration); + mPendingStash = false; + mPendingPlacement = null; + } + } - if (mUnstashRunnable != null) { - // currently stashed, use stashed pos - applyPlacementBounds(mPendingPlacement.getBounds(), - mPendingPlacementAnimationDuration); - } else { - applyPlacementBounds(mPendingPlacement.getUnstashedBounds(), - mPendingPlacementAnimationDuration); - } + private void applyPlacement(@NonNull final Placement placement, boolean shouldStash, + int animationDuration) { + if (placement.getStashType() != STASH_TYPE_NONE && shouldStash) { + scheduleUnstashIfNeeded(placement); } - mPendingPlacement = null; + Rect bounds = + mUnstashRunnable != null ? placement.getBounds() : placement.getUnstashedBounds(); + applyPlacementBounds(bounds, animationDuration); } void onPipDismissed() { diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipBoundsControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipBoundsControllerTest.kt index 05e472245b4af..cc51efd7e16b2 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipBoundsControllerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipBoundsControllerTest.kt @@ -178,6 +178,16 @@ class TvPipBoundsControllerTest { assertMovementAt(time + STASH_DURATION, ANCHOR_BOUNDS) } + @Test + fun testImmediatePlacement_DoNotStashIfAlreadyUnstashed() { + triggerImmediatePlacement(STASHED_PLACEMENT_RESTASH) + assertMovement(STASHED_BOUNDS) + assertMovementAt(time + STASH_DURATION, ANCHOR_BOUNDS) + + triggerImmediatePlacement(STASHED_PLACEMENT) + assertNoMovementUpTo(time + FAR_FUTURE) + } + @Test fun testInMoveMode_KeepAtAnchor() { startMoveMode()