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

Commit 63c52c62 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez Committed by Android (Google) Code Review
Browse files

Merge "Adding a logger to log long-press effect events" into main

parents 12fd7706 049f0d6a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.haptics.vibratorHelper
import com.android.systemui.kosmos.testScope
import com.android.systemui.log.core.FakeLogBuffer
import com.android.systemui.qs.qsTileFactory
import com.android.systemui.statusbar.policy.keyguardStateController
import com.android.systemui.testKosmos
@@ -72,6 +73,7 @@ class QSLongPressEffectTest : SysuiTestCase() {
            QSLongPressEffect(
                vibratorHelper,
                kosmos.keyguardStateController,
                FakeLogBuffer.Factory.create(),
            )
        longPressEffect.callback = callback
        longPressEffect.qsTile = qsTile
+30 −0
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@ import com.android.systemui.animation.DelegateTransitionAnimatorController
import com.android.systemui.animation.DialogCuj
import com.android.systemui.animation.DialogTransitionAnimator
import com.android.systemui.animation.Expandable
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.QSLog
import com.android.systemui.plugins.qs.QSTile
import com.android.systemui.statusbar.VibratorHelper
import com.android.systemui.statusbar.policy.KeyguardStateController
@@ -47,6 +50,7 @@ class QSLongPressEffect
constructor(
    private val vibratorHelper: VibratorHelper?,
    private val keyguardStateController: KeyguardStateController,
    @QSLog private val logBuffer: LogBuffer,
) {

    var effectDuration = 0
@@ -101,6 +105,7 @@ constructor(
    }

    fun handleActionDown() {
        logEvent(qsTile?.tileSpec, state, "action down received")
        when (state) {
            State.IDLE -> {
                setState(State.TIMEOUT_WAIT)
@@ -112,6 +117,7 @@ constructor(
    }

    fun handleActionUp() {
        logEvent(qsTile?.tileSpec, state, "action up received")
        if (state == State.RUNNING_FORWARD) {
            setState(State.RUNNING_BACKWARDS_FROM_UP)
            callback?.onReverseAnimator()
@@ -130,6 +136,7 @@ constructor(
    }

    fun handleAnimationStart() {
        logEvent(qsTile?.tileSpec, state, "animation started")
        if (state == State.TIMEOUT_WAIT) {
            vibrate(longPressHint)
            setState(State.RUNNING_FORWARD)
@@ -138,6 +145,7 @@ constructor(

    /** This function is called both when an animator completes or gets cancelled */
    fun handleAnimationComplete() {
        logEvent(qsTile?.tileSpec, state, "animation completed")
        when (state) {
            State.RUNNING_FORWARD -> {
                vibrate(snapEffect)
@@ -147,11 +155,13 @@ constructor(
                    callback?.onResetProperties()
                    setState(State.IDLE)
                }
                logEvent(qsTile?.tileSpec, state, "long click action triggered")
                qsTile?.longClick(expandable)
            }
            State.RUNNING_BACKWARDS_FROM_UP -> {
                callback?.onEffectFinishedReversing()
                setState(getStateForClick())
                logEvent(qsTile?.tileSpec, state, "click action triggered")
                qsTile?.click(expandable)
            }
            State.RUNNING_BACKWARDS_FROM_CANCEL -> {
@@ -179,6 +189,7 @@ constructor(
        if (keyguardStateController.isPrimaryBouncerShowing || !isStateClickable) return false

        setState(getStateForClick())
        logEvent(qsTile?.tileSpec, state, "click action triggered")
        qsTile?.click(expandable)
        return true
    }
@@ -273,6 +284,20 @@ constructor(
        return delegated
    }

    private fun logEvent(tileSpec: String?, state: State, event: String) {
        if (!DEBUG) return
        logBuffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = tileSpec
                str2 = event
                str3 = state.name
            },
            { "[long-press effect on $str1 tile] $str2 on state: $str3" }
        )
    }

    enum class State {
        IDLE, /* The effect is idle waiting for touch input */
        TIMEOUT_WAIT, /* The effect is waiting for a tap timeout period */
@@ -304,4 +329,9 @@ constructor(
        /** Cancel the effect animator */
        fun onCancelAnimator()
    }

    companion object {
        private const val TAG = "QSLongPressEffect"
        private const val DEBUG = true
    }
}
+8 −1
Original line number Diff line number Diff line
@@ -18,7 +18,14 @@ package com.android.systemui.haptics.qs

import com.android.systemui.haptics.vibratorHelper
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.log.core.FakeLogBuffer
import com.android.systemui.statusbar.policy.keyguardStateController

val Kosmos.qsLongPressEffect by
    Kosmos.Fixture { QSLongPressEffect(vibratorHelper, keyguardStateController) }
    Kosmos.Fixture {
        QSLongPressEffect(
            vibratorHelper,
            keyguardStateController,
            FakeLogBuffer.Factory.create(),
        )
    }