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

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

[72/n] Avoid creation for input surface when not used

In some cases reachability is not enabled even if the letterbox surfaces
are visible. This happens, for instance, when the letterbox happens in
Desktop Windowing.

Flag: EXEMPT Refactoring
Bug: 426435032
Test: atest WMShellUnitTests:LetterboxControllerStrategyTest
Test: atest WMShellUnitTests:MixedLetterboxControllerTest
Test: atest WMShellUnitTests:ActivityLetterboxLifecycleEventFactoryTest
Test: atest WMShellUnitTests:TaskInfoLetterboxLifecycleEventFactoryTest

Change-Id: I3d6508f559486f2d3aa430c9ad129373cd5d0318
parent 48461094
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@ class LetterboxControllerStrategy @Inject constructor(
    @Volatile
    private var currentMode: LetterboxMode = SINGLE_SURFACE

    @Volatile
    private var supportsInputSurface: Boolean = false

    fun configureLetterboxMode(event: LetterboxLifecycleEvent) {
        // Decides whether to use a single surface or multiple surfaces for the letterbox.
        // The primary trade-off is memory usage versus rendering performance.
@@ -51,10 +54,16 @@ class LetterboxControllerStrategy @Inject constructor(
            letterboxConfiguration.isLetterboxActivityCornersRounded() -> SINGLE_SURFACE
            else -> MULTIPLE_SURFACES
        }
        supportsInputSurface = event.supportsInput
    }

    /**
     * @return The specific mode to use for implementing letterboxing for the given [request].
     */
    fun getLetterboxImplementationMode(): LetterboxMode = currentMode

    /**
     * Tells if the input surface should be created or not. This enabled reachability.
     */
    fun shouldSupportInputSurface(): Boolean = supportsInputSurface
}
+6 −2
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ class MixedLetterboxController @Inject constructor(
    private val singleSurfaceController: SingleSurfaceLetterboxController,
    private val multipleSurfaceController: MultiSurfaceLetterboxController,
    private val controllerStrategy: LetterboxControllerStrategy,
    private val inputController: LetterboxInputController
    private val inputController: LetterboxInputController,
) : LetterboxController by singleSurfaceController.append(multipleSurfaceController)
    .append(inputController) {

@@ -59,6 +59,10 @@ class MixedLetterboxController @Inject constructor(
                )
            }
        }
        if (controllerStrategy.shouldSupportInputSurface()) {
            inputController.createLetterboxSurface(key, transaction, parentLeash, token)
        } else {
            inputController.destroyLetterboxSurface(key, transaction)
        }
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.wm.shell.compatui.letterbox.lifecycle
import android.graphics.Rect
import android.window.TransitionInfo.Change
import com.android.internal.protolog.ProtoLog
import com.android.wm.shell.compatui.letterbox.config.LetterboxDependenciesHelper
import com.android.wm.shell.compatui.letterbox.state.LetterboxTaskInfoRepository
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_APP_COMPAT

@@ -27,7 +28,8 @@ import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_APP_COMPAT
 * a [TransitionInfo.Change] using a [ActivityTransitionInfo] when present.
 */
class ActivityLetterboxLifecycleEventFactory(
    private val taskRepository: LetterboxTaskInfoRepository
    private val taskRepository: LetterboxTaskInfoRepository,
    private val letterboxDependenciesHelper: LetterboxDependenciesHelper
) : LetterboxLifecycleEventFactory {

    companion object {
@@ -65,7 +67,8 @@ class ActivityLetterboxLifecycleEventFactory(
                letterboxBounds = letterboxBounds,
                taskLeash = taskItem.containerLeash,
                containerToken = taskItem.containerToken,
                isTranslucent = change.isTranslucent()
                isTranslucent = change.isTranslucent(),
                supportsInput = letterboxDependenciesHelper.shouldSupportInputSurface(change)
            )
        }
        ProtoLog.w(WM_SHELL_APP_COMPAT, "$TAG: Task not found for taskId: $taskId")
+2 −1
Original line number Diff line number Diff line
@@ -46,7 +46,8 @@ data class LetterboxLifecycleEvent(
    val containerToken: WindowContainerToken? = null,
    val taskLeash: SurfaceControl? = null,
    val isBubble: Boolean = false,
    val isTranslucent: Boolean = false
    val isTranslucent: Boolean = false,
    val supportsInput: Boolean = true
)

/**
+6 −2
Original line number Diff line number Diff line
@@ -18,12 +18,15 @@ package com.android.wm.shell.compatui.letterbox.lifecycle

import android.graphics.Rect
import android.window.TransitionInfo.Change
import com.android.wm.shell.compatui.letterbox.config.LetterboxDependenciesHelper

/**
 * [LetterboxLifecycleEventFactory] implementation which creates a [LetterboxLifecycleEvent] from
 * a [TransitionInfo.Change] using a [TaskInfo] when present.
 */
class TaskInfoLetterboxLifecycleEventFactory : LetterboxLifecycleEventFactory {
class TaskInfoLetterboxLifecycleEventFactory(
    private val letterboxDependenciesHelper: LetterboxDependenciesHelper
) : LetterboxLifecycleEventFactory {
    override fun canHandle(change: Change): Boolean = change.taskInfo != null

    override fun createLifecycleEvent(change: Change): LetterboxLifecycleEvent? {
@@ -51,7 +54,8 @@ class TaskInfoLetterboxLifecycleEventFactory : LetterboxLifecycleEventFactory {
                containerToken = ti.token,
                taskLeash = change.leash,
                isBubble = ti.isAppBubble,
                isTranslucent = change.isTranslucent()
                isTranslucent = change.isTranslucent(),
                supportsInput = letterboxDependenciesHelper.shouldSupportInputSurface(change)
            )
        }
        return null
Loading