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

Commit 25bae835 authored by Massimo Carli's avatar Massimo Carli
Browse files

[40/n] Use taskId as unique key for letterbox surfaces

Each task has a unique id which can be used as the key to identify
each set of letterbox surfaces in it. The displayId is not always available
in TaskInfo which makes difficult to use it as part of the letterbox
surfaces identifier when a TaskListener or TaskVanishedListener are used.

Flag: com.android.window.flags.app_compat_refactoring
Fix: 416217659
Test: atest WMShellUnitTests:SingleSurfaceLetterboxControllerTest
Test: atest WMShellUnitTests:MultiSurfaceLetterboxControllerTest
Test: atest WMShellUnitTests:LetterboxInputControllerTest

Change-Id: I56e6c88d54933e4d5da87968bf9a83a77cf7528b
parent 51fd5c5c
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ class LetterboxInputController @Inject constructor(
        private val TAG = "LetterboxInputController"
    }

    private val inputDetectorMap = mutableMapOf<LetterboxKey, LetterboxInputItems>()
    private val inputDetectorMap = mutableMapOf<Int, LetterboxInputItems>()

    override fun createLetterboxSurface(
        key: LetterboxKey,
@@ -60,7 +60,7 @@ class LetterboxInputController @Inject constructor(
        parentLeash: SurfaceControl,
        token: WindowContainerToken?
    ) {
        inputDetectorMap.runOnItem(key, onMissed = { k, m ->
        inputDetectorMap.runOnItem(key.taskId, onMissed = { k, m ->
            val gestureListener =
                listenerFactory.createReachabilityGestureListener(key.taskId, token)
            val detector = LetterboxInputDetector(
@@ -82,10 +82,10 @@ class LetterboxInputController @Inject constructor(
        transaction: Transaction
    ) {
        with(inputDetectorMap) {
            runOnItem(key, onFound = { item ->
            runOnItem(key.taskId, onFound = { item ->
                item.inputDetector.stop(transaction)
            })
            remove(key)
            remove(key.taskId)
        }
    }

@@ -95,7 +95,7 @@ class LetterboxInputController @Inject constructor(
        visible: Boolean
    ) {
        with(inputDetectorMap) {
            runOnItem(key, onFound = { item ->
            runOnItem(key.taskId, onFound = { item ->
                item.inputDetector.updateVisibility(transaction, visible)
            })
        }
@@ -107,7 +107,7 @@ class LetterboxInputController @Inject constructor(
        taskBounds: Rect,
        activityBounds: Rect
    ) {
        inputDetectorMap.runOnItem(key, onFound = { item ->
        inputDetectorMap.runOnItem(key.taskId, onFound = { item ->
            item.inputDetector.updateTouchableRegion(transaction, Region(taskBounds))
            item.gestureListener.updateActivityBounds(activityBounds)
        })
+6 −6
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ class MultiSurfaceLetterboxController @Inject constructor(
        private val TAG = "MultiSurfaceLetterboxController"
    }

    private val letterboxMap = mutableMapOf<LetterboxKey, LetterboxSurfaces>()
    private val letterboxMap = mutableMapOf<Int, LetterboxSurfaces>()

    override fun createLetterboxSurface(
        key: LetterboxKey,
@@ -56,7 +56,7 @@ class MultiSurfaceLetterboxController @Inject constructor(
                "MultiSurfaceLetterboxController#createLetterboxSurface"
            )
        }
        letterboxMap.runOnItem(key, onMissed = { k, m ->
        letterboxMap.runOnItem(key.taskId, onMissed = { k, m ->
            m[k] = LetterboxSurfaces(
                leftSurface = surfaceBuilderFn("Left"),
                topSurface = surfaceBuilderFn("Top"),
@@ -70,12 +70,12 @@ class MultiSurfaceLetterboxController @Inject constructor(
        key: LetterboxKey,
        transaction: Transaction
    ) {
        letterboxMap.runOnItem(key, onFound = { item ->
        letterboxMap.runOnItem(key.taskId, onFound = { item ->
            item.forEach { s ->
                s.remove(transaction)
            }
        })
        letterboxMap.remove(key)
        letterboxMap.remove(key.taskId)
    }

    override fun updateLetterboxSurfaceVisibility(
@@ -83,7 +83,7 @@ class MultiSurfaceLetterboxController @Inject constructor(
        transaction: Transaction,
        visible: Boolean
    ) {
        letterboxMap.runOnItem(key, onFound = { item ->
        letterboxMap.runOnItem(key.taskId, onFound = { item ->
            item.forEach { s ->
                s.setVisibility(transaction, visible)
            }
@@ -96,7 +96,7 @@ class MultiSurfaceLetterboxController @Inject constructor(
        taskBounds: Rect,
        activityBounds: Rect
    ) {
        letterboxMap.runOnItem(key, onFound = { item ->
        letterboxMap.runOnItem(key.taskId, onFound = { item ->
            item.updateSurfacesBounds(transaction, taskBounds, activityBounds)
        })
    }
+6 −6
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ class SingleSurfaceLetterboxController @Inject constructor(
        private val TAG = "SingleSurfaceLetterboxController"
    }

    private val letterboxMap = mutableMapOf<LetterboxKey, SurfaceControl>()
    private val letterboxMap = mutableMapOf<Int, SurfaceControl>()

    /**
     * Creates a Letterbox Surface for a given displayId/taskId if it doesn't exist.
@@ -51,7 +51,7 @@ class SingleSurfaceLetterboxController @Inject constructor(
        parentLeash: SurfaceControl,
        token: WindowContainerToken?
    ) {
        letterboxMap.runOnItem(key, onMissed = { k, m ->
        letterboxMap.runOnItem(key.taskId, onMissed = { k, m ->
            m[k] = letterboxBuilder.createSurface(
                transaction,
                parentLeash,
@@ -68,12 +68,12 @@ class SingleSurfaceLetterboxController @Inject constructor(
        key: LetterboxKey,
        transaction: Transaction
    ) {
        letterboxMap.runOnItem(key, onFound = { item ->
        letterboxMap.runOnItem(key.taskId, onFound = { item ->
            item.run {
                transaction.remove(this)
            }
        })
        letterboxMap.remove(key)
        letterboxMap.remove(key.taskId)
    }

    /**
@@ -84,7 +84,7 @@ class SingleSurfaceLetterboxController @Inject constructor(
        transaction: Transaction,
        visible: Boolean
    ) {
        letterboxMap.runOnItem(key, onFound = { item ->
        letterboxMap.runOnItem(key.taskId, onFound = { item ->
            item.run {
                transaction.setVisibility(this, visible)
            }
@@ -100,7 +100,7 @@ class SingleSurfaceLetterboxController @Inject constructor(
        taskBounds: Rect,
        activityBounds: Rect
    ) {
        letterboxMap.runOnItem(key, onFound = { item ->
        letterboxMap.runOnItem(key.taskId, onFound = { item ->
            item.run {
                transaction.moveAndCrop(this, taskBounds)
            }
+3 −0
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@ abstract class LetterboxControllerRobotTest {
        @JvmStatic
        val TASK_ID = 20

        @JvmStatic
        val ANOTHER_TASK_ID = 10

        @JvmStatic
        private val TOKEN = mock<WindowContainerToken>()
    }
+5 −6
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.test.filters.SmallTest
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.common.suppliers.InputChannelSupplier
import com.android.wm.shell.common.suppliers.WindowSessionSupplier
import com.android.wm.shell.compatui.letterbox.LetterboxControllerRobotTest.Companion.ANOTHER_TASK_ID
import com.android.wm.shell.compatui.letterbox.LetterboxMatchers.asAnyMode
import com.android.wm.shell.compatui.letterbox.events.ReachabilityGestureListener
import com.android.wm.shell.compatui.letterbox.events.ReachabilityGestureListenerFactory
@@ -79,12 +80,10 @@ class LetterboxInputControllerTest : ShellTestCase() {
        runTestScenario { r ->
            r.sendCreateSurfaceRequest()
            r.sendCreateSurfaceRequest()
            r.sendCreateSurfaceRequest(displayId = 2)
            r.sendCreateSurfaceRequest(displayId = 2, taskId = 2)
            r.sendCreateSurfaceRequest(displayId = 2)
            r.sendCreateSurfaceRequest(displayId = 2, taskId = 2)
            r.sendCreateSurfaceRequest(taskId = ANOTHER_TASK_ID)
            r.sendCreateSurfaceRequest(taskId = ANOTHER_TASK_ID)

            r.checkInputSurfaceBuilderInvoked(times = 3)
            r.checkInputSurfaceBuilderInvoked(times = 2)
        }
    }

@@ -106,7 +105,7 @@ class LetterboxInputControllerTest : ShellTestCase() {
        runTestScenario { r ->
            r.sendCreateSurfaceRequest()
            r.sendUpdateSurfaceVisibilityRequest(visible = true)
            r.sendUpdateSurfaceVisibilityRequest(visible = true, displayId = 20)
            r.sendUpdateSurfaceVisibilityRequest(visible = true, taskId = ANOTHER_TASK_ID)

            r.checkVisibilityUpdated(expectedVisibility = true)
        }
Loading