Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Duo: fold onto a lit cover and rest the inner panel landscape

Jackyfb1ad8d7937e
diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.md
index 51f1cc69..720e093a 100644
--- a/Research/Guest/iphone_duo_bringup.md
+++ b/Research/Guest/iphone_duo_bringup.md
@@ -3897,3 +3897,20 @@ follow the target degrees. Verified: 90° and 270° both restore after a
closed→open cycle with correct landscape re-flow; a portrait fold cycle
stays portrait. The memory is session state: a reboot restores portrait
through the boot ladder.
+
+Follow-up (state machine rework): the orientation model now matches the
+hardware. The cover has no rotation state — it always presents portrait
+(466×678), and the fold closes onto a LIT cover screen (the earlier
+sleep-on-close made the fold button look like "screen off" and is
+removed; the cover arbiter override keeps portrait upright there for both
+the unlocked layout and the lock screen). The inner panel rests
+LANDSCAPE: its rotated mounting maps the natural device pose (accel 0°)
+to interface landscape-left (90°), so an unfold — and a folded boot —
+presents the inner default directly, and portrait on the inner panel
+stays an explicit rotation. The session-scoped fold rotation memory from
+the previous entry is removed (the default owns the post-unfold state);
+the boot ladder resolves the desired interface per target viewport
+(cover "0", inner "90") and stops only when SpringBoard answers the
+target degrees. Verified: folded boot and every unfold land 90° with a
+correct landscape re-flow; every close lands a lit portrait cover;
+explicit rotations 0/90/270 still settle; 3× cycles green.
diff --git a/VPhoneDaemon/Daemon/GuestAPI+Device.swift b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
index 1b2c49db..45e6f145 100644
--- a/VPhoneDaemon/Daemon/GuestAPI+Device.swift
+++ b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
@@ -8,29 +8,6 @@ import VphonedNative
extension GuestAPI {
private static let rotationLock = NSLock()
- /// The interface orientation the fold last closed with; opening returns
- /// to it so an explicit landscape survives a fold cycle. Session state
- /// only — a reboot restores portrait through the boot pose ladder.
- private nonisolated(unsafe) static var foldRotationMemory: Int?
- private static let foldRotationLock = NSLock()
-
- /// Records a landscape worth restoring; a portrait close clears it.
- private static func rememberFoldRotation() {
- let degrees = interfaceRotationDegrees()
- foldRotationLock.lock()
- foldRotationMemory = (degrees == 90 || degrees == 270) ? degrees : nil
- foldRotationLock.unlock()
- }
-
- /// Consumes the remembered orientation; nil means portrait at rest.
- private static func takeFoldRotation() -> Int? {
- foldRotationLock.lock()
- defer { foldRotationLock.unlock() }
- let degrees = foldRotationMemory
- foldRotationMemory = nil
- return degrees
- }
-
static func executeDevice(_ method: String, _ params: [String: Any]) throws -> [String: Any]? {
switch method {
case "device.info":
@@ -403,14 +380,13 @@ extension GuestAPI {
? vp_hinge_sweep(angle!, durationMs, Int32(profile))
: vp_hinge_set(angle!)
if ((try? deviceSnapshot())?["model"] as? String) == "iPhone19,4" {
- // A fold cycle returns to the orientation it started from:
- // portrait at rest, an explicit landscape survives the close.
- // The cover presents portrait either way; opening replays the
- // remembered direction through the same resolve-and-confirm
- // path. Session state only — a reboot restores portrait.
- if angle! < 5 { rememberFoldRotation() }
- let restoreDegrees = angle! < 5 ? nil : takeFoldRotation()
- let desiredInterface = angle! < 5 ? "0" : restoreDegrees.map(String.init) ?? "0"
+ // The Duo state machine: the cover has no rotation state and
+ // always presents portrait; the inner panel rests landscape —
+ // its rotated mounting maps the natural device pose (accel 0°)
+ // to interface landscape-left (90°), so an unfold presents the
+ // inner default and portrait there stays an explicit rotation
+ // away.
+ let desiredInterface = angle! < 5 ? "0" : "90"
// The cover arbiter derives its direction once, at the mode
// swap, from the scene pipeline's cached device orientation.
// The pose override above wrote portrait (device 1 on the
@@ -543,21 +519,11 @@ extension GuestAPI {
_ = try? setRotation(desiredInterface)
}
}
- // Real hardware blanks the inner panel when the fold closes and
- // the cover presents the lock experience. The single-scene
- // emulation cannot blank one panel, and an unlocked home layout
- // in cover mode keeps whatever direction the mode swap computed
- // from the inner pose — portrait arbitration does not settle
- // there — while the cover lock screen arbitrates portrait
- // natively (every folded boot presents its clock upright). Close
- // through the lock: sleep a lit, unlocked display so the next
- // wake presents the cover lock screen.
- if angle! < 5,
- let lock = ((try? collectDeviceSnapshot())?["lock"] as? [String: Any]),
- (lock["locked"] as? Bool ?? true) == false,
- (lock["screen_off"] as? Bool ?? true) == false {
- _ = try? pressButton("power")
- }
+ // Real hardware closes onto a lit cover screen; the lock
+ // presentation belongs to the sleep button, not to the fold.
+ // The cover arbiter override holds portrait there for both the
+ // unlocked home layout and the lock screen, so no sleep is
+ // needed to keep the folded presentation upright.
}
var hingeState = vp_hinge_get()
hingeState["applied"] = published
diff --git a/VPhoneDaemon/Daemon/GuestFoldPose.swift b/VPhoneDaemon/Daemon/GuestFoldPose.swift
index 64de4d81..8b32f2cd 100644
--- a/VPhoneDaemon/Daemon/GuestFoldPose.swift
+++ b/VPhoneDaemon/Daemon/GuestFoldPose.swift
@@ -122,16 +122,18 @@ private static let restoration = RestoreState()
Thread.sleep(forTimeInterval: delay - waited)
waited = delay
let expectedHinge = hingeState(for: angle)
- // Device 1 is the pose enum's portrait, not the mounted
- // device value: the Duo inner panel presents portrait as
- // device 3 under its rotated mounting. Resolve against the
- // live map; a later rung corrects an early read that still
- // carries the identity fallback table.
- let portraitDevice = (vp_display_orientation_mapping()["deviceOrientations"] as? [Int])
- .flatMap { GuestDisplayRotation.resolve("0", deviceOrientations: $0)?.deviceOrientation } ?? 1
+ // The cover is portrait-only; the inner panel rests
+ // landscape (its rotated mounting maps the natural pose to
+ // interface 90°). Resolve the desired interface against
+ // the live map; a later rung corrects an early read that
+ // still carries the identity fallback table.
+ let desiredInterface = angle < 5 ? "0" : "90"
+ let desiredDevice = (vp_display_orientation_mapping()["deviceOrientations"] as? [Int])
+ .flatMap { GuestDisplayRotation.resolve(desiredInterface, deviceOrientations: $0)?.deviceOrientation }
+ ?? (angle < 5 ? 1 : 4)
let published = restoration.lock.withLock {
guard !restoration.cancelled else { return false }
- _ = vp_device_pose_set(Int32(portraitDevice), Int32(expectedHinge), 0)
+ _ = vp_device_pose_set(Int32(desiredDevice), Int32(expectedHinge), 0)
_ = vp_hinge_set(angle)
requestViewport(for: angle)
restoration.latestPose = poseValues(vp_device_pose_get())
@@ -145,9 +147,10 @@ private static let restoration = RestoreState()
notify_post("com.vphone.display.orientation.arbitration.refresh")
notify_post("com.vphone.display.orientation.actuation.refresh")
let actual = vp_device_pose_get()
+ let targetDegrees = Int(desiredInterface) ?? 0
if actual["available"] as? Bool == true,
actual["hinge"] as? Int == expectedHinge,
- interfaceRotationDegrees() == 0 { return }
+ interfaceRotationDegrees() == targetDegrees { return }
}
}
}