Run a virtual iPhone on an Apple Silicon Mac.
Swift
Duo: rotate the cover and the inner panel
Jackybb690532fa7e
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex 38c10d7b..521063c8 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -5482,3 +5482,5 @@ The host VM view now derives its input geometry from the active Duo viewport (`a> loop and the off-center sheet.> **Duo display: two displays only (2026-10-29):** `system-springboard-cfw-fold_display` (now titled "Foldable inner display") keeps only the two-display path, and it is always on for iPhone19,4: `libvphonefolddisplay.dylib` checks `hw.machine` in backboardd and SpringBoard instead of the `vphone-duo-inner-display` marker. backboardd: the 2853x2007 `CAWindowServerVirtualDisplay` added from `-[CAWindowServer _detectDisplays]` (server-ready fallback), tagged `unknown`; `DeviceSurfaceType` 1 for the primary and 2 for the inner display through `-[CAWindowServerDisplay extendedProperties]`; `BKHIDDirectTouchEventProcessor` digitizer routing and the 270° position turn while the inner display is lit. SpringBoard: the CADisplay type/pointScale/isExternal adapter with the FrontBoard classification scope, `mainLike` in the inner identity's XPC encoding, the inner screen's idiom, the shared scanout (`-[CADisplayStateControl transitionToDisplayState:withCompletion:]`), the compositor, the content mode resolver hand-over (the resolver is now recorded by a pass-through `-[SBFDisplayContentModeResolver _startResolvingContentModeOfDisplay:]`), and the per-screen `STUIStatusBarGetVisualProviderClassForScreen` detour. Removed hooks: the Main configuration transformer, monitor and identity observers, `SBWindowScene surfaceType`/`sbhScreenType`, `SBWindow _shouldResizeWithScene`, the scene geometry callback, the clock and time-item adapters, the scene status policy, the Main status lookup and status profile factories, `SBHScreenTypeFor*`, `_os_feature_enabled_impl` (`TraitsArbiterWallpaperTokyoDrift`), `PF_IS_PAD_DEVICE`, `_SBWallpaperSecureWindow setHidden:`, the quick-action glyph subclass, the `UIWindow` target-window fallback, the `SBSDeviceDeterminedConfiguration`/`CSProminentLayoutController` loggers, and every `com.vphone.display.*` notification. `libvphoneposterprobe.dylib` (the poster orientation follower) is no longer built, staged, listed in the guest environment, or loaded by SystemHook. Details in `Research/Guest/iphone_duo_bringup.md`.++> **Duo display: flicker, capture and rotation (2026-10-29):** in `system-springboard-cfw-fold_display`, the compositor is now a layer at the top of Main's `UIRootSceneWindow` (points) instead of a display-level `CAContext` (pixels), its hosts sync from a main run loop observer before Core Animation's commit and change only when a value changes, and its per-frame damage alternates two clear colors. New SpringBoard hook: `+[CMMagicPoseManager orientationForMagicPose:deviceSurface:]` answers with `+[CMDeviceStateEvent propertyAForConfigType:propertyA:propertyB:propertyC:]` directly, because the guest has no `CMMagicPoseManager` shared manager and every panel read ambiguous, so neither panel rotated. vphoned's `display.rotation` on a foldable sets the pose orientation for the lit panel. Details in `Research/Guest/iphone_duo_bringup.md`.diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.mdindex 9947a1be..e89fdee4 100644--- a/Research/Guest/iphone_duo_bringup.md+++ b/Research/Guest/iphone_duo_bringup.md@@ -4512,7 +4512,8 @@ publishes the hinge angle (a sweep for `position`, at once otherwise) andreplies with the request's values and the hinge service state, as before.`GuestFoldPose` replays a configured hinge after boot (portrait, the savedangle's hinge state) until SpringBoard reports it, and the latest pose after-each SpringBoard startup. `display.rotation` is the generic iPhone path.+each SpringBoard startup. `display.rotation` went back to the generic iPhone+path here, which turns neither panel; see the rotation section below.To check on the device after this change:@@ -4526,3 +4527,78 @@ To check on the device after this change:the clock reference adapter (it worked around a detached reference viewwith a nil screen; see f7d145ca above).- `display.rotation` while open.++## 2026-10-29: flicker, screenshots and rotation on the two-display path++Verified on duospike-inner (iPhone19,4, iOS 27.1) with a bundle built from+this branch, running the cleaned-up code above.++**Flicker.** Measured with a ScreenCaptureKit capture of the VM window at+120 Hz and per-frame luma. Three causes, each confirmed by its frames:++- The compositor re-set every host's frame and zPosition on each sync pass,+ changed or not; each set made the render server drop every hosted window+ for one frame (a fully black frame, several a second at idle). Hosts are+ now updated only when a value changes.+- Hosts followed SpringBoard's windows on a 250 ms timer, so a window+ SpringBoard showed (the app-launch transition, the app's scene host) had no+ host for up to a quarter second. The sync now runs in a main run loop+ observer just before Core Animation's commit (order 1999999), in the same+ transaction as SpringBoard's own window changes.+- The per-frame damage layer: an opacity flip rendered the container+ offscreen (grey blocks over secure windows); a 1/255 tint alternated the+ panel's brightness at 30 Hz. It alternates between two clear colors.++Rejected while measuring: `setDisablesUpdates:YES` on the inner render+display (inner touch stops: backboardd hit-tests the rendered display) and+`CALayerHost.rendersAsynchronously` (hosts render nothing). Result: 0 black+frames in about 2700 captured frames across idle, taps, scrolling and+home/app transitions.++**Screenshots.** UIKit's screen capture (vphoned's `screen.screenshot`, and the+host's saved screenshot that goes through it) renders display-level contexts+in points, as it renders windows; a context of its own on the display works+in pixels. The compositor was such a context, so a capture with the device+open came out magnified by the screen scale (the top-right third of the inner+display), the way icli already notes for the boot logo. It is now a layer at+the top of Main's `UIRootSceneWindow`, the window Main's scenes are hosted in,+in points like every window (every SpringBoard window measured 669×951 points+with an identity transform). Closed, the capture is the full cover; the old+466×678 cut is gone.++**Rotation.** Neither panel turned: `display.rotation` reported "did not+apply" for the cover and the inner panel alike, in Safari too. The chain:++1. Each panel's traits pipeline (`SBTraitsEmbeddedDisplayPipelineManager`,+ `_surfaceType` 1 for the cover, 2 for the inner panel) takes its device+ orientation from the device pose, per panel:+ `BSDeviceOrientationForSurfaceFromPose(surface, pose)` reads the pose's+ cover or inner orientation, and `poseProvider:didUpdateFromPose:toPose:`+ updates the pipeline only when that per-panel value changes. The+ accelerometer orientation and AssistiveTouch's `setOrientation:` (icli's+ rotation) never reach it.+2. The test-automation pose override (`SBSTestAutomationService+ setDevicePoseOverride:`, which `display.posture` uses) carries one device+ orientation. SpringBoard derives each panel's from it with+ `+[CMMagicPoseManager orientationForMagicPose:deviceSurface:]`.+3. That method asks `+[CMMagicPoseManager sharedManager]` to rebuild a+ `CMDeviceStateEvent` first. The guest has no motion coprocessor, so there+ is no shared manager: the message goes to nil and both panels read+ ambiguous, whatever the pose.+4. The mapping itself is `+[CMDeviceStateEvent+ propertyAForConfigType:propertyA:propertyB:propertyC:]` (configuration =+ surface, A = orientation, B = hinge state, C = tabletop pose). Closed (B 1)+ the cover takes A and the inner panel is ambiguous; partially open or open+ flat (B 2, 3) the inner panel takes A and the cover takes A with landscape+ left/right and face up/down swapped; any other hinge state, including+ `open` 4, is ambiguous. `position: open` sets open flat (3).++FoldDisplay answers `orientationForMagicPose:deviceSurface:` with that+mapping directly, and vphoned's `display.rotation` on a foldable sets the pose+orientation for the lit panel (table in `Research/vphoned_http_api.md`).+Checked: cover 90/270/0 and inner 0/180/270/90 in Safari, each settled with+the interface and the host window upright; the cover home screen stays+portrait, as on any iPhone.++Open: in landscape on the cover, the `AxisAlignableSplitV68Cover` status bar+draws its time and battery over Safari's address field.diff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.mdindex 0b611eae..5dbaa31a 100644--- a/Research/vphoned_http_api.md+++ b/Research/vphoned_http_api.md@@ -1230,8 +1230,14 @@ On the iPhone Duo (iPhone19,4) the fold display patch(`system-springboard-cfw-fold_display`) publishes the inner panel as a seconddisplay, 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.+hinge and does nothing further. `display.rotation` turns a foldable guest+(one with the virtual hinge enabled) through the same pose: it sets the pose+orientation that gives the lit panel the requested interface orientation+(cover: 0 portrait, 90 landscape-right, 180 upside-down, 270 landscape-left;+inner panel, mounted a quarter turn from the cover: 0 landscape-left, 90+portrait, 180 landscape-right, 270 upside-down) and reads the interface back.+The accelerometer and the AssistiveTouch rotation other iPhones use do not+turn a foldable's panels.| Param | Values || --- | --- |diff --git a/VPhoneDaemon/Daemon/GuestAPI+Device.swift b/VPhoneDaemon/Daemon/GuestAPI+Device.swiftindex 5fc5c888..5cb2a3a1 100644--- a/VPhoneDaemon/Daemon/GuestAPI+Device.swift+++ b/VPhoneDaemon/Daemon/GuestAPI+Device.swift@@ -79,6 +79,9 @@ extension GuestAPI {case "display.rotation":rotationLock.lock()defer { rotationLock.unlock() }+ if let orientation = optionalString(params, "orientation"), vp_hinge_get()["enabled"] as? Bool == true {+ return try setFoldableRotation(orientation)+ }if let orientation = optionalString(params, "orientation") {// Preserve the physical pose across SpringBoard relaunches.// CoreMotion's app pose provider cannot feed this HID sink.@@ -296,6 +299,44 @@ extension GuestAPI {return reply}+ /// A foldable guest turns with SpringBoard's device pose: each panel's+ /// traits pipeline reads its own device orientation from the pose, so+ /// neither the accelerometer nor the AssistiveTouch rotation icli drives+ /// turns it. The rotation sets the pose orientation that gives the lit+ /// panel the requested interface orientation — the inner panel is mounted+ /// a quarter turn from the cover — and reads the interface back.+ private static func setFoldableRotation(_ spec: String) throws -> [String: Any] {+ let degreesByName = [+ "0": 0, "portrait": 0, "90": 90, "landscape-left": 90, "left": 90, "180": 180, "upside-down": 180,+ "portrait-upside-down": 180, "270": 270, "landscape-right": 270, "right": 270,+ ]+ guard let degrees = degreesByName[spec.lowercased()] else {+ throw GuestAPIError.invalidRequest("unknown rotation: \(spec)")+ }+ let pose = vp_device_pose_get()+ guard pose["available"] as? Bool == true, let hinge = (pose["hinge"] as? NSNumber)?.int32Value,+ let tabletop = (pose["tabletop"] as? NSNumber)?.int32Value+ else { throw GuestAPIError.operationFailed("SpringBoard's device pose is unavailable") }+ // Pose orientations (poseOrientations) by interface degrees, measured+ // on the cover (hinge closed) and on the inner panel (open).+ let cover: [Int: Int32] = [0: 1, 90: 4, 180: 2, 270: 3]+ let inner: [Int: Int32] = [0: 3, 90: 1, 180: 4, 270: 2]+ GuestFoldPose.cancelStartupRestore()+ defer { GuestFoldPose.finishExplicitRequest() }+ guard vp_device_pose_set((hinge == 1 ? cover : inner)[degrees]!, hinge, tabletop) else {+ throw GuestAPIError.operationFailed("SpringBoard refused the device pose")+ }+ for _ in 0 ..< 20 where interfaceRotationDegrees() != degrees {+ usleep(100_000)+ }+ guard interfaceRotationDegrees() == degrees else {+ throw GuestAPIError.operationFailed("The device did not apply the requested rotation.")+ }+ var info = rotationInfo()+ info["requested"] = degrees+ return info+ }+/// 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.diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayAdapter.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayAdapter.mindex 1dffd66c..0fdbaa1f 100644--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayAdapter.m+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayAdapter.m@@ -192,6 +192,39 @@ static void vpInstallContentModeResolution(void) {vpWatchInnerDisplayResolution();}+// MARK: - orientation++// Each panel's traits pipeline turns with its own device orientation, which+// SpringBoard reads from the device pose per panel+// (BSDeviceOrientationForSurfaceFromPose) and fills in from+// +[CMMagicPoseManager orientationForMagicPose:deviceSurface:]. That asks+// CoreMotion's shared magic pose manager to rebuild a device state event+// first, and this guest has no motion coprocessor, so there is no manager:+// the message goes to nil and every panel reads ambiguous, so neither turns.+// The answer is CMDeviceStateEvent's own mapping of the pose's orientation,+// hinge state and tabletop pose, asked directly.+static long long vpPanelOrientation(id self, SEL selector, id pose, long long surface) {+ long long (*read)(id, SEL) = (long long (*)(id, SEL))objc_msgSend;+ return ((long long (*)(id, SEL, long long, long long, long long, long long))objc_msgSend)(objc_getClass("CMDeviceStateEvent"),+ sel_registerName("propertyAForConfigType:propertyA:propertyB:propertyC:"), surface,+ read(pose, sel_registerName("deviceOrientation")), read(pose, sel_registerName("hingeState")),+ read(pose, sel_registerName("tabletopPose")));+}++static void vpInstallPanelOrientation(void) {+ Method orientation = class_getClassMethod(objc_getClass("CMMagicPoseManager"),+ sel_registerName("orientationForMagicPose:deviceSurface:"));+ Method mapping = class_getClassMethod(objc_getClass("CMDeviceStateEvent"),+ sel_registerName("propertyAForConfigType:propertyA:propertyB:propertyC:"));+ if (!orientation || !mapping || strcmp(method_getTypeEncoding(orientation), "q32@0:8@16q24") != 0 ||+ strcmp(method_getTypeEncoding(mapping), "q48@0:8q16q24q32q40") != 0) {+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: panel orientation ABI unavailable (%s, %s)",+ orientation ? method_getTypeEncoding(orientation) : "missing", mapping ? method_getTypeEncoding(mapping) : "missing"]);+ return;+ }+ method_setImplementation(orientation, (IMP)vpPanelOrientation);+}+// MARK: - installation// Installed before SpringBoard's display monitor reads the render displays.@@ -200,6 +233,7 @@ static void vpInstallContentModeResolution(void) {void vpInstallInnerDisplayAdapter(void) {vpInstallInnerScreenIdiom();vpInstallInnerIdentityEncode();+ vpInstallPanelOrientation();// Type 0 without the FrontBoard scope is a second UIKit-main-like// display, so no scope means no adapter.Method configurationInit = class_getInstanceMethod(objc_getClass("FBSDisplayConfiguration"),