Skip to content

fix(android): type literal %s correctly in the adb input text fallback - #161

Open
theworker02 wants to merge 1 commit into
google:mainfrom
theworker02:fix/adb-input-text-percent-s
Open

theworker02 wants to merge 1 commit into
google:mainfrom
theworker02:fix/adb-input-text-percent-s

Conversation

@theworker02

Copy link
Copy Markdown

Fixes #160

Problem

Android's input text turns every %s into a space and has no escape for a literal %s. _escape_for_adb_text() encodes spaces as %s but leaves real %s sequences alone, so text such as Hello %s or 50%sale was typed as Hello / 50 ale whenever the native fallback ran. AndroidInputIME.type_text() hits this for all ASCII text, because its fast path always uses input text.

Change

  • Added _adb_input_text_commands(line) in adb_driver.py. It splits the line at each literal %s so that % ends one input text command and s starts the next. Each command is decoded on its own, so the trailing % is typed literally. Lines without %s still produce exactly one command, same as before.
  • AndroidAdbDriver.input_text() Tier 3 and both input text paths in AndroidInputIME.type_text() use the new helper.
  • Removed the duplicate _escape_for_adb_text() from input_ime.py, which now imports the shared helper.

Testing

New tests/unit/test_adb_input_text.py:

  • A small decoder that mirrors how input text decodes its argument (shell backslash escapes, %s → space), used to assert round-trips for Hello %s, 50%sale, a%s%sb, 100% sure, %%s literal, ends with %, and plain text.
  • Exact command output for the plain and split cases.
  • End-to-end checks through AndroidAdbDriver.input_text() (native fallback) and AndroidInputIME.type_text() (ASCII fast path).

uv run pytest tests/unit/test_adb_input_text.py tests/unit/test_drivers.py passes, and ruff format --check, ruff check, and pyright --project pyright-core.json are clean.

@google-cla

google-cla Bot commented Sep 27, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@theworker02
theworker02 force-pushed the fix/adb-input-text-percent-s branch from 907401e to 32b95bf Compare September 27, 2026 19:30
Android's input text replaces every %s with a space and has no escape for it. Split each literal %s across two commands so the % is typed as-is.

Fixes google#160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Literal \%s\ in typed text becomes a space in the adb \input text\ fallback

1 participant