Repository navigation
fix: adb empty typeText clears the field; verify dismissKeyboard - #60
Merged
Merged
Conversation
`typeText("")` cleared the field, then ran `adb shell input text` with no
argument, which throws `Argument expected after "text"` on the device.
Return after the clear step when the text is empty.
`dismissKeyboard` sent one KEYCODE_ESCAPE and returned, so it reported success while the keyboard could stay up. Now it reads `mInputShown` from `dumpsys input_method` first and sends no key when the keyboard is hidden. Otherwise it sends ESCAPE and polls for up to 1 s, then sends BACK once (while the keyboard is shown, BACK only hides it), and throws when the keyboard is still shown.
On API 36 the Shift + MOVE_END selection selects nothing in a React Native text field, so the clear deleted one character: typing "abc" over "zzq" gave "zzabc", and an empty typeText left "zz". Also send Ctrl+A (`input keycombination`) before DEL. `keycombination` only exists on newer Android, so a failure there is ignored.
…oard Read the keyboard state with 'dumpsys input_method | grep -m1 mInputShown' instead of the ~1 MB dump, poll up to 2 s after ESCAPE, and re-read the state right before BACK so BACK is sent only while the keyboard is still shown. Document the remaining race and the unreadable-state path (ESCAPE only, as in 0.8.0). Assert that Ctrl+A is sent before DEL.
`expect(...).toBeDefined()` on the two call-order values only narrowed types that are already `number`, and the existing helper-trust test in this file asserts order the same way without them. The test still fails if either call is missing, through `toBeLessThan`.
cryptotavares
marked this pull request as ready for review
November 17, 2026 14:31
pnarayanaswamy
approved these changes
Nov 18, 2026
cryptotavares
deleted the
cryptotavares/mmcli-p1-49-adb-type-keyboard
branch
November 18, 2026 15:53
cryptotavares
added a commit
that referenced
this pull request
Nov 18, 2026
Part of the mm CLI v2 effort (ticket `P1-50`). Stacked on #60. Ships in device-mcp 0.9.0. > **Summary:** An Android tap on a target that something else covers now fails with `TARGET_OBSCURED`, and nothing is tapped. Before, the tap hit the overlay or the keyboard and the call reported success. ## Problem `AdbBackend.tapElement` checks only that the target is inside the viewport, then taps its center. On the MetaMask Mobile dev build, the Expo "Tools" button covers `navbar-hamburger-menu-button`. A click on the hamburger opens the Expo dev menu and returns `clicked: 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. ```text # 0.8.0 $ mm click --testid navbar-hamburger-menu-button {"clicked":true,"target":"testId:navbar-hamburger-menu-button"} # the Expo dev menu opens ``` ## Solution Before each tap and long press, `assertAndroidHittable` checks the tap point against the snapshot the target came from. The snapshot helper already records window type and layer, `drawing-order` and `visible-to-user`, so no Java change is needed. Three checks run in order: 1. **Higher window:** a drawn node of a window above the target's window (the keyboard, a system window). 2. **Keyboard area:** while the snapshot has a keyboard window, one `dumpsys window InputMethod` read gives the keyboard's live touchable region. 3. **Same window:** a node drawn after the target (higher `drawing-order` where the branches split) that draws at the point. `hitsTarget`, the iOS rule, decides whether it is part of the target. ```mermaid 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 stop ``` Yellow boxes are new. Red boxes stop the tap. ## What changes ```text TARGET_OBSCURED: android.view.ViewGroup id="navbar-hamburger-menu-button" is covered at (973, 137) by android.view.View around android.widget.ImageView label="Tools". Nothing was tapped. Close the overlay, or scroll the target into a free area. ``` | Condition | Result | |---|---| | Target is free | Tap, as before | | Overlay drawn later in the app window (Expo Tools button) | `TARGET_OBSCURED: … by <type> around <named node>. …` | | A keyboard node at the point | `… by the keyboard: <class>. … Dismiss the keyboard (device_dismiss_keyboard) and retry.` with `keyboard: true` | | Point in the keyboard's touchable region, key missing from the snapshot | `… by the keyboard: touchable area [l,t][r,b]. …` with `keyboard: true` | | Snapshot without window data, or an element that is not from a parsed snapshot | No check. Tap, as in 0.8.0 | Core 0.14.0 already maps `TARGET_OBSCURED` to `MM_TARGET_OBSCURED` (exit 4). With `keyboard: true`, `click --dismiss-keyboard` dismisses the keyboard and retries once. ## Decisions for reviewers | Decision | Reason | |---|---| | Read the keyboard's live touchable region (one adb call, about 22 ms) | Gboard's floating suggestion key is sometimes missing from the snapshot. The keyboard window's bounds lag behind it. Window bounds, or the drawn keys widened to full width, either miss that key or refuse free targets on the upper screen. The read runs only when the snapshot has a keyboard window. A failed read falls back to the snapshot rules. | | A later-drawn node inside the target's frame is accepted | React Native draws a control's own content (an input over its container, an icon over its background) as later-drawn siblings. A small sibling overlay inside the target is therefore a false accept. iOS behaviour is unchanged. | | A wrapper counts as drawn only when it is small or close around its drawn nodes | Each side at most 20% of the window's shorter side, or its area at most 2× the drawn area. This catches the Tools button's background and lets `box-none` hosts and full-width rows through. | | A large unlabelled, non-clickable leaf is transparent | At least 50% of the window area, or full width. These are React Native absolute-fill and `pointerEvents` hosts. | | Fail open without window data | A stock `uiautomator dump` has no `window-*` or `visible-to-user`. From android15-qpr2 it has `drawing-order`, so it must not reach the same-window check. | | `TargetObscuredError` gets an optional 4th argument | Android names the cover differently and knows the keyboard from the window type. iOS calls it with three arguments and is unchanged. | ## Review guide Read the files in this order: | # | File | What to check | |---|---|---| | 1 | `src/utils/android-hit-test.ts` | `assertAndroidHittable`: the three checks. Then `drawsItself`, `drawsAt` and `drawnAfter`. | | 2 | `src/backends/adb-backend.ts` | `#assertHittable` before `tapCoordinates` in `tapElement` and `longPress`. `parseHitTestAttributes` in `parseAndroidHierarchy`. | | 3 | `src/utils/hit-test.ts` | The optional `options` argument of `TargetObscuredError`. | | 4 | `*.test.ts` and `__fixtures__/` | Recorded helper XML (texts blanked) and `dumpsys window InputMethod` output, keyboard shown and hidden. | <details> <summary>Testing</summary> - `yarn build`, `yarn lint` and `yarn test` pass (36 files, 885 tests, 6 skipped). Coverage thresholds are unchanged. `hit-test.test.ts` and `idb-backend.test.ts` are unchanged. - Live: Android emulator (API 36, Gboard), MetaMask Mobile dev build, `mm` from core 0.14.0. Before = npm 0.8.0, after = a yalc build of this branch. | Check | 0.8.0 | This branch | |---|---|---| | `click` on the hamburger under the Tools button | `clicked: true`, Expo dev menu opens | exit 4 `MM_TARGET_OBSCURED`, still on wallet home | | Tap on a target under the keyboard, 10 tries | not sent (no check) | 10 of 10 refused, `keyboard: true` | | Same, with the suggestion key removed from each snapshot | – | 10 of 10 refused by the touchable region | | Free targets with the keyboard up | – | 4 of 4 tapped | | Read-only clicks: wallet home, account list, Settings, tab bar | – | 14 of 14 tapped, no refusal | | `click` p50 (wall / tool ms), 12 runs | 688 / 522 | 566 / 410 | - An offline replay of 9 recorded screens refuses only targets that are really covered: the hamburger, `account-list-manage-accounts-button` under Tools, and token rows under the floating tab bar. </details> <details> <summary>Known gaps</summary> - A helper tree cut at `maxNodes` can 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. - A copied or JSON-round-tripped `options.element` has no recorded node data, so the check is skipped. </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.
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.Problem
There are three bugs in the adb backend:
typeText("")runsadb shell input textwith no argument. The device throwsArgument expected after "text", somm type <field> ""fails with exit 4.DELremoves one character. A retype appends.dismissKeyboardsends oneKEYCODE_ESCAPEand returns. It reports success while the keyboard is still shown. The next tap can then hit a key.Solution
input keycombination KEYCODE_CTRL_LEFT KEYCODE_A, thenDEL.keycombinationexists only on newer Android, so the call is best effort.mInputShownline ofdumpsys input_method, not the full dump (about 1 MB).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 stopYellow boxes are new. Red boxes stop the call.
What changes
typeText("")Argument expected after "text"typeText("abc")overzzqzzabcabcdismissKeyboard(), keyboard shown, ESCAPE hides itdismissKeyboard(), ESCAPE does not hide itdismissKeyboard(), still shown after BACKKeyboard still shown after ESCAPE and BACK. …dismissKeyboard(), no keyboarddismissKeyboard(),mInputShownmissingCore maps the new throw to
MM_DEVICE_ACTION_FAILED.Decisions for reviewers
mInputShown.exec, result ignored)input keycombination. There the clear is the same as before.Review guide
Read the files in this order:
src/backends/adb-backend.tstypeText: the Ctrl+A step and the empty-text return.dismissKeyboard,#isKeyboardShown,#waitForKeyboardHidden.src/tools/type-text.ts,src/tools/dismiss-keyboard.tssrc/backends/adb-backend.test.tsTesting
yarn build,yarn lintandyarn testpass (35 files, 830 tests, 6 skipped). Coverage thresholds are unchanged.mmfrom core 0.14.0, account search field. Before = npm 0.8.0, after = a yalc build of this branch.mm type <search field> ""afterzzqMM_TYPE_FAILEDtextLength: 0, placeholder shown (6 of 6)dismiss-keyboard, keyboard showndismissed: true, keyboard still showndismiss-keyboardtime, keyboard showndismiss-keyboard, no keyboardIn the 5 BACK-path tries, the account sheet stayed open, so BACK did not reach the app.
Known gap (follow-up)
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.