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

Commit 4111bb2c authored by Massimo Carli's avatar Massimo Carli
Browse files

[60/n] Improve letterbox surfaces bounds calculation

The caluclation of taskBounds and letterboxBounds used to define
letterbox surfaces bounds needs to take offsets into account.
This allow to fix the problem related to Tasks that don't have
(0,0) as position.

Flag: EXEMPT Refactoring
Bug: 423072242
Bug: 377875664
Test: atest WMShellUnitTests:TaskInfoLetterboxLifecycleEventFactoryTest

Change-Id: Icbffcc537b7aa8800fd8f968a1628c8c37eb5a60
parent 869e3361
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -28,16 +28,20 @@ class TaskInfoLetterboxLifecycleEventFactory : LetterboxLifecycleEventFactory {

    override fun createLifecycleEvent(change: Change): LetterboxLifecycleEvent? {
        change.taskInfo?.let { ti ->
            val taskBounds = Rect(
                change.endRelOffset.x,
                change.endRelOffset.y,
                change.endAbsBounds.width(),
                change.endAbsBounds.height()
            )
            val isLetterboxed = ti.appCompatTaskInfo?.isTopActivityLetterboxed ?: false
            val taskBoundsAbs = change.endAbsBounds
            // The bounds are absolute to the screen but we need them relative to the Task.
            val taskBounds = Rect(taskBoundsAbs).apply {
                offset(-taskBoundsAbs.left, -taskBoundsAbs.top)
            }
            // Letterbox bounds are null when the activity is not letterboxed.
            val letterboxBounds =
            val letterboxBoundsAbs =
                if (isLetterboxed) ti.appCompatTaskInfo?.topActivityLetterboxBounds else null
            val letterboxBounds = letterboxBoundsAbs?.let { absBounds ->
                Rect(absBounds).apply {
                    offset(-taskBoundsAbs.left, -taskBoundsAbs.top)
                }
            }
            return LetterboxLifecycleEvent(
                type = change.asLetterboxLifecycleEventType(),
                displayId = ti.displayId,
+6 −9
Original line number Diff line number Diff line
@@ -56,19 +56,18 @@ class TaskInfoLetterboxLifecycleEventFactoryTest {
    }

    @Test
    fun `With TaskInfo taskBounds are calculated from endAbsBounds and endRelOffset`() {
    fun `With TaskInfo taskBounds are calculated from endAbsBounds`() {
        runTestScenario { r ->
            testLetterboxLifecycleEventFactory(r.getLetterboxLifecycleEventFactory()) {
                inputChange {
                    endAbsBounds = Rect(0, 0, 500, 1000)
                    endRelOffset = Point(100, 200)
                    endAbsBounds = Rect(100, 200, 2000, 1000)
                }
                validateCanHandle { canHandle ->
                    assert(canHandle == true)
                }
                validateCreateLifecycleEvent { event ->
                    assert(event != null)
                    assert(event?.taskBounds == Rect(100, 200, 500, 1000))
                    assert(event?.taskBounds == Rect(0, 0, 1900, 1800))
                }
            }
        }
@@ -83,7 +82,6 @@ class TaskInfoLetterboxLifecycleEventFactoryTest {
                        ti.appCompatTaskInfo.isTopActivityLetterboxed = false
                    }
                    endAbsBounds = Rect(0, 0, 500, 1000)
                    endRelOffset = Point(100, 200)
                }
                validateCanHandle { canHandle ->
                    assert(canHandle == true)
@@ -103,17 +101,16 @@ class TaskInfoLetterboxLifecycleEventFactoryTest {
                inputChange {
                    runningTaskInfo { ti ->
                        ti.appCompatTaskInfo.isTopActivityLetterboxed = true
                        ti.appCompatTaskInfo.topActivityLetterboxBounds = Rect(1, 2, 3, 4)
                        ti.appCompatTaskInfo.topActivityLetterboxBounds = Rect(300, 200, 2300, 1200)
                    }
                    endAbsBounds = Rect(0, 0, 500, 1000)
                    endRelOffset = Point(100, 200)
                    endAbsBounds = Rect(100, 50, 2500, 1500)
                }
                validateCanHandle { canHandle ->
                    assert(canHandle == true)
                }
                validateCreateLifecycleEvent { event ->
                    assert(event != null)
                    assert(event?.letterboxBounds == Rect(1, 2, 3, 4))
                    assert(event?.letterboxBounds == Rect(200, 150, 2400, 1150))
                }
            }
        }