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

Commit 093b415a authored by Hongyu Long's avatar Hongyu Long Committed by Android (Google) Code Review
Browse files

Merge "a11y: Ignore other dialogs while there is a dialog showing" into main

parents ffe8d252 8c8fdbf9
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() &&
@@ -79,11 +81,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 ->
@@ -124,23 +129,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.