Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

vphoned: let SpringBoard resolve the Duo posture itself

Jackyde7201af2c26
diff --git a/Documents/Guides/launchpad-cli.md b/Documents/Guides/launchpad-cli.md
index aa3cb93b..a1305a00 100644
--- a/Documents/Guides/launchpad-cli.md
+++ b/Documents/Guides/launchpad-cli.md
@@ -195,9 +195,5 @@ and headless launches. `display.geometry.capture_pixels` is the raw host
frame; `screenshot_pixels` and `input_orientation` describe input coordinates.
A swipe keeps the geometry sampled at its start.
-For Duo logical viewports, host socket full screenshots and tap/swipe pixel
-coordinates use the active upright viewport when fresh guest `display.geometry`
-is available. HID normalization still uses the physical framebuffer. Geometry
-changes across a screenshot cause an error rather than returning an image with
-ambiguous input coordinates. The native GUI viewport integration is separate
-from this automation contract and is still under validation.
+Geometry changes across a screenshot cause an error rather than returning an
+image with ambiguous input coordinates.
diff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.md
index b101fd1c..0b611eae 100644
--- a/Research/vphoned_http_api.md
+++ b/Research/vphoned_http_api.md
@@ -1226,6 +1226,13 @@ which needs the foldable's own `product-id` in the device tree
it; that is the half CoreDevice's `hingeAngle` stream reads, because
CoreDevice does not go through SpringBoard.
+On the iPhone Duo (iPhone19,4) the fold display patch
+(`system-springboard-cfw-fold_display`) publishes the inner panel as a second
+display, and SpringBoard picks the posture policy from the pose itself:
+`FoldingDual` open, `FullyClosed` closed. vphoned publishes the pose and the
+hinge and does nothing further; `display.rotation` takes the same path as on
+any other iPhone.
+
| Param | Values |
| --- | --- |
| `hinge` (required) | `ambiguous` 0, `closed` 1, `partially-open` 2, `open-flat` 3, `open` 4 |
@@ -1272,29 +1279,3 @@ properties, plus up to4096 bytes per available report descriptor as base64.
No HID event is dispatched. `available=false` reports missing native APIs or
failure to create the read client. Absent properties are omitted; their absence
does not establish a zero range. Service metadata is not a touch-hit receipt.
-
-### `display.orientation_mapping` (read-only)
-
-Requests the active SpringBoard scene's native inverse orientation permutation.
-Returns the newly generated scene/surface/bounds and `deviceOrientations`
-(indexed by UIKit interface orientation1...4), or `available=false`; stale
-records are not accepted. The fold-display adapter must be selected/loaded.
-On iPhone19,4, `display.rotation` uses this native map to keep the SBS physical
-pose and gravity coherent with the requested logical interface direction,
-retaining hinge/tabletop and reading back the applied pose. Other models use
-their existing rotation path.
-
-### `display.geometry` (read-only)
-
-Reads one fresh SpringBoard main-queue snapshot through the existing orientation
-mapping handshake. Returns `available`, `pid`, `generatedUptime`, `scene`,
-`bounds` (UIScreen points), `configurationBounds` (canonical logical display
-points), `coordinateBounds` (scene points), `scale`, `interfaceOrientation`
-(UIKit1...4), `viewportGeneration`, `surfaceType`, and `deviceOrientations`.
-`available:false` means no fresh matching SB-main snapshot; do not use a cached
-file as current geometry. The physical framebuffer is a separate host value.
-Older guest components may omit the added geometry fields; consumers must
-validate presence before using them. This differs from the host socket's
-`t:display.geometry` diagnostics. `device.screen` may retain the boot extent
-while a logical viewport changes and is not authoritative for Duo viewport
-cropping or input normalization.
diff --git a/VPhoneDaemon/Daemon/GuestAPI+Device.swift b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
index b4043833..5fc5c888 100644
--- a/VPhoneDaemon/Daemon/GuestAPI+Device.swift
+++ b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
@@ -86,89 +86,13 @@ extension GuestAPI {
let previousPose = (accelerometer["degrees"] as? NSNumber).map { String($0.intValue) }
let publishesPose = accelerometer["provider_running"] as? Bool == true
let previousInterface = interfaceRotationDegrees()
- var mappedRotation: GuestDisplayRotation?
- var originalDevicePose: [String: Any]?
- if ((try? deviceSnapshot())?["model"] as? String) == "iPhone19,4" {
- let mapping = vp_display_orientation_mapping()
- let pose = vp_device_pose_get()
- guard mapping["available"] as? Bool == true,
- let values = mapping["deviceOrientations"] as? [Int],
- let resolved = GuestDisplayRotation.resolve(orientation, deviceOrientations: values),
- pose["available"] as? Bool == true,
- pose["device_orientation"] is NSNumber, pose["hinge"] is NSNumber, pose["tabletop"] is NSNumber
- else {
- throw GuestAPIError.operationFailed("The active Duo scene orientation map or pose is unavailable")
+ if publishesPose {
+ guard vp_accelerometer_set_orientation(orientation) else {
+ throw GuestAPIError.operationFailed("Could not publish the accelerometer orientation")
}
- mappedRotation = resolved
- originalDevicePose = pose
}
- defer {
- if mappedRotation != nil { GuestFoldPose.finishExplicitRequest() }
- }
- var devicePosePublished = false
do {
- if let mappedRotation, let originalDevicePose {
- GuestFoldPose.cancelStartupRestore()
- guard vp_device_pose_set(
- Int32(mappedRotation.deviceOrientation),
- (originalDevicePose["hinge"] as! NSNumber).int32Value,
- (originalDevicePose["tabletop"] as! NSNumber).int32Value
- ) else { throw GuestAPIError.operationFailed("Could not publish the mapped Duo device pose") }
- devicePosePublished = true
- }
- if publishesPose {
- let physicalSpec = mappedRotation.map { String($0.accelerometerDegrees) } ?? orientation
- guard vp_accelerometer_set_orientation(physicalSpec) else {
- throw GuestAPIError.operationFailed("Could not publish the accelerometer orientation")
- }
- }
- if mappedRotation != nil {
- // The Duo scene's inverse mounting map is native and
- // does not itself enqueue UIKit's orientation
- // arbitration. Publish the same bounded refresh
- // sequence used by the native pose pipeline before
- // waiting for SpringBoard's scene receipt. The
- // pose-refresh channel re-reads the just-set device
- // orientation; inputs.refresh leaves the pipeline on
- // its previous value and the settle times out.
- _ = try? postDarwinNotification("com.vphone.display.orientation.mapping.request", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.orientation.arbitration.refresh", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.orientation.actuation.refresh", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.presentation.wallpaper.pulse", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.presentation.clock.refresh", state: nil)
- }
- var result: [String: Any]
- if let mappedRotation {
- // The foldable pose transition is asynchronous. An AX
- // forced rotation during that transition can race it;
- // accept the native scene's receipt instead.
- let deadline = ProcessInfo.processInfo.systemUptime + 2
- while interfaceRotationDegrees() != mappedRotation.interfaceDegrees,
- ProcessInfo.processInfo.systemUptime < deadline {
- Thread.sleep(forTimeInterval: 0.05)
- }
- guard interfaceRotationDegrees() == mappedRotation.interfaceDegrees else {
- throw GuestAPIError.operationFailed("The Duo scene did not settle at the requested orientation")
- }
- // Reassert only the already-settled angle: this also
- // refreshes Icli's upright screenshot geometry and
- // synchronizes the pointer without driving the fold.
- result = try setRotation(orientation)
- } else {
- result = try setRotation(orientation)
- }
- if let mappedRotation, let originalDevicePose {
- let actual = vp_device_pose_get()
- guard actual["device_orientation"] as? Int == mappedRotation.deviceOrientation,
- actual["hinge"] as? Int == originalDevicePose["hinge"] as? Int,
- actual["tabletop"] as? Int == originalDevicePose["tabletop"] as? Int
- else { throw GuestAPIError.operationFailed("The mapped Duo pose did not apply") }
- result["physical_pose"] = actual
- result["accelerometer_degrees"] = mappedRotation.accelerometerDegrees
- }
- broadcastInterfaceOrientation()
- return result
+ return try setRotation(orientation)
} catch {
// A refused rotation leaves the guest as it was. The pose
// is persisted, and a refused request still turns iPadOS's
@@ -176,35 +100,11 @@ extension GuestAPI {
// left the interface portrait and the pointer upside down,
// so the mouse ran backwards. Asking again for the
// interface's own orientation turns the pointer back.
- let ownsGravity = mappedRotation.map { vp_accelerometer_get()["degrees"] as? Int == $0.accelerometerDegrees } ?? true
- if publishesPose, ownsGravity, let previousPose {
+ if publishesPose, let previousPose {
_ = vp_accelerometer_set_orientation(previousPose)
}
- if devicePosePublished, let mappedRotation, let originalDevicePose {
- let current = vp_device_pose_get()
- if current["device_orientation"] as? Int == mappedRotation.deviceOrientation,
- current["hinge"] as? Int == originalDevicePose["hinge"] as? Int,
- current["tabletop"] as? Int == originalDevicePose["tabletop"] as? Int {
- _ = vp_device_pose_set(
- (originalDevicePose["device_orientation"] as! NSNumber).int32Value,
- (originalDevicePose["hinge"] as! NSNumber).int32Value,
- (originalDevicePose["tabletop"] as! NSNumber).int32Value
- )
- }
- }
if let previousInterface {
- if mappedRotation == nil {
- _ = try? setRotation(String(previousInterface))
- } else {
- let deadline = ProcessInfo.processInfo.systemUptime + 2
- while interfaceRotationDegrees() != previousInterface,
- ProcessInfo.processInfo.systemUptime < deadline {
- Thread.sleep(forTimeInterval: 0.05)
- }
- if interfaceRotationDegrees() == previousInterface {
- _ = try? setRotation(String(previousInterface))
- }
- }
+ _ = try? setRotation(String(previousInterface))
}
throw error
}
@@ -214,8 +114,6 @@ extension GuestAPI {
return rotation
case "display.orientation":
return interfaceOrientation()
- case "display.orientation_mapping", "display.geometry":
- return vp_display_orientation_mapping()
case "display.posture":
return try setDevicePose(params)
case "display.pose":
@@ -360,7 +258,7 @@ extension GuestAPI {
}
}
- let hinge = try value("hinge", names: poseHingeStates, range: 0 ... 4, default: angle.map(angleToHingeState))
+ let hinge = try value("hinge", names: poseHingeStates, range: 0 ... 4, default: angle.map(hingeState(for:)))
let orientation = try value("orientation", names: poseOrientations, range: 0 ... 6, default: 1)
let tabletop = try value("tabletop", names: [:], range: 0 ... 10, default: 0)
if angle == nil {
@@ -383,158 +281,11 @@ extension GuestAPI {
let published = sweep
? vp_hinge_sweep(angle!, durationMs, Int32(profile))
: vp_hinge_set(angle!)
- if ((try? deviceSnapshot())?["model"] as? String) == "iPhone19,4" {
- // 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
- // identity-mounted cover), but the pipeline only re-reads it
- // through the pose-refresh channel; without the poke the swap
- // still sees the inner panel's rotated portrait (device 3) and
- // latches the cover landscape with no later channel able to
- // reopen arbitration. The same channel feeds the accelerometer
- // seed below; both land on SpringBoard's queue ahead of the
- // viewport apply posted right after.
- if angle! < 5 {
- _ = vp_accelerometer_set_orientation("0")
- _ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)
- } else if let seed = GuestDisplayRotation.resolve(desiredInterface, deviceOrientations: [3, 4, 2, 1])
- ?? GuestDisplayRotation.resolve("0", deviceOrientations: [3, 4, 2, 1]) {
- // Opening carries the same problem in reverse: the swap
- // derives the inner interface from the cover's portrait pose
- // (device 1), which the rotated inner mounting renders as
- // landscape-left. The live export cannot carry the inner
- // table while the cover viewport holds the scene, so seed
- // the measured inner table's device value for the desired
- // interface (portrait is device 3 / 270°); the post-swap
- // loop re-resolves from the live table either way.
- let current = vp_device_pose_get()
- _ = vp_device_pose_set(
- Int32(seed.deviceOrientation),
- (current["hinge"] as? NSNumber)?.int32Value ?? Int32(hinge),
- (current["tabletop"] as? NSNumber)?.int32Value ?? Int32(tabletop)
- )
- _ = vp_accelerometer_set_orientation(String(seed.accelerometerDegrees))
- _ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)
- }
- GuestFoldPose.requestViewport(for: angle!)
- let expected = angle! < 5 ? [0.0, 0.0, 466.0, 678.0] : [0.0, 0.0, 669.0, 951.0]
- let deadline = ProcessInfo.processInfo.systemUptime + 3
- var applied = false
- repeat {
- let geometry = vp_display_orientation_mapping()
- if geometry["available"] as? Bool == true,
- geometry["persistentViewport"] as? Bool == true,
- let bounds = geometry["configurationBounds"] as? [NSNumber],
- bounds.map(\.doubleValue) == expected {
- applied = true
- break
- }
- Thread.sleep(forTimeInterval: 0.05)
- } while ProcessInfo.processInfo.systemUptime < deadline
- guard applied else { throw GuestAPIError.operationFailed("Duo logical viewport did not reach the requested size") }
-
- // A fold transition changes the active panel's native mounting
- // map (inner [3,4,2,1], cover identity). The map JSON refreshes
- // on the next export tick, so the first read after the viewport
- // lands can still carry the previous panel's table: resolving
- // portrait against the stale inner table picks device 3, which
- // the identity-mounted cover panel renders as landscape. Ask
- // for a fresh export, resolve against it, and confirm through
- // SpringBoard's own interface answer, re-resolving once with
- // the settled table when the first pick mounts sideways.
- if orientation == Self.poseOrientations["portrait"] {
- var settled = false
- for pass in 0..<2 where !settled {
- if pass > 0 {
- // The first pass pokes immediately with the best
- // table it has; only a failed confirmation waits
- // for a post-apply export to settle the table.
- let staleUptime = (vp_display_orientation_mapping()["generatedUptime"] as? NSNumber)?.doubleValue ?? 0
- _ = try? postDarwinNotification("com.vphone.display.orientation.mapping.request", state: nil)
- let exportDeadline = ProcessInfo.processInfo.systemUptime + 0.8
- while ProcessInfo.processInfo.systemUptime < exportDeadline {
- let live = vp_display_orientation_mapping()
- if ((live["generatedUptime"] as? NSNumber)?.doubleValue ?? 0) > staleUptime,
- (live["configurationBounds"] as? [NSNumber])?.map(\.doubleValue) == expected { break }
- Thread.sleep(forTimeInterval: 0.05)
- }
- }
- if let values = vp_display_orientation_mapping()["deviceOrientations"] as? [Int],
- let portrait = GuestDisplayRotation.resolve(desiredInterface, deviceOrientations: values) {
- let current = vp_device_pose_get()
- _ = vp_device_pose_set(
- Int32(portrait.deviceOrientation),
- (current["hinge"] as? NSNumber)?.int32Value ?? Int32(hinge),
- (current["tabletop"] as? NSNumber)?.int32Value ?? Int32(tabletop)
- )
- _ = vp_accelerometer_set_orientation(String(portrait.accelerometerDegrees))
- // The pipeline re-reads the device pose only through
- // the pose-refresh channel; inputs.refresh leaves the
- // previous panel's value latched, which is exactly how
- // a cover swap kept the interface landscape.
- _ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.orientation.arbitration.refresh", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.orientation.actuation.refresh", state: nil)
- let confirmDeadline = ProcessInfo.processInfo.systemUptime + 1.2
- while ProcessInfo.processInfo.systemUptime < confirmDeadline {
- if interfaceRotationDegrees() == portrait.interfaceDegrees {
- settled = true
- break
- }
- Thread.sleep(forTimeInterval: 0.05)
- }
- }
- }
- // A hinge sweep re-derives the cover direction once more when
- // it crosses the fully-closed band near its end; hold the
- // portrait actuation until the sweep has finished.
- if sweep {
- let sweepDeadline = ProcessInfo.processInfo.systemUptime + 2.5
- while ProcessInfo.processInfo.systemUptime < sweepDeadline {
- let hingeNow = vp_hinge_get()
- if (hingeNow["sweeping"] as? Bool) != true { break }
- Thread.sleep(forTimeInterval: 0.05)
- }
- _ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.orientation.arbitration.refresh", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.orientation.actuation.refresh", state: nil)
- let targetDegrees = Int(desiredInterface) ?? 0
- if interfaceRotationDegrees() != targetDegrees {
- Thread.sleep(forTimeInterval: 0.3)
- _ = try? postDarwinNotification("com.vphone.display.orientation.actuation.refresh", state: nil)
- }
- }
- _ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.orientation.arbitration.refresh", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.orientation.actuation.refresh", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.presentation.wallpaper.pulse", state: nil)
- _ = try? postDarwinNotification("com.vphone.display.presentation.clock.refresh", state: nil)
- if !settled {
- // Reuse the same public rotation path once the new panel
- // is fully selected; it resolves the post-fold map again
- // instead of relying on a stale pre-transition snapshot.
- _ = try? setRotation(desiredInterface)
- }
- }
- // 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
- broadcastInterfaceOrientation()
+ var hingeHID = vp_hinge_get()
+ hingeHID["applied"] = published
var reply: [String: Any] = [
"hinge": hinge, "orientation": orientation, "tabletop": tabletop,
- "angle": angle!, "hinge_hid": hingeState,
+ "angle": angle!, "hinge_hid": hingeHID,
]
if sweep {
reply["sweep"] = [
@@ -548,7 +299,7 @@ extension GuestAPI {
/// The hinge state a settled angle reports: closed under 5°, open flat
/// from 170°, partially open between — the bands Apple's recorded Duo
/// samples hold.
- private static func angleToHingeState(_ angle: Double) -> Int {
+ static func hingeState(for angle: Double) -> Int {
if angle < 5 { return 1 }
if angle >= 170 { return 3 }
return 2
@@ -569,20 +320,6 @@ extension GuestAPI {
}
return state
}
-
- /// Publishes SpringBoard's live interface degrees for the wallpaper and
- /// poster extension processes: their hosted scenes never see the host's
- /// rotation (measured stuck at portrait across a landscape pass), and the
- /// per-second orientation map can lag, so the settled value rides the
- /// notify state where the extension followers read it.
- static func broadcastInterfaceOrientation() {
- // The extension followers read the interface code (1 portrait,
- // 2 upside-down, 3 landscape-right, 4 landscape-left) off the
- // notification state; degrees 0/180/270/90 map onto it directly.
- guard let degrees = interfaceRotationDegrees() else { return }
- let code = [0: 1, 180: 2, 270: 3, 90: 4][degrees] ?? 1
- _ = try? postDarwinNotification("com.vphone.display.orientation.broadcast", state: UInt64(code))
- }
}
// MARK: - Network configuration
diff --git a/VPhoneDaemon/Daemon/GuestDisplayRotation.swift b/VPhoneDaemon/Daemon/GuestDisplayRotation.swift
deleted file mode 100644
index c2819ee7..00000000
--- a/VPhoneDaemon/Daemon/GuestDisplayRotation.swift
+++ /dev/null
@@ -1,25 +0,0 @@
-import Foundation
-
-/// Interface requests use UIKit orientation codes; the native scene supplies
-/// the inverse device map, including a foldable panel's mounting transform.
-struct GuestDisplayRotation: Equatable, Sendable {
- let interfaceDegrees: Int
- let deviceOrientation: Int
- let accelerometerDegrees: Int
-
- static func resolve(_ spec: String, deviceOrientations: [Int]) -> Self? {
- guard deviceOrientations.count == 4, Set(deviceOrientations) == Set(1 ... 4) else { return nil }
- let interfaceOrientation: Int
- switch spec.lowercased() {
- case "0", "portrait": interfaceOrientation = 1
- case "90", "landscape-left", "left": interfaceOrientation = 4
- case "180", "upside-down", "portrait-upside-down": interfaceOrientation = 2
- case "270", "landscape-right", "right": interfaceOrientation = 3
- default: return nil
- }
- let device = deviceOrientations[interfaceOrientation - 1]
- let degrees = [1: 0, 2: 180, 3: 270, 4: 90][device]!
- let interfaceDegrees = [1: 0, 2: 180, 3: 270, 4: 90][interfaceOrientation]!
- return Self(interfaceDegrees: interfaceDegrees, deviceOrientation: device, accelerometerDegrees: degrees)
- }
-}
diff --git a/VPhoneDaemon/Daemon/GuestFoldPose.swift b/VPhoneDaemon/Daemon/GuestFoldPose.swift
index 8b32f2cd..436c5025 100644
--- a/VPhoneDaemon/Daemon/GuestFoldPose.swift
+++ b/VPhoneDaemon/Daemon/GuestFoldPose.swift
@@ -1,5 +1,4 @@
import Foundation
-import IcliKit
import notify
import VphonedNative
@@ -10,16 +9,14 @@ import VphonedNative
/// with it at shutdown — and the virtual hinge preference, which survives
/// but is only read when the provider enumerates. A rebooted guest that had
/// the pose open therefore starts with the hinge reporting open while
-/// SpringBoard still holds its default pose, until the pose is set again;
-/// SpringBoard's own VM-sub-type restore path cannot stand in, because its
-/// `SBFDevicePoseLastKnown*` defaults are written on display-mode
-/// transitions, which a single display never makes (measured 2026-10-25:
-/// they stay zero). Retry until SpringBoard reports the restored pose, but
-/// cancel immediately when an explicit request supersedes the boot snapshot.
+/// SpringBoard still holds its default pose, until the pose is set again.
+/// Retry until SpringBoard reports the restored hinge state, but cancel
+/// immediately when an explicit request supersedes the boot snapshot. A
+/// SpringBoard restart drops the override too, so the latest pose is
+/// replayed after each SpringBoard startup.
///
-/// Only a guest whose hinge was configured is touched. The home grid itself
-/// still needs a working display-content transition; this restore does not
-/// establish one. See Research/Guest/iphone_duo_bringup.md.
+/// Only a guest whose hinge was configured is touched. See
+/// Research/Guest/iphone_duo_bringup.md.
enum GuestFoldPose {
private final class RestoreState: @unchecked Sendable {
let lock = NSLock()
@@ -30,11 +27,7 @@ enum GuestFoldPose {
var observerInstalled = false
}
-private static let restoration = RestoreState()
-
- static func requestViewport(for angle: Double) {
- notify_post(angle < 5 ? "com.vphone.display.viewport.apply.cover" : "com.vphone.display.viewport.apply.inner")
- }
+ private static let restoration = RestoreState()
/// A new explicit request supersedes the boot snapshot. Serialize this
/// with publication so an in-flight retry cannot overwrite the request.
@@ -84,18 +77,10 @@ private static let restoration = RestoreState()
restoration.lock.withLock {
guard restoration.generation == generation, !restoration.explicitRequest,
let pose = restoration.latestPose,
- vp_hinge_get()["enabled"] as? Bool == true else { return }
- if let angle = vp_hinge_get()["angle"] as? Double {
- if poseValues(vp_device_pose_get()) != pose {
- _ = vp_device_pose_set(pose[0], pose[1], pose[2])
- // The pipeline re-reads the pose only through
- // this channel; feed it before the viewport
- // apply so the swap arbitrates from the pose.
- notify_post("com.vphone.display.orientation.pose.refresh")
- NSLog("vphoned: replay latest fold pose after SpringBoard startup")
- }
- requestViewport(for: angle)
- }
+ vp_hinge_get()["enabled"] as? Bool == true,
+ poseValues(vp_device_pose_get()) != pose else { return }
+ _ = vp_device_pose_set(pose[0], pose[1], pose[2])
+ NSLog("vphoned: replay latest fold pose after SpringBoard startup")
}
}
}
@@ -116,50 +101,23 @@ private static let restoration = RestoreState()
guard hinge["enabled"] as? Bool == true, let angle = hinge["angle"] as? Double else { return }
observeSpringBoardStartup()
NSLog("vphoned: fold pose restore: %.0f° over the boot ladder", angle)
+ let expectedHinge = GuestAPI.hingeState(for: angle)
DispatchQueue.global(qos: .utility).async {
var waited: TimeInterval = 0
for delay in attemptDelays {
Thread.sleep(forTimeInterval: delay - waited)
waited = delay
- let expectedHinge = hingeState(for: angle)
- // 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(desiredDevice), Int32(expectedHinge), 0)
+ _ = vp_device_pose_set(1, Int32(expectedHinge), 0)
_ = vp_hinge_set(angle)
- requestViewport(for: angle)
restoration.latestPose = poseValues(vp_device_pose_get())
return true
}
guard published else { return }
- // The running scene re-reads the device pose only through
- // the pose-refresh channel; without the poke the pipeline
- // keeps whatever direction it held before the restore.
- notify_post("com.vphone.display.orientation.pose.refresh")
- 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() == targetDegrees { return }
+ if actual["available"] as? Bool == true, actual["device_orientation"] as? Int == 1, actual["hinge"] as? Int == expectedHinge { return }
}
}
}
-
- /// SpringBoard's hinge-state bands: closed below 5°, open-flat from 170°,
- /// partially open between.
- private static func hingeState(for angle: Double) -> Int {
- if angle < 5 { return 1 }
- if angle >= 170 { return 3 }
- return 2
- }
}
diff --git a/VPhoneDaemon/Native/Include/VphonedNative.h b/VPhoneDaemon/Native/Include/VphonedNative.h
index f5a0d08e..bdc0b065 100644
--- a/VPhoneDaemon/Native/Include/VphonedNative.h
+++ b/VPhoneDaemon/Native/Include/VphonedNative.h
@@ -202,8 +202,6 @@ NSArray * _Nonnull vp_display_probe(void);
/// Read-only CoreAnimation display modes and capability surface.
NSDictionary<NSString *, id> * _Nonnull vp_display_modes(void);
NSDictionary<NSString *, id> * _Nonnull vp_device_pose_get(void);
-/// Fresh read-only inverse orientation map exported by the active SB scene.
-NSDictionary<NSString *, id> * _Nonnull vp_display_orientation_mapping(void);
BOOL vp_hinge_set(double angleDegrees);
/// Sweep the hinge to `targetDegrees` the way Apple's Duo tooling does: over
/// a profiled transition (0 continuous fold, 1 fade-in-out), `durationMs` < 0
diff --git a/VPhoneDaemon/Native/vphoned_pose.m b/VPhoneDaemon/Native/vphoned_pose.m
index 33568713..af2007e7 100644
--- a/VPhoneDaemon/Native/vphoned_pose.m
+++ b/VPhoneDaemon/Native/vphoned_pose.m
@@ -67,22 +67,6 @@ NSDictionary<NSString *, id> *vp_device_pose_get(void) {
@"tabletop": @(pose.tabletopPose)};
}
-NSDictionary<NSString *, id> *vp_display_orientation_mapping(void) {
- NSTimeInterval requested = NSProcessInfo.processInfo.systemUptime;
- notify_post("com.vphone.display.orientation.mapping.request");
- NSString *path = @"/var/mobile/Library/Caches/vphone-display-orientation-map.json";
- for (unsigned int attempt = 0; attempt < 15; attempt++) {
- NSData *data = [NSData dataWithContentsOfFile:path];
- id record = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL] : nil;
- if ([record isKindOfClass:NSDictionary.class] && [record[@"version"] isEqual:@1] &&
- [record[@"generatedUptime"] isKindOfClass:NSNumber.class] &&
- [record[@"generatedUptime"] doubleValue] >= requested && [record[@"scene"] isEqual:@"SB-main"])
- return record;
- usleep(10000);
- }
- return @{@"available": @NO, @"reason": @"active native scene orientation map unavailable"};
-}
-
/* The virtual hinge publishes one coherent preference dictionary per update. */
NSDictionary *vp_hinge_get(void) {
CFPreferencesSynchronize(CFSTR(VP_HINGE_DOMAIN), CFSTR("mobile"), kCFPreferencesAnyHost);
diff --git a/VPhoneDaemon/Tests/LogicTests.swift b/VPhoneDaemon/Tests/LogicTests.swift
index c03625d7..93126615 100644
--- a/VPhoneDaemon/Tests/LogicTests.swift
+++ b/VPhoneDaemon/Tests/LogicTests.swift
@@ -37,7 +37,6 @@ enum LogicTests {
dataMigrationRecord()
deviceNameRule()
pointerScroll()
- displayRotationMapping()
processSpawnPolicy()
bootstrapPlatform()
setupAssistantState()
@@ -457,29 +456,3 @@ enum LogicTests {
expect(!GuestBootstrapPlatform.isTVOS, "the Mac is not tvOS")
}
}
-
-extension LogicTests {
- static func displayRotationMapping() {
- let specs = ["0", "90", "180", "270"]
- let coverDevices = [1, 4, 2, 3]
- let innerDevices = [3, 1, 4, 2]
- let innerDegrees = [270, 0, 90, 180]
- for index in specs.indices {
- let cover = GuestDisplayRotation.resolve(specs[index], deviceOrientations: [1, 2, 3, 4])
- expectEqual(cover?.deviceOrientation, coverDevices[index], "cover uses native toll-free map")
- expectEqual(cover?.accelerometerDegrees, Int(specs[index]), "ordinary gravity direction is preserved")
- let inner = GuestDisplayRotation.resolve(specs[index], deviceOrientations: [3, 4, 2, 1])
- expectEqual(inner?.deviceOrientation, innerDevices[index], "inner uses measured native inverse map")
- expectEqual(inner?.accelerometerDegrees, innerDegrees[index], "inner gravity and device pose agree")
- expectEqual(inner?.interfaceDegrees, Int(specs[index]), "receipt stays in logical interface degrees")
- }
- for (alias, canonical) in [("portrait", "0"), ("LEFT", "90"), ("portrait-upside-down", "180"), ("right", "270")] {
- expectEqual(GuestDisplayRotation.resolve(alias, deviceOrientations: [3, 4, 2, 1]),
- GuestDisplayRotation.resolve(canonical, deviceOrientations: [3, 4, 2, 1]), "existing rotation aliases")
- }
- expect(GuestDisplayRotation.resolve("45", deviceOrientations: [1, 2, 3, 4]) == nil, "unknown rotation is refused")
- expect(GuestDisplayRotation.resolve("0", deviceOrientations: [1, 1, 3, 4]) == nil, "non-invertible native map is refused")
- expect(GuestDisplayRotation.resolve("0", deviceOrientations: [1, 2, 3, 5]) == nil, "invalid device orientation is refused")
- expect(GuestDisplayRotation.resolve("0", deviceOrientations: [1, 2]) == nil, "partial native map is refused")
- }
-}
diff --git a/VPhoneDaemon/Tests/run-logic-tests.sh b/VPhoneDaemon/Tests/run-logic-tests.sh
index 48575107..bd1cbe10 100755
--- a/VPhoneDaemon/Tests/run-logic-tests.sh
+++ b/VPhoneDaemon/Tests/run-logic-tests.sh
@@ -16,7 +16,6 @@ trap '/bin/rm -rf "$temporary"' EXIT
"$daemon/Daemon/GuestFirstBootSettle.swift" \
"$daemon/Daemon/GuestDeviceNameRule.swift" \
"$daemon/Daemon/GuestPointerScroll.swift" \
- "$daemon/Daemon/GuestDisplayRotation.swift" \
"$daemon/Daemon/GuestProcessSpawnPolicy.swift" \
"$daemon/Daemon/Bootstrap/GuestBootstrapPlatform.swift" \
"$daemon/Daemon/GuestSetupAssistantState.swift" \
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift
index fed4b3b1..608c19f0 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift
@@ -195,8 +195,8 @@ class VPhoneVirtualMachineWindowController: NSObject, NSWindowDelegate {
timers.append(Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in
Task { @MainActor in self?.pollOrientation() }
})
- // Duo uses live logical viewports. Do not hide its cover screen
- // behind the old single-panel fold chrome.
+ // A Duo guest shows its lit panel itself, so it takes no fold
+ // chrome.
control.observeFoldAngle { [weak self] angle, duration in
guard let self, !self.foldableGuest else { return }
self.displayContainer?.setFold(angle: angle ?? 180, duration: duration)
@@ -296,44 +296,6 @@ class VPhoneVirtualMachineWindowController: NSObject, NSWindowDelegate {
orientationPollInFlight = true
Task {
defer { orientationPollInFlight = false }
- if foldableGuest,
- let geometry = try? await control.call("display.geometry"),
- geometry["available"] as? Bool == true,
- !control.isChangingOrientation,
- let bounds = geometry["configurationBounds"] as? [NSNumber], bounds.count == 4,
- let container = displayContainer, let window = displayWindow {
- // On Duo the native scene geometry can retain its portrait
- // UIKit code while SpringBoard's logical orientation has
- // already settled (the inverse mounting map owns that
- // direction). Read the authoritative orientation endpoint
- // first; use geometry's code only for older guests.
- let orientationResult = try? await control.call("display.orientation")
- let orientation = orientationResult?.int("degrees")
- .flatMap(VPhoneDisplayOrientation.init(degrees:))
- ?? (geometry["interfaceOrientation"] as? NSNumber)
- .flatMap { [1: 0, 2: 180, 3: 270, 4: 90][$0.intValue] }
- .flatMap(VPhoneDisplayOrientation.init(degrees:))
- guard let orientation else { return }
- let active = CGSize(width: bounds[2].doubleValue, height: bounds[3].doubleValue)
- let backing = container.backingPanelSize
- if bounds[0].doubleValue == 0, bounds[1].doubleValue == 0,
- (active == CGSize(width: 466, height: 678) || active == CGSize(width: 669, height: 951)),
- active.width <= backing.width, active.height <= backing.height {
- let changedPanel = panelSize != active
- panelSize = active
- container.panelSize = active
- control.interfaceOrientation = orientation
- // A rotation keeps the panel and only turns the guest;
- // the window must follow the orientation change itself,
- // not just a fold's panel-size change.
- if changedPanel {
- applyOrientation(orientation, to: window, force: true)
- } else if container.orientation != orientation {
- applyOrientation(orientation, to: window, force: false)
- }
- return
- }
- }
guard let result = try? await control.call("display.orientation"),
!control.isChangingOrientation,
let degrees = (result["degrees"] as? NSNumber)?.intValue,
@@ -705,10 +667,8 @@ class VPhoneVirtualMachineWindowController: NSObject, NSWindowDelegate {
} catch {
VPhoneAlert.present(title: VPhoneLocalization.text("Duo Fold Posture"), message: error.localizedDescription, style: .warning)
}
- // The window must take the new panel immediately: waiting for
- // the orientation poll leaves the inner-aspect window showing
- // the whole framebuffer for up to a second, with the folded
- // state reading as a black band under the cover content.
+ // The posture can turn the interface; read it now rather than on
+ // the next poll.
self.pollOrientation()
self.updateFoldButton(position: control.foldPosition, connected: control.isConnected)
}
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneHostAutomationServer.swift b/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneHostAutomationServer.swift
index 12d8cea6..49be92f0 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneHostAutomationServer.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneHostAutomationServer.swift
@@ -435,21 +435,6 @@ class VPhoneHostAutomationServer {
let view = windowedView
let panel = view?.recordingGraphicsDisplay?.sizeInPixels ?? CGSize(width: screenWidth, height: screenHeight)
guard panel.width > 0, panel.height > 0 else { throw HostControlError.inputGeometryUnavailable }
- if let control, control.isConnected,
- let snapshot = try? await control.rpcAfterQueuedInput("display.geometry"),
- snapshot["available"] as? Bool == true {
- guard let bounds = snapshot["configurationBounds"] as? [NSNumber], bounds.count == 4,
- bounds[0].doubleValue == 0, bounds[1].doubleValue == 0,
- let scale = snapshot["scale"] as? NSNumber, scale.doubleValue == 3,
- let code = (snapshot["interfaceOrientation"] as? NSNumber)?.intValue,
- let degrees = [1: 0, 2: 180, 3: 270, 4: 90][code],
- let orientation = VPhoneDisplayOrientation(degrees: degrees),
- let viewport = VPhoneDisplayViewport(panel: panel,
- active: CGSize(width: bounds[2].doubleValue * scale.doubleValue,
- height: bounds[3].doubleValue * scale.doubleValue), orientation: orientation)
- else { throw HostControlError.inputGeometryUnavailable }
- return viewport
- }
if let control, control.isConnected,
let result = try? await control.rpcAfterQueuedInput("display.orientation"),
let degrees = (result["degrees"] as? NSNumber)?.intValue,