summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt14
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileViewImplTest.kt24
2 files changed, 30 insertions, 8 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt
index b7ebce247ec9..b0351ad027a3 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt
@@ -776,11 +776,15 @@ constructor(
lastIconTint = icon.getColor(state)
// Long-press effects
- longPressEffect?.qsTile?.state?.handlesLongClick = state.handlesLongClick
- if (
- state.handlesLongClick &&
- longPressEffect?.initializeEffect(longPressEffectDuration) == true
- ) {
+ updateLongPressEffect(state.handlesLongClick)
+ }
+
+ private fun updateLongPressEffect(handlesLongClick: Boolean) {
+ // The long press effect in the tile can't be updated if it is still running
+ if (longPressEffect?.state != QSLongPressEffect.State.IDLE) return
+
+ longPressEffect.qsTile?.state?.handlesLongClick = handlesLongClick
+ if (handlesLongClick && longPressEffect.initializeEffect(longPressEffectDuration)) {
showRippleEffect = false
longPressEffect.qsTile?.state?.state = lastState // Store the tile's state
longPressEffect.resetState()
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileViewImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileViewImplTest.kt
index 90ffaf19be96..67c5986fe5d8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileViewImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileViewImplTest.kt
@@ -236,7 +236,7 @@ class QSTileViewImplTest : SysuiTestCase() {
context.orCreateTestableResources.addOverride(
R.array.tile_states_internet,
- arrayOf(unavailableString, offString, onString)
+ arrayOf(unavailableString, offString, onString),
)
// State UNAVAILABLE
@@ -341,7 +341,7 @@ class QSTileViewImplTest : SysuiTestCase() {
val testA11yLabel = "TEST_LABEL"
context.orCreateTestableResources.addOverride(
R.string.accessibility_tile_disabled_by_policy_action_description,
- testA11yLabel
+ testA11yLabel,
)
val stateDisabledByPolicy = QSTile.State()
@@ -374,7 +374,7 @@ class QSTileViewImplTest : SysuiTestCase() {
context.orCreateTestableResources.addOverride(
R.array.tile_states_internet,
- arrayOf(unavailableString, offString, onString)
+ arrayOf(unavailableString, offString, onString),
)
tileView.changeState(state)
@@ -477,6 +477,24 @@ class QSTileViewImplTest : SysuiTestCase() {
}
@Test
+ fun onStateChange_fromLongPress_toNoLongPress_whileLongPressRuns_doesNotClearResources() {
+ // GIVEN that the long-press effect has been initialized
+ val state = QSTile.State()
+ state.handlesLongClick = true
+ tileView.changeState(state)
+
+ // WHEN the long-press effect is running
+ kosmos.qsLongPressEffect.setState(QSLongPressEffect.State.RUNNING_FORWARD)
+
+ // WHEN a state changed happens so that the tile no longer handles long-press
+ state.handlesLongClick = false
+ tileView.changeState(state)
+
+ // THEN the long-press effect resources are not cleared
+ assertThat(tileView.areLongPressEffectPropertiesSet).isTrue()
+ }
+
+ @Test
fun onStateChange_withoutLongPressEffect_fromLongPress_to_noLongPress_neverSetsProperties() {
// GIVEN a tile where the long-press effect is null
tileView = FakeTileView(context, false, null)