Skip to content

Control a real USB-connected iPhone from Linux (no Mac, no paid developer account) and expose it to AI agents as MCP tools

fix(daemon): no HID fallback is said before any orientation check (#98)

Qinghe Li13b0b26ae8cc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f3f41fa..2660a82 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ All notable changes to this project are documented here. The format is based on
### Fixed
+- Without WDA, a device below iOS 27 (no HID fallback) is told so at once for taps, swipes and touches, like every other action, instead of an orientation error after a needless screenshot that suggested turning it to portrait.
- A confirmation (`iphone_confirm`, or a step outside a task's apps) no longer cancels the user's pause or takeover: it is asked once the task runs again. Two at once are asked in turn; before, the first was counted as rejected and the second couldn't be answered.
- A step the agent sent just before the user paused or took over no longer runs after it; a tap of the user's sent just before handing back no longer runs after that.
- After the user handed back, the agent has to have actually seen the screen (a screenshot that worked) before acting.
diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md
index 23b199b..5568015 100644
--- a/CHANGELOG.zh-CN.md
+++ b/CHANGELOG.zh-CN.md
@@ -19,6 +19,7 @@
### 修复
+- WDA 不可用时,iOS 27 以下的设备(没有 HID 后备)做点按、滑动、触摸会立刻说明没有 HID 后备,和其他操作一样;不再白截一张图后报横竖屏的错,还让人"转回竖屏"。
- 确认(`iphone_confirm`,或任务范围外的一步)不再冲掉你的暂停或接管:等任务恢复运行后才问。同时出现两个确认时依次问;原来第一个会被记成拒绝,第二个无法回答。
- 你暂停或接管前 agent 刚发出的一步,不会在暂停或接管之后才执行;你交还前刚发出的点按,也不会在交还之后才执行。
- 你交还控制后,agent 必须真的看过屏幕(截图成功)才能操作。
diff --git a/crates/ictl-daemon/src/tools/input.rs b/crates/ictl-daemon/src/tools/input.rs
index e4f69e0..e999777 100644
--- a/crates/ictl-daemon/src/tools/input.rs
+++ b/crates/ictl-daemon/src/tools/input.rs
@@ -92,6 +92,13 @@ impl Daemon {
g.dev.last_rotation = Some((Instant::now(), r));
r
}
+ // no HID fallback below iOS 27: as `send_touch` says it, so the page sends the whole gesture
+ None if !hid_supported(g.info.as_ref()) => {
+ return Err(Response::Error {
+ message: wda_down(&g.state, g.info.as_ref()),
+ retry_as_gesture: true,
+ });
+ }
None => self.hid_touch_rotation(g).await.map_err(Response::error)?,
}
};
diff --git a/crates/ictl-daemon/src/tools/mod.rs b/crates/ictl-daemon/src/tools/mod.rs
index 2c86a03..af7f7f7 100644
--- a/crates/ictl-daemon/src/tools/mod.rs
+++ b/crates/ictl-daemon/src/tools/mod.rs
@@ -84,7 +84,12 @@ impl Daemon {
/// 每次 HID 触摸前重新截图核对横竖,不依赖上次截图(转屏、回主屏、解锁都可能改变方向)。
/// 截图只给宽高,不能分辨横屏左右;短暂掉线时借用近期实测方向,过期或不匹配就不触摸。
+ /// A device below iOS 27 has no HID fallback: said at once, like every other action, not after a screenshot
+ /// whose orientation doesn't matter (it used to answer "landscape without a fresh WDA rotation… or turn it")
async fn hid_touch_rotation(&self, g: &mut Inner) -> crate::error::Result<Rotation> {
+ if !hid_supported(g.info.as_ref()) {
+ return Err(wda_down(&g.state, g.info.as_ref()).into());
+ }
self.sample_display(g, false).await;
let png = self.hid_screenshot(g).await.map_err(|e| {
ictl_l10n::trf!(
@@ -376,6 +381,28 @@ mod tests {
std::fs::remove_dir_all(dir).unwrap();
}
+ /// Without WDA, a device below iOS 27 gets the usual "no HID fallback" for taps, swipes and a finger, at once:
+ /// not an orientation error after a screenshot (iPad mini 5, iPadOS 26: "turn it to portrait")
+ #[tokio::test]
+ async fn no_hid_fallback_is_said_before_any_orientation_check() {
+ let (d, dir) = crate::core::tests::test_daemon("no-hid-touch");
+ let mut g = d.inner.lock().await;
+ g.info = Some(ictl_device::DeviceInfo { product_version: "26.7.3".into(), ..Default::default() });
+ g.state = crate::machine::DeviceState::WdaStarting { last_error: None };
+ let down = |e: &str| e.contains("没有 HID 后备路线") || e.contains("no HID fallback");
+ let tap = d.tap(&mut g, 20., 50., None).await.unwrap_err().to_string();
+ assert!(down(&tap), "{tap}");
+ let swipe = d.swipe(&mut g, (20., 50.), (20., 300.), 0.3, None).await.unwrap_err().to_string();
+ assert!(down(&swipe), "{swipe}");
+ // a finger: the same, and the page may still send the whole gesture once WDA is back
+ match d.touch(&mut g, TouchPhase::Down, 20., 50., None).await {
+ Err(Response::Error { message, retry_as_gesture: true }) => assert!(down(&message), "{message}"),
+ other => panic!("{other:?}"),
+ }
+ assert!(g.dev.touch_rotation.is_none());
+ std::fs::remove_dir_all(dir).unwrap();
+ }
+
#[test]
fn hid_rotation_requires_fresh_matching_landscape() {
use Rotation::*;