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

Commit 3e3fe4d9 authored by Chandru S's avatar Chandru S Committed by Android (Google) Code Review
Browse files

Merge changes I91f41dec,I9a6fccf9 into main

* changes:
  Use scaledTouchSlop for DeviceEntryIconView
  Add addtional logging for long press event handling in the lock screen
parents f3c3a0d0 8e1097b9
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import com.android.systemui.keyguard.ui.view.DeviceEntryIconView
import com.android.systemui.keyguard.ui.viewmodel.AlternateBouncerDependencies
import com.android.systemui.keyguard.ui.viewmodel.AlternateBouncerMessageAreaViewModel
import com.android.systemui.keyguard.ui.viewmodel.AlternateBouncerUdfpsIconViewModel
import com.android.systemui.log.LongPressHandlingViewLogger
import com.android.systemui.res.R
import kotlinx.coroutines.ExperimentalCoroutinesApi

@@ -97,6 +98,7 @@ fun AlternateBouncer(
            Box {
                DeviceEntryIcon(
                    viewModel = alternateBouncerDependencies.udfpsIconViewModel,
                    logger = alternateBouncerDependencies.logger,
                    modifier =
                        Modifier.width { udfpsLocation.width }
                            .height { udfpsLocation.height }
@@ -151,13 +153,14 @@ private fun StatusMessage(
@Composable
private fun DeviceEntryIcon(
    viewModel: AlternateBouncerUdfpsIconViewModel,
    logger: LongPressHandlingViewLogger,
    modifier: Modifier = Modifier,
) {
    AndroidView(
        modifier = modifier,
        factory = { context ->
            val view =
                DeviceEntryIconView(context, null).apply {
                DeviceEntryIconView(context, null, logger = logger).apply {
                    id = R.id.alternate_bouncer_udfps_icon_view
                    contentDescription =
                        context.resources.getString(R.string.accessibility_fingerprint_label)
+25 −12
Original line number Diff line number Diff line
@@ -44,6 +44,9 @@ import com.android.systemui.keyguard.ui.view.DeviceEntryIconView
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryBackgroundViewModel
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryForegroundViewModel
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryIconViewModel
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LongPressHandlingViewLogger
import com.android.systemui.log.dagger.LongPressTouchLog
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.res.R
import com.android.systemui.statusbar.VibratorHelper
@@ -64,6 +67,7 @@ constructor(
    private val deviceEntryBackgroundViewModel: Lazy<DeviceEntryBackgroundViewModel>,
    private val falsingManager: Lazy<FalsingManager>,
    private val vibratorHelper: Lazy<VibratorHelper>,
    @LongPressTouchLog private val logBuffer: LogBuffer,
) {
    @Composable
    fun SceneScope.LockIcon(overrideColor: Color? = null, modifier: Modifier = Modifier) {
@@ -77,7 +81,12 @@ constructor(
            factory = { context ->
                val view =
                    if (DeviceEntryUdfpsRefactor.isEnabled) {
                        DeviceEntryIconView(context, null).apply {
                        DeviceEntryIconView(
                                context,
                                null,
                                logger = LongPressHandlingViewLogger(logBuffer, tag = TAG)
                            )
                            .apply {
                                id = R.id.device_entry_icon_view
                                DeviceEntryIconViewBinder.bind(
                                    applicationScope,
@@ -178,6 +187,10 @@ constructor(

        return IntRect(center, radius)
    }

    companion object {
        private const val TAG = "LockSection"
    }
}

private val LockIconElementKey = ElementKey("LockIcon")
+2 −1
Original line number Diff line number Diff line
@@ -67,7 +67,8 @@ class LongPressHandlingViewInteractionHandlerTest : SysuiTestCase() {
                isAttachedToWindow = { isAttachedToWindow },
                onLongPressDetected = onLongPressDetected,
                onSingleTapDetected = onSingleTapDetected,
                longPressDuration = { ViewConfiguration.getLongPressTimeout().toLong() }
                longPressDuration = { ViewConfiguration.getLongPressTimeout().toLong() },
                allowedTouchSlop = ViewConfiguration.getTouchSlop(),
            )
        underTest.isLongPressHandlingEnabled = true
    }
+5 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.ViewConfiguration
import android.view.accessibility.AccessibilityNodeInfo
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat
import com.android.systemui.log.LongPressHandlingViewLogger
import com.android.systemui.shade.TouchLogger
import kotlin.math.pow
import kotlin.math.sqrt
@@ -42,6 +43,8 @@ class LongPressHandlingView(
    context: Context,
    attrs: AttributeSet?,
    longPressDuration: () -> Long,
    allowedTouchSlop: Int = ViewConfiguration.getTouchSlop(),
    logger: LongPressHandlingViewLogger? = null,
) :
    View(
        context,
@@ -97,6 +100,8 @@ class LongPressHandlingView(
            },
            onSingleTapDetected = { listener?.onSingleTapDetected(this@LongPressHandlingView) },
            longPressDuration = longPressDuration,
            allowedTouchSlop = allowedTouchSlop,
            logger = logger,
        )
    }

+19 −4
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@

package com.android.systemui.common.ui.view

import android.view.ViewConfiguration
import com.android.systemui.log.LongPressHandlingViewLogger
import kotlinx.coroutines.DisposableHandle

/** Encapsulates logic to handle complex touch interactions with a [LongPressHandlingView]. */
@@ -35,6 +35,14 @@ class LongPressHandlingViewInteractionHandler(
    private val onSingleTapDetected: () -> Unit,
    /** Time for the touch to be considered a long-press in ms */
    var longPressDuration: () -> Long,
    /**
     * Default touch slop that is allowed, if the movement between [MotionEventModel.Down] and
     * [MotionEventModel.Up] is more than [allowedTouchSlop] then the touch is not processed as
     * single tap or a long press.
     */
    val allowedTouchSlop: Int,
    /** Optional logger that can be passed in to log touch events */
    val logger: LongPressHandlingViewLogger? = null,
) {
    sealed class MotionEventModel {
        object Other : MotionEventModel()
@@ -70,22 +78,26 @@ class LongPressHandlingViewInteractionHandler(
                true
            }
            is MotionEventModel.Move -> {
                if (event.distanceMoved > ViewConfiguration.getTouchSlop()) {
                if (event.distanceMoved > allowedTouchSlop) {
                    logger?.cancelingLongPressDueToTouchSlop(event.distanceMoved, allowedTouchSlop)
                    cancelScheduledLongPress()
                }
                false
            }
            is MotionEventModel.Up -> {
                logger?.onUpEvent(event.distanceMoved, allowedTouchSlop, event.gestureDuration)
                cancelScheduledLongPress()
                if (
                    event.distanceMoved <= ViewConfiguration.getTouchSlop() &&
                    event.distanceMoved <= allowedTouchSlop &&
                        event.gestureDuration < longPressDuration()
                ) {
                    logger?.dispatchingSingleTap()
                    dispatchSingleTap()
                }
                false
            }
            is MotionEventModel.Cancel -> {
                logger?.motionEventCancelled()
                cancelScheduledLongPress()
                false
            }
@@ -97,15 +109,18 @@ class LongPressHandlingViewInteractionHandler(
        x: Int,
        y: Int,
    ) {
        val duration = longPressDuration()
        logger?.schedulingLongPress(duration)
        scheduledLongPressHandle =
            postDelayed(
                {
                    logger?.longPressTriggered()
                    dispatchLongPress(
                        x = x,
                        y = y,
                    )
                },
                longPressDuration(),
                duration,
            )
    }

Loading