Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75a803b9 authored by Robert Horvath's avatar Robert Horvath Committed by Android (Google) Code Review
Browse files

Merge "Only unrestricted KCA can move expanded PiP off the edge"

parents 761c38a4 13626d09
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -284,8 +284,10 @@ class TvPipKeepClearAlgorithm() {
    ): Rect? {
        val movementBounds = transformedMovementBounds
        val candidateEdgeRects = mutableListOf<Rect>()
        val maxRestrictedXDistanceFraction =
                if (isPipAnchoredToCorner()) maxRestrictedDistanceFraction else 0.0
        val minRestrictedLeft =
            pipAnchorBounds.right - screenSize.width * maxRestrictedDistanceFraction
                pipAnchorBounds.right - screenSize.width * maxRestrictedXDistanceFraction

        candidateEdgeRects.add(
            movementBounds.offsetCopy(movementBounds.width() + pipAreaPadding, 0)
@@ -296,7 +298,6 @@ class TvPipKeepClearAlgorithm() {
        // throw out edges that are too close to the left screen edge to fit the PiP
        val minLeft = movementBounds.left + pipAnchorBounds.width()
        candidateEdgeRects.retainAll { it.left - pipAreaPadding > minLeft }
        candidateEdgeRects.sortBy { -it.left }

        val maxRestrictedDY = (screenSize.height * maxRestrictedDistanceFraction).roundToInt()

@@ -335,8 +336,7 @@ class TvPipKeepClearAlgorithm() {
            }
        }

        candidateBounds.sortBy { candidateCost(it, pipAnchorBounds) }
        return candidateBounds.firstOrNull()
        return candidateBounds.minByOrNull { candidateCost(it, pipAnchorBounds) }
    }

    private fun getNearbyStashedPosition(bounds: Rect, keepClearAreas: Set<Rect>): Rect {
+38 −5
Original line number Diff line number Diff line
@@ -21,23 +21,24 @@ import android.graphics.Rect
import android.testing.AndroidTestingRunner
import android.util.Size
import android.view.Gravity
import org.junit.runner.RunWith
import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE
import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_BOTTOM
import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE
import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT
import com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_TOP
import com.android.wm.shell.pip.tv.TvPipKeepClearAlgorithm.Placement
import org.junit.Before
import org.junit.Test
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertNull
import junit.framework.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidTestingRunner::class)
class TvPipKeepClearAlgorithmTest {
    private val DEFAULT_PIP_SIZE = Size(384, 216)
    private val EXPANDED_WIDE_PIP_SIZE = Size(384 * 2, 216)
    private val EXPANDED_TALL_PIP_SIZE = Size(384, 216 * 4)
    private val DASHBOARD_WIDTH = 484
    private val BOTTOM_SHEET_HEIGHT = 524
    private val STASH_OFFSET = 64
@@ -485,6 +486,38 @@ class TvPipKeepClearAlgorithmTest {
        testAnchorPositionWithInsets(insets)
    }

    @Test
    fun test_AnchorRightExpandedPiP_UnrestrictedRightSidebar_PushedLeft() {
        pipSize = EXPANDED_TALL_PIP_SIZE
        gravity = Gravity.RIGHT

        val sidebar = makeSideBar(DASHBOARD_WIDTH, Gravity.RIGHT)
        unrestrictedAreas.add(sidebar)

        val expectedBounds = anchorBoundsOffsetBy(SCREEN_EDGE_INSET - sidebar.width() - PADDING, 0)

        val placement = getActualPlacement()
        assertEquals(expectedBounds, placement.bounds)
        assertNotStashed(placement)
    }

    @Test
    fun test_AnchorRightExpandedPiP_RestrictedRightSidebar_StashedRight() {
        pipSize = EXPANDED_TALL_PIP_SIZE
        gravity = Gravity.RIGHT

        val sidebar = makeSideBar(DASHBOARD_WIDTH, Gravity.RIGHT)
        restrictedAreas.add(sidebar)

        val expectedBounds = getExpectedAnchorBounds()
        expectedBounds.offsetTo(SCREEN_SIZE.width - STASH_OFFSET, expectedBounds.top)

        val placement = getActualPlacement()
        assertEquals(expectedBounds, placement.bounds)
        assertEquals(STASH_TYPE_RIGHT, placement.stashType)
        assertEquals(getExpectedAnchorBounds(), placement.unstashDestinationBounds)
    }

    private fun testAnchorPositionWithInsets(insets: Insets) {
        var pipRect = Rect(0, 0, pipSize.width, pipSize.height)
        pipRect.inset(insets)