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
This commit is contained in:
Robert Horvath
2022-05-31 14:20:47 +02:00
parent bfe127e4c8
commit 63cd654af2
2 changed files with 24 additions and 15 deletions

View File

@@ -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() {

View File

@@ -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()