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

Commit 8c8fdbf9 authored by Hongyu Long's avatar Hongyu Long
Browse files

a11y: Ignore other dialogs while there is a dialog showing

This CL will update the logic to that if there is a dialog showing, when
the user presses confirmation dialog shortcuts, we will still show the
existing dialog.

Bug: b/436349085
Flag:com.android.hardware.input.enable_talkback_and_magnifier_key_gestures
Test: atest KeyGestureDialogStartableTest & manual
Change-Id: Icebe65d1798cd980b0885628101cf1aeb671c740
parent 134e2345
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -99,6 +99,35 @@ class KeyGestureDialogStartableTest : SysuiTestCase() {
            assertThat(underTest.currentDialog?.isShowing).isTrue()
        }

    @Test
    fun start_onValidRequestReceived_dialogShowing_ignoreAdditionalRequests() =
        testScope.runTest {
            underTest.start()
            runCurrent()

            // Trigger to send a broadcast event at the first-time for Magnification
            sendIntentBroadcast(
                KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION,
                KeyEvent.META_META_ON or KeyEvent.META_ALT_ON,
                KeyEvent.KEYCODE_M,
                "targetNameForMagnification",
            )
            runCurrent()
            // Trigger to send a broadcast event at the second-time for TalkBack
            sendIntentBroadcast(
                KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SCREEN_READER,
                KeyEvent.META_META_ON or KeyEvent.META_ALT_ON,
                KeyEvent.KEYCODE_T,
                "targetNameForScreenReader",
            )
            runCurrent()

            // Only show the Magnification dialog.
            assertThat(underTest.currentDialog?.isShowing).isTrue()
            assertThat(underTest.dialogType)
                .isEqualTo(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION)
        }

    @Test
    fun start_onInvalidRequestReceived_noDialog() =
        testScope.runTest {
+18 −15
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ constructor(
) : CoreStartable {
    @VisibleForTesting var currentDialog: ComponentSystemUIDialog? = null

    @VisibleForTesting var dialogType: Int = 0

    override fun start() {
        if (
            !Flags.enableTalkbackAndMagnifierKeyGestures() && !Flags.enableVoiceAccessKeyGestures()
@@ -77,11 +79,14 @@ constructor(
    }

    private fun createDialog(keyGestureConfirmInfo: KeyGestureConfirmInfo?) {
        // Ignore other type of first-time keyboard shortcuts while the dialog is showing.
        if (currentDialog != null) {
            return
        }

        if (keyGestureConfirmInfo == null) {
            dismissDialog()
            return
        }
        dismissDialog()

        currentDialog =
            dialogFactory.create { dialog ->
@@ -122,23 +127,21 @@ constructor(
            }

        currentDialog?.let { dialog ->
            dialog.show()

            // We need to announce the text for the TalkBack dialog.
            if (
                keyGestureConfirmInfo.keyGestureType ==
                    KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SCREEN_READER
            ) {
                val tts = interactor.performTtsPromptForText(keyGestureConfirmInfo.contentText)
                dialog.setOnDismissListener { tts.dismiss() }
            }
        }
            dialogType = keyGestureConfirmInfo.keyGestureType
            val tts =
                if (dialogType == KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SCREEN_READER) {
                    interactor.performTtsPromptForText(keyGestureConfirmInfo.contentText)
                } else {
                    null
                }

    private fun dismissDialog() {
        currentDialog?.dismiss()
            dialog.setOnDismissListener {
                tts?.dismiss()
                currentDialog = null
            }
            dialog.show()
        }
    }

    private fun buildAnnotatedStringFromResource(resourceText: CharSequence): AnnotatedString {
        // `resourceText` is an instance of SpannableStringBuilder, so we can cast it to a Spanned.