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

Commit 48461094 authored by Massimo Carli's avatar Massimo Carli
Browse files

[71/n] Add Rule for Input Surface Creation

We should create the input surfaces only in case reachability is actually enabled.
This is not happening when in Desktop Windowing.

Flag: EXEMPT Refactoring
Bug: 426435032
Test: atest WMShellUnitTests:DefaultLetterboxDependenciesHelperTest

Change-Id: I04aa1854014d78184664e84788cce9f69c7db9fb
parent f43be0ca
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -25,6 +25,10 @@ import com.android.wm.shell.desktopmode.DesktopRepository
class DefaultLetterboxDependenciesHelper(val desktopRepository: DesktopRepository) :
    LetterboxDependenciesHelper {

    override fun shouldDestroyLetterboxSurfaces(change: TransitionInfo.Change): Boolean =
        desktopRepository.isAnyDeskActive(change.endDisplayId)
    /**
     * When in Desktop Windowing the reachability feature is disabled so the creation of the input
     * surface for event detection can be ignored.
     */
    override fun shouldSupportInputSurface(change: TransitionInfo.Change): Boolean =
        !desktopRepository.isAnyDeskActive(change.endDisplayId)
}
+3 −3
Original line number Diff line number Diff line
@@ -24,9 +24,9 @@ import android.window.TransitionInfo.Change
 * that don't allow the Desktop Windowing feature (a.g. Auto).
 */
class IgnoreLetterboxDependenciesHelper : LetterboxDependenciesHelper {

    /**
     * We should ignore all the changes related to Desktop Windowing when the feature is not
     * available.
     * By default the input surface should always be created.
     */
    override fun shouldDestroyLetterboxSurfaces(change: Change): Boolean = false
    override fun shouldSupportInputSurface(change: Change): Boolean = true
}
+2 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import android.window.TransitionInfo.Change
interface LetterboxDependenciesHelper {

    /**
     * Tells if we need to destroy the existing letterbox surfaces for a given [Change].
     * Tells if the input surface should be created or not. This enables reachability.
     */
    fun shouldDestroyLetterboxSurfaces(change: Change): Boolean
    fun shouldSupportInputSurface(change: Change): Boolean
}
+8 −8
Original line number Diff line number Diff line
@@ -41,26 +41,26 @@ import org.mockito.kotlin.mock
class DefaultLetterboxDependenciesHelperTest : ShellTestCase() {

    @Test
    fun `Should not destroy letterbox surfaces if not isAnyDeskActive`() {
    fun `When in Desktop Windowing the input surface should not be created`() {
        runTestScenario { r ->
            testLetterboxDependenciesHelper(r.getLetterboxLifecycleEventFactory()) {
                inputChange { }
                r.configureDesktopRepository(isAnyDeskActive = false)
                validateIsDesktopWindowingAction { shouldDestroy ->
                    assertFalse(shouldDestroy)
                r.configureDesktopRepository(isAnyDeskActive = true)
                validateShouldSupportInputSurface { shouldSupportInputSurface ->
                    assertFalse(shouldSupportInputSurface)
                }
            }
        }
    }

    @Test
    fun `Should destroy letterbox surfaces if isAnyDeskActive`() {
    fun `When NOT in Desktop Windowing the input surface should be created`() {
        runTestScenario { r ->
            testLetterboxDependenciesHelper(r.getLetterboxLifecycleEventFactory()) {
                inputChange { }
                r.configureDesktopRepository(isAnyDeskActive = true)
                validateIsDesktopWindowingAction { shouldDestroy ->
                    assertTrue(shouldDestroy)
                r.configureDesktopRepository(isAnyDeskActive = false)
                validateShouldSupportInputSurface { shouldSupportInputSurface ->
                    assertTrue(shouldSupportInputSurface)
                }
            }
        }
+2 −2
Original line number Diff line number Diff line
@@ -28,9 +28,9 @@ class LetterboxDependenciesHelperTestContext(

    val deskId: Int = -1

    fun validateIsDesktopWindowingAction(verifier: (Boolean) -> Unit) {
    fun validateShouldSupportInputSurface(verifier: (Boolean) -> Unit) {
        // We execute the test subject using the input
        verifier(testSubjectFactory().shouldDestroyLetterboxSurfaces(inputObject))
        verifier(testSubjectFactory().shouldSupportInputSurface(inputObject))
    }
}