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

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

Merge "Adding an early falsing check to reset properties if necessary." into main

parents 3f4361a4 7860b959
Loading
Loading
Loading
Loading
+18 −5
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.classifier.falsingManager
import com.android.systemui.haptics.fakeVibratorHelper
import com.android.systemui.haptics.fakeVibratorHelper
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.testScope
import com.android.systemui.log.core.FakeLogBuffer
import com.android.systemui.log.core.FakeLogBuffer
@@ -68,11 +69,13 @@ class QSLongPressEffectTest : SysuiTestCase() {
        vibratorHelper.primitiveDurations[VibrationEffect.Composition.PRIMITIVE_SPIN] = spinDuration
        vibratorHelper.primitiveDurations[VibrationEffect.Composition.PRIMITIVE_SPIN] = spinDuration


        whenever(kosmos.keyguardStateController.isUnlocked).thenReturn(true)
        whenever(kosmos.keyguardStateController.isUnlocked).thenReturn(true)
        kosmos.falsingManager.setFalseLongTap(false)


        longPressEffect =
        longPressEffect =
            QSLongPressEffect(
            QSLongPressEffect(
                vibratorHelper,
                vibratorHelper,
                kosmos.keyguardStateController,
                kosmos.keyguardStateController,
                kosmos.falsingManager,
                FakeLogBuffer.Factory.create(),
                FakeLogBuffer.Factory.create(),
            )
            )
        longPressEffect.callback = callback
        longPressEffect.callback = callback
@@ -180,11 +183,7 @@ class QSLongPressEffectTest : SysuiTestCase() {


        // THEN the expected texture is played
        // THEN the expected texture is played
        val reverseHaptics =
        val reverseHaptics =
            LongPressHapticBuilder.createReversedEffect(
            LongPressHapticBuilder.createReversedEffect(progress, lowTickDuration, effectDuration)
                progress,
                lowTickDuration,
                effectDuration,
            )
        assertThat(reverseHaptics).isNotNull()
        assertThat(reverseHaptics).isNotNull()
        assertThat(vibratorHelper.hasVibratedWithEffects(reverseHaptics!!)).isTrue()
        assertThat(vibratorHelper.hasVibratedWithEffects(reverseHaptics!!)).isTrue()
    }
    }
@@ -223,6 +222,20 @@ class QSLongPressEffectTest : SysuiTestCase() {
            verify(callback, times(1)).onResetProperties()
            verify(callback, times(1)).onResetProperties()
        }
        }


    @Test
    fun onAnimationComplete_isFalseLongClick_effectEndsInIdleWithReset() =
        testWhileInState(QSLongPressEffect.State.RUNNING_FORWARD) {
            // GIVEN that the long-click is false
            kosmos.falsingManager.setFalseLongTap(true)

            // GIVEN that the animation completes
            longPressEffect.handleAnimationComplete()

            // THEN the long-press effect ends in the idle state and the properties are reset
            assertThat(longPressEffect.state).isEqualTo(QSLongPressEffect.State.IDLE)
            verify(callback, times(1)).onResetProperties()
        }

    @Test
    @Test
    fun onAnimationComplete_whenRunningBackwardsFromUp_endsWithFinishedReversingAndClick() =
    fun onAnimationComplete_whenRunningBackwardsFromUp_endsWithFinishedReversingAndClick() =
        testWhileInState(QSLongPressEffect.State.RUNNING_BACKWARDS_FROM_UP) {
        testWhileInState(QSLongPressEffect.State.RUNNING_BACKWARDS_FROM_UP) {
+22 −8
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.animation.Expandable
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.QSLog
import com.android.systemui.log.dagger.QSLog
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.plugins.qs.QSTile
import com.android.systemui.plugins.qs.QSTile
import com.android.systemui.statusbar.VibratorHelper
import com.android.systemui.statusbar.VibratorHelper
import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.statusbar.policy.KeyguardStateController
@@ -50,6 +51,7 @@ class QSLongPressEffect
constructor(
constructor(
    private val vibratorHelper: VibratorHelper?,
    private val vibratorHelper: VibratorHelper?,
    private val keyguardStateController: KeyguardStateController,
    private val keyguardStateController: KeyguardStateController,
    private val falsingManager: FalsingManager,
    @QSLog private val logBuffer: LogBuffer,
    @QSLog private val logBuffer: LogBuffer,
) {
) {


@@ -72,7 +74,7 @@ constructor(
    private val durations =
    private val durations =
        vibratorHelper?.getPrimitiveDurations(
        vibratorHelper?.getPrimitiveDurations(
            VibrationEffect.Composition.PRIMITIVE_LOW_TICK,
            VibrationEffect.Composition.PRIMITIVE_LOW_TICK,
            VibrationEffect.Composition.PRIMITIVE_SPIN
            VibrationEffect.Composition.PRIMITIVE_SPIN,
        )
        )


    private var longPressHint: VibrationEffect? = null
    private var longPressHint: VibrationEffect? = null
@@ -152,15 +154,27 @@ constructor(
        logEvent(qsTile?.tileSpec, state, "animation completed")
        logEvent(qsTile?.tileSpec, state, "animation completed")
        when (state) {
        when (state) {
            State.RUNNING_FORWARD -> {
            State.RUNNING_FORWARD -> {
                val wasFalseLongTap = falsingManager.isFalseLongTap(FalsingManager.LOW_PENALTY)
                if (wasFalseLongTap) {
                    callback?.onResetProperties()
                    setState(State.IDLE)
                    logEvent(qsTile?.tileSpec, state, "false long click. No action triggered")
                } else if (keyguardStateController.isUnlocked) {
                    vibrate(snapEffect)
                    vibrate(snapEffect)
                if (keyguardStateController.isUnlocked) {
                    setState(State.LONG_CLICKED)
                    setState(State.LONG_CLICKED)
                    qsTile?.longClick(expandable)
                    logEvent(qsTile?.tileSpec, state, "long click action triggered")
                } else {
                } else {
                    vibrate(snapEffect)
                    callback?.onResetProperties()
                    callback?.onResetProperties()
                    setState(State.IDLE)
                    setState(State.IDLE)
                }
                logEvent(qsTile?.tileSpec, state, "long click action triggered")
                    qsTile?.longClick(expandable)
                    qsTile?.longClick(expandable)
                    logEvent(
                        qsTile?.tileSpec,
                        state,
                        "properties reset and long click action triggered",
                    )
                }
            }
            }
            State.RUNNING_BACKWARDS_FROM_UP -> {
            State.RUNNING_BACKWARDS_FROM_UP -> {
                callback?.onEffectFinishedReversing()
                callback?.onEffectFinishedReversing()
@@ -236,7 +250,7 @@ constructor(
            LongPressHapticBuilder.createLongPressHint(
            LongPressHapticBuilder.createLongPressHint(
                durations?.get(0) ?: LongPressHapticBuilder.INVALID_DURATION,
                durations?.get(0) ?: LongPressHapticBuilder.INVALID_DURATION,
                durations?.get(1) ?: LongPressHapticBuilder.INVALID_DURATION,
                durations?.get(1) ?: LongPressHapticBuilder.INVALID_DURATION,
                effectDuration
                effectDuration,
            )
            )
        setState(State.IDLE)
        setState(State.IDLE)
        return true
        return true
@@ -265,7 +279,7 @@ constructor(
                }
                }


                override fun dialogTransitionController(
                override fun dialogTransitionController(
                    cuj: DialogCuj?,
                    cuj: DialogCuj?
                ): DialogTransitionAnimator.Controller? =
                ): DialogTransitionAnimator.Controller? =
                    DialogTransitionAnimator.Controller.fromView(view, cuj)
                    DialogTransitionAnimator.Controller.fromView(view, cuj)
            }
            }
@@ -298,7 +312,7 @@ constructor(
                str2 = event
                str2 = event
                str3 = state.name
                str3 = state.name
            },
            },
            { "[long-press effect on $str1 tile] $str2 on state: $str3" }
            { "[long-press effect on $str1 tile] $str2 on state: $str3" },
        )
        )
    }
    }


+2 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.systemui.haptics.qs
package com.android.systemui.haptics.qs


import com.android.systemui.classifier.fakeFalsingManager
import com.android.systemui.haptics.vibratorHelper
import com.android.systemui.haptics.vibratorHelper
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.log.core.FakeLogBuffer
import com.android.systemui.log.core.FakeLogBuffer
@@ -26,6 +27,7 @@ val Kosmos.qsLongPressEffect by
        QSLongPressEffect(
        QSLongPressEffect(
            vibratorHelper,
            vibratorHelper,
            keyguardStateController,
            keyguardStateController,
            fakeFalsingManager,
            FakeLogBuffer.Factory.create(),
            FakeLogBuffer.Factory.create(),
        )
        )
    }
    }