Loading libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithm.kt +11 −7 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -471,12 +472,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 } Loading Loading @@ -781,6 +780,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) Loading @@ -790,11 +790,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) } Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithmTest.kt +59 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) { Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithm.kt +11 −7 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -471,12 +472,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 } Loading Loading @@ -781,6 +780,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) Loading @@ -790,11 +790,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) } Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipKeepClearAlgorithmTest.kt +59 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) { Loading