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

Commit 3527f237 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Allowing IDLE long clicks on QSLongPressEffect.

If the View's OnLongClickListener detects a long click, we dispatch the
long click action if the QSLongPressEffect state is IDLE. This allows
accessibility services from Voice Access to perform actions on the QS
tiles.

Test: QSLongPressEffectTest
Flag: com.android.systemui.quick_settings_visual_haptics_longpress
Bug: 379225278
Change-Id: I2caa7ddac47d0e39e1a43980cbab05ce2c0875e3
parent ec13cf21
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -398,6 +398,16 @@ class QSLongPressEffectTest : SysuiTestCase() {
            verify(controller).onTransitionAnimationCancelled(newOccludedState)
        }

    @Test
    fun onTileLongClick_whileIdle_performsLongClick() =
        testWhileInState(QSLongPressEffect.State.IDLE) {
            // WHEN a long-click is detected by the view
            val longClicks = longPressEffect.onTileLongClick()

            // THEN the long click is handled
            assertThat(longClicks).isTrue()
        }

    private fun testWithScope(initialize: Boolean = true, test: suspend TestScope.() -> Unit) =
        with(kosmos) {
            testScope.runTest {
+15 −0
Original line number Diff line number Diff line
@@ -215,6 +215,21 @@ constructor(
        return true
    }

    fun onTileLongClick(): Boolean {
        if (state == State.IDLE) {
            // This case represents a long-click detected outside of the QSLongPressEffect. This can
            // be due to accessibility services
            qsTile?.longClick(expandable)
            logEvent(
                qsTile?.tileSpec,
                state,
                "long click action triggered from OnLongClickListener",
            )
            return true
        }
        return false
    }

    /**
     * Get the appropriate state for a click action.
     *
+4 −1
Original line number Diff line number Diff line
@@ -415,7 +415,10 @@ constructor(
            initLongPressEffectCallback()
            init(
                { _: View -> longPressEffect.onTileClick() },
                { _: View -> true }, // Haptics and long-clicks are handled by [QSLongPressEffect]
                { _: View ->
                    longPressEffect.onTileLongClick()
                    true
                }, // Haptics and long-clicks are handled by [QSLongPressEffect]
            )
        } else {
            val expandable = Expandable.fromView(this)