Repository navigation
fix: refuse Android taps on a covered target (TARGET_OBSCURED) - #61
Merged
cryptotavares merged 7 commits intoNov 18, 2026
Conversation
Android taps had no occlusion check: a tap on a target covered by the Expo dev-client "Tools" button, a floating tab bar or the keyboard reported success and hit the overlay. Before each tap and long press, check the snapshot the target came from (no device call): a drawn node of a higher window (the keyboard, a system window) at the tap point, or a node of the same window drawn after the target (by the helper's drawing-order) that is not part of the target per `hitsTarget`, throws `TargetObscuredError`. A node of the input-method window sets `keyboard: true`, so `click --dismiss-keyboard` can retry. Stock uiautomator dumps have no window or draw-order data, so their taps go ahead as before.
…otavares/mmcli-p1-50-android-occlusion
Return early when the target's window root has no window metadata: a stock uiautomator dump from android15-qpr2 on has drawing-order but no window-* or visible-to-user. Count a wrapper as drawn only when it is small or at most twice the area of its drawn content, so a box-none host around a floating button is transparent. Do not count large non-clickable, unlabelled leaves (at least half the window or full width) as opaque. Keep accepting a later-drawn sibling inside the target as a documented trade-off. Document the fail-open cases (copied element, maxNodes cut) and name the keyboard by its class only.
…pe-keyboard' into cryptotavares/mmcli-p1-50-android-occlusion
While the snapshot has an input-method window above the target, read the keyboard's touchable region (dumpsys window InputMethod, visible IME windows only) at tap time and refuse a point inside it as the keyboard. The accessibility tree can miss Gboard's floating suggestion key, and the IME window bounds lag behind it and are far larger than the keys with a hardware keyboard, so neither can stand in for it. No extra device call without a keyboard window; a failed read falls back to the snapshot.
- AdbBackend#assertHittable: compute the keyboard dump in one expression instead of a mutable local assigned inside an `if`. - assertAndroidHittable: carry each higher window's metadata with its root, which drops the unchecked `as AndroidWindowInfo` cast and the repeated `nodeInfo` lookup while sorting. - drawsAt: one guard for the node's visibility, area and full width. No behaviour change.
…pe-keyboard' into cryptotavares/mmcli-p1-50-android-occlusion
pnarayanaswamy
approved these changes
Nov 18, 2026
cryptotavares
deleted the
cryptotavares/mmcli-p1-50-android-occlusion
branch
November 18, 2026 15:53
cryptotavares
added a commit
that referenced
this pull request
Nov 18, 2026
Fixes #57. Fixes #58. Part of the mm CLI v2 effort (ticket `P1-49`). Bottom of stack #62 (#61 is on top). Ships in device-mcp 0.9.0. > **Summary:** On Android, `typeText("")` now clears the field, and a retype replaces the old text. `dismissKeyboard` now checks that the keyboard closed, and fails if it is still shown. ## Problem There are three bugs in the adb backend: 1. `typeText("")` runs `adb shell input text` with no argument. The device throws `Argument expected after "text"`, so `mm type <field> ""` fails with exit 4. 2. The clear step selects nothing in a React Native field on API 36, so `DEL` removes one character. A retype appends. 3. `dismissKeyboard` sends one `KEYCODE_ESCAPE` and returns. It reports success while the keyboard is still shown. The next tap can then hit a key. ```text # 0.8.0, account search field type "zzq", then type "abc" → field shows "zzabc" type "" → MM_TYPE_FAILED … Argument expected after "text" dismiss-keyboard → {"dismissed":true}, but mInputShown=true ``` ## Solution 1. **Clear:** after the old select step, send `input keycombination KEYCODE_CTRL_LEFT KEYCODE_A`, then `DEL`. `keycombination` exists only on newer Android, so the call is best effort. 2. **Empty text:** return after the clear step. 3. **Verified dismiss:** read only the `mInputShown` line of `dumpsys input_method`, not the full dump (about 1 MB). ```mermaid flowchart TD A[dismissKeyboard] --> B{"mInputShown?"} B -->|false| R[Return. No key sent.] B -->|unknown| E0[Send ESCAPE. Return, as in 0.8.0.] B -->|true| E[Send ESCAPE] E --> W{"hidden within 2 s?"} W -->|yes| OK[Return] W -->|no| C{"read again: still shown?"} C -->|no| OK C -->|yes| K[Send BACK] K --> W2{"hidden within 2 s?"} W2 -->|yes| OK W2 -->|no| X[Throw. The caller gets a failure, not dismissed: true.] classDef new fill:#fff3cd,stroke:#d39e00 classDef stop fill:#f8d7da,stroke:#c82333 class B,W,C,K,W2 new class X stop ``` Yellow boxes are new. Red boxes stop the call. ## What changes | Call | 0.8.0 | This PR | |---|---|---| | `typeText("")` | Throws `Argument expected after "text"` | Clears the field | | `typeText("abc")` over `zzq` | Field shows `zzabc` | Field shows `abc` | | `dismissKeyboard()`, keyboard shown, ESCAPE hides it | Returns | Returns after the keyboard hides | | `dismissKeyboard()`, ESCAPE does not hide it | Returns, keyboard still shown | Sends BACK, returns after the keyboard hides | | `dismissKeyboard()`, still shown after BACK | Returns | Throws `Keyboard still shown after ESCAPE and BACK. …` | | `dismissKeyboard()`, no keyboard | Sends ESCAPE | Sends nothing | | `dismissKeyboard()`, `mInputShown` missing | Sends ESCAPE | Same, no check | Core maps the new throw to `MM_DEVICE_ACTION_FAILED`. ## Decisions for reviewers | Decision | Reason | |---|---| | BACK after ESCAPE fails | ESCAPE is not a documented "hide keyboard" key, and it sometimes does nothing. While the keyboard is shown, BACK only hides it. | | Wait 2 s after ESCAPE, then read again right before BACK | If the keyboard hides in the gap between the last read and BACK, BACK reaches the app and can navigate. The long wait and the fresh read make that gap one adb round trip. The remaining risk is in the doc comment. The cost is about 2 s when ESCAPE does nothing. | | An unreadable state sends ESCAPE only, unverified | A blind BACK could navigate. This keeps 0.8.0 behaviour on devices without `mInputShown`. | | Ctrl+A is best effort (`exec`, result ignored) | Older Android has no `input keycombination`. There the clear is the same as before. | ## Review guide Read the files in this order: | # | File | What to check | |---|---|---| | 1 | `src/backends/adb-backend.ts` | `typeText`: the Ctrl+A step and the empty-text return. `dismissKeyboard`, `#isKeyboardShown`, `#waitForKeyboardHidden`. | | 2 | `src/tools/type-text.ts`, `src/tools/dismiss-keyboard.ts` | Tool descriptions for the new Android behaviour | | 3 | `src/backends/adb-backend.test.ts` | Exact adb call sequences, the BACK path, the unreadable state, the throw | <details> <summary>Testing</summary> - `yarn build`, `yarn lint` and `yarn test` pass (35 files, 830 tests, 6 skipped). Coverage thresholds are unchanged. - Live: Android emulator (API 36, Gboard), MetaMask Mobile dev build, `mm` from core 0.14.0, account search field. Before = npm 0.8.0, after = a yalc build of this branch. | Check | 0.8.0 | This branch | |---|---|---| | `mm type <search field> ""` after `zzq` | exit 4 `MM_TYPE_FAILED` | exit 0, `textLength: 0`, placeholder shown (6 of 6) | | `dismiss-keyboard`, keyboard shown | `dismissed: true`, keyboard still shown | 10 of 10 hidden, then 5 of 5 after the BACK change | | `dismiss-keyboard` time, keyboard shown | 27–69 ms, unverified | p50 316 ms when ESCAPE hides it, about 2.4 s when BACK does | | `dismiss-keyboard`, no keyboard | sends ESCAPE | p50 24 ms, no key | In the 5 BACK-path tries, the account sheet stayed open, so BACK did not reach the app. </details> <details> <summary>Known gap (follow-up)</summary> A retype over existing text kept one stray character in 3 of 9 tries (`abc` → `c`). The cause is probably a race between the focusing tap and the clear. Clearing to empty passed 6 of 6, and every retype is better than 0.8.0. A follow-up can add a settle step or a read-back. </details>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the mm CLI v2 effort (ticket
P1-50). Stacked on #60. Ships in device-mcp 0.9.0.Problem
AdbBackend.tapElementchecks only that the target is inside the viewport, then taps its center. On the MetaMask Mobile dev build, the Expo "Tools" button coversnavbar-hamburger-menu-button. A click on the hamburger opens the Expo dev menu and returnsclicked: true. With the keyboard up, a tap on a covered target can hit a key. iOS has had this check since #51. Android has not.Solution
Before each tap and long press,
assertAndroidHittablechecks the tap point against the snapshot the target came from. The snapshot helper already records window type and layer,drawing-orderandvisible-to-user, so no Java change is needed. Three checks run in order:dumpsys window InputMethodread gives the keyboard's live touchable region.drawing-orderwhere the branches split) that draws at the point.hitsTarget, the iOS rule, decides whether it is part of the target.flowchart TD A[tapElement / longPress] --> B[viewport check] B --> C{"window data in the snapshot?"} C -->|no: stock uiautomator dump| T[tap, as in 0.8.0] C -->|yes| D{"drawn node of a higher window at the point?"} D -->|yes| X[TARGET_OBSCURED] D -->|no| E{"keyboard window above the target?"} E -->|yes| F["read the keyboard touchable region"] F --> G{"point inside it?"} G -->|yes| X G -->|no| H E -->|no| H{"later-drawn node in the same window draws at the point, and is not part of the target?"} H -->|yes| X H -->|no| T X --> N[No tap. Error names the cover. Keyboard sets keyboard: true.] classDef new fill:#fff3cd,stroke:#d39e00 classDef stop fill:#f8d7da,stroke:#c82333 class C,D,E,F,G,H new class X,N stopYellow boxes are new. Red boxes stop the tap.
What changes
TARGET_OBSCURED: … by <type> around <named node>. …… by the keyboard: <class>. … Dismiss the keyboard (device_dismiss_keyboard) and retry.withkeyboard: true… by the keyboard: touchable area [l,t][r,b]. …withkeyboard: trueCore 0.14.0 already maps
TARGET_OBSCUREDtoMM_TARGET_OBSCURED(exit 4). Withkeyboard: true,click --dismiss-keyboarddismisses the keyboard and retries once.Decisions for reviewers
box-nonehosts and full-width rows through.pointerEventshosts.uiautomator dumphas nowindow-*orvisible-to-user. From android15-qpr2 it hasdrawing-order, so it must not reach the same-window check.TargetObscuredErrorgets an optional 4th argumentReview guide
Read the files in this order:
src/utils/android-hit-test.tsassertAndroidHittable: the three checks. ThendrawsItself,drawsAtanddrawnAfter.src/backends/adb-backend.ts#assertHittablebeforetapCoordinatesintapElementandlongPress.parseHitTestAttributesinparseAndroidHierarchy.src/utils/hit-test.tsoptionsargument ofTargetObscuredError.*.test.tsand__fixtures__/dumpsys window InputMethodoutput, keyboard shown and hidden.Testing
yarn build,yarn lintandyarn testpass (36 files, 885 tests, 6 skipped). Coverage thresholds are unchanged.hit-test.test.tsandidb-backend.test.tsare unchanged.mmfrom core 0.14.0. Before = npm 0.8.0, after = a yalc build of this branch.clickon the hamburger under the Tools buttonclicked: true, Expo dev menu opensMM_TARGET_OBSCURED, still on wallet homekeyboard: trueclickp50 (wall / tool ms), 12 runsaccount-list-manage-accounts-buttonunder Tools, and token rows under the floating tab bar.Known gaps
maxNodescan miss the nodes drawn last. An overlay there is not seen, so the tap goes ahead. This is a false accept, never a false refusal.options.elementhas no recorded node data, so the check is skipped.