Skip to content

fix(helper): report denied clipboard writes so text input can fall back - #159

Open
theworker02 wants to merge 1 commit into
google:mainfrom
theworker02:fix/127-clipboard-write-denied
Open

theworker02 wants to merge 1 commit into
google:mainfrom
theworker02:fix/127-clipboard-write-denied

Conversation

@theworker02

Copy link
Copy Markdown

Fixes #127

Problem

GestureController.setClipboard() returned true whenever setPrimaryClip() did not throw. On builds that restrict WRITE_CLIPBOARD to the foreground via AppOps (the reported OPPO PMT110 shows WRITE_CLIPBOARD: foreground), ClipboardService drops the write silently (op=30 result=false). The host then sent KEYCODE_PASTE, reported success, and never reached the ADBKeyboard fallback, so Chinese text was never entered.

Change

  • GestureController.setClipboard() now checks the android:write_clipboard AppOps mode before writing:
    • MODE_ALLOWED / MODE_DEFAULT: write as before.
    • MODE_FOREGROUND: write only if the helper process importance is foreground or foreground-service; otherwise return false.
    • MODE_IGNORED / MODE_ERRORED: return false.
    • If the op name is unknown on a build, it keeps the previous optimistic behaviour.
  • A false result already makes AndroidAdbDriver.input_text() skip the paste and fall through to the ADBKeyboard broadcast and native input text, so no host-side logic change is needed.
  • Added test_android_input_text_falls_back_to_adbkeyboard_when_clipboard_rejected, which pins that a rejected clipboard write never sends KEYCODE_PASTE and delivers the text via ADB_INPUT_B64.

Testing

  • uv run pytest tests/unit/test_drivers.py passes (6 tests).
  • ruff format --check and ruff check pass on the changed test file.
  • I could not build the helper APK or test on a device locally (no Android SDK), so the Java change is compile-unverified. It only uses public APIs available at minSdk 24 (checkOpNoThrow below API 29, unsafeCheckOpNoThrow from API 29, ActivityManager.getMyMemoryState). A device check on a build with WRITE_CLIPBOARD: foreground would be appreciated.
  • The full make test run on Windows shows failures in unrelated agent/CLI tests. tests/unit/agents/flash/test_turn_index_snapshot.py fails the same way on unmodified main (see test(flash): mock VisualStepSummarizer in test_turn_index_snapshot for offline execution #32 / fix(tests): mock VisualStepSummarizer in test_turn_index_snapshot #35).

@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.

Some OEM builds restrict WRITE_CLIPBOARD to the foreground via AppOps and ClipboardService drops the write without throwing. Check the AppOps mode before writing so setClipboard returns false and the host falls back to ADBKeyboard instead of pasting nothing.

Fixes google#127
@theworker02
theworker02 force-pushed the fix/127-clipboard-write-denied branch from 2373b46 to 08ccd79 Compare September 27, 2026 19:30
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.

Chinese text input silently fails when clipboard writes are denied, preventing fallback

1 participant