Skip to content

fix(daemon): native unlocking keeps the HID session open until a key tap has landed - #154

Merged
Derrors merged 1 commit into
mainfrom
fix/native-unlock-tap-cancelled
Nov 18, 2026
Merged

Derrors merged 1 commit into
mainfrom
fix/native-unlock-tap-cancelled

Conversation

@Derrors

@Derrors Derrors commented Nov 18, 2026

Copy link
Copy Markdown
Owner

What and why

With native control (iOS 27), automatic unlocking could fail with "couldn't bring up the passcode keypad" while the keypad was on screen: no key went down and the passcode field stayed at 0 digits (now and then it stopped at the 2nd or 3rd digit instead).

Unlocking reads the passcode field after every key, and read_lock_screen closes the HID session first, because the phone hides the lock screen from accessibility while the session's screen stream is open. Closed right after the tap, the phone sometimes doesn't take the touch. It isn't every time: the same phone unlocked for hours on main, then lost every key until the end of the day, across daemon restarts.

read_lock_screen now keeps the session open until 350 ms after the last HID action (TOUCH_LANDS). Unlocks while the phone was losing keys, by wait, the waits taken in turn within one daemon: 0 ms 0/9, 50 ms 0/3, 100 ms 0/3, 150 ms 1/3, 200 ms 3/4, 250 ms 5/5, 350 ms 3/3. An unlock takes about 1.5 s longer (about 10.0 s instead of 8.3 s).

Not found out: what puts the phone into the state where it loses the keys. It began after the second restart of axauditd (#152) within a minute, during scenarios.py lock; reading the passcode field still worked afterwards (typed by hand, it read 0 → 2 → 3), and a single tap on a key through a fresh HID session that stayed open for 3 s registered.

Tests

1. Unit tests

  • cargo test --workspace --all-features --locked, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings and cargo fmt --check (per package) pass
  • New or changed behaviour / the fixed bug has a unit test: the_hid_session_stays_open_until_the_last_touch_has_landed (how long is left to wait; that the phone drops the touch can only be seen on a device)
  • No existing test removed, ignored or loosened
  • #[ignore] tests of the changed area run by hand: none apply

2. Real-device regression

  • Device, iOS version, host (Linux / macOS): iPhone19,7, iOS 27.2.1, native control, macOS 27.2 (Apple Silicon)
  • tests/device/run.py default steps pass on this branch (exit code 0)
  • tests/device/scenarios.py passes on this branch: default scenarios, lock and url, 57 checks, 0 failed; lock three more times, 13/13 each
  • The same steps on main or the latest release, same device, for comparison (run.py --repeat 5 --json, compare.py); no step clearly slower, or why: compare.py refused both files ("NOT THE SAME STEPS": the two Clock tabs run.py taps came in the other order), so the medians were compared by its rule by hand. One step is over it: the last Home, 1.36 s on main, 1.77 s here (1.8 s in 3 of 5 runs, twice). It comes from how the daemon was started, not from the change: main's binary started by hand like the branch's took 1.72–1.78 s in 5 of 5, under launchd 1.31–1.45 s in 10 of 10. The new wait is only on the unlock path.
  • Steps exercising this change: scenarios.py --lock lock, see part 4
  • Longer run (WDA start-up/recovery, reconnecting, unlocking, live picture, timers): not run for an hour. 16 automatic unlocks in a row over about 12 minutes, all succeeded (9.8–10.8 s each)
  • tests/device/tasks.py: 71 checks, 1 failed, [self] nor through the control page's API (Linux); it fails the same way on main on this Mac
run.py output
this branch (b85cb68; the phone was locked at the start, the 2nd step unlocked it first):
### iPhone19,7, iOS 27.2.1, 440x956 pt, native, <udid>
=== iphone_status {} 0.03s
=== iphone_tap_element {"text": "不存在的按钮xyz"} 11.59s
=== iphone_press_button {"button": "home"} 1.48s
=== iphone_launch_app {"app": "时钟"} 1.71s
=== iphone_list_elements {"limit": 40} 0.13s
=== iphone_tap_element {"text": "世界时钟", "then": "elements", "then_filter": "Button"} 1.92s
=== iphone_tap_element {"text": "闹钟", "then": "elements", "then_filter": "Button"} 0.86s
=== iphone_screenshot {} 0.35s
=== iphone_screenshot {"x": 0, "y": 0, "width": 440.0, "height": 60} 0.28s
=== iphone_press_button {"button": "home"} 1.26s
=== iphone_swipe {"from_x": 220, "from_y": 411, "to_x": 220, "to_y": 717} 1.39s
=== iphone_type_text {"text": "设置"} 1.98s
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.17s
=== iphone_screenshot {} 0.68s
=== iphone_press_button {"button": "home"} 1.82s
=== iphone_status {} 0.03s
--- 16 calls, 0 failed, 26.3s in all

main (e2afc62, 0.2.8; run 1 of 5):
### iPhone19,7, iOS 27.2.1, 440x956 pt, native, <udid>
=== iphone_status {} 0.03s
=== iphone_tap_element {"text": "不存在的按钮xyz"} 0.36s
=== iphone_press_button {"button": "home"} 0.80s
=== iphone_launch_app {"app": "时钟"} 0.96s
=== iphone_list_elements {"limit": 40} 0.14s
=== iphone_tap_element {"text": "闹钟", "then": "elements", "then_filter": "Button"} 1.94s
=== iphone_tap_element {"text": "世界时钟", "then": "elements", "then_filter": "Button"} 1.75s
=== iphone_screenshot {} 0.35s
=== iphone_screenshot {"x": 0, "y": 0, "width": 440.0, "height": 60} 0.30s
=== iphone_press_button {"button": "home"} 1.18s
=== iphone_swipe {"from_x": 220, "from_y": 411, "to_x": 220, "to_y": 717} 1.27s
=== iphone_type_text {"text": "设置"} 3.13s
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.32s
=== iphone_screenshot {} 0.70s
=== iphone_press_button {"button": "home"} 1.31s
--- 80 calls, 0 failed, 71.4s in all

medians of 5 runs, seconds (main under launchd / this branch started by hand):
iphone_status           0.03  0.03
iphone_tap_element      0.34  0.32
iphone_press_button     0.79  0.76
iphone_launch_app       0.96  0.94
iphone_list_elements    0.16  0.15
iphone_tap_element      1.76  1.70
iphone_tap_element      1.74  1.67
iphone_screenshot       0.35  0.34
iphone_screenshot       0.30  0.28
iphone_press_button     1.19  1.18
iphone_swipe            1.24  1.14
iphone_type_text        3.11  3.00
iphone_wait_for         0.31  0.22
iphone_screenshot       0.70  0.68
iphone_press_button     1.36  1.77   (main started by hand: 1.75)
iphone_status           0.04  0.03
total                  14.37 14.22

3. Regression cases (docs/dev/regression-cases.md)

4. Real-device proof of the fix or feature

  • Device, iOS version, host (Linux / macOS): iPhone19,7, iOS 27.2.1, macOS 27.2
  • Bug fix: reproduced on main / the release, gone with this branch, same device and steps
  • Untested conditions (device kind, iOS version, orientation, host OS), if any: iPad, landscape, other iOS 27 versions, a Linux host. WDA doesn't go through this code.
Steps and results (before / after, output, log lines, screenshots)
Steps: Clock in front, then tests/device/scenarios.py --lock lock (lock button, then a tap by text that has to unlock first, three times).

before, main 0.2.8 (e2afc62):
PASS [lock] the lock button locks the phone, 1 of 3 (0.24s, the status says so 1.18s later)
PASS [lock] the status says the next action unlocks it
FAIL [lock] #144 the next action unlocks first and says how long it took (0.0s of 17.6s)  ← 调不出锁屏密码键盘(一位都没输进去),需要人工解锁;…
FAIL [lock] #127 the tap right after unlocking takes effect  ← 调不出锁屏密码键盘(一位都没输进去),需要人工解锁;…
STOP [lock] it did not unlock: not locking again
--- 4 checks, 2 failed, 25.4s in all

main's daemon log for one such attempt (ICTL_LOG=…,ictl_unlock=debug), the keypad and the field are read, the key isn't taken:
DEBUG ictl_unlock: unlock round 0: locked, tree read with the check: true
DEBUG ictl_unlock: unlock round 0: the first digit didn't register (field reads 0)
DEBUG ictl_unlock: unlock round 1: the first digit didn't register (field reads 0)
DEBUG ictl_unlock: unlock round 2: the first digit didn't register (field reads 0)

after, this branch, started right after the failure above with the phone still locked:
PASS [lock] #144 the next action unlocks first and says how long it took (10.0s of 11.9s)
PASS [lock] #144 the next action unlocks first and says how long it took (10.0s of 10.8s)
PASS [lock] #144 the next action unlocks first and says how long it took (10.0s of 11.7s)
--- 13 checks, 0 failed, 65.1s in all

The same day, unpatched builds failed every attempt from the moment it began (12 of 12 tool calls and scenario runs, under launchd and started by hand); this branch unlocked 16 of 16.

Unlocks by how long the session stayed open after the touch (a build of this branch reading the wait from a file, one daemon, the waits taken in turn):
0 ms 0/9   50 ms 0/3   100 ms 0/3   150 ms 1/3   200 ms 3/4 (once the 3rd digit wasn't taken)   250 ms 5/5   350 ms 3/3

Checklist

  • MCP tool names, parameters and default outputs stay compatible (docs/decisions.md D10)
  • New or changed dependencies are pinned to exact versions; vendor changes recorded in THIRD_PARTY.md (none)
  • User-visible changes noted in CHANGELOG.md (and CHANGELOG.zh-CN.md if you can) under Unreleased
  • No private data in fixtures, screenshots, logs or the outputs above

🤖 Generated with Claude Code

…tap has landed

With native control (iOS 27), unlocking reads the passcode field after every
key, and closes the HID session first (the phone hides the lock screen from
accessibility while its screen stream is open). Closed right after the tap,
the phone sometimes doesn't take the touch: the keypad is up, no key goes
down, and unlocking fails with "couldn't bring up the passcode keypad".

The session now stays open until 350 ms after the last HID action. Measured
on an iPhone19,7 (iOS 27.2.1) while it was losing keys, unlocks by wait:
0 ms 0/9, 50 ms 0/3, 100 ms 0/3, 150 ms 1/3, 200 ms 3/4, 250 ms 5/5,
350 ms 3/3.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Derrors
Derrors force-pushed the fix/native-unlock-tap-cancelled branch from b85cb68 to bfce25d Compare November 18, 2026 06:34
@Derrors
Derrors merged commit 121a498 into main Nov 18, 2026
7 checks passed
Derrors added a commit that referenced this pull request Nov 18, 2026
Version 0.2.9 in Cargo.toml and Cargo.lock (this workspace's crates
only), and the changelogs' Unreleased section dated. The entries of
#154, #155 and #156 end with their pull requests and say only what the
user sees, as CONTRIBUTING asks.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors deleted the fix/native-unlock-tap-cancelled branch November 18, 2026 09:08
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.

1 participant