From 32d2816a875b9ba18dcb97ddbf2575a5634ad85e Mon Sep 17 00:00:00 2001 From: abdelrahman fahmy <104788132+Apdelrahman1911@users.noreply.github.com> Date: Sun, 6 Dec 2026 08:16:42 +0000 Subject: [PATCH] fix(ax): exclude com.apple.InputUI from snap.front and rank-0 spaces --- tools/launcher/core/src/ax.rs | 93 ++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/tools/launcher/core/src/ax.rs b/tools/launcher/core/src/ax.rs index 6f483c4d..62906ee3 100644 --- a/tools/launcher/core/src/ax.rs +++ b/tools/launcher/core/src/ax.rs @@ -27,6 +27,7 @@ use std::time::{Duration, Instant}; static TMP_SEQ: AtomicU64 = AtomicU64::new(0); const SPRINGBOARD: &str = "com.apple.springboard"; +const INPUT_UI: &str = "com.apple.InputUI"; /// The system shells that are not apps, per platform: SpringBoard (iOS / iPadOS), PineBoard (tvOS's SpringBoard: /// alerts), Carousel (watchOS: the app grid, the time over apps), visionOS's SurfBoard; the homes that are apps of /// their own: tvOS's HeadBoard (TVSystemUIService: its clock corner), a watch face (com.apple.clockface), visionOS's @@ -1349,11 +1350,11 @@ fn snapshot_once_with_guest_states( h["window"] = json!(wins.get(h["win"].as_u64().unwrap_or(0) as usize).cloned().unwrap_or_default()); snap.hidden.push(h); } - if !is_shell(&bundle) && has_app_content { + if !is_shell(&bundle) && bundle != INPUT_UI && has_app_content { fronts.push((pid, bundle.clone(), state == "active")); } if let Some(sp) = proc_space { - let rank = if bundle != SPRINGBOARD && !is_wallpaper(&bundle) && has_app_content && state == "active" { + let rank = if bundle != SPRINGBOARD && !is_wallpaper(&bundle) && bundle != INPUT_UI && has_app_content && state == "active" { 0 } else if bundle == SPRINGBOARD { 1 @@ -3573,4 +3574,92 @@ mod tests { let _ = server.join(); let _ = std::fs::remove_dir_all(&dir); } + + #[test] + fn inputui_never_wins_front_over_active_app() { + use std::io::{BufRead, BufReader, Write}; + use std::os::unix::net::UnixListener; + + let dir = std::env::temp_dir().join(format!("x86sim-ax-inputui-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let inst = Instance { + id: "fixture-inputui".into(), + dir: dir.clone(), + name: "test".into(), + model: String::new(), + model_id: String::new(), + runtime_dir: String::new(), + runtime_root: dir.clone(), + runtime_present: true, + unavailable: None, + ios: String::new(), + platform: "ios".into(), + build: String::new(), + screen: (390, 844), + scale: 3.0, + corner: 0.0, + ring: dir.join("ring"), + inner: None, + sock: dir.join("simhid.sock"), + state_dir: dir.clone(), + prefix: dir.clone(), + log_dir: dir.clone(), + is_default: false, + udid: "fixture-inputui".into(), + created: 0, + }; + + let kb_sock = dir.join("x86sim-ax-fixture-inputui-150.sock"); + std::fs::write(dir.join("x86sim-ax-fixture-inputui-150.fg"), "com.apple.InputUI\n").unwrap(); + let kb_listener = UnixListener::bind(&kb_sock).unwrap(); + let kb_server = std::thread::spawn(move || { + let mut stream = kb_listener.incoming().next().unwrap().unwrap(); + let mut line = String::new(); + let _ = BufReader::new(&stream).read_line(&mut line); + // InputUI replies immediately (faster than the Compose/UIKit app). + let reply = json!({ + "pid": 150, + "bundle": "com.apple.InputUI", + "state": "active", + "partial": false, + "screen": [390.0, 844.0, 3.0], + "windows": [{"class": "UIWindow", "frame": [0.0, 540.0, 390.0, 304.0], "screen": [390.0, 844.0, 3.0]}], + "elements": [{"oid": "0x10", "role": "key", "label": "a", "focused": false, "enabled": true, "frame": [10.0, 620.0, 32.0, 42.0]}] + }); + let _ = stream.write_all(format!("{reply}\n").as_bytes()); + }); + + let app_sock = dir.join("x86sim-ax-fixture-inputui-250.sock"); + std::fs::write(dir.join("x86sim-ax-fixture-inputui-250.fg"), "com.example.app\n").unwrap(); + let app_listener = UnixListener::bind(&app_sock).unwrap(); + let app_server = std::thread::spawn(move || { + let mut stream = app_listener.incoming().next().unwrap().unwrap(); + let mut line = String::new(); + let _ = BufReader::new(&stream).read_line(&mut line); + std::thread::sleep(Duration::from_millis(60)); + let reply = json!({ + "pid": 250, + "bundle": "com.example.app", + "state": "active", + "partial": false, + "screen": [390.0, 844.0, 3.0], + "windows": [{"class": "UIWindow", "frame": [0.0, 0.0, 390.0, 844.0], "screen": [390.0, 844.0, 3.0]}], + "elements": [{"oid": "0x20", "role": "textfield", "label": "Password", "focused": true, "enabled": true, "frame": [20.0, 200.0, 350.0, 48.0]}] + }); + let _ = stream.write_all(format!("{reply}\n").as_bytes()); + }); + + let opts = SnapOpts { no_ocr: true, timeout_ms: 1000, ..Default::default() }; + let states = HashMap::from([(150, 'S'), (250, 'S')]); + let snap = snapshot_once_with_guest_states(&inst, opts, Some(states)).unwrap(); + assert_eq!(snap.front, vec!["com.example.app".to_string()]); + assert!(!snap.overlay); + assert!(snap.elements.iter().any(|e| e.app == "com.apple.InputUI" && e.role == "key")); + assert!(snap.elements.iter().any(|e| e.app == "com.example.app" && e.role == "textfield")); + + let _ = kb_server.join(); + let _ = app_server.join(); + let _ = std::fs::remove_dir_all(&dir); + } }