Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Keep unlocking at startup until the Lock Screen has come and gone

Jacky4fa2e447b587
diff --git a/Research/Guest/screen_unlock.md b/Research/Guest/screen_unlock.md
index ed669f18..4a1773be 100644
--- a/Research/Guest/screen_unlock.md
+++ b/Research/Guest/screen_unlock.md
@@ -105,6 +105,29 @@ device, not a failed unlock. The very first reading after a boot can say
"unlocked, lit" before SpringBoard has started (see step 1 above), so a check
has to watch for a while, not trust one sample.
+On a second guest (`unlockpr-iphone`, same build, 2026-10-05) one start with
+the setting on stayed locked: the log read `[unlock] the guest was already
+unlocked`. `com.apple.springboard.finishedstartup` was already set, yet the
+two notify states still read unlocked, and the Lock Screen came up a few
+seconds after `screen.unlock` had returned. So the host does not take
+"already unlocked" at startup as final: it polls `device.screen` once a
+second and calls `screen.unlock` again when the Lock Screen appears, for up to
+90 s after the connect (`VPhoneGuestControl.unlockAtStartup`). With that:
+
+| Guest | Setting | Lock state every 3 s after `vm start --wait` (L locked, u unlocked) |
+| --- | --- | --- |
+| `unlockpr-iphone`, iOS 27.0, three starts in a row | on | `Luuuuuuuuuuuuuuuuuuu` then L (Auto-Lock) each time |
+| `unlockpr-ipad`, iPad16,1, iPadOS 26.6.2 23G90 | off | `LLLLLLLLLLLLLLLLLLLLLLLLL` |
+| `unlockpr-ipad` | on | `Luuuuuuuuuuuuuuuuuuuuuuuu` |
+
+Device › Unlock at Startup in the VM window checked itself, wrote
+`unlocksAtStartup = true` to config.plist at once, left the running guest
+locked, and the next start unlocked it.
+
+Setting a passcode on these guests through Settings did not work: every
+entry, by taps on the pad, by coordinates or as keyboard input, ended in
+"Passcodes Did Not Match". The passcode path therefore stays unmeasured.
+
## Not yet measured
- **Passcode guests.** Setting a passcode on a research guest is not
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlSystem.swift b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlSystem.swift
index a90da89d..fb49a6cf 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlSystem.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlSystem.swift
@@ -65,16 +65,38 @@ extension VPhoneGuestControl {
/// SpringBoard on a cold boot; the method waits for SpringBoard itself, so
/// it is given the longest timeout it takes. A guest with a passcode
/// refuses without one and stays locked: the passcode is never stored.
+ ///
+ /// SpringBoard can still read "unlocked, lit" after it reports that it has
+ /// started, before it raises the Lock Screen, and `screen.unlock` then has
+ /// nothing to do. So an answer that the guest was already unlocked is
+ /// checked again until the Lock Screen appears or the startup window ends.
func unlockAtStartup() async {
+ let window = ContinuousClock.now + .seconds(90)
do {
- let result = try await call("screen.unlock", params: ["timeout": 60])
- if result["was_locked"] as? Bool == true {
- print("[unlock] dismissed the Lock Screen at startup")
- } else {
- print("[unlock] the guest was already unlocked")
+ while true {
+ let result = try await call("screen.unlock", params: ["timeout": 60])
+ if result["was_locked"] as? Bool == true {
+ print("[unlock] dismissed the Lock Screen at startup")
+ return
+ }
+ guard try await waitForLockScreen(until: window) else {
+ print("[unlock] the guest stayed unlocked through startup")
+ return
+ }
}
} catch {
print("[unlock] could not unlock the guest at startup: \(error)")
}
}
+
+ /// Whether the guest shows its Lock Screen before `deadline`.
+ private func waitForLockScreen(until deadline: ContinuousClock.Instant) async throws -> Bool {
+ while ContinuousClock.now < deadline {
+ try await Task.sleep(for: .seconds(1))
+ if try await call("device.screen")["locked"] as? Bool == true {
+ return true
+ }
+ }
+ return false
+ }
}
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift
index bf992041..23486ea6 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift
@@ -241,7 +241,8 @@
{"name":"research-01","cpuCount":8,"memoryMB":8192,"diskSizeBytes":64000000000,
"network":{"mode":"nat","macAddress":"5a:94:ef:12:30:01"},
"restoreInfo":{"ios":{"version":"26.4.2","build":"23E261"},"cloudOS":{"version":"26.4","build":"23E224"},"variant":"jb","device":"iPhone99,11"},
- "udid":"00008140-001A2B3C4D5E6F70"},
+ "udid":"00008140-001A2B3C4D5E6F70",
+ "unlocksAtStartup":true},
{"name":"ios27-rc","cpuCount":8,"memoryMB":12288,"diskSizeBytes":128000000000,
"network":{"mode":"nat","macAddress":"5a:94:ef:12:30:02"}},
{"name":"frida-lab","cpuCount":6,"memoryMB":8192,"diskSizeBytes":64000000000,