From 440f367b280c926e4853b4b0afef5d2bfb56a3ab Mon Sep 17 00:00:00 2001 From: cosine <1726697408@qq.com> Date: Tue, 17 Nov 2026 15:23:54 +0800 Subject: [PATCH] fix(wda): a first launch behind the privacy notice returns at once The first time a system app such as Notes or Reminders is opened, iOS shows its privacy notice in a separate process (com.apple.PDUIApp) on top of it. /wda/apps/launch waits until XCTest sees the app in the foreground, so it waited the full 60 s, the call failed with a timeout, and the daemon then judged WDA stalled and restarted it: 65 s and a WDA restart for one iphone_launch_app. Launch with /wda/apps/launchUnattached instead, which goes through LSApplicationWorkspace and returns at once, and keep polling the foreground as before. When the foreground is the privacy notice, report it as blocking, like a permission alert. In this state the route answers "failed to launch" although the notice is up, so that answer is treated like a successful launch and the foreground decides. An older WDA without the route falls back to /wda/apps/launch. On an iPhone 12 mini (iOS 26.4.1) launching a never-opened Notes now returns in 0.7 s without a WDA restart; 0.2.7 took 65 s and restarted WDA. Regression case #152. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 + CHANGELOG.zh-CN.md | 2 + crates/ictl-wda/src/client.rs | 72 ++++++++++++++++++++++++++++++++++- docs/dev/regression-cases.md | 1 + 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d433e42..eb3e20e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ What changed in each release, one line per change. Versions follow [Semantic Ver ### Fixes +- Launching a system app for the first time no longer hangs for 60 seconds behind its privacy notice and restarts WDA; it returns at once and says the notice is in the way. + - A WDA probe that answers, even with an error, resets the timeout count instead of accumulating unrelated slow requests into a stall. Recovery logs state the reason, and timeout logs include the endpoint and elapsed time. ## [0.2.7] - 2026-11-15 diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index fa578f6..1d25271 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -12,6 +12,8 @@ ### 修复 +- 第一次启动系统 App 时,不再被隐私说明页卡住 60 秒、还把 WDA 判成卡死重启;马上返回,并说明被说明页挡着。 + - WDA 的短探测正常应答或返回远端错误时清零超时计数,不再把多个独立慢请求累计成卡死;恢复日志写明判定依据,请求超时日志包含端点和耗时。 ## [0.2.7] - 2026-11-15 diff --git a/crates/ictl-wda/src/client.rs b/crates/ictl-wda/src/client.rs index f9d8c44..64938ed 100644 --- a/crates/ictl-wda/src/client.rs +++ b/crates/ictl-wda/src/client.rs @@ -177,6 +177,9 @@ const MJPEG_SCALE: u32 = 100; /// 主屏、锁屏、系统弹窗所属的进程 pub const SPRINGBOARD: &str = "com.apple.springboard"; +/// 系统 App 第一次打开前的隐私说明页(「欢迎使用“备忘录”… 接受并继续」)。它在自己的进程里,盖在要启动的 App 上面, +/// 点了它的按钮 App 才会到前台 +pub const PRIVACY_SHEET: &str = "com.apple.PDUIApp"; /// IOHID 消费者页(Consumer) const HID_PAGE_CONSUMER: u32 = 0x0C; /// 消费者页里的电源键 @@ -204,6 +207,12 @@ pub enum Launch { Slow, } +/// WDA 不认识这个路径(旧版本没有的接口)时的报错,同 [`WdaClient::interface_rotation`] +fn unknown_route(kind: &str, message: &str) -> bool { + matches!(kind, "unknown command" | "unknown method" | "unsupported operation") + || (kind == "http" && matches!(message, "404" | "405")) +} + /// [`WdaClient::check_lock`] 的结果 #[derive(Debug)] pub struct LockCheck { @@ -922,8 +931,19 @@ impl WdaClient { /// 等待期间查前台出错不算失败(启动命令已经成功了) pub async fn launch_app(&mut self, bundle_id: &str) -> Result { let started = tokio::time::Instant::now(); - self.in_session("POST", "/wda/apps/launch", Some(json!({"bundleId": bundle_id})), Duration::from_secs(60)) - .await?; + // 不经 XCTest 启动(LSApplicationWorkspace),发出就返回,到没到前台由下面自己查。`/wda/apps/launch` 要等 XCTest + // 看到 App 在前台:系统 App 第一次打开时隐私说明页盖在上面,它就一直等到 60 秒超时,WDA 也被判卡死重启 + // (iPhone 12 mini,iOS 26.4.1,「备忘录」「提醒事项」都是 65 秒)。这时它回「failed to launch」,说明页已经出来了 + let body = json!({"bundleId": bundle_id}); + match self.call("POST", "/wda/apps/launchUnattached", Some(body.clone()), DEFAULT_TIMEOUT).await { + Ok(_) => {} + Err(WdaError::Remote { message, .. }) if message.contains("failed to launch") => {} + // older WDA without the route: launch as before + Err(WdaError::Remote { kind, message }) if unknown_route(&kind, &message) => { + self.in_session("POST", "/wda/apps/launch", Some(body), Duration::from_secs(60)).await?; + } + Err(e) => return Err(e), + } let t0 = tokio::time::Instant::now(); let deadline = t0 + Duration::from_secs(8); let mut foreground = false; @@ -933,6 +953,15 @@ impl WdaClient { foreground = true; break; } + Ok(a) if a == PRIVACY_SHEET => { + return Ok(Launch::Blocked( + ictl_l10n::tr!( + "第一次打开时的隐私说明页(点「继续」或「接受并继续」后才进入 App)", + "the privacy notice shown on first launch (tap Continue or Accept & Continue to get into the app)" + ) + .into(), + )); + } // 系统弹窗(权限请求)挡着时前台一直是 SpringBoard,原来要白等满 8 秒。 // 刚启动的一瞬间前台也还是 SpringBoard,过 1 秒还是才去查弹窗(查一次约 0.4 秒) Ok(a) if a == SPRINGBOARD && bundle_id != SPRINGBOARD && t0.elapsed() >= Duration::from_secs(1) => { @@ -1237,6 +1266,45 @@ mod tests { assert_eq!(steps.iter().filter(|s| s["type"] == "pointerDown").count(), 1); } + /// 启动不经 XCTest(`launchUnattached`),发出就返回;系统 App 第一次打开时它回 failed to launch,前台是隐私说明页, + /// 马上报被挡住,不再等 60 秒 + #[tokio::test] + async fn a_first_launch_privacy_notice_is_reported_at_once() { + let fail = r#"{"value":{"error":"unknown error","message":"LSApplicationWorkspace failed to launch app"}}"#; + let m = Mock::with(&[(500, fail), (200, r#"{"value":{"bundleId":"com.apple.PDUIApp"}}"#)]); + let mut w = WdaClient::new(&m); + let t0 = std::time::Instant::now(); + let r = w.launch_app("com.apple.mobilenotes").await.unwrap(); + assert!(matches!(r, Launch::Blocked(ref t) if !t.is_empty()), "{r:?}"); + assert!(t0.elapsed() < Duration::from_secs(1)); + let seen = m.seen.lock().unwrap(); + assert_eq!(seen[0].1, "/wda/apps/launchUnattached"); + assert!(seen.iter().all(|(_, p, _)| !p.ends_with("/wda/apps/launch"))); + } + + /// 旧版 WDA 没有 launchUnattached:照旧经会话启动 + #[tokio::test] + async fn an_older_wda_without_unattached_launch_launches_as_before() { + let m = Mock::with(&[ + (404, r#"{"value":{"error":"unknown command","message":"Unhandled endpoint"}}"#), + (200, r#"{"sessionId":"A"}"#), + (200, r#"{"value":null}"#), + (200, r#"{"value":{"bundleId":"com.apple.PDUIApp"}}"#), + ]); + let mut w = WdaClient::new(&m); + assert!(matches!(w.launch_app("com.apple.mobilenotes").await.unwrap(), Launch::Blocked(_))); + let seen = m.seen.lock().unwrap(); + assert_eq!(seen[2].1, "/session/A/wda/apps/launch"); + } + + /// 别的错误照样报出来,不当成启动了 + #[tokio::test] + async fn other_launch_errors_are_errors() { + let m = Mock::with(&[(500, r#"{"value":{"error":"invalid argument","message":"bad bundle"}}"#)]); + let mut w = WdaClient::new(&m); + assert!(matches!(w.launch_app("x").await, Err(WdaError::Remote { .. }))); + } + #[tokio::test] async fn remote_error_keeps_first_line_and_unreachable_maps_to_unavailable() { let m = Mock::with(&[ diff --git a/docs/dev/regression-cases.md b/docs/dev/regression-cases.md index 5f0a9f3..0c39772 100644 --- a/docs/dev/regression-cases.md +++ b/docs/dev/regression-cases.md @@ -149,3 +149,4 @@ | 143 | 原生:Spotlight 打开时选中上次的搜索词,再粘贴同样的词会把它替换成自己,输入框的值不变,`iphone_type_text` 报「粘贴了…但输入框里没有这段文字」(带 `submit` 时还不按回车),其实已经输进去了 | 「允许粘贴」点过之后,输入框原来就有这段文字、1.5 秒不变,算输入成功并提示截图确认;没点过「允许粘贴」时仍报错 | 单测 `a_paste_that_replaced_the_same_text_is_told_apart_from_one_that_missed` + 真机(Spotlight 留着「设置」时再输入「设置」,`run.py` 连跑两遍);真机脚本 `scenarios.py typing` | | 144 | 设备闲置时自动锁屏,下一个操作先自动解锁(iPad 经 WDA 约 15 秒,iPhone 原生约 9 秒),结果和事件日志都没说,看着像「切换设备后第一个操作慢」 | 结果第一行(截图在说明里、出错时在报错里)写「手机锁着,先自动解锁了,用时 X 秒」,事件日志记「已自动解锁」 | 单测 `an_unlock_first_is_said_on_the_answers_first_line` + 真机(锁屏后按名字点击、截图,两台设备);真机脚本 `scenarios.py lock` | | 145 | WDA 的短探测已正常应答或返回远端错误,却不清零超时计数,三个独立慢请求仍会触发重启;连接失败反而清零。日志还把长请求和短探测均未应答写成「连续 3 次」、宣称尚未检查的 `/status` 正常,请求超时本身缺端点日志 | 只有正常响应或远端错误清零,连接失败不清零;连续无应答和长请求后的失败探测分别记录原因及实际次数;超时诊断记录方法、短路径和耗时,不记录查询参数或正文 | 单测 `answered_probe_resets_stall_count_after_each_slow_request`、`connection_error_does_not_reset_unanswered_count`、`long_request_and_failed_probe_keep_the_actual_count_and_reason`、`three_short_unanswered_requests_report_a_consecutive_stall`、`answered_session_delete_does_not_mask_a_failed_probe`、`failed_request_log_keeps_endpoint_and_time_without_query`、`successful_request_log_does_not_include_response_body`;真机:同一 iPad、同一 WDA,把只读业务请求的客户端时限缩短到 20ms,短探测保留 5s,对照修复前后各 3 轮 | +| 152 | 第一次启动系统 App(备忘录、提醒事项)时,系统先在另一个进程(`com.apple.PDUIApp`)里显示隐私说明页盖在上面;`/wda/apps/launch` 要等 XCTest 看到 App 到前台,一直等到 60 秒超时,接着 WDA 被判卡死重启,`iphone_launch_app` 报超时(65 秒) | 先用 `/wda/apps/launchUnattached`(不经 XCTest,发出就返回),再照旧轮询前台:前台是隐私说明页就马上报「被挡住」,结果和权限弹窗一样提示先点它的按钮;它回「failed to launch」时说明页已经出来,照样往下查;旧版 WDA 没有这个接口时退回 `/wda/apps/launch` | 单测 `a_first_launch_privacy_notice_is_reported_at_once`、`an_older_wda_without_unattached_launch_launches_as_before`、`other_launch_errors_are_errors` + 真机(iPhone 12 mini,iOS 26.4.1:没打开过的「备忘录」0.7 秒返回、WDA 不重启,0.2.7 是 65 秒并重启 WDA;冷启动「时钟」后马上点标签页照常点中)|