Allowing state logic to progress from terminal states on touch down.
Action down events can now progress from terminal states (CLICK,
LONG_CLICK). In case tile updates and animations do not reset the state,
a new action down will not be unblocked by the terminal states.
Test: atest SystemUiRoboTests:QSLongPressEffectTest
Flag: com.android.systemui.quick_settings_visual_haptics_longpress
Bug: 353890656
Change-Id: I2194b2adab5e449a14bb0f12a9bcd99a4bc126ca
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/haptics/qs/QSLongPressEffectTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/haptics/qs/QSLongPressEffectTest.kt
index 273e3cb..fd4ed38 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/haptics/qs/QSLongPressEffectTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/haptics/qs/QSLongPressEffectTest.kt
@@ -112,6 +112,26 @@
}
@Test
+ fun onActionDown_whileClicked_startsWait() =
+ testWhileInState(QSLongPressEffect.State.CLICKED) {
+ // GIVEN an action down event occurs
+ longPressEffect.handleActionDown()
+
+ // THEN the effect moves to the TIMEOUT_WAIT state
+ assertThat(longPressEffect.state).isEqualTo(QSLongPressEffect.State.TIMEOUT_WAIT)
+ }
+
+ @Test
+ fun onActionDown_whileLongClicked_startsWait() =
+ testWhileInState(QSLongPressEffect.State.LONG_CLICKED) {
+ // GIVEN an action down event occurs
+ longPressEffect.handleActionDown()
+
+ // THEN the effect moves to the TIMEOUT_WAIT state
+ assertThat(longPressEffect.state).isEqualTo(QSLongPressEffect.State.TIMEOUT_WAIT)
+ }
+
+ @Test
fun onActionCancel_whileWaiting_goesIdle() =
testWhileInState(QSLongPressEffect.State.TIMEOUT_WAIT) {
// GIVEN an action cancel occurs
diff --git a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt
index 4652b2a..e50c05c 100644
--- a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt
+++ b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt
@@ -107,7 +107,11 @@
fun handleActionDown() {
logEvent(qsTile?.tileSpec, state, "action down received")
when (state) {
- State.IDLE -> {
+ State.IDLE,
+ // ACTION_DOWN typically only happens in State.IDLE but including CLICKED and
+ // LONG_CLICKED just to be safe`b
+ State.CLICKED,
+ State.LONG_CLICKED -> {
setState(State.TIMEOUT_WAIT)
}
State.RUNNING_BACKWARDS_FROM_UP,