diff options
| author | 2022-04-06 13:26:22 +0200 | |
|---|---|---|
| committer | 2022-04-06 17:00:49 +0200 | |
| commit | 413044b7de8d8474e56e69fcbfecc06b2bd9e032 (patch) | |
| tree | 36fe0e47eeb92cac13ee3b3420ce025708b81cb8 /libs | |
| parent | 6166d7a7afb4ed51053e65d2c9b7a5d5f7934a3c (diff) | |
Fix strange pip size in horizontal expanded mode
Fix: 228188320
Test: atest TvPipKeepClearAlgorithmTest#test_PipInsets
Change-Id: I217663863acbf15e8bdd6f7a7942f6de56942b95
Diffstat (limited to 'libs')
2 files changed, 70 insertions, 7 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithm.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithm.kt index 9ede4433a978..5086bede4647 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithm.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithm.kt @@ -133,7 +133,8 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) { val pipAnchorBoundsWithAllDecors = getNormalPipAnchorBounds(pipSizeWithAllDecors, transformedMovementBounds) - val pipAnchorBoundsWithPermanentDecors = removeTemporaryDecors(pipAnchorBoundsWithAllDecors) + val pipAnchorBoundsWithPermanentDecors = + removeTemporaryDecorsTransformed(pipAnchorBoundsWithAllDecors) val result = calculatePipPositionTransformed( pipAnchorBoundsWithPermanentDecors, transformedRestrictedAreas, @@ -465,12 +466,10 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) { } fun setPipPermanentDecorInsets(insets: Insets) { - if (pipPermanentDecorInsets == insets) return pipPermanentDecorInsets = insets } fun setPipTemporaryDecorInsets(insets: Insets) { - if (pipTemporaryDecorInsets == insets) return pipTemporaryDecorInsets = insets } @@ -775,6 +774,7 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) { /** * Removes the space that was reserved for permanent decorations around the pip + * @param bounds the bounds (in screen space) to remove the insets from */ private fun removePermanentDecors(bounds: Rect): Rect { val pipDecorReverseInsets = Insets.subtract(Insets.NONE, pipPermanentDecorInsets) @@ -784,11 +784,15 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) { /** * Removes the space that was reserved for temporary decorations around the pip + * @param bounds the bounds (in base case) to remove the insets from */ - private fun removeTemporaryDecors(bounds: Rect): Rect { - val pipDecorReverseInsets = Insets.subtract(Insets.NONE, pipTemporaryDecorInsets) - bounds.inset(pipDecorReverseInsets) - return bounds + private fun removeTemporaryDecorsTransformed(bounds: Rect): Rect { + if (pipTemporaryDecorInsets == Insets.NONE) return bounds + + var reverseInsets = Insets.subtract(Insets.NONE, pipTemporaryDecorInsets) + var boundsInScreenSpace = fromTransformedSpace(bounds) + boundsInScreenSpace.inset(reverseInsets) + return toTransformedSpace(boundsInScreenSpace) } private fun Rect.offsetCopy(dx: Int, dy: Int) = Rect(this).apply { offset(dx, dy) } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithmTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithmTest.kt index e6ba70e1b60e..9919214642fc 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithmTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithmTest.kt @@ -16,6 +16,7 @@ package com.android.wm.shell.pip.tv +import android.graphics.Insets import android.graphics.Rect import android.testing.AndroidTestingRunner import android.util.Size @@ -432,6 +433,64 @@ class TvPipKeepClearAlgorithmTest { assertEquals(currentTime + algorithm.stashDuration, placement.unstashTime) } + @Test + fun test_PipInsets() { + val permInsets = Insets.of(-1, -2, -3, -4) + algorithm.setPipPermanentDecorInsets(permInsets) + testInsetsForAllPositions(permInsets) + + val tempInsets = Insets.of(-4, -3, -2, -1) + algorithm.setPipPermanentDecorInsets(Insets.NONE) + algorithm.setPipTemporaryDecorInsets(tempInsets) + testInsetsForAllPositions(tempInsets) + + algorithm.setPipPermanentDecorInsets(permInsets) + algorithm.setPipTemporaryDecorInsets(tempInsets) + testInsetsForAllPositions(Insets.add(permInsets, tempInsets)) + } + + private fun testInsetsForAllPositions(insets: Insets) { + gravity = Gravity.BOTTOM or Gravity.RIGHT + testAnchorPositionWithInsets(insets) + + gravity = Gravity.BOTTOM or Gravity.LEFT + testAnchorPositionWithInsets(insets) + + gravity = Gravity.TOP or Gravity.LEFT + testAnchorPositionWithInsets(insets) + + gravity = Gravity.TOP or Gravity.RIGHT + testAnchorPositionWithInsets(insets) + + pipSize = EXPANDED_WIDE_PIP_SIZE + + gravity = Gravity.BOTTOM + testAnchorPositionWithInsets(insets) + + gravity = Gravity.TOP + testAnchorPositionWithInsets(insets) + + pipSize = Size(pipSize.height, pipSize.width) + + gravity = Gravity.LEFT + testAnchorPositionWithInsets(insets) + + gravity = Gravity.RIGHT + testAnchorPositionWithInsets(insets) + } + + private fun testAnchorPositionWithInsets(insets: Insets) { + var pipRect = Rect(0, 0, pipSize.width, pipSize.height) + pipRect.inset(insets) + var expectedBounds = Rect() + Gravity.apply(gravity, pipRect.width(), pipRect.height(), movementBounds, expectedBounds) + val reverseInsets = Insets.subtract(Insets.NONE, insets) + expectedBounds.inset(reverseInsets) + + var placement = getActualPlacement() + assertEquals(expectedBounds, placement.bounds) + } + private fun makeSideBar(width: Int, @Gravity.GravityFlags side: Int): Rect { val sidebar = Rect(0, 0, width, SCREEN_SIZE.height) if (side == Gravity.RIGHT) { |