From b0851b5d475950f7885f09d27556f57fb3988543 Mon Sep 17 00:00:00 2001 From: Dennis V <2119348+dzianisv@users.noreply.github.com> Date: Mon, 22 Jun 2026 22:17:12 +0000 Subject: [PATCH] Fix type action: use file-based input text with shell command substitution ADB input text with %s escaping didn't trigger React Native onChangeText. New approach: write text to /sdcard/ file on device, then use shell command-substitution "$(cat ...)" to pass raw text to input text. This preserves spaces without %s conversion and avoids quote-escaping issues that prevented React Native from detecting text changes. --- scripts/android-cua-smoke.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts/android-cua-smoke.py b/scripts/android-cua-smoke.py index f71452c..1de0a65 100755 --- a/scripts/android-cua-smoke.py +++ b/scripts/android-cua-smoke.py @@ -356,11 +356,27 @@ def execute_action(action: dict) -> str: elif act == "type": text = action.get("text", "") - # Escape for Android's input text: %s = space - escaped = text.replace(" ", "%s") - # Wrap in shell single quotes to protect against metacharacters - # (single quotes inside the text would break this, but we avoid those in prompts) - adb("shell", "input", "text", f"'{escaped}'") + # Write text to device file, then use `input text` with shell + # command-substitution quoting to avoid %s and quote issues. + # This ensures spaces and special chars are passed correctly + # to the `input` command while triggering React Native's onChangeText. + import tempfile, os as _os + _tmp = tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) + _tmp.write(text) + _tmp_path = _tmp.name + _tmp.close() + try: + subprocess.run(["adb", "push", _tmp_path, "/sdcard/_cua_type.txt"], + capture_output=True, timeout=10) + # Pass text via shell command substitution with double quotes + subprocess.run( + ["adb", "shell", + f"input text \"$(cat /sdcard/_cua_type.txt)\""], + capture_output=True, timeout=30, + ) + _sleep(0.3) + finally: + _os.unlink(_tmp_path) return f"typed '{text}'" elif act == "key":