From a2828a891d6e7c6ec3060d3f2ad89c987d009222 Mon Sep 17 00:00:00 2001 From: Derrors <33656531+Derrors@users.noreply.github.com> Date: Wed, 18 Nov 2026 14:41:06 +0800 Subject: [PATCH] fix(daemon): native Home waits out its animation even when the HID session had to be opened With native control (iOS 27), Home on the home screen is answered no sooner than 0.6 s after it was pressed (#130), but the time was taken before the HID session was opened. After the daemon had left the session idle (30 s), opening it again (the screen stream) took about as long, so nothing was waited for, and an app launched right after was sent back to the home screen when the animation ended: 7 times in 8 on an iPhone19,7 (iOS 27.2.1), 0 in 8 with the session already open. It is why run.py's first run after a daemon start failed with "Clock's tab bar isn't among the first 40 elements". The session is now opened first and the wait counted from the press. scenarios.py has a new `idle` scenario for it. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + CHANGELOG.zh-CN.md | 1 + crates/ictl-daemon/src/tools/native.rs | 4 ++++ docs/dev/regression-cases.md | 1 + tests/device/scenarios.py | 25 ++++++++++++++++++++++++- 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 752cdfc..f474808 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ What changed in each release, one line per change. Versions follow [Semantic Ver - With native control (iOS 27), reading the screen no longer keeps failing until the phone is replugged when the phone's accessibility service stops answering; it is restarted on its own (#152). - With native control (iOS 27), automatic unlocking no longer fails with "couldn't bring up the passcode keypad" while the keypad is on screen: the keys it tapped were sometimes not taken by the phone. +- With native control (iOS 27), an app launched right after Home is no longer sent back to the home screen when the daemon had left the touch session idle (for example the first actions after the daemon started). ## [0.2.8] - 2026-11-18 diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index daeed3f..d594a47 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -10,6 +10,7 @@ - 原生控制(iOS 27)下,手机上的无障碍服务不再应答时,读界面不会再一直失败到重新插线为止;会自动把它重启(#152)。 - 原生控制(iOS 27)下,自动解锁不会再在密码键盘已经出来时报「调不出锁屏密码键盘」:点下去的数字键有时没被手机认。 +- 原生控制(iOS 27)下,触摸会话闲置后(比如守护进程刚启动)按 Home 再马上启动 App,App 不会再被送回主屏幕。 ## [0.2.8] - 2026-11-18 diff --git a/crates/ictl-daemon/src/tools/native.rs b/crates/ictl-daemon/src/tools/native.rs index 4c54c1c..62d91bc 100644 --- a/crates/ictl-daemon/src/tools/native.rs +++ b/crates/ictl-daemon/src/tools/native.rs @@ -486,6 +486,10 @@ impl Daemon { blocking(&text) )); } + // the HID session opened first, the wait below counted from the press: opening it (the screen stream, about + // 0.6 s after the daemon left it idle) used up the whole wait, and an app launched right after a Home on the + // home screen was sent back there (7 times in 8; 0 in 8 with the session already open) + self.hid(g).await?; let pressed = Instant::now(); self.hid_do(g, |h| Box::pin(h.press(Button::Home))).await?; if self.native_reached_home(g).await { diff --git a/docs/dev/regression-cases.md b/docs/dev/regression-cases.md index cd73c2f..0fac22d 100644 --- a/docs/dev/regression-cases.md +++ b/docs/dev/regression-cases.md @@ -160,3 +160,4 @@ | 154 | `iphone_tap_element` 没找到(或序号超出、整个被盖住)时什么都没点,带 `then` 却先等界面稳定 0.7~0.8 秒,再拿它点之前读的树比较,说「界面和操作前一样:操作可能没生效(点在了空白处…),不要原样再做一遍」,好像点过了 | 没点就清掉「操作前的界面」,不做比较;MCP 端看到没点到东西时不等稳定,直接用按名字点击刚读的树列元素或截图 | 真机(iPhone 12 mini,iOS 26.4.1:设置里按不存在的文字点,带 `then=elements` 和 `then=screenshot`,0.2.7 是 1.3~1.45 秒带那句提示,本分支 0.6~0.9 秒不带;只换守护进程(旧 MCP)时仍等稳定但也不带;按存在的文字点照常等稳定、说界面变了)| | 155 | 原生控制(iOS 27):手机上的 axauditd(remoteAXService 背后的进程)卡住后,每次读界面都超时(先 `remoteAXService: request`,之后每次握手 `deviceAPIVersion`),守护进程一直「准备手机失败,稍后重试」,重连、重建隧道、重启守护进程都没用,只有重新插线才恢复。iPhone 15 Pro Max(iOS 27.2.1)上见过三次:两次在部署重启守护进程后,一次在自动解锁后。2026-11-18 排查:只在锁屏键按下后马上读界面时出现(完整场景回归里约 35 次锁屏碰上 2 次),卡住前 axauditd 不报错、日志停住 8 秒,像在等一个不回的应答;没能复现的有:客户端请求中途断开或不发 clientNeedsAccessibility: false(10 次)、40 个半开连接加 48 次切换 App、锁屏状态下重启守护进程(5 次)、锁屏前后每 0.1 秒读一次(20 轮,带或不带 SpringBoard 的元素)。根因在 axauditd 内部,要抓它卡住时的调用栈(sysdiagnose)才看得到 | 无障碍服务不应答单独成一种错误(`DeviceError::AxUnanswered`,文字同超时);读界面、读前台 App 碰到它时经 CoreDevice 结束 axauditd(下次连接系统自动拉起),再读一次;同一台设备一分钟内最多一次,事件日志记「已重启手机上的 axauditd」 | 单测 `an_unanswered_accessibility_service_is_told_apart_and_reads_as_a_timeout`、`only_axauditd_is_the_accessibility_daemon` + 真机(经 AppService 给 axauditd 发 SIGSTOP 冻住:main 上一直报超时,修复后下一次读界面直接成功、axauditd 换了进程号) | | 156 | 原生控制(iOS 27):自动解锁时密码键盘出来了,却一位都输不进去,三轮后报「调不出锁屏密码键盘」(偶尔停在第 2、3 位)。每点一个数字键就要读密码栏,读之前得先关 HID 会话(开着时手机不让无障碍服务看锁屏);点完马上关,手机不认这次触摸。时有时无:同一台手机(iPhone19,7,iOS 27.2.1)不等也能解锁了几个小时,之后每一下都丢 | 关 HID 会话前,等上一次 HID 操作发出满 `TOUCH_LANDS`(0.35 秒)。丢键期间同一个守护进程里轮流量的解锁成功数:0 毫秒 0/9,50 毫秒 0/3,100 毫秒 0/3,150 毫秒 1/3,200 毫秒 3/4,250 毫秒 5/5,350 毫秒 3/3 | 单测 `the_hid_session_stays_open_until_the_last_touch_has_landed` + 真机脚本 `scenarios.py lock` | +| 157 | 原生:守护进程闲置 30 秒关掉 HID 会话后,在主屏幕上按 Home、马上启动 App,App 到了前台又被送回主屏幕(7/8);守护进程刚启动后 `run.py` 第一轮常因此失败。#130 的 0.6 秒是从调用 HID 算起的,重开会话(屏幕媒体流,约 0.6 秒)把它用完了,按下后一点没等 | 先开好 HID 会话,再从按下 Home 算 0.6 秒 | 真机(iPhone19,7,iOS 27.2.1:闲置后 Home 再启动时钟,0.2.8 是 7/8 回到主屏幕,会话开着时 0/8);真机脚本 `scenarios.py idle` | diff --git a/tests/device/scenarios.py b/tests/device/scenarios.py index 8e2eaff..63a0d8c 100644 --- a/tests/device/scenarios.py +++ b/tests/device/scenarios.py @@ -20,6 +20,8 @@ the rest is not done menu a long press on a home-screen icon takes about as long as it was asked to (#34); Home closes the menu and an app started right afterwards stays in front (#130) + idle after the daemon has closed the idle HID session, Home on the home screen and an app started right + afterwards stays in front (#157); takes about 2 minutes (it waits for the session to close) url a link opened right after its app was terminated opens (#131); text on the web page can be waited for (#133) lock the lock button locks within seconds, again and again (#59, #102, #105); the next action unlocks first and says so (#144); a tap right after unlocking isn't swallowed (#127) @@ -50,6 +52,8 @@ results: list[bool] = [] MISSING = "不存在的按钮xyz" +# seconds without a touch before the daemon closes the HID session (crates/ictl-daemon/src/supervise.rs HID_IDLE) +HID_IDLE = 30 AUTO_UNLOCK = dev.T("操作时会自动解锁", "actions unlock automatically") PINNED = dev.T("(选定)", "(selected)") @@ -214,6 +218,23 @@ async def fresh(p: Phone): await p.home(c) +async def idle(p: Phone): + c = "idle" + for n in range(2): + await p.home(c) + await asyncio.sleep(2) + # the daemon closes the HID session after 30 s without a touch (supervise::HID_IDLE); not with the control + # page showing the screen, when this passes either way + await asyncio.sleep(HID_IDLE + 5) + await p.home(c) + await p.ok(c, "iphone_launch_app", {"app": dev.CLOCK}) + await asyncio.sleep(1.5) + status = await p.front() + check(c, f"#157 Home with the HID session idle, then an app started: it stays in front, {n + 1} of 2", + dev.CLOCK in status, status) + await p.home(c) + + async def batch(p: Phone): c = "batch" await p.home(c) @@ -342,7 +363,9 @@ async def lock(p: Phone): await p.home(c) -SCENARIOS = {"tools": tools, "typing": typing, "fresh": fresh, "batch": batch, "menu": menu, "url": url, "lock": lock} +SCENARIOS = { + "tools": tools, "typing": typing, "fresh": fresh, "batch": batch, "menu": menu, "idle": idle, "url": url, "lock": lock +} OPT_IN = {"lock": "--lock", "url": "--url"}