From 363e4f91ad840f7febae5f2c684b6e77c79961b2 Mon Sep 17 00:00:00 2001 From: Derrors <33656531+Derrors@users.noreply.github.com> Date: Wed, 25 Nov 2026 22:08:52 +0800 Subject: [PATCH 1/2] fix: request checks and protocol edges (review P1-1) - PressButton sets Outcome::alert_reported when it reports a system alert - long_press falls back to HID like a tap (Route::Hid, WDA unreachable) - Tap count, TapSequence points, PressButton's button and non-finite coordinates are checked before the device lock and the cache drop - Touch Prepare isn't a device action: not refused during a task, not the user acting under takeover; touch_rotation is cleared once an up was sent - ScrollCollect no longer denies unknown fields (forward compatibility) - a stored passcode needs 4 digits; state.json isn't replaced by an empty file when it doesn't serialize; NotifyConfig's Debug hides the keys Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 ++ CHANGELOG.zh-CN.md | 7 ++ crates/ictl-daemon/src/config.rs | 33 ++++++++- crates/ictl-daemon/src/core.rs | 94 +++++++++++++++++++++++--- crates/ictl-daemon/src/tasks.rs | 16 +++++ crates/ictl-daemon/src/tools/input.rs | 21 ++++-- crates/ictl-daemon/src/tools/keys.rs | 30 ++++---- crates/ictl-daemon/src/tools/native.rs | 40 ++++++----- crates/ictl-protocol/src/lib.rs | 7 +- crates/ictl-unlock/src/lib.rs | 9 ++- docs/dev/regression-cases.md | 6 ++ 11 files changed, 220 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f99eb2f8..88ad51b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,13 @@ What changed in each release, one line per change. Versions follow [Semantic Ver ### Fixes +- `iphone_press_button` that finds a system alert in the way says so in a way the MCP server reads, so it no longer checks for the alert a second time (#200). +- A long press falls back to HID like a tap when WebDriverAgent can't be reached (#200). +- Requests that can't run (a tap count of 0, an empty tap sequence, an unknown button, a point that isn't a number) are refused at once, before waiting for the phone and without dropping the cached screen (#200). +- The control page getting ready for a touch no longer counts as acting: it isn't refused while an AI task runs and doesn't make the agent look again after you take over (#200). +- Requests for a list scan sent by a newer client with extra fields are no longer refused by an older daemon (#200). +- Auto-unlock refuses a saved passcode shorter than 4 digits, as `passcode set` does; `state.json` is no longer replaced by an empty file if it can't be written out; notification keys are never shown in debug output (#200). + - iPads with Touch ID in a language other than Chinese or English: the "Touch ID" prompt after swiping up is known as the lock screen, and auto-unlock taps "Use Passcode" on it; the iPad was taken for unlocked and never checked again (#198). - A malformed accessibility answer from the phone (iOS 27+) can no longer keep the daemon busy for ever; a malformed touch (a coordinate or duration that isn't a number) is refused instead of crashing or tapping the top-left corner (#198). - The phone's log is read from now on only: the daemon took old lines for new, such as a past "Enable UI Automation" prompt, and `iphone_app_logs` showed them as just logged (#198). diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 61198b4d..55e150d4 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -16,6 +16,13 @@ ### 修复 +- `iphone_press_button` 发现有系统弹窗挡着时,会以 MCP 服务读得懂的方式报出来,不再重复检查一次弹窗(#200)。 +- 长按和点击一样,连不上 WebDriverAgent 时改用 HID(#200)。 +- 执行不了的请求(点击次数为 0、空的点击序列、不认识的按键、坐标不是有效数字)立刻拒绝,不再先排队等手机,也不会清掉缓存的界面(#200)。 +- 控制台准备触摸不再算作操作:AI 任务进行中不会被拒,你接管时也不会让 agent 之后重新看一遍(#200)。 +- 新版客户端发来带额外字段的列表滚动收集请求,旧版守护进程不再拒绝(#200)。 +- 自动解锁不再接受不足 4 位的已存密码,和 `passcode set` 一致;`state.json` 写不出来时不会被换成空文件;通知密钥不会出现在调试输出里(#200)。 + - 界面语言不是中文或英文的 Touch ID iPad:上滑后的「触控 ID」提示也认作锁屏,自动解锁会点上面的「使用密码」;之前会把锁着的 iPad 当成已解锁,之后再也不查(#198)。 - 手机(iOS 27 起)发来格式异常的无障碍应答,不会再让守护进程一直忙下去;坐标或时长不是有效数字的触摸会被拒绝,不再崩溃或点到左上角(#198)。 - 手机日志只读从现在起产生的:之前守护进程会把旧日志当成新的(比如以前出现过的「Enable UI Automation」密码框),`iphone_app_logs` 也会把它们当成刚记下的(#198)。 diff --git a/crates/ictl-daemon/src/config.rs b/crates/ictl-daemon/src/config.rs index 4f8a0831..aaa5752d 100644 --- a/crates/ictl-daemon/src/config.rs +++ b/crates/ictl-daemon/src/config.rs @@ -55,7 +55,7 @@ impl IosBackend { } } -#[derive(Debug, Clone, Default)] +#[derive(Clone, Default)] pub struct NotifyConfig { pub tg_bot_token: Option, pub tg_chat_id: Option, @@ -63,6 +63,19 @@ pub struct NotifyConfig { pub bark_key: Option, } +/// Written out (a `{:?}` of the [`Config`] in a log or a panic) without the keys: only whether each is set +impl std::fmt::Debug for NotifyConfig { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let set = |v: &Option| if v.is_some() { "" } else { "" }; + f.debug_struct("NotifyConfig") + .field("tg_bot_token", &set(&self.tg_bot_token)) + .field("tg_chat_id", &set(&self.tg_chat_id)) + .field("bark_server", &self.bark_server) + .field("bark_key", &set(&self.bark_key)) + .finish() + } +} + impl NotifyConfig { pub fn any(&self) -> bool { (self.tg_bot_token.is_some() && self.tg_chat_id.is_some()) || self.bark_key.is_some() @@ -200,3 +213,21 @@ impl Config { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + + /// A debug print of the settings shows whether a key is set, never the key + #[test] + fn notification_keys_stay_out_of_debug_output() { + let n = NotifyConfig { + tg_bot_token: Some("123:secret-token".into()), + tg_chat_id: Some("42".into()), + bark_server: "https://api.day.app".into(), + bark_key: Some("bark-secret".into()), + }; + let s = format!("{n:?}"); + assert!(!s.contains("secret") && s.contains("") && s.contains("api.day.app"), "{s}"); + } +} diff --git a/crates/ictl-daemon/src/core.rs b/crates/ictl-daemon/src/core.rs index dabab4b1..9b991ae2 100644 --- a/crates/ictl-daemon/src/core.rs +++ b/crates/ictl-daemon/src/core.rs @@ -274,13 +274,16 @@ impl Persisted { pub(crate) fn save(&self, path: &Path) { use std::io::Write; let tmp = path.with_extension("json.tmp"); - // sync before the rename, or a power cut can leave state.json empty - let r = std::fs::File::create(&tmp) - .and_then(|mut f| { - f.write_all(&serde_json::to_vec_pretty(self).unwrap_or_default())?; - f.sync_all() - }) - .and_then(|_| std::fs::rename(&tmp, path)); + // nothing written when it doesn't serialize: an empty file in its place would lose the whole state + let r = serde_json::to_vec_pretty(self).map_err(std::io::Error::other).and_then(|data| { + // sync before the rename, or a power cut can leave state.json empty + std::fs::File::create(&tmp) + .and_then(|mut f| { + f.write_all(&data)?; + f.sync_all() + }) + .and_then(|_| std::fs::rename(&tmp, path)) + }); if let Err(e) = r { tracing::warn!("{}", ictl_l10n::log_trf!("保存 state.json 失败:{e}", "Saving state.json failed: {e}")); } @@ -1440,7 +1443,10 @@ impl Daemon { message }) } - Request::PressButton { button } => self.press_button(g, &button, watched).await, + Request::PressButton { button } => self.press_button(g, &button, watched).await.map(|(t, alert)| { + outcome.alert_reported = alert; + t + }), Request::Touch { phase, x, y } => { return self .touch(g, phase, x, y, view) @@ -1755,9 +1761,43 @@ fn check_request(req: &Request) -> Result<(), String> { MAX_WAIT_MS / 1000 )); } - Request::Touch { x, y, .. } if !x.is_finite() || !y.is_finite() => { + Request::Touch { x, y, .. } | Request::Tap { x, y, .. } | Request::LongPress { x, y, .. } + if !x.is_finite() || !y.is_finite() => + { return Err(ictl_l10n::tr!("x、y 要是有效的数", "x and y must be valid numbers").into()); } + Request::Swipe { from, to, .. } if ![from.0, from.1, to.0, to.1].iter().all(|v| v.is_finite()) => { + return Err( + ictl_l10n::tr!("起点、终点要是有效的数", "the start and end points must be valid numbers").into() + ); + } + // checked before the device lock is taken and the element cache dropped: a request that can't run doesn't + // cost the next one its cached tree + Request::Tap { count, .. } if !(1..=crate::protocol::MAX_TAP_COUNT).contains(count) => { + return Err(ictl_l10n::trf!( + "count 要是 1 到 {} 的整数", + "count must be a whole number from 1 to {}", + crate::protocol::MAX_TAP_COUNT + )); + } + Request::TapSequence { points } + if points.is_empty() + || points.len() > crate::protocol::MAX_SEQUENCE_POINTS + || !points.iter().all(|(x, y)| x.is_finite() && y.is_finite()) => + { + return Err(ictl_l10n::trf!( + "一个手势要点 1 到 {} 个点,坐标要是有效的数", + "a gesture takes 1 to {} points, with valid numbers", + crate::protocol::MAX_SEQUENCE_POINTS + )); + } + Request::PressButton { button } if ictl_device::hid::Button::parse(button).is_none() => { + return Err(ictl_l10n::tr!( + "button 只能是 home / volume_up / volume_down / lock", + "button must be home / volume_up / volume_down / lock" + ) + .into()); + } Request::AppLogs { since_secs, limit, .. } if *since_secs > 3600 || *limit == 0 || *limit > 1000 => { return Err(ictl_l10n::tr!( "since 最多 3600 秒,limit 要在 1 到 1000 之间", @@ -1813,8 +1853,12 @@ pub(crate) mod tests { assert!(!crate::tasks::observes(&req), "this cannot clear a takeover's observation requirement"); let mut wire = serde_json::to_value(&req).unwrap(); assert_eq!(serde_json::from_value::(wire.clone()).unwrap(), req); - wire["scroll"] = serde_json::json!("sideways"); - assert!(serde_json::from_value::(wire).is_err(), "unknown direct protocol fields must fail"); + // a key this daemon doesn't know (a newer client's) is ignored, as for every other request + wire["added_by_a_newer_client"] = serde_json::json!(true); + assert_eq!(serde_json::from_value::(wire.clone()).unwrap(), req); + // the scan's own fields are still checked: a wrong type is an error + wire["max_scrolls"] = serde_json::json!("sideways"); + assert!(serde_json::from_value::(wire).is_err()); for (max, limit) in [(0, 1), (16, 1), (1, 0), (1, 151)] { scan.max_scrolls = max; scan.limit = limit; @@ -2102,6 +2146,34 @@ pub(crate) mod tests { assert!(!m.contains("的 ,"), "no empty name in the text: {m}"); } + /// Requests that can't run are refused before they take the device lock and drop the cached tree + #[test] + fn hopeless_requests_are_refused_up_front() { + let bad = [ + Request::Tap { x: 1.0, y: 1.0, count: 0 }, + Request::Tap { x: 1.0, y: 1.0, count: crate::protocol::MAX_TAP_COUNT + 1 }, + Request::Tap { x: f64::NAN, y: 1.0, count: 1 }, + Request::LongPress { x: 1.0, y: f64::INFINITY, seconds: 1.0 }, + Request::Swipe { from: (1.0, f64::NAN), to: (1.0, 2.0), seconds: 0.3, hold: 0.0 }, + Request::TapSequence { points: vec![] }, + Request::TapSequence { points: vec![(1.0, 1.0); crate::protocol::MAX_SEQUENCE_POINTS + 1] }, + Request::TapSequence { points: vec![(1.0, f64::NAN)] }, + Request::PressButton { button: "power".into() }, + ]; + for r in bad { + assert!(check_request(&r).is_err(), "{r:?}"); + } + let good = [ + Request::Tap { x: 1.0, y: 1.0, count: crate::protocol::MAX_TAP_COUNT }, + Request::TapSequence { points: vec![(1.0, 1.0); crate::protocol::MAX_SEQUENCE_POINTS] }, + Request::PressButton { button: "home".into() }, + Request::PressButton { button: "volume_up".into() }, + ]; + for r in good { + assert!(check_request(&r).is_ok(), "{r:?}"); + } + } + #[test] fn a_tap_by_text_scrolls_within_bounds() { let tap = |max| Request::TapElement { diff --git a/crates/ictl-daemon/src/tasks.rs b/crates/ictl-daemon/src/tasks.rs index b69e9263..313ff01a 100644 --- a/crates/ictl-daemon/src/tasks.rs +++ b/crates/ictl-daemon/src/tasks.rs @@ -1289,6 +1289,8 @@ mod tests { assert!(matches!(admit(&ts, &shot, None).await, Ok((Admission::Free, _)))); let up = Request::Touch { phase: TouchPhase::Up, x: 0.0, y: 0.0 }; assert!(admit(&ts, &up, None).await.is_ok(), "a finger that was down can always be lifted"); + let prepare = Request::Touch { phase: TouchPhase::Prepare, x: 0.0, y: 0.0 }; + assert!(matches!(admit(&ts, &prepare, None).await, Ok((Admission::Free, _))), "getting ready touches nothing"); let select = Request::SelectDevice { device: "auto".into() }; assert!(admit(&ts, &select, None).await.is_err()); @@ -1333,6 +1335,20 @@ mod tests { assert!(message(r).contains("取消")); } + /// The page getting ready for a touch isn't an action: let through while the task runs, and while the user has + /// taken over it doesn't count as the user acting (a [`Admission::Supervisor`]) + #[tokio::test] + async fn getting_ready_for_a_touch_is_not_acting() { + let ts = tasks(); + let t = open(&ts); + let prepare = Request::Touch { phase: TouchPhase::Prepare, x: 0.0, y: 0.0 }; + t.control("takeover", None, false, None).unwrap(); + assert!(matches!(admit(&ts, &prepare, None).await, Ok((Admission::Free, _)))); + assert!(matches!(admit(&ts, &tap(), None).await, Ok((Admission::Supervisor(_), _))), "a tap is acting"); + assert!(!prepare.is_device_action()); + assert!(Request::Touch { phase: TouchPhase::Down, x: 0.0, y: 0.0 }.is_device_action()); + } + #[tokio::test] async fn after_someone_else_acted_the_agent_looks_before_acting() { let ts = tasks(); diff --git a/crates/ictl-daemon/src/tools/input.rs b/crates/ictl-daemon/src/tools/input.rs index 72917381..e3310c8b 100644 --- a/crates/ictl-daemon/src/tools/input.rs +++ b/crates/ictl-daemon/src/tools/input.rs @@ -234,9 +234,6 @@ impl Daemon { "No finger is down; send down first" ))); }; - if !contact { - g.dev.touch_rotation = None; - } // Reuse the open session without another WDA screen-size lookup on every move. let h = match g.tunnel.as_mut().and_then(|t| t.open_hid()) { Some(h) => h, @@ -256,6 +253,8 @@ impl Daemon { let result = Box::pin(h.touch(contact, x, y)).await; g.hid_used = Some(Instant::now()); match result { + // the finger is up once that was sent, not before: an up refused below leaves it down, to be lifted + Ok(()) if !contact => g.dev.touch_rotation = None, Ok(()) => {} // refused before anything was sent (a point that isn't a number, an unknown screen size): the tunnel and // its sessions are fine; a finger that is down stays where it was @@ -454,12 +453,22 @@ impl Daemon { view: Option<&str>, ) -> crate::error::Result { self.prepare_coordinates(g, view, true).await.map_err(Error::preflight)?; - match self.route(g) { - Route::Wda(w) => w.touch_and_hold(x, y, seconds).await.map_err(Error::wda_input)?, - Route::Native => Box::pin(self.native_long_press(g, x, y, seconds)).await?, + // as for a tap: without WDA (or when it can't be reached) by HID where the phone has it, unless the point was + // measured on the page's view through WDA + let by_hid = match self.route(g) { + Route::Wda(w) => match w.touch_and_hold(x, y, seconds).await { + Ok(()) => false, + Err(WdaError::Unavailable(_)) if view.is_none() && hid_supported(g.info.as_ref()) => true, + Err(e) => return Err(Error::wda_input(e)), + }, + Route::Native => true, + Route::Hid if view.is_none() => true, Route::Hid | Route::Unavailable => { return Err(Error::preflight(wda_down(&g.state, g.info.as_ref()))); } + }; + if by_hid { + Box::pin(self.native_long_press(g, x, y, seconds)).await?; } Ok(ictl_l10n::trf!("已长按 ({},{}) {} 秒", "Long-pressed ({},{}) for {} s", fmt_g(x), fmt_g(y), fmt_g(seconds))) } diff --git a/crates/ictl-daemon/src/tools/keys.rs b/crates/ictl-daemon/src/tools/keys.rs index c4da1593..19b607e3 100644 --- a/crates/ictl-daemon/src/tools/keys.rs +++ b/crates/ictl-daemon/src/tools/keys.rs @@ -10,13 +10,13 @@ impl Daemon { g: &mut Inner, button: &str, watched: bool, - ) -> crate::error::Result { + ) -> crate::error::Result<(String, bool)> { let hid_button = Button::parse(button).ok_or(ictl_l10n::tr!( "button 只能是 home / volume_up / volume_down / lock", "button must be home / volume_up / volume_down / lock" ))?; let wda_name = match hid_button { - Button::Lock => return self.lock_screen(g).await, + Button::Lock => return self.lock_screen(g).await.map(|t| (t, false)), Button::Home => "home", Button::VolumeUp => "volumeUp", Button::VolumeDown => "volumeDown", @@ -30,10 +30,13 @@ impl Daemon { && !watched && let Ok(Some(text)) = w.alert_text().await { - return Ok(ictl_l10n::trf!( - "{},按 Home 不会生效,没有按;{TAP_ALERT}", - "{}, pressing Home would have no effect, not pressed; {TAP_ALERT_EN}", - blocking(&text) + return Ok(( + ictl_l10n::trf!( + "{},按 Home 不会生效,没有按;{TAP_ALERT}", + "{}, pressing Home would have no effect, not pressed; {TAP_ALERT_EN}", + blocking(&text) + ), + true, )); } let mut home_worked = None; @@ -52,17 +55,20 @@ impl Daemon { && r.is_ok() && let Ok(Some(text)) = w.alert_text().await { - return Ok(ictl_l10n::trf!( - "{},按 Home 没有生效,先点弹窗上的按钮", - "{}, pressing Home had no effect; first tap a button on the alert", - blocking(&text) + return Ok(( + ictl_l10n::trf!( + "{},按 Home 没有生效,先点弹窗上的按钮", + "{}, pressing Home had no effect; first tap a button on the alert", + blocking(&text) + ), + true, )); } if let Some(via_xctest) = home_worked { self.learn(g, |w| w.home_via_xctest = via_xctest); } match r { - Ok(text) => return Ok(text), + Ok(text) => return Ok((text, false)), Err(WdaError::Unavailable(_)) => {} Err(e) => return Err(e.into()), } @@ -71,7 +77,7 @@ impl Daemon { return Box::pin(self.native_home(g, watched)).await; } self.hid_do(g, |h| Box::pin(h.press(hid_button))).await?; - Ok(ictl_l10n::trf!("已按 {button}", "Pressed {button}")) + Ok((ictl_l10n::trf!("已按 {button}", "Pressed {button}"), false)) } pub(super) async fn lock_screen(&self, g: &mut Inner) -> crate::error::Result { diff --git a/crates/ictl-daemon/src/tools/native.rs b/crates/ictl-daemon/src/tools/native.rs index 92b1a48c..0f8d2784 100644 --- a/crates/ictl-daemon/src/tools/native.rs +++ b/crates/ictl-daemon/src/tools/native.rs @@ -547,13 +547,17 @@ impl Daemon { } /// Home, natively: not pressed under a system alert (it would do nothing), and confirmed by the home screen - /// coming to the front; when the key does nothing, a swipe up from the bottom edge does it - pub(crate) async fn native_home(&self, g: &mut Inner, watched: bool) -> crate::error::Result { + /// coming to the front; when the key does nothing, a swipe up from the bottom edge does it. The bool: the text + /// reports a system alert ([`crate::protocol::Outcome::alert_reported`]) + pub(crate) async fn native_home(&self, g: &mut Inner, watched: bool) -> crate::error::Result<(String, bool)> { if !watched && let (_, Some(text)) = self.native_alert(g).await? { - return Ok(ictl_l10n::trf!( - "{},按 Home 不会生效,没有按;{TAP_ALERT}", - "{}, pressing Home would have no effect, not pressed; {TAP_ALERT_EN}", - blocking(&text) + return Ok(( + ictl_l10n::trf!( + "{},按 Home 不会生效,没有按;{TAP_ALERT}", + "{}, pressing Home would have no effect, not pressed; {TAP_ALERT_EN}", + blocking(&text) + ), + true, )); } // the HID session opened first, the wait below counted from the press: opening it (the screen stream, about @@ -568,7 +572,7 @@ impl Daemon { if let Some(left) = HOME_ANIMATION.checked_sub(pressed.elapsed()) { tokio::time::sleep(left).await; } - return Ok(ictl_l10n::tr!("已按 home", "Pressed home").into()); + return Ok((ictl_l10n::tr!("已按 home", "Pressed home").into(), false)); } let s = self.screen(g).await?; let rot = self.hid_touch_rotation(g).await?; @@ -581,24 +585,28 @@ impl Daemon { }) .await?; if self.native_reached_home(g).await { - return Ok(ictl_l10n::tr!( + let text = ictl_l10n::tr!( "已按 home(Home 键没反应,改为从屏幕底部上滑)", "Pressed home (the key did nothing, swiped up from the bottom edge instead)" - ) - .into()); + ); + return Ok((text.into(), false)); } if let (_, Some(text)) = self.native_alert(g).await? { - return Ok(ictl_l10n::trf!( - "{},按 Home 没有生效,先点弹窗上的按钮", - "{}, pressing Home had no effect; first tap a button on the alert", - blocking(&text) + return Ok(( + ictl_l10n::trf!( + "{},按 Home 没有生效,先点弹窗上的按钮", + "{}, pressing Home had no effect; first tap a button on the alert", + blocking(&text) + ), + true, )); } let app = self.native_foreground(g).await.unwrap_or_default(); - Ok(ictl_l10n::trf!( + let text = ictl_l10n::trf!( "已按 home,但前台还是 {app},先截图看看", "Pressed home, but the foreground is still {app}; take a screenshot" - )) + ); + Ok((text, false)) } /// Whether the home screen comes to the front within [`HOME_SETTLE`] diff --git a/crates/ictl-protocol/src/lib.rs b/crates/ictl-protocol/src/lib.rs index 358f05be..c01366c6 100644 --- a/crates/ictl-protocol/src/lib.rs +++ b/crates/ictl-protocol/src/lib.rs @@ -54,9 +54,10 @@ pub struct ScrollSearch { pub const MAX_SEARCH_SCROLLS: u32 = 15; pub const MAX_SCROLL_ROWS: usize = 150; -/// Bounds and matching rules for a standalone list scan. +/// Bounds and matching rules for a standalone list scan. Unknown fields are ignored, as in every other request: keys +/// that apply to all requests (`lang`, `watched`, `cancel_on_close`…) sit beside these, and one a newer client adds +/// would otherwise make an older daemon refuse this request alone #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] pub struct ScrollCollect { pub down: bool, pub max_scrolls: u32, @@ -630,6 +631,8 @@ impl Request { /// Every variant is listed (no `_`), so a new request type has to be classified here pub fn is_device_action(&self) -> bool { match self { + // only opens the HID session ahead of the finger: nothing on the screen changes + Self::Touch { phase: TouchPhase::Prepare, .. } => false, Self::Tap { .. } | Self::ScrollCollect(_) | Self::TapElement { .. } diff --git a/crates/ictl-unlock/src/lib.rs b/crates/ictl-unlock/src/lib.rs index 83bf6c33..c5043d05 100644 --- a/crates/ictl-unlock/src/lib.rs +++ b/crates/ictl-unlock/src/lib.rs @@ -95,7 +95,7 @@ impl Screen for WdaClient { pub enum UnlockError { #[error("{}", ictl_l10n::tr!("手机已锁屏,且没有配置锁屏密码,需要人工解锁", "The phone is locked and no passcode is configured; unlock it by hand"))] NoPasscode, - #[error("{}", ictl_l10n::tr!("自动解锁只支持纯数字锁屏密码", "Auto-unlock only supports numeric passcodes"))] + #[error("{}", ictl_l10n::tr!("自动解锁只支持至少 4 位的纯数字锁屏密码", "Auto-unlock only supports numeric passcodes of at least 4 digits"))] NotDigits, #[error("{}", ictl_l10n::tr!("手机已锁屏;自动解锁之前失败过已停用,请人工解锁、核对密码后运行 iphone-control unlock-reset", "The phone is locked; auto-unlock was disabled after an earlier failure. Unlock it by hand, check the passcode, then run iphone-control unlock-reset"))] Disabled, @@ -215,7 +215,9 @@ fn passcode(cfg: &UnlockConfig) -> Result { return Err(UnlockError::Disabled); } let code = std::fs::read_to_string(&cfg.passcode_file).map_err(|_| UnlockError::NoPasscode)?.trim().to_owned(); - if code.is_empty() || !code.bytes().all(|b| b.is_ascii_digit()) { + // as `passcode set` takes it: an iPhone's passcode has at least 4 digits, and entering one relies on that (the + // first digit never completes it); a file edited by hand to fewer isn't used + if code.len() < 4 || !code.bytes().all(|b| b.is_ascii_digit()) { return Err(UnlockError::NotDigits); } Ok(code) @@ -815,7 +817,10 @@ mod tests { assert!(matches!(ensure_unlocked(&mut WdaClient::new(&fake), &cfg_none).await, Err(UnlockError::NoPasscode))); let (cfg_alpha, d2) = cfg(Some("abc123")); assert!(matches!(ensure_unlocked(&mut WdaClient::new(&fake), &cfg_alpha).await, Err(UnlockError::NotDigits))); + let (cfg_short, d3) = cfg(Some("123")); + assert!(matches!(ensure_unlocked(&mut WdaClient::new(&fake), &cfg_short).await, Err(UnlockError::NotDigits))); std::fs::remove_dir_all(d1).unwrap(); std::fs::remove_dir_all(d2).unwrap(); + std::fs::remove_dir_all(d3).unwrap(); } } diff --git a/docs/dev/regression-cases.md b/docs/dev/regression-cases.md index 6a21746a..f321517c 100644 --- a/docs/dev/regression-cases.md +++ b/docs/dev/regression-cases.md @@ -205,3 +205,9 @@ | 199 | ictl-sign:登录写完 `accounts.json` 不收紧权限;新证书的私钥按默认 umask(0644)写出,要等整包签完才收紧,中途失败就一直是 0644(账号目录本身是 0700,别的用户进不去);调用方超时丢掉签名 future 时 `/tmp/ictl-sign-*` 留在那里;`pack`、`from_app_zip` 直接截断目标文件 | 登录后、证书建好后立刻 `restrict_tree`,签名失败也再收紧一次;临时目录交给 RAII guard 删;打包写到同目录的临时文件、fsync 后改名 | 单测 `a_failed_pack_leaves_the_old_package`、`the_scratch_directory_is_removed_when_dropped`、原有的 `account_tree_is_locked_down`(真机没有重签:重签后 iPad 要用户手输一次密码) | | 200 | macOS 内置编码器(`video/vt.rs`):`Decoder::decode` 拿着解码槽的 `&mut` 跨过 `VTDecompressionSessionDecodeFrame`,回调 `on_decoded` 同时对同一个地方又造了一个 `&mut`,两个活着的可变引用是未定义行为 | FFI 调用前后只经原始指针短暂读写,不持有跨调用的引用 | CI 的 macOS 编译(本机没有 macOS,也没有 darwin 编译目标) | | 201 | 界面语言不是简中或英文的 Touch ID iPad:上滑后的「触控 ID」提示只认「使用密码」「Use Passcode」「Enter Passcode」,认不出就返回 `CoverSheet::None`,锁屏被当成已解锁,`lock_state_trusted` 置真后不再查;自动解锁也找不到「使用密码」按钮 | 按结构认:`SBCoverSheetWindow` 里没有锁屏日期、只有两个按钮就是锁屏;认不出文字时取上下叠在同一条竖线上的两个按钮中上面那个(锁屏本身有 `call-to-action-label` 等标识的不算,不会点到锁屏上的通知) | 单测 `a_touch_id_prompt_in_any_language`(三个真机样本换成德文)+ 真机(iPad mini 5 iPadOS 26.7.3 中文:锁屏后自动解锁两次,16.8 秒、15.6 秒;没有在别的语言的真机上试过) | +| 202 | `iphone_press_button` 按 Home 时有系统弹窗挡着:文字里说了,`Outcome::alert_reported` 却一直是 false,MCP 端再做一次弹窗检查、可能重复拼接提示 | `press_button`、`native_home` 返回 (文字, 是否报了弹窗),派发时写进 `alert_reported` | 编译期类型保证(四个报弹窗的返回点都带 true);真机没有造系统弹窗(能造的电话、FaceTime 提示有误拨风险) | +| 203 | `long_press` 在 `Route::Hid`(没有 WDA、手机支持 HID)时直接报 WDA 不可用,WDA 调用中途 `Unavailable` 也不退 HID;点击两种情况都会退 HID | 和点击一样:没有页面坐标(`view`)时走 HID | 真机(iPhone 15 Pro Max iOS 27.2.1 原生:长按照常);`Route::Hid` 这条路两台测试机都走不到(iOS 27 是原生,iPad iOS 26 没有 HID 后备) | +| 204 | `Tap.count`、`TapSequence.points`、`PressButton.button` 和点击、长按、滑动的坐标不在 `check_request` 里查:执行不了的请求先排队拿设备锁,还清掉缓存的元素树 | 在 `check_request` 里先查:次数 1~10、点 1~20 个且都是有限数、按键名认得、坐标是有限数 | 单测 `hopeless_requests_are_refused_up_front` + 真机(count 0、未知按键立刻被拒) | +| 205 | `Touch` 的 `Prepare`(控制台在手指按下前先开 HID 会话)算作设备操作:任务进行中被拒,接管时被当成用户在操作,还会清掉元素缓存、让后台检查等着 | `is_device_action` 对 `Prepare` 返回 false;手指抬起成功后才清 `touch_rotation`(参数被拒的抬起后手指还能抬起) | 单测 `getting_ready_for_a_touch_is_not_acting`、`others_may_look_but_not_act_until_the_user_takes_over` + 真机 | +| 206 | `ScrollCollect` 带 `deny_unknown_fields`:所有请求共用的顶层键(`lang`、`watched`……)和它的字段在同一层,新客户端加一个新键,旧守护进程就只拒这一种请求 | 去掉 `deny_unknown_fields`,和其他请求一样忽略不认识的字段;字段类型不对仍报错 | 单测 `raw_scroll_collect_validates_scope_and_bounds`(原来断言未知字段报错,改成断言被忽略:这是有意放宽) | +| 207 | 存的锁屏密码只查是不是纯数字,手改成不足 4 位也照用(输入逻辑以至少 4 位为前提);`Persisted::save` 序列化失败时写入空文件替换 `state.json`;`NotifyConfig` 派生 `Debug`,打印配置会带出通知密钥 | 不足 4 位报 `NotDigits`;序列化失败什么都不写;`NotifyConfig` 手写 `Debug`,密钥只显示有没有设 | 单测 `notification_keys_stay_out_of_debug_output`、`missing_or_non_digit_passcode`(加了 3 位的情况) | From 284f2f5e16a85d4135839e1726db94b9ef3e409b Mon Sep 17 00:00:00 2001 From: Derrors <33656531+Derrors@users.noreply.github.com> Date: Wed, 25 Nov 2026 22:22:08 +0800 Subject: [PATCH 2/2] docs: say what the PressButton fix changes; long press says "via HID" The MCP server never checked for alerts after a button (wants_alert_check), so the fix fills Outcome::alert_reported for protocol clients; the changelog and regression case said otherwise. A long press done by HID in WDA's place says so, as the other gestures do. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- CHANGELOG.zh-CN.md | 2 +- crates/ictl-daemon/src/tools/input.rs | 10 +++++++++- docs/dev/regression-cases.md | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88ad51b5..6a81d2f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ What changed in each release, one line per change. Versions follow [Semantic Ver ### Fixes -- `iphone_press_button` that finds a system alert in the way says so in a way the MCP server reads, so it no longer checks for the alert a second time (#200). +- When pressing Home finds a system alert in the way, the daemon's answer now also marks it in its structured result (`alert_reported`), as launching an app or opening a link does; programs reading the result rather than its text missed it (#200). - A long press falls back to HID like a tap when WebDriverAgent can't be reached (#200). - Requests that can't run (a tap count of 0, an empty tap sequence, an unknown button, a point that isn't a number) are refused at once, before waiting for the phone and without dropping the cached screen (#200). - The control page getting ready for a touch no longer counts as acting: it isn't refused while an AI task runs and doesn't make the agent look again after you take over (#200). diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 55e150d4..9bf9f9bf 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -16,7 +16,7 @@ ### 修复 -- `iphone_press_button` 发现有系统弹窗挡着时,会以 MCP 服务读得懂的方式报出来,不再重复检查一次弹窗(#200)。 +- 按 Home 时发现有系统弹窗挡着,守护进程的应答现在也会在结构化结果里标出(`alert_reported`),和启动 App、打开链接一样;之前只读结果字段、不看文字的程序会漏掉(#200)。 - 长按和点击一样,连不上 WebDriverAgent 时改用 HID(#200)。 - 执行不了的请求(点击次数为 0、空的点击序列、不认识的按键、坐标不是有效数字)立刻拒绝,不再先排队等手机,也不会清掉缓存的界面(#200)。 - 控制台准备触摸不再算作操作:AI 任务进行中不会被拒,你接管时也不会让 agent 之后重新看一遍(#200)。 diff --git a/crates/ictl-daemon/src/tools/input.rs b/crates/ictl-daemon/src/tools/input.rs index e3310c8b..20d2cf7e 100644 --- a/crates/ictl-daemon/src/tools/input.rs +++ b/crates/ictl-daemon/src/tools/input.rs @@ -470,7 +470,15 @@ impl Daemon { if by_hid { Box::pin(self.native_long_press(g, x, y, seconds)).await?; } - Ok(ictl_l10n::trf!("已长按 ({},{}) {} 秒", "Long-pressed ({},{}) for {} s", fmt_g(x), fmt_g(y), fmt_g(seconds))) + let (px, py, s) = (fmt_g(x), fmt_g(y), fmt_g(seconds)); + // said like the other gestures when HID stood in for WDA (natively it is the way, not a fallback) + if by_hid && !self.native(g) { + return Ok(ictl_l10n::trf!( + "已长按 ({px},{py}) {s} 秒(经 HID)", + "Long-pressed ({px},{py}) for {s} s (via HID)" + )); + } + Ok(ictl_l10n::trf!("已长按 ({px},{py}) {s} 秒", "Long-pressed ({px},{py}) for {s} s")) } pub(crate) async fn swipe( diff --git a/docs/dev/regression-cases.md b/docs/dev/regression-cases.md index f321517c..d2f7bd4b 100644 --- a/docs/dev/regression-cases.md +++ b/docs/dev/regression-cases.md @@ -205,7 +205,7 @@ | 199 | ictl-sign:登录写完 `accounts.json` 不收紧权限;新证书的私钥按默认 umask(0644)写出,要等整包签完才收紧,中途失败就一直是 0644(账号目录本身是 0700,别的用户进不去);调用方超时丢掉签名 future 时 `/tmp/ictl-sign-*` 留在那里;`pack`、`from_app_zip` 直接截断目标文件 | 登录后、证书建好后立刻 `restrict_tree`,签名失败也再收紧一次;临时目录交给 RAII guard 删;打包写到同目录的临时文件、fsync 后改名 | 单测 `a_failed_pack_leaves_the_old_package`、`the_scratch_directory_is_removed_when_dropped`、原有的 `account_tree_is_locked_down`(真机没有重签:重签后 iPad 要用户手输一次密码) | | 200 | macOS 内置编码器(`video/vt.rs`):`Decoder::decode` 拿着解码槽的 `&mut` 跨过 `VTDecompressionSessionDecodeFrame`,回调 `on_decoded` 同时对同一个地方又造了一个 `&mut`,两个活着的可变引用是未定义行为 | FFI 调用前后只经原始指针短暂读写,不持有跨调用的引用 | CI 的 macOS 编译(本机没有 macOS,也没有 darwin 编译目标) | | 201 | 界面语言不是简中或英文的 Touch ID iPad:上滑后的「触控 ID」提示只认「使用密码」「Use Passcode」「Enter Passcode」,认不出就返回 `CoverSheet::None`,锁屏被当成已解锁,`lock_state_trusted` 置真后不再查;自动解锁也找不到「使用密码」按钮 | 按结构认:`SBCoverSheetWindow` 里没有锁屏日期、只有两个按钮就是锁屏;认不出文字时取上下叠在同一条竖线上的两个按钮中上面那个(锁屏本身有 `call-to-action-label` 等标识的不算,不会点到锁屏上的通知) | 单测 `a_touch_id_prompt_in_any_language`(三个真机样本换成德文)+ 真机(iPad mini 5 iPadOS 26.7.3 中文:锁屏后自动解锁两次,16.8 秒、15.6 秒;没有在别的语言的真机上试过) | -| 202 | `iphone_press_button` 按 Home 时有系统弹窗挡着:文字里说了,`Outcome::alert_reported` 却一直是 false,MCP 端再做一次弹窗检查、可能重复拼接提示 | `press_button`、`native_home` 返回 (文字, 是否报了弹窗),派发时写进 `alert_reported` | 编译期类型保证(四个报弹窗的返回点都带 true);真机没有造系统弹窗(能造的电话、FaceTime 提示有误拨风险) | +| 202 | `iphone_press_button` 按 Home 时有系统弹窗挡着:文字里说了,`Outcome::alert_reported` 却一直是 false,和启动 App、打开链接不一致,只读 `Outcome` 的协议客户端会漏判(MCP 端对按键本来就不另查弹窗,不受影响) | `press_button`、`native_home` 返回 (文字, 是否报了弹窗),派发时写进 `alert_reported` | 编译期类型保证(四个报弹窗的返回点都带 true);真机没有造系统弹窗(能造的电话、FaceTime 提示有误拨风险) | | 203 | `long_press` 在 `Route::Hid`(没有 WDA、手机支持 HID)时直接报 WDA 不可用,WDA 调用中途 `Unavailable` 也不退 HID;点击两种情况都会退 HID | 和点击一样:没有页面坐标(`view`)时走 HID | 真机(iPhone 15 Pro Max iOS 27.2.1 原生:长按照常);`Route::Hid` 这条路两台测试机都走不到(iOS 27 是原生,iPad iOS 26 没有 HID 后备) | | 204 | `Tap.count`、`TapSequence.points`、`PressButton.button` 和点击、长按、滑动的坐标不在 `check_request` 里查:执行不了的请求先排队拿设备锁,还清掉缓存的元素树 | 在 `check_request` 里先查:次数 1~10、点 1~20 个且都是有限数、按键名认得、坐标是有限数 | 单测 `hopeless_requests_are_refused_up_front` + 真机(count 0、未知按键立刻被拒) | | 205 | `Touch` 的 `Prepare`(控制台在手指按下前先开 HID 会话)算作设备操作:任务进行中被拒,接管时被当成用户在操作,还会清掉元素缓存、让后台检查等着 | `is_device_action` 对 `Prepare` 返回 false;手指抬起成功后才清 `touch_rotation`(参数被拒的抬起后手指还能抬起) | 单测 `getting_ready_for_a_touch_is_not_acting`、`others_may_look_but_not_act_until_the_user_takes_over` + 真机 |