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

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

Merge "a11y: Finalize the intro string for Voice Access dialog" into main

parents 58b811c5 be8b41db
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() {
            val type = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS

            val a11yServiceInfo = spy(getMockAccessibilityServiceInfo("Voice access"))
            whenever(a11yServiceInfo.loadIntro(any())).thenReturn("Voice access Intro.")
            whenever(a11yServiceInfo.loadIntro(any())).thenReturn("Voice access default Intro.")
            whenever(
                    accessibilityManager.getInstalledServiceInfoWithComponentName(
                        ComponentName.unflattenFromString(getTargetNameByType(type))
@@ -168,12 +168,12 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() {
            assertThat(titleToContent?.first).isEqualTo("Turn on Voice access?")
            val contentText = titleToContent?.second
            assertThat(hasExpectedAnnotation(contentText)).isTrue()
            // `contentText` here is an instance of SpannableStringBuilder, so we only need to
            // compare its value here.
            // The intro should be the string below instead of the intro from
            // AccessibilityServiceInfo.
            assertThat(contentText?.toString())
                .isEqualTo(
                    "Action icon + Alt + V is the keyboard shortcut to use Voice access." +
                        " Voice access Intro."
                        " Voice access lets you control your device hands-free."
                )
        }
    }
+2 −0
Original line number Diff line number Diff line
@@ -2854,6 +2854,8 @@
    <string name="accessibility_key_gesture_dialog_magnifier_intro">This allows you to quickly zoom in on the screen to make content larger.</string>
    <!-- The text for the TalkBack introduction. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_dialog_talkback_intro"><xliff:g name="feature_name" example="TalkBack">%1$s</xliff:g> is a screen reader that allows you to hear items spoken aloud. It can be helpful for people who have difficulty seeing the screen.</string>
    <!-- The text for the Voice Access introduction. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_dialog_va_intro"><xliff:g name="feature_name" example="Voice Access">%1$s</xliff:g> lets you control your device hands-free.</string>
    <!-- Positive button text for the dialog. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_dialog_positive_button_text">Turn on</string>

+30 −11
Original line number Diff line number Diff line
@@ -149,17 +149,13 @@ constructor(
                        getFeatureName(
                            accessibilityServiceInfo.resolveInfo.loadLabel(packageManager)
                        )
                    var intro = accessibilityServiceInfo.loadIntro(packageManager) ?: ""

                    // We don't re-use the existing intro from AccessibilityServiceInfo for
                    // TalkBack.
                    if (keyGestureType == KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SCREEN_READER) {
                        intro =
                            resources.getString(
                                R.string.accessibility_key_gesture_dialog_talkback_intro,
                    val intro =
                        getFeatureIntro(
                            keyGestureType,
                            featureName,
                            accessibilityServiceInfo.loadIntro(packageManager),
                        )
                    }

                    Pair(featureName, intro)
                }
@@ -173,4 +169,27 @@ constructor(
        val locale = context.resources.configuration.getLocales().get(0)
        return BidiFormatter.getInstance(locale).unicodeWrap(label)
    }

    /**
     * @param defaultIntro The intro we get from AccessibilityServiceInfo
     * @return A customize introduction
     */
    private fun getFeatureIntro(
        keyGestureType: Int,
        featureName: CharSequence,
        defaultIntro: CharSequence?,
    ): CharSequence {
        return when (keyGestureType) {
            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SCREEN_READER ->
                resources.getString(
                    R.string.accessibility_key_gesture_dialog_talkback_intro,
                    featureName,
                )

            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS ->
                resources.getString(R.string.accessibility_key_gesture_dialog_va_intro, featureName)

            else -> defaultIntro ?: ""
        }
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -63,7 +63,9 @@ constructor(
    @VisibleForTesting var currentDialog: ComponentSystemUIDialog? = null

    override fun start() {
        if (!Flags.enableTalkbackAndMagnifierKeyGestures()) {
        if (
            !Flags.enableTalkbackAndMagnifierKeyGestures() && !Flags.enableVoiceAccessKeyGestures()
        ) {
            return
        }