diff --git a/differences.md b/differences.md index 813bf26c5..89bf146e1 100644 --- a/differences.md +++ b/differences.md @@ -469,6 +469,12 @@ Backtalk adds voice commands for settings that Android lets apps change: Say "find [name]", "focus [name]", "search for [name]", or "locate [name]" (for example, "find play button", "focus search", "locate cancel") to search the screen and move accessibility focus directly to the matching control. +### Voice command scripts API + +Backtalk scripts can create custom voice commands: +* **Manifest commands**: Add `voice: 'phrase'` or `voice: ['phrase 1', 'phrase 2']` to any entry in `manifest.commands`. When spoken, Backtalk runs the command with `via: 'voice'`, `event.command`, and `event.remainder`. +* **Dynamic voice API**: Use `backtalk.onVoiceCommand(pattern, callback)` to register exact phrases, fuzzy phrases, or wildcard capture patterns (such as `'search for *'`). + ## Screen and brightness ### Brightness reading control diff --git a/docs/scripting.md b/docs/scripting.md index 655b8b520..09c40f4df 100644 --- a/docs/scripting.md +++ b/docs/scripting.md @@ -248,8 +248,8 @@ A command is something the user runs. Declare it in the manifest, and give it at ```js commands: [ - { id: 'unread', title: 'Next unread', gesture: 'swipeUpThenRight', keys: 'backtalk+u' }, - { id: 'summary', title: 'Read summary', menu: true }, + { id: 'unread', title: 'Next unread', gesture: 'swipeUpThenRight', keys: 'backtalk+u', voice: 'next unread' }, + { id: 'summary', title: 'Read summary', menu: true, voice: ['read summary', 'summarize'] }, { id: 'messages', title: 'Messages', control: true }, ], ``` @@ -258,18 +258,37 @@ commands: [ * `keys` is keys or a list. Keys start with `backtalk`, Backtalk's modifier key, then any of `shift`, `ctrl`, `alt` and `meta`, then a key: `'backtalk+shift+n'`. A second key can follow a comma: `'backtalk+t, s'`. * `menu: true` adds the command to the Backtalk menu. * `control: true` adds it to the reading controls. Swiping up or down with the control selected runs the command with `direction` set to `'previous'` or `'next'`. +* `voice` is a voice phrase or a list of phrases that trigger the command when spoken. -Commands need the `input` permission. The user can turn each gesture and key off on the script's page, or assign others. While a script runs, its gestures and keys come before Backtalk's own, except for the gesture assigned to **Turn all scripts on or off**. +Commands need the `input` permission. The user can turn each gesture, key, and voice trigger off on the script's page, or assign others. While a script runs, its gestures, keys and voice commands come before Backtalk's built-in actions, except for the gesture assigned to **Turn all scripts on or off**. ```js backtalk.onCommand('unread', (event) => { - // event.id, event.via ('gesture', 'keys', 'menu' or 'control'), event.direction, event.node + // event.id, event.via ('gesture', 'keys', 'menu', 'control' or 'voice'), event.direction, event.command, event.remainder, event.node }); ``` -`event.node` is the focused item. Return `false` to have Backtalk do what the gesture or keys normally do. +`event.node` is the focused item. Return `false` to have Backtalk do what the action normally does. -`backtalk.bind(command, { gesture })` or `backtalk.bind(command, { keys })` adds a gesture or keys to a declared command, and `backtalk.unbind` removes one. +`backtalk.bind(command, { gesture })`, `backtalk.bind(command, { keys })` or `backtalk.bind(command, { voice: 'phrase' })` adds a trigger to a declared command, and `backtalk.unbind` removes one. + +#### Custom voice commands + +A script can also register dynamic voice commands directly: + +```js +// Exact or fuzzy phrase match: +backtalk.onVoiceCommand('cheer', (event) => { + backtalk.speak('You are doing great!'); +}); + +// Wildcard capture pattern: +backtalk.onVoiceCommand('search for *', (event) => { + backtalk.speak('Searching for ' + event.remainder); +}); +``` + +`onVoiceCommand` returns a function that unregisters the command. Return text or `{ speak: text }` to speak feedback. ### Navigation diff --git a/lint.xml b/lint.xml index 08b73472d..42dfefba3 100644 --- a/lint.xml +++ b/lint.xml @@ -21,6 +21,7 @@ + diff --git a/talkback/src/main/java/com/google/android/accessibility/talkback/actor/voicecommands/VoiceCommandProcessor.java b/talkback/src/main/java/com/google/android/accessibility/talkback/actor/voicecommands/VoiceCommandProcessor.java index 8e36cd237..a0c9c68e8 100644 --- a/talkback/src/main/java/com/google/android/accessibility/talkback/actor/voicecommands/VoiceCommandProcessor.java +++ b/talkback/src/main/java/com/google/android/accessibility/talkback/actor/voicecommands/VoiceCommandProcessor.java @@ -102,6 +102,7 @@ import com.google.android.accessibility.talkback.TalkBackService; import com.google.android.accessibility.talkback.actor.DimScreenActor; import com.google.android.accessibility.talkback.actor.gemini.GeminiConfiguration; +import com.google.android.accessibility.talkback.scripting.Scripts; import com.google.android.accessibility.talkback.analytics.TalkBackAnalytics; import com.google.android.accessibility.talkback.analytics.TalkBackAnalytics.VoiceCommandTypeId; import com.google.android.accessibility.talkback.contextmenu.ContextMenuItem; @@ -330,6 +331,12 @@ public boolean handleSpeechCommand(String command, boolean isPartialResult) { LogUtils.i(LOG_TAG, "handleSpeechCommand() command=\"%s\"", command); EventId eventId = EVENT_ID_UNTRACKED; + // Check custom script voice commands + if (!isPartialResult && Scripts.onVoiceCommand(command)) { + analytics.onVoiceCommandEvent(VOICE_COMMAND_RECOGNIZED); + return true; + } + // Calls, and the answers to their questions ("say yes to confirm") if (callVoiceCommands.handleCommand( VoiceCommandFuzzyMatcher.normalize(command), isPartialResult)) { diff --git a/talkback/src/main/java/com/google/android/accessibility/talkback/scripting/ScriptHost.kt b/talkback/src/main/java/com/google/android/accessibility/talkback/scripting/ScriptHost.kt index e156adae4..e3953ced7 100644 --- a/talkback/src/main/java/com/google/android/accessibility/talkback/scripting/ScriptHost.kt +++ b/talkback/src/main/java/com/google/android/accessibility/talkback/scripting/ScriptHost.kt @@ -56,6 +56,8 @@ interface ScriptHost { fallback: Runnable, ): Boolean + fun onVoiceCommand(command: String): Boolean + fun menuItems(): List fun readingControls(): List @@ -246,6 +248,9 @@ object Scripts { @JvmStatic fun readingControls(): List = host?.readingControls().orEmpty() + @JvmStatic + fun onVoiceCommand(command: String): Boolean = host?.onVoiceCommand(command) == true + @JvmStatic fun itemActions(node: AccessibilityNodeInfoCompat): List = host?.itemActions(node).orEmpty() diff --git a/talkback/src/main/java/com/google/android/accessibility/talkback/scripting/ScriptInput.kt b/talkback/src/main/java/com/google/android/accessibility/talkback/scripting/ScriptInput.kt index 5197c49f9..0e1de007d 100644 --- a/talkback/src/main/java/com/google/android/accessibility/talkback/scripting/ScriptInput.kt +++ b/talkback/src/main/java/com/google/android/accessibility/talkback/scripting/ScriptInput.kt @@ -147,11 +147,14 @@ object ScriptInput { const val GESTURE_BINDING = "gesture/" const val KEYS_BINDING = "keys/" + const val VOICE_BINDING = "voice/" fun gestureBinding(name: String): String = GESTURE_BINDING + name fun keysBinding(keys: Keys): String = KEYS_BINDING + keys.id + fun voiceBinding(phrase: String): String = VOICE_BINDING + phrase.trim().lowercase() + val gestureNames: List = (gestures.keys + fingerprintGestures.keys).toList() fun isGesture(name: String): Boolean = name in gestures || name in fingerprintGestures diff --git a/talkback/src/main/res/values/strings_voicecommands.xml b/talkback/src/main/res/values/strings_voicecommands.xml index b6b907c9a..d61ac128e 100644 --- a/talkback/src/main/res/values/strings_voicecommands.xml +++ b/talkback/src/main/res/values/strings_voicecommands.xml @@ -437,4 +437,6 @@ Found %1$s Could not find %1$s on screen + + Voice: "%1$s" diff --git a/talkback/src/phone/assets/scripting/prelude.js b/talkback/src/phone/assets/scripting/prelude.js index 4f99c3ecd..81a9f8e1f 100644 --- a/talkback/src/phone/assets/scripting/prelude.js +++ b/talkback/src/phone/assets/scripting/prelude.js @@ -151,10 +151,12 @@ ].map((name) => [name, []]), ); const commands = new Map(); + const voiceCommands = new Map(); const syncHooks = () => send('hooks', { names: Object.keys(handlers).filter((name) => handlers[name].length > 0), commands: [...commands.keys()], + voicePatterns: [...voiceCommands.keys()], }); const subscribe = (add, remove) => { add(); @@ -183,6 +185,31 @@ () => commands.get(id) === fn && commands.delete(id), ); }; + const onVoiceCommand = (pattern, fn) => { + if (typeof fn !== 'function') throw new TypeError('onVoiceCommand needs a function'); + const patterns = Array.isArray(pattern) ? pattern : [pattern]; + for (const p of patterns) { + if (typeof p !== 'string' || !p.trim()) { + throw new TypeError('onVoiceCommand pattern must be a non-empty string or array of strings'); + } + } + const clean = patterns.map((p) => p.trim()); + return subscribe( + () => { + for (const p of clean) voiceCommands.set(p.toLowerCase(), fn); + }, + () => { + let changed = false; + for (const p of clean) { + if (voiceCommands.get(p.toLowerCase()) === fn) { + voiceCommands.delete(p.toLowerCase()); + changed = true; + } + } + return changed; + }, + ); + }; const notify = (name, ...args) => { for (const fn of handlers[name]) guard(name, fn, ...args); @@ -207,18 +234,36 @@ return text === input ? undefined : { text }; }; - const runCommand = ({ id, via, direction, node: snapshot }) => { + const runCommand = ({ id, via, direction, node: snapshot, command, remainder }) => { const fn = commands.get(id); if (!fn) return { fallback: true }; const event = Object.freeze({ id, via, direction: direction ?? undefined, + command: command ?? undefined, + remainder: remainder ?? undefined, node: node(snapshot), }); return guard(`command ${id}`, fn, event) === false ? { fallback: true } : undefined; }; + const runVoiceCommand = ({ command, pattern, remainder, node: snapshot }) => { + const fn = voiceCommands.get(pattern?.toLowerCase()); + if (!fn) return { fallback: true }; + const event = Object.freeze({ + command, + pattern, + remainder: remainder ?? undefined, + node: node(snapshot), + }); + const result = guard(`voice ${pattern}`, fn, event); + if (result === false || result?.fallback) return { fallback: true }; + if (typeof result === 'string') return { speak: result }; + if (typeof result?.speak === 'string') return { speak: result.speak }; + return { handled: true }; + }; + const offers = new Map(); let nextOffer = 1; const offerActions = ({ node: snapshot }) => { @@ -285,6 +330,7 @@ settingChange: (data) => notify('settingChange', data.key, data.value), button: (data) => notify('button', data.key), command: runCommand, + voiceCommand: runVoiceCommand, actions: offerActions, dialogEvent: (data) => formEvent(data), runAction, @@ -551,8 +597,8 @@ alert: (message, { title } = {}) => dialog('ui.alert', { message: String(message), title: text(title) }).then(() => undefined), }); - const binding = (method) => (command, { gesture, keys } = {}) => - send(method, { command: String(command), gesture, keys }); + const binding = (method) => (command, { gesture, keys, voice } = {}) => + send(method, { command: String(command), gesture, keys, voice }); const backtalk = Object.freeze({ apiVersion: call('apiVersion'), @@ -565,6 +611,7 @@ }, ...Object.fromEntries(Object.keys(handlers).map((name) => [handlerName(name), listen(name)])), onCommand, + onVoiceCommand, get locale() { return call('locale'); }, diff --git a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/LazyScriptHost.kt b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/LazyScriptHost.kt index 098bbb8b2..bc8596f26 100644 --- a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/LazyScriptHost.kt +++ b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/LazyScriptHost.kt @@ -161,6 +161,8 @@ class LazyScriptHost( fallback: Runnable, ): Boolean = manager?.onKeys(modifiers, keyCode, withBacktalkModifier, fallback) == true + override fun onVoiceCommand(command: String): Boolean = manager?.onVoiceCommand(command) == true + override fun menuItems(): List = manager?.menuItems().orEmpty() override fun readingControls(): List = diff --git a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ManifestParser.kt b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ManifestParser.kt index 995753eda..efa354892 100644 --- a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ManifestParser.kt +++ b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ManifestParser.kt @@ -284,6 +284,7 @@ class ManifestParser(private val strict: Boolean) { gestures .firstOrNull { !ScriptInput.isGesture(it) } ?.let { manifestError("Unknown gesture $it. docs/scripting.md lists the gestures.") } + val voice = command.stringList("voice").distinct() ScriptCommand( id = id, title = command.requiredString("title"), @@ -294,10 +295,11 @@ class ManifestParser(private val strict: Boolean) { }, menu = command.optBoolean("menu", false), control = command.optBoolean("control", false), + voice = voice, ) .also { manifestCheck(it.bindings.isNotEmpty()) { - "The command $id needs gesture, keys, menu or control" + "The command $id needs gesture, keys, menu or control, or voice" } } } diff --git a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptBindings.kt b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptBindings.kt index c0d4d1f25..ab2b60b96 100644 --- a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptBindings.kt +++ b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptBindings.kt @@ -27,18 +27,20 @@ private constructor( val menu: List, val controls: List, val navigation: List, + val voice: Map, ) { val layers: Set = keys.keys.filter { it.next != null }.mapTo(HashSet()) { it.first } companion object { - val EMPTY = ScriptBindings(emptyMap(), emptyMap(), emptyList(), emptyList(), emptyList()) + val EMPTY = ScriptBindings(emptyMap(), emptyMap(), emptyList(), emptyList(), emptyList(), emptyMap()) fun of(runtimes: List, store: ScriptStore): ScriptBindings { val gestures = HashMap() val keys = HashMap() val menu = mutableListOf() val controls = mutableListOf() + val voice = HashMap() for (runtime in runtimes) { val commands = runtime.script.manifest.commands.filter { it.id in runtime.commands } if (commands.isEmpty() || !runtime.allowed(ScriptPermission.INPUT, "Commands")) continue @@ -49,6 +51,7 @@ private constructor( when (binding) { is CommandBinding.Gesture -> gestures.putIfAbsent(binding.name, bound) is CommandBinding.KeyCombo -> keys.putIfAbsent(binding.keys, bound) + is CommandBinding.Voice -> voice.putIfAbsent(binding.phrase.trim().lowercase(), bound) CommandBinding.MenuItem -> menu += bound CommandBinding.ReadingControl -> controls += bound } @@ -66,7 +69,7 @@ private constructor( BoundNavigation(runtime, index, item) } } - return ScriptBindings(gestures, keys, menu, controls, navigation) + return ScriptBindings(gestures, keys, menu, controls, navigation, voice) } } } diff --git a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptManager.kt b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptManager.kt index c3fb4ed23..3245095bc 100644 --- a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptManager.kt +++ b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptManager.kt @@ -27,6 +27,7 @@ import androidx.core.view.accessibility.AccessibilityNodeInfoCompat import com.google.android.accessibility.scripting.quickjs.QuickJsException import com.google.android.accessibility.talkback.R import com.google.android.accessibility.talkback.focusmanagement.TraversalTreeCache +import com.google.android.accessibility.talkback.actor.voicecommands.VoiceCommandFuzzyMatcher import java.util.concurrent.CountDownLatch import org.json.JSONObject @@ -163,6 +164,65 @@ class ScriptManager( feedback.paused = paused } + override fun onVoiceCommand(command: String): Boolean { + if (activation.inBacktalk) return false + val norm = VoiceCommandFuzzyMatcher.normalize(command) + if (norm.isBlank()) return false + + // 1. Check manifest voice bindings + for ((phrase, bound) in bindings.voice) { + if (norm.equals(phrase, ignoreCase = true) || VoiceCommandFuzzyMatcher.matchesPhrase(norm, phrase)) { + runCommand(bound, "voice", command = command) + return true + } + } + + // 2. Check dynamic voice commands in loaded runtimes + for (runtime in loaded.values) { + if (!runtime.isLoaded || !runtime.allowed(ScriptPermission.INPUT, "Voice")) continue + for (pattern in runtime.voicePatterns) { + val normPattern = pattern.trim().lowercase() + var matched = false + var remainder: String? = null + + if (normPattern.contains('*')) { + val prefix = normPattern.substringBefore('*').trim() + val suffix = normPattern.substringAfter('*').trim() + if (norm.startsWith(prefix) && (suffix.isEmpty() || norm.endsWith(suffix))) { + matched = true + remainder = norm.removePrefix(prefix).removeSuffix(suffix).trim() + } + } else if (norm == normPattern || VoiceCommandFuzzyMatcher.matchesPhrase(norm, normPattern)) { + matched = true + } + + if (matched) { + onScriptThread { + if (runtime.isLoaded) { + val copy = focusedNode()?.let { AccessibilityNodeInfoCompat.obtain(it) } + val data = jsonObject( + "command" to command, + "pattern" to pattern, + "remainder" to remainder, + "node" to runtime.snapshotIfAllowed(copy), + ) + val result = runtime.dispatch("voiceCommand", data) + result?.let { + val toSpeak = runCatching { JSONObject(it).optString("speak") }.getOrNull() + if (!toSpeak.isNullOrEmpty()) { + feedback.speak(toSpeak, interrupt = false) + } + } + } + } + return true + } + } + } + + return false + } + override fun onGesture(name: String, fallback: Runnable): Boolean = !activation.inBacktalk && bindings.gestures[name]?.also { runCommand(it, "gesture", fallback = fallback) } != null @@ -407,6 +467,8 @@ class ScriptManager( via: String, node: AccessibilityNodeInfoCompat? = null, direction: String? = null, + command: String? = null, + remainder: String? = null, fallback: Runnable? = null, ) { @Suppress("DEPRECATION") val copy = node?.let { AccessibilityNodeInfoCompat.obtain(it) } @@ -419,6 +481,8 @@ class ScriptManager( "id" to bound.command.id, "via" to via, "direction" to direction, + "command" to command, + "remainder" to remainder, "node" to runtime.snapshotIfAllowed(copy ?: focusedNode()), ) runtime.dispatch("command", data) diff --git a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptManifest.kt b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptManifest.kt index 3721f01b5..7eaf2666b 100644 --- a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptManifest.kt +++ b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptManifest.kt @@ -171,6 +171,8 @@ sealed class CommandBinding(val key: String) { data object ReadingControl : CommandBinding("control") + class Voice(val phrase: String) : CommandBinding(ScriptInput.voiceBinding(phrase)) + companion object { fun fromKey(key: String): CommandBinding? = when { @@ -183,6 +185,8 @@ sealed class CommandBinding(val key: String) { ?.let(::Gesture) key.startsWith(ScriptInput.KEYS_BINDING) -> ScriptInput.keysFromId(key.removePrefix(ScriptInput.KEYS_BINDING))?.let(::KeyCombo) + key.startsWith(ScriptInput.VOICE_BINDING) -> + CommandBinding.Voice(key.removePrefix(ScriptInput.VOICE_BINDING)) else -> null } } @@ -195,6 +199,7 @@ data class ScriptCommand( val keys: List, val menu: Boolean, val control: Boolean, + val voice: List = emptyList(), ) { fun isDefault(binding: CommandBinding): Boolean = bindings.any { it.key == binding.key } @@ -202,6 +207,7 @@ data class ScriptCommand( get() = gestures.map { CommandBinding.Gesture(it) } + keys.map { CommandBinding.KeyCombo(it) } + + voice.map { CommandBinding.Voice(it) } + listOfNotNull( CommandBinding.MenuItem.takeIf { menu }, CommandBinding.ReadingControl.takeIf { control }, diff --git a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptRuntime.kt b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptRuntime.kt index 5cc9126fb..64e691fea 100644 --- a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptRuntime.kt +++ b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptRuntime.kt @@ -57,6 +57,9 @@ class ScriptRuntime( var commands: Set = emptySet() private set + var voicePatterns: Set = emptySet() + private set + private val addedRules = LinkedHashMap() private var nextRule = 1 @@ -186,6 +189,7 @@ class ScriptRuntime( on("hooks") { hooks = it.optJSONArray("names").strings().toSet() commands = it.optJSONArray("commands").strings().toSet() + voicePatterns = it.optJSONArray("voicePatterns").strings().toSet() manager.onHooksChanged() } on("manifest") { JSONObject(script.manifest.json) } @@ -417,12 +421,14 @@ class ScriptRuntime( ?: apiError("The manifest declares no command $commandId") val gesture = args.optString("gesture") val keys = args.optString("keys") + val voice = args.optString("voice") val binding = when { ScriptInput.isGesture(gesture) -> CommandBinding.Gesture(gesture) gesture.isNotEmpty() -> apiError("Unknown gesture $gesture") keys.isNotEmpty() -> CommandBinding.KeyCombo(asApiError { ScriptInput.parseKeys(keys) }) - else -> apiError("A binding needs gesture or keys") + voice.isNotEmpty() -> CommandBinding.Voice(voice) + else -> apiError("A binding needs gesture, keys or voice") } return command to binding } diff --git a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptTexts.kt b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptTexts.kt index 10808020e..cc89feaa8 100644 --- a/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptTexts.kt +++ b/talkback/src/phone/java/com/google/android/accessibility/talkback/scripting/ScriptTexts.kt @@ -61,6 +61,8 @@ fun Context.bindingText(binding: CommandBinding): String = getString(R.string.script_binding_gesture, ScriptInput.gestureTitle(this, binding.name)) is CommandBinding.KeyCombo -> getString(R.string.script_binding_keys, ScriptInput.keysTitle(this, binding.keys)) + is CommandBinding.Voice -> + getString(R.string.script_binding_voice, binding.phrase) CommandBinding.MenuItem -> getString(R.string.script_binding_menu) CommandBinding.ReadingControl -> getString(R.string.script_binding_control) } diff --git a/talkback/src/testPhone/java/com/google/android/accessibility/talkback/scripting/ManifestParserTest.kt b/talkback/src/testPhone/java/com/google/android/accessibility/talkback/scripting/ManifestParserTest.kt index 95739303f..656b48c8d 100644 --- a/talkback/src/testPhone/java/com/google/android/accessibility/talkback/scripting/ManifestParserTest.kt +++ b/talkback/src/testPhone/java/com/google/android/accessibility/talkback/scripting/ManifestParserTest.kt @@ -327,6 +327,14 @@ class ManifestParserTest { ) } + @Test + fun aCommandAcceptsVoice() { + val manifest = + parse(""","permissions":["input"],"commands":[{"id":"go","title":"Go","voice":["start go","go"]}]""") + assertEquals(listOf("start go", "go"), manifest.commands[0].voice) + assertTrue(manifest.commands[0].bindings.any { it is CommandBinding.Voice && it.phrase == "start go" }) + } + @Test fun aCommandsGestureAndKeysAreChecked() { val permission = """"permissions":["input"]"""