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

Commit cf417f01 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Resetting long-press effect state for clicks when keyguard is showing.

The state of the long-press effect resets to IDLE in the broader case in
which the keyguard is showing. This ensures that the state resets
properly if the click action does not launch an animation but requires
the keyguard to be dismissed.

Test: atest SystemUiRoboTests:QSLongPressEffectTest
Bug: 353979684
Flag: com.android.systemui.quick_settings_visual_haptics_longpress

Change-Id: I56ac704df313993637f8c8e96a07db7ecd37a89a
parent 002ab534
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.classifier.falsingManager
import com.android.systemui.haptics.vibratorHelper
import com.android.systemui.kosmos.testScope
import com.android.systemui.qs.qsTileFactory
@@ -73,7 +72,6 @@ class QSLongPressEffectTest : SysuiTestCase() {
            QSLongPressEffect(
                vibratorHelper,
                kosmos.keyguardStateController,
                kosmos.falsingManager,
            )
        longPressEffect.callback = callback
        longPressEffect.qsTile = qsTile
@@ -304,13 +302,12 @@ class QSLongPressEffectTest : SysuiTestCase() {
    }

    @Test
    fun getStateForClick_withFalseTapWhenLocked_returnsIdle() {
    fun getStateForClick_whenKeyguardsIsShowing_returnsIdle() {
        // GIVEN an active tile
        qsTile.state?.state = Tile.STATE_ACTIVE

        // GIVEN that the device is locked and a false tap is detected
        whenever(kosmos.keyguardStateController.isUnlocked).thenReturn(false)
        kosmos.falsingManager.setFalseTap(true)
        // GIVEN that the keyguard is showing
        whenever(kosmos.keyguardStateController.isShowing).thenReturn(true)

        // WHEN determining the state of a click action
        val clickState = longPressEffect.getStateForClick()
@@ -324,9 +321,8 @@ class QSLongPressEffectTest : SysuiTestCase() {
        // GIVEN an active tile
        qsTile.state?.state = Tile.STATE_ACTIVE

        // GIVEN that the device is locked and a false tap is not detected
        whenever(kosmos.keyguardStateController.isUnlocked).thenReturn(false)
        kosmos.falsingManager.setFalseTap(false)
        // GIVEN that the keyguard is not showing
        whenever(kosmos.keyguardStateController.isShowing).thenReturn(false)

        // WHEN determining the state of a click action
        val clickState = longPressEffect.getStateForClick()
@@ -340,9 +336,8 @@ class QSLongPressEffectTest : SysuiTestCase() {
        // GIVEN that the tile is null
        longPressEffect.qsTile = null

        // GIVEN that the device is locked and a false tap is not detected
        whenever(kosmos.keyguardStateController.isUnlocked).thenReturn(false)
        kosmos.falsingManager.setFalseTap(false)
        // GIVEN that the keyguard is not showing
        whenever(kosmos.keyguardStateController.isShowing).thenReturn(false)

        // WHEN determining the state of a click action
        val clickState = longPressEffect.getStateForClick()
+1 −6
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ 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.plugins.FalsingManager
import com.android.systemui.plugins.qs.QSTile
import com.android.systemui.statusbar.VibratorHelper
import com.android.systemui.statusbar.policy.KeyguardStateController
@@ -48,7 +47,6 @@ class QSLongPressEffect
constructor(
    private val vibratorHelper: VibratorHelper?,
    private val keyguardStateController: KeyguardStateController,
    private val falsingManager: FalsingManager,
) {

    var effectDuration = 0
@@ -195,11 +193,8 @@ constructor(
    @VisibleForTesting
    fun getStateForClick(): State {
        val isTileUnavailable = qsTile?.state?.state == Tile.STATE_UNAVAILABLE
        val isFalseTapWhileLocked =
            !keyguardStateController.isUnlocked &&
                falsingManager.isFalseTap(FalsingManager.LOW_PENALTY)
        val handlesLongClick = qsTile?.state?.handlesLongClick == true
        return if (isTileUnavailable || isFalseTapWhileLocked || !handlesLongClick) {
        return if (isTileUnavailable || !handlesLongClick || keyguardStateController.isShowing) {
            // The click event will not perform an action that resets the state. Therefore, this is
            // the last opportunity to reset the state back to IDLE.
            State.IDLE
+1 −2
Original line number Diff line number Diff line
@@ -16,10 +16,9 @@

package com.android.systemui.haptics.qs

import com.android.systemui.classifier.falsingManager
import com.android.systemui.haptics.vibratorHelper
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.statusbar.policy.keyguardStateController

val Kosmos.qsLongPressEffect by
    Kosmos.Fixture { QSLongPressEffect(vibratorHelper, keyguardStateController, falsingManager) }
    Kosmos.Fixture { QSLongPressEffect(vibratorHelper, keyguardStateController) }