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

Commit 6d3e5bee authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Avoid state changes clearing long-press effect properties while running.

The visual properties of a long-press effect should not change if the
effect is running and if a QS tile changes its state unexpectedly.

Test: QSTileViewImplTest
Flag: com.android.systemui.quick_settings_visual_haptics_longpress
Bug: 383402866
Change-Id: I56328d243f022eff4bf21004591720ee6c0523b3
parent 3633fa1c
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -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()
+21 −3
Original line number Diff line number Diff line
@@ -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)
@@ -476,6 +476,24 @@ class QSTileViewImplTest : SysuiTestCase() {
        assertThat(tileView.areLongPressEffectPropertiesSet).isTrue()
    }

    @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