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

Commit 6b07fd6d authored by Massimo Carli's avatar Massimo Carli Committed by Android (Google) Code Review
Browse files

Merge "[23/n] Integrate listeners in InputController" into main

parents a84741bc f408c3be
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.wm.shell.compatui.letterbox
import android.graphics.Rect
import android.view.SurfaceControl
import android.view.SurfaceControl.Transaction
import android.window.WindowContainerToken

/**
 * Abstracts the component responsible to handle a single or multiple letterbox surfaces for a
@@ -32,7 +33,8 @@ interface LetterboxController {
    fun createLetterboxSurface(
        key: LetterboxKey,
        transaction: Transaction,
        parentLeash: SurfaceControl
        parentLeash: SurfaceControl,
        token: WindowContainerToken?
    )

    /**
+7 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.wm.shell.compatui.letterbox

import android.view.SurfaceControl
import com.android.wm.shell.compatui.letterbox.events.ReachabilityGestureListener

// The key to use for identify the letterbox sessions.
data class LetterboxKey(val displayId: Int, val taskId: Int)
@@ -31,3 +32,9 @@ data class LetterboxSurfaces(
    override fun iterator() =
        listOf(leftSurface, topSurface, rightSurface, bottomSurface).iterator()
}

// Encapsulate the object used for event detection.
data class LetterboxInputItems(
    val inputDetector: LetterboxInputDetector,
    val gestureListener: ReachabilityGestureListener
)
+0 −65
Original line number Diff line number Diff line
/*
 * Copyright 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.compatui.letterbox

import android.view.GestureDetector.OnContextClickListener
import android.view.GestureDetector.OnDoubleTapListener
import android.view.GestureDetector.OnGestureListener
import android.view.MotionEvent

/**
 * Interface which unions all the interfaces related to gestures.
 */
interface LetterboxGestureListener : OnGestureListener, OnDoubleTapListener, OnContextClickListener

/**
 * Convenience class which provide an overrideable implementation of
 * {@link LetterboxGestureListener}.
 */
object LetterboxGestureDelegate : LetterboxGestureListener {
    override fun onDown(e: MotionEvent): Boolean = false

    override fun onShowPress(e: MotionEvent) {
    }

    override fun onSingleTapUp(e: MotionEvent): Boolean = false

    override fun onScroll(
        e1: MotionEvent?,
        e2: MotionEvent,
        distanceX: Float,
        distanceY: Float
    ): Boolean = false

    override fun onLongPress(e: MotionEvent) {
    }

    override fun onFling(
        e1: MotionEvent?,
        e2: MotionEvent,
        velocityX: Float,
        velocityY: Float
    ): Boolean = false

    override fun onSingleTapConfirmed(e: MotionEvent): Boolean = false

    override fun onDoubleTap(e: MotionEvent): Boolean = false

    override fun onDoubleTapEvent(e: MotionEvent): Boolean = false

    override fun onContextClick(e: MotionEvent): Boolean = false
}
+25 −19
Original line number Diff line number Diff line
@@ -22,13 +22,15 @@ import android.graphics.Region
import android.os.Handler
import android.view.SurfaceControl
import android.view.SurfaceControl.Transaction
import android.window.WindowContainerToken
import com.android.internal.protolog.ProtoLog
import com.android.wm.shell.common.InputChannelSupplier
import com.android.wm.shell.common.WindowSessionSupplier
import com.android.wm.shell.compatui.letterbox.LetterboxUtils.Maps.runOnItem
import com.android.wm.shell.compatui.letterbox.events.ReachabilityGestureListenerFactory
import com.android.wm.shell.dagger.WMSingleton
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_APP_COMPAT
import java.util.function.Supplier
import com.android.wm.shell.shared.annotations.ShellMainThread
import javax.inject.Inject

/**
@@ -38,9 +40,9 @@ import javax.inject.Inject
@WMSingleton
class LetterboxInputController @Inject constructor(
    private val context: Context,
    private val handler: Handler,
    @ShellMainThread private val handler: Handler,
    private val inputSurfaceBuilder: LetterboxInputSurfaceBuilder,
    private val listenerSupplier: Supplier<LetterboxGestureListener>,
    private val listenerFactory: ReachabilityGestureListenerFactory,
    private val windowSessionSupplier: WindowSessionSupplier,
    private val inputChannelSupplier: InputChannelSupplier
) : LetterboxController {
@@ -50,25 +52,28 @@ class LetterboxInputController @Inject constructor(
        private val TAG = "LetterboxInputController"
    }

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

    override fun createLetterboxSurface(
        key: LetterboxKey,
        transaction: Transaction,
        parentLeash: SurfaceControl
        parentLeash: SurfaceControl,
        token: WindowContainerToken?
    ) {
        inputDetectorMap.runOnItem(key, onMissed = { k, m ->
            m[k] =
                LetterboxInputDetector(
            val gestureListener =
                listenerFactory.createReachabilityGestureListener(key.taskId, token)
            val detector = LetterboxInputDetector(
                context,
                handler,
                    listenerSupplier.get(),
                gestureListener,
                inputSurfaceBuilder,
                windowSessionSupplier,
                inputChannelSupplier
            ).apply {
                start(transaction, parentLeash, key)
            }
            m[k] = LetterboxInputItems(detector, gestureListener)
        })
    }

@@ -78,7 +83,7 @@ class LetterboxInputController @Inject constructor(
    ) {
        with(inputDetectorMap) {
            runOnItem(key, onFound = { item ->
                item.stop(transaction)
                item.inputDetector.stop(transaction)
            })
            remove(key)
        }
@@ -91,7 +96,7 @@ class LetterboxInputController @Inject constructor(
    ) {
        with(inputDetectorMap) {
            runOnItem(key, onFound = { item ->
                item.updateVisibility(transaction, visible)
                item.inputDetector.updateVisibility(transaction, visible)
            })
        }
    }
@@ -103,7 +108,8 @@ class LetterboxInputController @Inject constructor(
        activityBounds: Rect
    ) {
        inputDetectorMap.runOnItem(key, onFound = { item ->
            item.updateTouchableRegion(transaction, Region(taskBounds))
            item.inputDetector.updateTouchableRegion(transaction, Region(taskBounds))
            item.gestureListener.updateActivityBounds(activityBounds)
        })
    }

+5 −6
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_APP_COMPAT
class LetterboxInputDetector(
    private val context: Context,
    private val handler: Handler,
    private val listener: LetterboxGestureListener,
    private val letterboxListener: GestureDetector.SimpleOnGestureListener,
    private val inputSurfaceBuilder: LetterboxInputSurfaceBuilder,
    private val windowSessionSupplier: WindowSessionSupplier,
    private val inputChannelSupplier: InputChannelSupplier
@@ -64,7 +64,7 @@ class LetterboxInputDetector(
                    handler,
                    source,
                    key.displayId,
                    listener,
                    letterboxListener,
                    inputSurfaceBuilder,
                    windowSessionSupplier.get(),
                    inputChannelSupplier
@@ -112,7 +112,7 @@ class LetterboxInputDetector(
        val handler: Handler,
        val source: SurfaceControl,
        val displayId: Int,
        val listener: LetterboxGestureListener,
        val letterboxListener: GestureDetector.SimpleOnGestureListener,
        val inputSurfaceBuilder: LetterboxInputSurfaceBuilder,
        val windowSession: IWindowSession,
        inputChannelSupplier: InputChannelSupplier
@@ -152,8 +152,7 @@ class LetterboxInputDetector(
                    "$TAG of $source",
                    inputChannel
                )

                receiver = EventReceiver(context, inputChannel, handler, listener)
                receiver = EventReceiver(context, inputChannel, handler, letterboxListener)
                return true
            } catch (e: RemoteException) {
                e.rethrowFromSystemServer()
@@ -213,7 +212,7 @@ class LetterboxInputDetector(
        context: Context,
        inputChannel: InputChannel,
        uiHandler: Handler,
        listener: LetterboxGestureListener
        listener: GestureDetector.SimpleOnGestureListener
    ) : InputEventReceiver(inputChannel, uiHandler.looper) {
        private val eventDetector: GestureDetector

Loading