Skip to content

fix: let clear_text see the "Unknown command" answer on Android 7-11 - #40

Merged
Jeomon merged 1 commit into
CursorTouch:masterfrom
aftabkh4n:fix/clear-text-fallback-old-android
Oct 25, 2026
Merged

Jeomon merged 1 commit into
CursorTouch:masterfrom
aftabkh4n:fix/clear-text-fallback-old-android

Conversation

@aftabkh4n

Copy link
Copy Markdown
Contributor

Problem

clear_text tries input keycombination 113 29 (Ctrl+A) and falls back to repeated Delete / Forward Delete when the output contains "Unknown command". The README documents that fallback for devices older than Android 12.

On Android 7-11 the fallback never runs:

  • Before Android 12, input is app_process … com.android.commands.input.Input. For an unknown subcommand it prints Error: Unknown command: keycombination to stderr and returns normally, so it exits 0. On Android 10-11 this goes through BaseCommand.run, which catches the IllegalArgumentException and prints to System.err. Android 9 prints with System.err.println and returns.
  • Since Android 7, adb shell keeps stderr separate from stdout, and core.shell() returns stdout only. It raises only on a non-zero exit.

So output is empty, clear_text assumes Ctrl+A worked, and it presses Delete once. That removes one character. When type is called with clear=True, the new text is typed after the field's old contents.

Change

  • Append 2>&1 to the probe, so the device shell merges stderr into stdout and the "Unknown command" answer is seen.
  • The test_old_devices_fall_back_to_repeated_deletes test double now returns the answer only when the command merges the streams, as a real device does. The old double returned it on stdout unconditionally, which is why the suite didn't catch this.

Testing

  • uv run pytest: 577 passed, 21 skipped. ruff check and ruff format --check are clean.
  • The updated tests fail on main and pass with the fix.
  • End to end through the real subprocess path, with ANDROID_MCP_ADB_PATH pointing at a fake adb that mimics each device (stderr kept separate, exit 0):
Fake device Before After
Android 11 (keycombination unknown) 1 key sent (single Delete) 400 keys sent (the documented fallback)
Android 12+ (keycombination supported) keycombination + Delete keycombination + Delete (unchanged)

I don't have a physical Android 7-11 device, so the device behavior is taken from AOSP source: cmds/input/.../Input.java on android-9.0.0_r1 and android11-release, and core/java/com/android/internal/os/BaseCommand.java.

Before Android 12, `input` has no keycombination command. AOSP's Input
(through BaseCommand on Android 10-11) prints "Error: Unknown command:
keycombination" to stderr and still exits 0. adb shell keeps stderr apart
from stdout, and shell() returns only stdout, so clear_text never saw the
answer: it pressed Delete once, removing one character, and the text that
followed was typed after the field's old contents.

Merge stderr into stdout for the probe so the documented fallback runs.
The test double now answers on stdout only when the command merges the
streams, as a real device does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014TonJ1geSd97oAtSBZofUK
@Jeomon
Jeomon merged commit 35759d8 into CursorTouch:master Oct 25, 2026
@Jeomon

Jeomon commented Oct 25, 2026

Copy link
Copy Markdown
Member

Thanks

Jeomon pushed a commit that referenced this pull request Nov 11, 2026
input draganddrop exists from Android 8.0. On Android 7.x, AOSP's Input
prints "Error: Unknown command: draganddrop" to stderr and returns
normally, so it exits 0. shell() returns stdout only and raises only on a
non-zero exit, so drag() returned as if it had worked: the Drag tool told
the agent "Dragged from ... and dropped on ..." while nothing moved, and
the docstring's "earlier releases fail with an adb error" never happened.

Merge stderr into stdout for the command and raise AdbError on "Unknown
command", which every tool already turns into a message for the agent.
Same cause as the clear_text fix in #40.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014TonJ1geSd97oAtSBZofUK
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.

2 participants