Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Duo: drive DeviceHub's fold controls and draw book right

Jackyb74916c953cb
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index a6506fb6..919c83de 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -1602,7 +1602,7 @@ do NOT execute these).
| 23 | No binary change: `libvcamcaptured.dylib`, which SystemHook already loads into `cameracaptured`, rewrites the `bl PrewarmThreadSafeSBPs` in `__FigCapturePreloadShadersInternal_block_invoke_2` to `nop` in the daemon's own memory. This runs from the dylib's constructor and only when the paravirtual Metal driver is installed — **all bases** | none (guest dylib `VPhoneGuestComponents/VCamCaptured/Prewarm/`, installed at `/usr/lib/libvcamcaptured.dylib`) | **Stop `cameracaptured` crashing at every boot, and the SpringBoard freeze that follows.** At launch the daemon preloads its shaders. `PrewarmThreadSafeSBPs` runs each video processor's `-prewarm`, and NRFV3's reaches `-[ToneMappingCurves initWithWithContext:]`, which fills textures made from a shared `MTLHeap` with `-replaceRegion:…`. The cloudOS 26.4 `AppleParavirtGPUMetalIOGPUFamily` never sets `_dimension` (a texture's CPU layout) in `-initWithHeap:resource:offset:length:descriptor:`, and `-replaceRegion:` loads it unchecked, so the daemon faults with `KERN_INVALID_ADDRESS` at `0xc` (measured on `iPad16,1 26.6.2 (23G90)`, `standard`: launchd at `successive crashes = 6`). While the daemon crash-loops, SpringBoard's main thread blocked in a synchronous XPC to it as soon as an app started recording. The daemon does have a Metal device, so `kernel-exp-paravirt_user_clients` does not help. Prewarming is only an optimisation, and nothing waits on that function: no return value, no global, no signal. The rest of the preload (processor flags, data migration, and the deferred shader cache copy, whose semaphore deferred processing waits on) is kept. The call site is found from the exported `FigCapturePreloadShaders`: its `b` to the internal function, that function's one `adrp/add/pacia x16` block invoke, then the block's one `ldr x0, [xN, #0x20]; bl` into CMCapture's `__text`. That gives `0x1aeb2fd68` on 23G90 and `0x1b0759d10` on 24A435. Any mismatch leaves the prewarm in place and logs the step that failed. Host test: `make -C VPhoneGuestComponents test-vcam-prewarm`. Validation: `vcamcaptured.log` has `gpu prewarm: … skipped`, no new `cameracaptured` crash report, and `successive crashes = 0`. See `Research/Guest/gpu_acceleration.md` ("Heap Textures Have No CPU Layout"). | Y | Y | Y |
| 24 | No binary change: both spawn hooks insert `libbatteryhealthfix.dylib` into `Settings` (`/Applications/Preferences.app/Preferences`) beside SystemHook, where it interposes `IOPSCopyPowerSourcesInfo`, `IOPSCopyPowerSourcesByType`, `IOPSCopyPowerSourcesByTypePrecise`, `notify_register_check` / `notify_get_state` / `notify_cancel` and `MGGetBoolAnswer` — **all bases** | none (new guest dylib `VPhoneGuestComponents/BatteryHealthFix/libbatteryhealthfix.c`, installed at `/usr/lib/libbatteryhealthfix.dylib`) | **Stop Settings → Battery → Battery Health & Charging loading forever.** The VM's battery is Virtualization.framework's synthetic power source (charge and connectivity only), and the health half of a real battery's description comes from AppleSmartBattery, which no VM has. Measured on `iPhone17,3 27.0 (24A435)`: powerd's internal battery description has one `BatteryPacks` entry holding only `PackID`, `Cycle count` and `Transport Type`, no `Battery Service State`/`Flags` or `Maximum Capacity Percent` anywhere, and `com.apple.thermalmonitor.ageAwareMitigationState` stays 0. `-[BatteryHealthUIController specifiers]` asks `-[BatteryHealthUIInformation batteryDataUnavailable]`, which answers YES while `+getManagementState` is 0, while no pack parses (`-[BatteryHealthUIPackInformation initWithPowerSourceInformation:]` drops a pack without service flags and state), or while the overall genuine status is -1 — and it is -1 because `MGGetBoolAnswer("D6/BMDrlb8V3WSiqL8gL+w")` (HasBatteryModuleAuth, `+[PLGestaltUtilities hasBatteryModuleAuth]`) answers 1 on the guest, sending `+genuineBatteryStatusForPackIndex:` to an `AppleBatteryAuth`/`AppleAuthCPRelay` service that does not exist. The controller then shows its global spinner and re-asks on a timer. iPadOS 26.6.2 (23G90) has the same gate in `+[BatteryUIResourceClass batteryDataUnavailable]`, reading the flat keys of `IOPSCopyPowerSourcesByType`'s array, the same notify name and the same MobileGestalt key. The hook answers as a new battery without battery authentication: each internal-battery description is copied with `Battery Service State` 0, `Battery Service Flags` 0, `Maximum Capacity Percent` 100 and `Cycle count` 0 at the top level, and each of powerd's packs (or one new pack) completed with a `BatteryHealth` dictionary of the same three numbers plus `Date of manufacture`/`Date of first use` (the birth time of `/private/var/mobile`, i.e. the restore); keys already present are never replaced, and a description that already has them is passed through. A mitigation state of 0 on a token registered for the age-aware name reads as 2 ("supporting normal peak performance"). HasBatteryModuleAuth reads as no only while `IOServiceGetMatchingService("AppleBatteryAuth")` finds nothing. Interposing reaches the callers because `BatteryUsageUI.bundle` is a standalone Mach-O bound through dyld's interposing table (cache-to-cache calls are not; see `MISFix/MISFixSignature.c`), and inserting it — rather than SystemHook `dlopen`ing it like row 21 — is what puts the table in place before the bundle loads. `vpInsertedLibraryFor` in `Shared/InjectionEnvironment.h` picks it or libmisfix for a path; the two target sets do not overlap. Ships with `system-launchdaemons-boot-environment`; existing guests get it from the vphoned environment update on their next start with the new bundle (offline `cfw update-environment` only replaces libraries a VM already has). launchd starts Settings itself, so it is the launchd hook that inserts it: a guest updated only by that online sync needs one more reboot before launchd runs the new hook, which the update already reports as `reboot_required`; an offline environment update replaces the hook before boot. **Validated (2026-10-04, `bhtest-iphone`, `iPhone17,3 27.0 (24A435)` + cloudOS 26.4):** before, the page showed only the spinner and the two charging switches; after, Maximum Capacity 100%, Peak Performance Capability "Your battery is currently supporting normal peak performance", the two switches, no spinner; the hook's log shows all three answers taken once per process. Re-checked on the final bundle after a reboot of the same guest, with the launchd hook logging `inserted+batteryhealthfix` for each Settings launch. **iPad16,1 26.6.2 (23G90), `bhtest-ipad`, created with the new bundle:** the hook is inserted and stays inert, and Settings runs without a crash; that iPad has no Battery Health page at all, because `-[BatteryUIController setUpBatteryHealthGroup]` offers the row only on an iPhone or, through `+[PLBatteryUIBackendModel shouldShowModifiedHealthController]`, on an iPad that supports the fixed charge limit with the `PerfPowerServices/battery_health_details` feature on — the model decides, as on hardware. The 26.x gate inside the page is from static analysis; no 26.x iPhone image was at hand to run it. | Y | Y | Y |
| 25 | No binary change: `libvcamcaptured.dylib` stops every other thread in `cameracaptured` (`task_threads` + `thread_suspend`, self excluded, one patcher at a time) around each `vcc_patch_word` / `vcc_patch_two_nops` text rewrite — **all bases** | none (guest dylib `VPhoneGuestComponents/VCamCaptured/Image/VCamCodePatch.m`, installed at `/usr/lib/libvcamcaptured.dylib`) | **Stop the hook's own runtime patching from crashing `cameracaptured`, which froze the whole VM when the camera was opened.** The hook rewrites CMCapture shared-cache `__text` through `vm_protect(RW|COPY)` → write → `vm_protect(RX)`; for the whole flip the 16K page carries no execute permission, and the pages it touches (the `-12783` error-code sites, the master-clock gate, the prewarm call) are live XPC server code. Two crash reports caught a thread fetching an instruction in a page mid-flip while the patching thread was in `vcc_patch_word` on the same boot: `ipad-mini-01` `cameracaptured-2026-10-03-045638.ips` died in `__FigFlashlightGetClassID_block_invoke` on `com.apple.coremedia.flashlight(34)-messages`, and `ipad-pro-13` `cameracaptured-2026-10-04-225558.ips` died in `captureSourceServer_handleRegisterNotificationForProprietaryDefaultChangesMessage` on `com.apple.coremedia.capturesource(523)-messages` — the register-for-source-changes XPC that camera enumeration itself sends. Both are `EXC_BAD_ACCESS (SIGBUS)`, `KERN_PROTECTION_FAILURE` on an instruction fetch, in a region snapshotted `r-x/rwx`, `SM=COW` (the rwx max-protection is the flip's fingerprint). The card: with row 23 removing the boot crash, any later `cameracaptured` restart (jetsam, another crash) while a camera client reconnects sends its first XPCs straight into the +3 s reinstall window; one SIGBUS → launchd throttles → every AVCapture client, SpringBoard's main thread included, blocks forever in a synchronous XPC — the "VM 卡死" report of 2026-10-05. The stopped section is exactly two `vm_protect` calls, the word write and `sys_icache_invalidate`: no locks, no allocation, no logging, so a frozen thread holding any userspace lock cannot deadlock the patcher; every `vcc_log` moved after the resume, and a mutex serialises patchers (constructor prewarm patch vs the +3 s install block). All five runtime text-patching call sites (`vcc_scan_and_patch` ×2, the prewarm NOP, the session-hook pair, the source-installation NOPs) funnel through the two fixed functions. Validation: kill-and-relaunch stress with Camera.app auto-reconnecting (the same collision that produced both crashes) produces no new `cameracaptured` crash report, and the boot log's `patch_word OK` lines are unchanged. See `Research/Guest/virtual_camera_transport.md` ("The patch race that froze the whole VM"). | Y | Y | Y |
-| 26 | No binary change: both spawn hooks insert `libdevicehubfix.dylib` into `cryptexd`, the DDI's `dtremotedisplayd` and `dtdeviceinfod`, and `avconferenced`. In `cryptexd` it interposes `fcntl` and reports an `EPERM` from `F_SETPROTECTIONCLASS` as `ENOTSUP`; in `dtremotedisplayd` it interposes `MediaStreamSupportedFeatures.current` (answers `0x8c`) and `CurrentDevice.isCustomerRestricted` (answers false) from the DDI's `CoreDeviceUtilities`; in `dtdeviceinfod` it interposes `MGCopyAnswer` and fills a missing `FramebufferIdentifier` for `phone11` chrome, and stands in for CoreMotion's `CMAngleManager` and `CMDeviceStateManager` (the foldable hinge and pose DeviceHub draws from); in `avconferenced` it replaces `VCPSideCarMetal`'s two band reads through the Objective-C runtime and runs one synchronous scaler transform before the first read of each frame — **all bases** | none (new guest dylib `VPhoneGuestComponents/DeviceHubFix/libdevicehubfix.c`, installed at `/usr/lib/libdevicehubfix.dylib`) | **Let Xcode 27's DeviceHub show the guest's screen.** On iOS 27 `cryptexd` stages each DDI asset with `open(O_RDWR)` + `fcntl(F_SETPROTECTIONCLASS, 4)` and accepts only `ENOTSUP` as a failure; a guest answers `EPERM` (`set protection class: [1: Operation not permitted]`, `staging failed`), so CoreDevice shows the device as "connected (no DDI)" for good. With the DDI mounted, DeviceHub asks `dtremotedisplayd` for its media stream features and gets 0 from CoreDeviceUtilities' policy: `isCustomerRestricted` (`isProductionFused && !hasInternalOSBuild && hasInternalDDI == false`) refuses every pre-27.0 device, and remote control is limited to iPhone, Apple Watch and Apple TV, which refuses every iPad. `0x8c` is what a Mac host reports for itself (mirrored primary display 0x4, system audio 0x8, display information 0x80). The 27.x iPhone guest reports `phone11` chrome with no `FramebufferIdentifier`, so DeviceHub drew the screen over the bezel corners; the hook answers only that missing key with Xcode's matching mask `4E5532ED-1470-47D1-BDF4-7AA90C26957A` from `/Library/Developer/DeviceKit/chrome_map.plist`. Interposing reaches all of them because `cryptexd`, `dtremotedisplayd`, `dtdeviceinfod` and `CoreDeviceUtilities` are standalone images; the two Swift symbols are weak flat-namespace imports, resolving to nothing outside `dtremotedisplayd`. On 27.x the view also needs row 11's conditional dispatch, or the capture display stays black. A stream that splits each frame into four bands (`tilesPerFrame` 4) deadlocked the host GPU within 16–35 s of screen activity: `VCPSideCarMetal` reads every frame once per band while the paravirtual scaler's write of that frame can still be unregistered on the host, and a band read that registers the first of the frame's two planes before the write and the second after it waits on the write, which waits on it (`Timeout in timestamp wait`, the guest loses its GPU). Waiting for one synchronous transform puts the band reads behind the frame's write. `VideoProcessing` is in the shared cache, so this part is a method replacement, not an interpose. Ships with `system-launchdaemons-boot-environment`; an existing guest gets it from the environment update. Details: `Research/Guest/devicehub_screen_viewing.md`. **Validated (2026-10-06/07):** `iPad16,1 26.6.2 (23G90)`: DeviceHub receives `supportedFeatures: 140`, `MediaStreamStart` succeeds and the view shows the live home screen. `iPhone17,3 27.0.1 (24A446)`: the DDI mounts (`F_SETPROTECTIONCLASS EPERM, reported as ENOTSUP`), and with row 11's conditional dispatch DeviceHub shows the home screen and Settings live, clipped inside the chrome (`Found FramebufferMaskIdentifier from displayInfo`). **Band reads validated (2026-10-07/08, `iPhone17,3 27.0.1 (24A446)`):** a four-band stream with screen activity deadlocked after 18 s without the barrier and ran 60, 180 and 300 s with it without a GPU error; in the host trace of the 180 s run no IOSurface access waited, and every band read of 6258 frames registered after the frame's write was released, a median 0.76 ms after it. Open: latency that grows over a long session and occasional stalls after a cold start, both upstream of the Mac receiver. | Y | Y | Y |
+| 26 | No binary change: both spawn hooks insert `libdevicehubfix.dylib` into `cryptexd`, the DDI's `dtremotedisplayd` and `dtdeviceinfod`, and `avconferenced`. In `cryptexd` it interposes `fcntl` and reports an `EPERM` from `F_SETPROTECTIONCLASS` as `ENOTSUP`; in `dtremotedisplayd` it interposes `MediaStreamSupportedFeatures.current` (answers `0x18c`; `0x8c` before the iPhone Duo's per-display stream, below) and `CurrentDevice.isCustomerRestricted` (answers false) from the DDI's `CoreDeviceUtilities`; in `dtdeviceinfod` it interposes `MGCopyAnswer` and fills a missing `FramebufferIdentifier` for `phone11` chrome, and stands in for CoreMotion's `CMAngleManager` and `CMDeviceStateManager` (the foldable hinge and pose DeviceHub draws from) and reports the iPhone Duo's inner `CADisplay` (`VPhone Duo Inner`) as integrated at point scale 3; in `avconferenced` it replaces `VCPSideCarMetal`'s two band reads through the Objective-C runtime and runs one synchronous scaler transform before the first read of each frame — **all bases** | none (new guest dylib `VPhoneGuestComponents/DeviceHubFix/libdevicehubfix.c`, installed at `/usr/lib/libdevicehubfix.dylib`) | **Let Xcode 27's DeviceHub show the guest's screen.** On iOS 27 `cryptexd` stages each DDI asset with `open(O_RDWR)` + `fcntl(F_SETPROTECTIONCLASS, 4)` and accepts only `ENOTSUP` as a failure; a guest answers `EPERM` (`set protection class: [1: Operation not permitted]`, `staging failed`), so CoreDevice shows the device as "connected (no DDI)" for good. With the DDI mounted, DeviceHub asks `dtremotedisplayd` for its media stream features and gets 0 from CoreDeviceUtilities' policy: `isCustomerRestricted` (`isProductionFused && !hasInternalOSBuild && hasInternalDDI == false`) refuses every pre-27.0 device, and remote control is limited to iPhone, Apple Watch and Apple TV, which refuses every iPad. `0x8c` is what a Mac host reports for itself (mirrored primary display 0x4, system audio 0x8, display information 0x80). The 27.x iPhone guest reports `phone11` chrome with no `FramebufferIdentifier`, so DeviceHub drew the screen over the bezel corners; the hook answers only that missing key with Xcode's matching mask `4E5532ED-1470-47D1-BDF4-7AA90C26957A` from `/Library/Developer/DeviceKit/chrome_map.plist`. Interposing reaches all of them because `cryptexd`, `dtremotedisplayd`, `dtdeviceinfod` and `CoreDeviceUtilities` are standalone images; the two Swift symbols are weak flat-namespace imports, resolving to nothing outside `dtremotedisplayd`. On 27.x the view also needs row 11's conditional dispatch, or the capture display stays black. A stream that splits each frame into four bands (`tilesPerFrame` 4) deadlocked the host GPU within 16–35 s of screen activity: `VCPSideCarMetal` reads every frame once per band while the paravirtual scaler's write of that frame can still be unregistered on the host, and a band read that registers the first of the frame's two planes before the write and the second after it waits on the write, which waits on it (`Timeout in timestamp wait`, the guest loses its GPU). Waiting for one synchronous transform puts the band reads behind the frame's write. `VideoProcessing` is in the shared cache, so this part is a method replacement, not an interpose. Ships with `system-launchdaemons-boot-environment`; an existing guest gets it from the environment update. Details: `Research/Guest/devicehub_screen_viewing.md`. **Validated (2026-10-06/07):** `iPad16,1 26.6.2 (23G90)`: DeviceHub receives `supportedFeatures: 140`, `MediaStreamStart` succeeds and the view shows the live home screen. `iPhone17,3 27.0.1 (24A446)`: the DDI mounts (`F_SETPROTECTIONCLASS EPERM, reported as ENOTSUP`), and with row 11's conditional dispatch DeviceHub shows the home screen and Settings live, clipped inside the chrome (`Found FramebufferMaskIdentifier from displayInfo`). **Band reads validated (2026-10-07/08, `iPhone17,3 27.0.1 (24A446)`):** a four-band stream with screen activity deadlocked after 18 s without the barrier and ran 60, 180 and 300 s with it without a GPU error; in the host trace of the 180 s run no IOSurface access waited, and every band read of 6258 frames registered after the frame's write was released, a median 0.76 ms after it. Open: latency that grows over a long session and occasional stalls after a cold start, both upstream of the Mac receiver. | Y | Y | Y |
| 27 | No binary change: both spawn hooks insert `libdevicename.dylib` into `configd` and `lockdownd` (after `libmisfix.dylib`, the first process to take two inserted libraries). In `configd` it interposes `SCDynamicStoreSetMultiple` and `SCDynamicStoreSetValue` and pins `Setup:/System`'s `ComputerName`; in `lockdownd` it interposes `SCPreferencesSetComputerName`, `SCPreferencesSetHostName` and `SCPreferencesSetLocalHostName` and refuses every rename with `kSCStatusAccessError`. Inert unless `/var/db/vphone/devicename.plist` holds a valid `DeviceName` — **all bases** | none (new guest dylib `VPhoneGuestComponents/DeviceName/libdevicename.c`, installed at `/usr/lib/libdevicename.dylib`; vphoned `device.name.get`/`device.name.set`) | **Pin the guest's device name to the VM's name.** The name is `System/System/ComputerName` in `preferences.plist`; configd's PreferencesMonitor (`updateConfiguration`, 24A435 `0x100062098`) flattens it into `Setup:/System` with one `SCDynamicStoreSetMultiple`, and every reader (`SCDynamicStoreCopyComputerName` in lockdownd's `copy_device_name`, MobileGestalt `UserAssignedDeviceName`, `UIDevice.name`) reads the store. The hook rewrites that publication, not the preferences read: the monitor's model-change path (`sub_10006155c`) writes the `kSCPrefSystem` value it reads back to disk, and the publication route leaves `preferences.plist` with the guest's own name. A publication that leaves `Setup:/System` out as unchanged gets the store's value pinned; one that removes it gets the pinned name instead. `vphone-vm` sends the VM's name to vphoned's `device.name.set` after every connect; vphoned writes the file (one rename, 0644) and applies the preferences unchanged, so configd publishes again and the new pin, or the guest's own name when the file is removed, is live within a second. The file outlives a reboot, so configd's first publication at boot carries it. The library re-reads the file when its inode, size or mtime change. lockdownd's `set_device_name` (`0x1000073b0`) is the only caller of the three setters; it logs their failure and still commits, and the `SetValue DeviceName` handler ignores the result, so a host rename reports success and the name stays. The pinned name itself is refused too: lockdownd runs `set_device_name(copy_device_name())` whenever it starts, and a lockdownd restarted after configd published would otherwise write the pinned name and derived host names into `preferences.plist` (seen once). An NVRAM variable was the first channel and never reached the guest: iBoot keeps only the variables it knows (even `vphone-vm`'s `boot-args` write is replaced). Interposing works because both daemons are standalone images. Ships with `system-launchdaemons-boot-environment` and the environment update; takes effect at the next boot. Verified on iOS 27.0 (24A435) on 2026-10-07: pin at boot and live, host rename refused, `vm rename` followed, preferences untouched. CoreDevice (`devicectl`, DeviceHub) reads the name when the device appears and can lag one boot after a rename. Details: `Research/Guest/device_name_pinning.md`. | Y | Y | Y |
| 28 | `cbz`/`cbnz` -> `b` at the four compact-command choices in `-[PGSerializerRenderCommandEncoder drawIndexedPrimitives:…]` (`0x140b0`, `0x1421c`, `0x143b4`, `0x143c4` in 23E5207q) — **cloudOS 26.4** | `AppleParavirtGPUMetalIOGPUFamily` (`/System/Library/Extensions/AppleParavirtGPUMetalIOGPUFamily.bundle`) | **Heap index buffer fix.** The compact command stores `parentResourceOffset + indexBufferOffset` in 16 bits but is chosen by testing `indexBufferOffset` alone, so an index buffer 64 KiB or more into an `MTLHeap` is read from the wrong address and meshes (Unity games) draw with another mesh's indices. Every indexed draw takes the 64-bit command instead. `system-paravirt_gpu-cfw-heap_index_offset`; see "Heap index buffers reach the host whole (2026-10-14)" and `Research/Guest/gpu_acceleration.md` | Y | Y | Y |
| 29 | No binary change: SystemHook calls `setenv("FS_CACHE_REUSE_ON_REBOOT", "1", 0)` first thing in its constructor, in every process it is inserted into, while `/usr/lib/vphone-metal-cache-reuse` exists — **all bases** | none (`VPhoneGuestComponents/SystemHook/SystemHook-vphone.c`; marker written by `cfw install` / `cfw update-environment`) | **Keep the guest's Metal shader caches across a reboot.** `libCoreFSCache` stamps each cache with `kern.bootsessionuuid` and resets it at the next boot unless the variable is set; on the paravirtual GPU CoreAnimation's precompiled pipelines are disabled, so backboardd rebuilt every pipeline after every boot. `system-systemhook-cfw-metal_cache_reuse`; see "Guest Metal caches survive a reboot (2026-10-19)" | Y | Y | Y |
@@ -5675,3 +5675,5 @@ The host VM view now derives its input geometry from the active Duo viewport (`a
> **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`.
> **Duo: folds through SpringBoard, and DeviceHub follows them (2026-10-29 night, PR Lakr233/vphone-cli#774):** no binary change. vphoned's `display.posture` `position` asks SpringBoard to fold itself through `SBSDisplayToolService` (entitlement `com.apple.springboard.sbdisplay.service`) and then sets only the virtual hinge (`Research/vphoned_http_api.md`, "Device pose"). In `system-springboard-cfw-fold_display`, `libvphonefolddisplay.dylib` (1) re-reads the shared panel's owner on `-[SpringBoard displayContentModeCoordinator:handleSwapTransitionFromPrimaryWindowScene:toPrimaryWindowScene:withContinuationLockProvider:]` as well, because a continuous close swaps the primary content as it finishes and the panel kept showing the (black) inner display for 3 s; and (2) in backboardd keeps every clone on the panel: `-[CAWindowServerDisplay addClone:options:]` on the inner render display attaches the clone to display 1 instead, and `removeClone:` removes a clone from its real `cloneMaster` (CoreAnimation aborts otherwise). backboardd moves a mirror (DeviceHub's capture display, AirPlay, recording) to the display with the primary content, so open it carried the inner display upright, while DeviceHub draws an open Duo's stream as the inner panel's native portrait framebuffer and turned it a quarter more; the panel is that framebuffer. Row 26's `libdevicehubfix` gains a `CMDeviceStateManager` stand-in in dtdeviceinfod (`VPCMAngleManager.m`: `isAvailable`, `startUpdatesToQueue:withHandler:`, `stopUpdates`, real `CMDeviceStateEvent`s with A device orientation 1, B the hinge state from `VPhoneHingeLatest`, C 0, delivered at start and on change): Xcode 27.1's DeviceHub (CoreDevicePop plugins) draws a foldable from CoreDevice's device motion state (`streamdevicemotionstate`), which a guest's CoreMotion could not answer ("Pose monitoring failed … 1001"), so the device was always drawn closed. **Validated on iPhone19,4 27.1 (24A94425):** closed shows the folded device with the cover screen, open the opened device with the inner screen upright and filling the panel, following live folds; the VM window is unchanged. **Open:** at book DeviceHub draws the cover (it names the inner panel only from DisplayInfo's `active` integrated display, and reporting the inner display as integrated makes DeviceHub want a per-display stream the guest cannot supply); DeviceHub's own pose controls (vendor-defined HID) are not wired to the guest.
+
+> **Duo: a hardware-shaped inner display, and DeviceHub's controls (2026-10-29 late, PR Lakr233/vphone-cli#774):** supersedes the clone redirect above and closes both of its open items. In `system-springboard-cfw-fold_display`, backboardd's inner `CAWindowServerVirtualDisplay` is now a portrait 2007×2853 framebuffer at 3× (the simulator's inner `CADisplay`), its `extendedProperties` adding `DisplayRotation` 270, `DisplayScale` 3, `ChromeIdentifier` `com.apple.dt.devicekit.chrome.phone14` and `DeviceCornerRadius` 55 beside `DeviceSurfaceType` 2; its one 120 Hz timing is 2007×2853; the digitizer's 270° position turn and both clone hooks (`addClone:options:`, `removeClone:`) are removed; SpringBoard's compositor draws the inner display's frames onto the panel without a turn. SpringBoard lays the inner UI out at interface orientation 90 into that framebuffer. Row 26's `libdevicehubfix`: `dtremotedisplayd` answers `0x18c` (adds `0x100`, video output by display ID: DeviceHub draws each integrated panel from its own stream and shows its pose controls only then); in `dtdeviceinfod`, `CADisplay` `displayType` answers 0 (integrated) and `pointScale` 3 for the display named `VPhone Duo Inner`; the `CMAngleManager` stand-in's `angleDegrees`, `mechanicalAngleDegrees` and `velocityDegreesPerSeconds` return floats, as `dtdeviceinfod`'s `CMAngle_Bridge` declares them (`Tf`, read from `s0`): doubles read as 0° for every whole angle, which in book (where DeviceHub takes the angle from this stream) drew the device nearly shut and focused the cover; `CMDeviceStateManager`'s A is the device orientation vphoned publishes (`VPhoneDeviceOrientation`). vphoned (no binary change) decodes DeviceHub's vendor-defined HID controls (usage page `0xFF61`, usage `0x5B`, an IOKit binary-serialized dictionary from the DDI's `dtuhidd`) and folds or turns through `display.posture`'s paths. **Validated on iPhone19,4 27.1 (24A94425), sbdisplay-duo:** open and closed from DeviceHub's buttons follow and settle; book at 130° (DeviceHub's preset) draws the inner face upright with a vertical crease, as DeviceHub draws a simulator Duo; open and book fill the panel without black bars; 48 scripted folds over every path came back in the expected orientation; `display.rotation` 0/90/180/270 on the open inner panel turns it and DeviceHub's model with it. **Open:** DeviceHub's orientation picker and its book button were not pressed since the float fix (both run the paths measured above). **With the foldable product-id** (on in standard since Lakr233/vphone-cli#778) both `dtdeviceinfod` stand-ins (`CMAngleManager`, `CMDeviceStateManager`) step aside for CoreMotion's own managers, and vphoned sets the virtual hinge from DeviceHub's controls instead of folding through SpringBoard; not measured with DeviceHub.
diff --git a/Research/Guest/devicehub_screen_viewing.md b/Research/Guest/devicehub_screen_viewing.md
index ed8511ae..e3935bd9 100644
--- a/Research/Guest/devicehub_screen_viewing.md
+++ b/Research/Guest/devicehub_screen_viewing.md
@@ -185,8 +185,10 @@ processes only (`vpIsDeviceHubFixTarget` in `Shared/InjectionEnvironment.h`):
filesystem without protection classes. Every other call and failure is
untouched.
- **`dtremotedisplayd`**: interposes `MediaStreamSupportedFeatures.current`,
- which answers `0x8c` (what a Mac host reports for itself; the host
- intersects it with its own), and `CurrentDevice.isCustomerRestricted`, which
+ which answers `0x18c`: `0x8c`, what a Mac host reports for itself (the host
+ intersects it with its own), plus video output by display ID `0x100`, which
+ an iPhone Duo's inner panel streams through (see
+ [iPhone Duo](#iphone-duo-the-fold)); and `CurrentDevice.isCustomerRestricted`, which
answers false. The struct is resilient (the framework is built for library
evolution), so the getter returns it indirectly through `x8`; the
replacement is three instructions of assembly.
@@ -195,6 +197,9 @@ processes only (`vpIsDeviceHubFixTarget` in `Shared/InjectionEnvironment.h`):
`phone11`, it answers with Xcode's matching mask `4E5532ED-…`, retained under
the Copy ownership rule. Existing answers and other chromes are unchanged.
This is display metadata, not a change to the guest's hardware identity.
+ On an iPhone Duo it also stands in for CoreMotion's hinge angle and device
+ state managers and reports the inner display as integrated (see
+ [iPhone Duo](#iphone-duo-the-fold)).
- **`avconferenced`**: replaces `VCPSideCarMetal`'s two band reads and runs
one synchronous scaler transform before the first read of each frame (see
[Banded streams](#banded-streams-deadlock-the-host-gpu)).
@@ -564,30 +569,101 @@ and draws the device closed whatever the hinge angle stream says.
`libdevicehubfix` answers it in `dtdeviceinfod` (`VPCMAngleManager.m`, beside
the hinge angle stand-in): `isAvailable` follows the hinge provider, and
updates are real `CMDeviceStateEvent`s built from the provider's newest
-sample, sent at start and on every change. With it DeviceHub draws the folded
-device on the cover and the opened device on the inner panel, and follows
-live folds.
-
-The stream is the mirrored primary display (display ID 1) for both panels.
-DeviceHub draws it on the inner panel as that panel's native framebuffer,
-portrait and mounted a quarter turn. backboardd moves every clone to the
-display holding the primary content, which open is the guest's landscape
-inner render display, rotated upright; DeviceHub turned that a quarter more
-(sideways and pillarboxed). FoldDisplay keeps clones on the panel instead
-(`FoldDisplayBackboard.m`), which open shows the inner display turned a
-quarter, exactly the native framebuffer DeviceHub expects.
-
-Not done:
-
-- At book (100°) DeviceHub draws the cover. It takes the lit panel at that
- angle from DisplayInfo's `active` integrated display, and the inner render
- display is `virtual`. Reporting it as integrated gives DeviceHub the
- evidence, but DeviceHub then wants a stream for that display ID, which
- needs feature `0x100` and a capture path the mirror patch does not cover
- (tried: the picture comes out small and centred).
-- DeviceHub's own pose controls (a hinge slider and closed / book / open
- presets, which appear once an integrated inner display is reported) send
- vendor-defined HID reports; nothing in the guest acts on them.
+sample, sent at start and on every change. `propertyA` is the device
+orientation vphoned publishes (`VPhoneDeviceOrientation` in
+`com.apple.backboardd`, portrait until a rotation or DeviceHub's orientation
+picker sets one), `propertyB` the provider's hinge state.
+
+DeviceHub's model (decompiled, `CoreDevicePopDeviceKitExtension`):
+
+- `PhysicalState.update` reads only `propertyA`, `propertyB` and `propertyC`
+ (each a `CodableValue.int`). Closed pins the angle at 0°, open flat at
+ 180°; partially open keeps the angle from the hinge angle stream
+ (`streamhingeangle`, samples with `isAngleValid`, a `Measurement` in
+ degrees).
+- The focused panel (the face the model shows, and whose stream it draws) is,
+ in order: the panel a command is heading for, cover when closed, the active
+ display DisplayInfo reports (accepted only fully open or closed), then the
+ hinge: partially open at 55° or more is the inner panel, 45° or less the
+ cover.
+- The model's rotation comes from the pose orientation and the focused panel,
+ not the hinge state; `DisplayInfo.orientation.currentDeviceOrientation`
+ stands in only while the device lies face up or down. The pose buttons'
+ icons turn with `propertyA`.
+- The presets are closed 0°, partially open **130°** and open 180°.
+
+The hinge angle stand-in's three angles are **floats**: `dtdeviceinfod`'s
+`CMAngle_Bridge` declares `angleDegrees`, `mechanicalAngleDegrees` and
+`velocityDegreesPerSeconds` as `Tf` and reads `s0`. The first stand-in
+returned doubles, whose low half is zero for every whole angle, so DeviceHub
+read 0° throughout. Open and closed hid it (their hinge states pin the
+angle); in book DeviceHub drew the device nearly shut and focused the cover,
+whose stream is the composited portrait output, so the inner picture looked a
+quarter turned. Reporting landscape right made that picture upright only by
+rolling the whole model.
+
+Each panel streams on its own. DeviceHub shows its pose controls only when
+DisplayInfo lists the inner display as `integrated` with its own ID, and then
+draws that panel from that display's stream (feature `0x100`) and geometry.
+FoldDisplay publishes the inner display with the hardware's shape: a portrait
+2007×2853 framebuffer at 3×, mounted at 270° (`DisplayRotation`, as the
+simulator's inner `CADisplay`), into which SpringBoard lays the inner UI out
+at interface orientation 90. In `dtdeviceinfod` the library reports that
+display as integrated at point scale 3 (`displayType`, `pointScale` on the
+`CADisplay` named `VPhone Duo Inner`). An earlier landscape inner display
+streamed pillarboxed with black bars, and with the mirror of display 1 the
+picture came out turned a quarter.
+
+DeviceHub's controls reach the guest as vendor-defined HID events (usage
+page `0xFF61`, usage `0x5B`) from the DDI's `dtuhidd` virtual service
+`CoreDevice avpCustom`. The payload is an IOKit binary-serialized dictionary
+(`IOCFUnserializeBinary`): `provider` `com.apple.Virtualization.VirtualMachines`,
+`source` `hinge-slider-control` (`type` range, `value` degrees, sent every
+frame of DeviceHub's own animation) or `orientation-picker-control` (`type`
+enum, `value` `portrait`, `portraitUpsideDown`, `landscapeLeft` or
+`landscapeRight`). vphoned watches for them on an iPhone Duo
+(`vphoned_devicehub.m`, an unmatched HID event monitor; matching by usage
+missed them) and acts through the `display.posture` paths
+(`GuestDeviceHubControl`): a run of slider values is folded once it has been
+quiet for 200 ms, to where it ended, and a picker value sets the pose
+orientation with the hinge where it is, as `display.rotation` does. The
+orientation DeviceHub reads back changes only once SpringBoard's interface
+has turned, and a refused turn gets the old pose orientation back (SpringBoard
+keeps a refused one, and later folds carry it). Book is left alone: the
+override means 90° there and slides the fold toward the cover. Measured with
+`display.rotation` on the open inner panel: 0, 90, 180 and 270 all turn, and
+DeviceHub turns its model with each, picture upright. The picker itself was
+not pressed.
+DeviceHub then waits for its hinge
+reading to agree; vphoned moves the virtual hinge to the target as
+SpringBoard's sweep starts, since a stale angle through the sweep made
+DeviceHub's slider send the old angle back and fold the guest again.
+Restarting backboardd breaks `dtuhidd`'s HID connection and DeviceHub keeps
+the dead one: restart DeviceHub after a respring.
+
+Measured on the same guest, portrait: closed and open from DeviceHub's
+buttons settle without bouncing and the guest follows; book at 130° (folded
+by `display.posture`) draws the inner face upright with the crease vertical,
+as DeviceHub draws a simulator Duo in book. Not yet repeated from DeviceHub's
+own book button since the float fix. Once, after DeviceHub's close from book,
+the cover came up in landscape (interface 90°); it did not recur in 48
+scripted folds over every path, and the guest's device orientation had been
+left non-portrait by rotation experiments just before, which the swap keeps.
+
+With the foldable's product-id (`preboot-cfw-devicetree_foldable_product_id`,
+on in standard since Lakr233/vphone-cli#778) CoreMotion has its own angle and device-state
+managers, and locationd's device-state relay reads the virtual hinge's host
+controls, the same `0xFF61/0x5B` dictionaries DeviceHub sends. Both
+`dtdeviceinfod` stand-ins then step aside, and DeviceHub reads the real
+managers. vphoned's handling splits the same way: on such a guest a DeviceHub
+slider run sets the virtual hinge to where it ended at once (keeping its
+orientation) and the picker sets the hinge's orientation, so the hinge,
+which resends its stored values every 5 s, agrees with DeviceHub and
+SpringBoard folds from the hinge; the SpringBoard display-swap path above is
+for guests without the relay. The provider check keeps vphoned from
+following the hinge's own dictionaries, which carry none. The relay path was
+not measured with DeviceHub: the test VM above predates the product-id
+patch.
## Other open items
diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.md
index 97e672be..c104f21b 100644
--- a/Research/Guest/iphone_duo_bringup.md
+++ b/Research/Guest/iphone_duo_bringup.md
@@ -4787,6 +4787,58 @@ Measured on the test VM (bundle built from this change):
three cover orientations (cover tested with Safari, which rotates on iPhone).
- Three launch-sequence captures: no black frames, 2-5 transient tiles.
+## 2026-10-29 night: the inner display at 120 Hz
+
+Open, the VM window counted 60 fps while the cover (the paravirtual panel,
+with the ProMotion patch) runs at 120. Two caps, one in each process:
+
+- **backboardd.** A `CAWindowServerVirtualDisplay` gets one 60 Hz mode whatever
+ `kCAVirtualDisplayUpdateRate` says. `VirtualDisplay::refresh_rate()` uses the
+ update rate only while the display has no current mode; with one, it takes
+ the mode's 16.16 rate. `heartbeat_rate()` is that mode's period divided by
+ the integer `kCAVirtualDisplayMinimumFrameDuration` (default 1). Clients read
+ `CADisplay.refreshRate` (the mode), and `UIScreen.maximumFramesPerSecond`
+ is its inverse, so every app on the inner display was capped at 60
+ (UpdateRate 120: the display ticked faster, apps still saw 60; UpdateRate
+ 60 + MinimumFrameDuration 2: heartbeat 1/120, refresh still 1/60).
+ The display's modes can be replaced with `-[CAWindowServerDisplay
+ setDigitalModes:withTimings:]` (`VirtualDisplay::set_digital_modes`), which
+ takes the framebuffer timing format: timings with `HorizontalAttributes` /
+ `VerticalAttributes` `{Active}` and `VerticalAttributes.PreciseSyncRate`
+ (16.16, default `0x3c0000` = 60), optional `Score`, and color modes
+ (`PixelEncoding` 0, `Depth` ≤ 8, `Colorimetry` 1/10/16, `EOTF` 0,
+ `DynamicRange` 0). A mode is preferred only when its score is above 0
+ (Colorimetry 16 adds 2, plain RGB nothing); with no preferred mode the
+ display comes up 0×0 and SpringBoard aborts in
+ `-[SBMainDisplayConfigurationTransformer transformDisplayConfiguration:]`.
+ FoldDisplay now sets one timing at 120 (2853×2007 when this was measured,
+ 2007×2853 since the inner display took the hardware's shape, below), with
+ Colorimetry 1 and Score 1: the inner mode reads `RGB_8bit` like the
+ panel's.
+- **SpringBoard.** The compositor's display link asks for the panel's
+ `maximumFramesPerSecond` (120 with the ProMotion patch, else 60).
+
+backboardd cannot read the panel's rate while it adds the inner display: the
+primary's rate is not set yet during display detection, and asking
+`CADisplay` there blocks backboardd (the inner display never appeared).
+
+Measured on duospike-inner (iOS 27.1, Settings open, 3 s windows):
+
+| | panel (LCD) | inner |
+|---|---|---|
+| `UIScreen.maximumFramesPerSecond` | 120 | 120 (was 60) |
+| `CADisplay.refreshRate` / heartbeat | 1/120 / 1/120 | 1/120 / 1/120 (was 1/60) |
+| default `CADisplayLink`, ticks in 3 s | 377 | 377 |
+| compositor renders in 3 s | | 375-378 |
+
+Idle CPU on the home screen, three 10 s samples each: 60 Hz build SpringBoard
+6.9-7.9%, backboardd 37.8-45.6%; 120 Hz build 9.3-10.4% and 50.3-51.3%.
+
+Window captures (ScreenCaptureKit) cannot judge 120 Hz here: the cover, which
+is natively 120, measures the same 40-55 changes per second as the inner
+display, because the host composites the window at its own rate. Use guest
+display links, or the host's `lastSubmittedTime` poller from the vGPU notes.
+
## 2026-10-29 night: folds go through SpringBoard's display tool service
Xcode 27's iPhone Duo simulator has no hinge: CoreSimulator gives it two real
@@ -4836,61 +4888,39 @@ test VM (iPhone19,4 27.1, 24A94425) with the two-display path:
7 s), as on hardware.
- DeviceHub (Xcode 27.1) draws a Duo guest as a 3D V68 model from CoreDevice's
device motion state, which needed a `CMDeviceStateManager` stand-in in
- `dtdeviceinfod`, and draws the open stream as the inner panel's native
- portrait framebuffer, which needed every mirror clone kept on the panel
- (backboardd moved it to the landscape inner render display). Closed and
- open now look right there; book does not. Details:
- `Research/Guest/devicehub_screen_viewing.md`, "iPhone Duo: the fold".
-
-## 2026-10-29 night: the inner display at 120 Hz
-
-Open, the VM window counted 60 fps while the cover (the paravirtual panel,
-with the ProMotion patch) runs at 120. Two caps, one in each process:
-
-- **backboardd.** A `CAWindowServerVirtualDisplay` gets one 60 Hz mode whatever
- `kCAVirtualDisplayUpdateRate` says. `VirtualDisplay::refresh_rate()` uses the
- update rate only while the display has no current mode; with one, it takes
- the mode's 16.16 rate. `heartbeat_rate()` is that mode's period divided by
- the integer `kCAVirtualDisplayMinimumFrameDuration` (default 1). Clients read
- `CADisplay.refreshRate` (the mode), and `UIScreen.maximumFramesPerSecond`
- is its inverse, so every app on the inner display was capped at 60
- (UpdateRate 120: the display ticked faster, apps still saw 60; UpdateRate
- 60 + MinimumFrameDuration 2: heartbeat 1/120, refresh still 1/60).
- The display's modes can be replaced with `-[CAWindowServerDisplay
- setDigitalModes:withTimings:]` (`VirtualDisplay::set_digital_modes`), which
- takes the framebuffer timing format: timings with `HorizontalAttributes` /
- `VerticalAttributes` `{Active}` and `VerticalAttributes.PreciseSyncRate`
- (16.16, default `0x3c0000` = 60), optional `Score`, and color modes
- (`PixelEncoding` 0, `Depth` ≤ 8, `Colorimetry` 1/10/16, `EOTF` 0,
- `DynamicRange` 0). A mode is preferred only when its score is above 0
- (Colorimetry 16 adds 2, plain RGB nothing); with no preferred mode the
- display comes up 0×0 and SpringBoard aborts in
- `-[SBMainDisplayConfigurationTransformer transformDisplayConfiguration:]`.
- FoldDisplay now sets one timing, 2853×2007 at 120, with Colorimetry 1 and
- Score 1: the inner mode reads `RGB_8bit` like the panel's.
-- **SpringBoard.** The compositor's display link asks for the panel's
- `maximumFramesPerSecond` (120 with the ProMotion patch, else 60).
-
-backboardd cannot read the panel's rate while it adds the inner display: the
-primary's rate is not set yet during display detection, and asking
-`CADisplay` there blocks backboardd (the inner display never appeared).
-
-Measured on duospike-inner (iOS 27.1, Settings open, 3 s windows):
-
-| | panel (LCD) | inner |
-|---|---|---|
-| `UIScreen.maximumFramesPerSecond` | 120 | 120 (was 60) |
-| `CADisplay.refreshRate` / heartbeat | 1/120 / 1/120 | 1/120 / 1/120 (was 1/60) |
-| default `CADisplayLink`, ticks in 3 s | 377 | 377 |
-| compositor renders in 3 s | | 375-378 |
-
-Idle CPU on the home screen, three 10 s samples each: 60 Hz build SpringBoard
-6.9-7.9%, backboardd 37.8-45.6%; 120 Hz build 9.3-10.4% and 50.3-51.3%.
-
-Window captures (ScreenCaptureKit) cannot judge 120 Hz here: the cover, which
-is natively 120, measures the same 40-55 changes per second as the inner
-display, because the host composites the window at its own rate. Use guest
-display links, or the host's `lastSubmittedTime` poller from the vGPU notes.
+ `dtdeviceinfod`. Details: `Research/Guest/devicehub_screen_viewing.md`,
+ "iPhone Duo: the fold".
+- One posture request runs at a time. SpringBoard answers a swap it refuses
+ ("rejecting swap request — system is not idle") at once and the same way
+ as a finished one, so a reply under 0.3 s for a sweep that had to move
+ counts as a refusal and is retried every 0.25 s for 10 s plus the
+ duration.
+
+## 2026-10-29 late: the inner display takes the hardware's shape
+
+DeviceHub shows its pose controls only for an integrated inner display with
+its own stream, and draws that stream on the inner panel as the panel's
+native framebuffer. The landscape 2853×2007 inner render display therefore
+came out pillarboxed through the mirror and sideways through a per-display
+stream. FoldDisplay now publishes it the way the simulator's inner
+`CADisplay` is: a portrait 2007×2853 framebuffer at 3×, with
+`DisplayRotation` 270, `DeviceSurfaceType` 2, chrome `phone14` and corner
+radius 55 in its extended properties. SpringBoard lays the inner UI out at
+interface orientation 90 and rotates it into the framebuffer, the
+compositor draws the inner display's frames onto the panel without a turn,
+and the 120 Hz timing is 2007×2853. The digitizer needs no turn either. The
+clone redirect from the first DeviceHub fix is gone.
+
+`display.rotation`'s inner map (0 landscape-left, 90 portrait, 180
+landscape-right, from pose orientations 3, 1, 4) still holds on the portrait
+framebuffer: measured on sbdisplay-duo, pose orientation 1 gives interface
+90, 3 gives 0 and 4 gives 180.
+
+The host window follows folds it did not ask for (DeviceHub's, another
+client's): `display.orientation` carries `fold_angle`, the virtual hinge's
+settled angle, and the window's once-a-second orientation poll moves its
+fold chrome to the nearest of closed, book and open while none of its own
+fold requests is in flight.
## 2026-10-30: CoreMotion, MobileGestalt displays and the book angle, against Apple's simulator
diff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.md
index 172bb597..2c0586d7 100644
--- a/Research/vphoned_http_api.md
+++ b/Research/vphoned_http_api.md
@@ -497,7 +497,7 @@ request carries `"force": true`.
| Area | Methods |
| --- | --- |
| Device | `device.snapshot`, `device.info` (snapshot plus network, screen, rotation, brightness, volume, low power, Developer Mode, agent, `device_name` `{name, own_name}`: the pinned name and the guest's own ComputerName), `device.screen`, `device.network`, `device.displays` (a flat IOService probe of every display-ish object with its small properties — what the display stack bound; built for the foldable display work: `AppleParavirtGPU` `DisplayPortCount`, and each `AppleParavirtDisplay` width/height/`primary`), `device.ioreg {plane}`, `device.environment`, `device.basebin {archive?}` |
-| Display, audio | `display.pose` (read-only SpringBoard pose snapshot: orientation, device_orientation, hinge, tabletop; reports unavailable for an unsupported ABI), `display.modes` (read-only CoreAnimation display bounds, native size, current/available modes, and virtual-mode selector availability; availability does not prove a mode change is supported), `display.brightness {value?}`, `display.rotation {orientation?}`, `display.posture {hinge, orientation?, tabletop?}` (a foldable guest's pose through SpringBoard's test-automation override, see below; capability `device_pose`), `display.orientation` (`{degrees, source}`: SpringBoard's interface orientation without a screen capture, for polling; `degrees` is null while SpringBoard has no answer; capability `display_orientation`), `display.rotation_lock {locked}`, `display.auto_lock` (`{auto_lock_seconds, never, lock_screen_minimum_seconds}`), `display.auto_lock.set {seconds}` (writes the mobile UserSettings input through cfprefsd, posts profiled's effective-settings notification, and returns an immediate readback; the caller must verify the effective value), `screen.unlock {passcode?, timeout?}` (`{locked, screen_off, was_locked, was_screen_off}`: the display on and the Lock Screen passed, see below; capability `screen_unlock`), `audio.volume {value?, category?}`, `audio.state` |
+| Display, audio | `display.pose` (read-only SpringBoard pose snapshot: orientation, device_orientation, hinge, tabletop; reports unavailable for an unsupported ABI), `display.modes` (read-only CoreAnimation display bounds, native size, current/available modes, and virtual-mode selector availability; availability does not prove a mode change is supported), `display.brightness {value?}`, `display.rotation {orientation?}`, `display.posture {hinge, orientation?, tabletop?}` (a foldable guest's pose through SpringBoard's test-automation override, see below; capability `device_pose`), `display.orientation` (`{degrees, source, fold_angle?}`: SpringBoard's interface orientation without a screen capture, for polling; `degrees` is null while SpringBoard has no answer; on a foldable `fold_angle` is the virtual hinge's settled angle, which every fold leaves it at, so a host can follow folds it did not ask for; capability `display_orientation`), `display.rotation_lock {locked}`, `display.auto_lock` (`{auto_lock_seconds, never, lock_screen_minimum_seconds}`), `display.auto_lock.set {seconds}` (writes the mobile UserSettings input through cfprefsd, posts profiled's effective-settings notification, and returns an immediate readback; the caller must verify the effective value), `screen.unlock {passcode?, timeout?}` (`{locked, screen_off, was_locked, was_screen_off}`: the display on and the Lock Screen passed, see below; capability `screen_unlock`), `audio.volume {value?, category?}`, `audio.state` |
| Input | `input.touch`, `input.hid {page, usage, down?, long_press?}`, `input.button {name}`, `input.key {name}`, `input.type {text, delay_ms?}`, `input.paste {text}`, `input.tap`, `input.double_tap`, `input.long_press`, `input.swipe`, `input.drag {points}`, `input.touch_sequence {events}` — gesture coordinates are screen points; `input.pointer {x, y, seq?, buttons?}`, `input.scroll {phase, dx?, dy?, x?, y?}` (capabilities `pointer_scroll` and `pointer_buttons`, see below) |
| UI | `ui.tree` (alias `accessibility.tree`), `ui.element_at`, `ui.tap_element`, `ui.wait`, `ui.wait_gone`, `ui.ocr {languages?, min_confidence?}`, `ui.describe`, `screen.screenshot` |
| Processes | `processes.list {filter?}`, `processes.kill {pid, signal?}` **force**, `process.spawn {executable, arguments?, timeout_seconds?}`, `memory.jetsam`, `memory.pressure` (only the three kernel memory sysctls, for polling) |
@@ -1247,11 +1247,15 @@ 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 host controls' orientation picker has no
upside-down, so with CoreMotion the cover's 180 and the inner panel's 270 are
-refused. The accelerometer and the AssistiveTouch rotation other iPhones use
-do not turn a foldable's panels.
-
-A `position` request is a fold, and SpringBoard runs it the way Apple's
-`suiatool swap` does: vphoned calls
+refused. With the override, a turn that does not land gets the old pose
+orientation back, since SpringBoard keeps a refused one and later folds carry
+it, and partially open the request is refused, because the override means 90°
+there and slides the fold toward the cover. The accelerometer and the
+AssistiveTouch rotation other iPhones use do not turn a foldable's panels.
+
+Without CoreMotion's relay a `position` request is a fold that SpringBoard
+runs the way Apple's `suiatool swap` does (with the relay the virtual hinge
+sweeps and SpringBoard folds from the hinge): vphoned calls
`-[SBSDisplayToolService swapDisplayWithSettings:completion:]` with the
position as an absolute hinge target (0 closed, 1 open flat), the duration
(−1 the per-direction default, measured 0.391 s opening and 0.420 s
@@ -1279,6 +1283,19 @@ answered. On a guest without the service (or one that does not answer
within 10 s plus the duration) the virtual hinge sweeps and the override
jumps, as before. Verified 2026-10-29 on iPhone19,4 27.1 (24A94425).
+Posture requests run one at a time. SpringBoard answers a swap it refuses
+("system is not idle") at once and exactly like a finished one, so a reply
+under 0.3 s for a sweep that had to move is treated as a refusal and retried
+every 0.25 s until 10 s plus the duration have passed; then the request
+fails with "SpringBoard kept refusing the fold". The virtual hinge takes the
+target angle as SpringBoard's sweep starts, and the old angle again if the
+fold does not run: Xcode's DeviceHub reads it and, with the old angle
+lingering through the sweep, sent its slider back there. DeviceHub's own fold
+and orientation controls arrive in the guest as vendor-defined HID events,
+and vphoned runs them through this request on an iPhone Duo; with the relay
+a DeviceHub fold sets the hinge at once and keeps its orientation (see
+`Guest/devicehub_screen_viewing.md`, "iPhone Duo: the fold").
+
| Param | Values |
| --- | --- |
| `hinge` (required) | `ambiguous` 0, `closed` 1, `partially-open` 2, `open-flat` 3, `open` 4 |
diff --git a/VPhoneDaemon/Daemon/GuestAPI+Device.swift b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
index d6f7b0b3..020fea27 100644
--- a/VPhoneDaemon/Daemon/GuestAPI+Device.swift
+++ b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
@@ -168,11 +168,24 @@ extension GuestAPI {
}
/// Reads SpringBoard directly; the UIScreen path can abort before display registration.
+ /// A foldable guest adds the angle its last fold settled at, so a host
+ /// polling the orientation also follows folds it did not ask for (Xcode's
+ /// DeviceHub).
private static func interfaceOrientation() -> [String: Any] {
- [
+ var reply: [String: Any] = [
"degrees": interfaceRotationDegrees().map { $0 as Any } ?? NSNull(),
"source": "springboard",
]
+ if let angle = settledFoldAngle() { reply["fold_angle"] = angle }
+ return reply
+ }
+
+ /// The angle the virtual hinge holds, which every fold leaves it at; nil
+ /// on a guest whose hinge was never configured.
+ private static func settledFoldAngle() -> Double? {
+ let hinge = vp_hinge_get()
+ guard hinge["enabled"] as? Bool == true else { return nil }
+ return (hinge["angle"] as? NSNumber)?.doubleValue
}
// MARK: Device pose
@@ -280,6 +293,8 @@ extension GuestAPI {
if relayed, orientation == 2 {
throw GuestAPIError.invalidRequest("the host controls have no upside-down orientation")
}
+ foldLock.lock()
+ defer { foldLock.unlock() }
GuestFoldPose.cancelStartupRestore()
var springBoardSwept = false
defer { GuestFoldPose.finishExplicitRequest(settledHinge: springBoardSwept ? Int32(hinge) : nil) }
@@ -314,14 +329,16 @@ extension GuestAPI {
// angle. Without the service the virtual hinge sweeps and the
// override jumps, as before.
if sweep {
- let profileOverride: Int32 = profile == "fade" ? 1 : profile == "continuous" ? 2 : 0
- let seconds = durationMs < 0 ? -1 : durationMs / 1000
- springBoardSwept = vp_display_swap(angle! / 180, seconds, params["orientation"] == nil ? 0 : Int32(orientation),
- profileOverride, 10 + max(seconds, 0)) == 1
+ springBoardSwept = try springBoardFold(
+ to: angle!, seconds: durationMs < 0 ? -1 : durationMs / 1000,
+ orientation: params["orientation"] == nil ? 0 : Int32(orientation),
+ profile: profile == "fade" ? 1 : profile == "continuous" ? 2 : 0,
+ )
}
guard springBoardSwept || vp_device_pose_set(Int32(orientation), Int32(hinge), Int32(tabletop)) else {
throw GuestAPIError.operationFailed("SpringBoardServices has no device pose override on this guest")
}
+ if params["orientation"] != nil { vp_device_orientation_publish(Int32(orientation)) }
// The pose has landed; the hinge half is published beside it, and
// its absence (no virtual hinge service on this guest) does not
// undo the pose.
@@ -345,6 +362,44 @@ extension GuestAPI {
return reply
}
+ /// One posture request at a time: SpringBoard refuses a swap while another
+ /// is running, and the next request reads the hinge this one leaves.
+ private static let foldLock = NSLock()
+
+ /// Fold through SpringBoard's display tool service, waiting for it to
+ /// finish. True once SpringBoard ran the fold, false without the service
+ /// or a reply (the caller falls back to the override). SpringBoard answers
+ /// a swap it refuses (another one is running) at once and the same way as
+ /// a finished one, so a reply faster than any sweep that had to move is a
+ /// refusal, retried until SpringBoard is idle. The virtual hinge holds the
+ /// angle the last fold ended at, and takes the target as the fold starts:
+ /// DeviceHub reads it (through dtdeviceinfod) while its own model animates
+ /// to the target, and an old angle lingering through the sweep sent its
+ /// slider back there, folding the guest again. A fold that does not run
+ /// puts the old angle back.
+ private static func springBoardFold(to angle: Double, seconds: Double, orientation: Int32, profile: Int32) throws -> Bool {
+ let current = (vp_hinge_get()["angle"] as? NSNumber)?.doubleValue
+ let moves = current.map { abs($0 - angle) >= 1 } ?? true
+ var ran = false
+ if moves { _ = vp_hinge_set(angle, 0) }
+ defer { if moves, !ran, let current { _ = vp_hinge_set(current, 0) } }
+ let deadline = Date().addingTimeInterval(10 + max(seconds, 0))
+ while true {
+ let started = Date()
+ switch vp_display_swap(angle / 180, seconds, orientation, profile, max(1, deadline.timeIntervalSinceNow)) {
+ case -1, 0:
+ return false
+ default:
+ ran = !moves || seconds == 0 || Date().timeIntervalSince(started) >= 0.3
+ if ran { return true }
+ }
+ guard Date() < deadline else {
+ throw GuestAPIError.operationFailed("SpringBoard kept refusing the fold; another fold is still running")
+ }
+ Thread.sleep(forTimeInterval: 0.25)
+ }
+ }
+
/// 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
@@ -360,39 +415,103 @@ extension GuestAPI {
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,
+ guard pose["available"] as? Bool == true, let readHinge = (pose["hinge"] as? NSNumber)?.int32Value,
let tabletop = (pose["tabletop"] as? NSNumber)?.int32Value
else { throw GuestAPIError.operationFailed("SpringBoard's device pose is unavailable") }
+ // The pose readback does not follow SpringBoard's own folds; the
+ // virtual hinge holds where the last one ended.
+ let hinge = settledFoldAngle().map { Int32(hingeState(for: $0)) } ?? readHinge
// 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]
- let orientation = (hinge == 1 ? cover : inner)[degrees]!
+ let deviceOrientation = (hinge == 1 ? cover : inner)[degrees]!
+ // Partially open the override stands for 90° and slides the fold
+ // toward the cover; CoreMotion's relay reads the hinge instead.
+ guard hinge != 2 || vp_core_motion_hinge() else {
+ throw GuestAPIError.operationFailed("A partially open fold does not turn through the device pose.")
+ }
GuestFoldPose.cancelStartupRestore()
defer { GuestFoldPose.finishExplicitRequest() }
+ guard try turn(to: deviceOrientation, hinge: hinge, tabletop: tabletop, reaching: { $0 == degrees }) else {
+ throw GuestAPIError.operationFailed("The device did not apply the requested rotation.")
+ }
+ var info = rotationInfo()
+ info["requested"] = degrees
+ return info
+ }
+
+ /// A fold Xcode's DeviceHub asked for (GuestDeviceHubControl): the sweep
+ /// `display.posture` runs for a position, to `angle` degrees.
+ /// With CoreMotion's relay the hinge takes the angle at once, keeping its
+ /// orientation: SpringBoard folds from the hinge as on a device.
+ static func foldFromDeviceHub(angle: Double) throws {
+ let angle = min(max(angle, 0), 180)
if vp_core_motion_hinge() {
- // The device orientation goes through the host controls with the
- // angle the hinge holds; CoreMotion turns it into each panel's.
- guard orientation != 2 else {
- throw GuestAPIError.invalidRequest("the host controls have no upside-down orientation")
- }
- guard let angle = vp_hinge_get()["angle"] as? Double, vp_hinge_set(angle, orientation) else {
+ _ = try setDevicePose(["hinge": hingeState(for: angle), "angle": angle, "orientation": 0])
+ } else {
+ _ = try setDevicePose(["position": NSNumber(value: angle / 180)])
+ }
+ }
+
+ /// A device orientation DeviceHub's picker chose (1 portrait … 6 face
+ /// down): the pose override takes it with the hinge where it is. The
+ /// orientation DeviceHub reads back is published only once the interface
+ /// has turned, so a refused turn leaves its model where the guest is: an
+ /// iPhone19,4 scene refuses programmatic orientation (see
+ /// `display.rotation`), and in book the override, which means 90°, slides
+ /// the fold toward the cover, so book is left alone. With CoreMotion's
+ /// relay the host controls carry the orientation at any fold.
+ static func orientFromDeviceHub(_ deviceOrientation: Int32) throws {
+ foldLock.lock()
+ defer { foldLock.unlock() }
+ GuestFoldPose.cancelStartupRestore()
+ defer { GuestFoldPose.finishExplicitRequest() }
+ let hinge = settledFoldAngle().map { Int32(hingeState(for: $0)) } ??
+ (vp_device_pose_get()["hinge"] as? NSNumber)?.int32Value ?? 1
+ guard hinge != 2 || vp_core_motion_hinge() else {
+ throw GuestAPIError.operationFailed("a partially open fold does not turn through the pose override")
+ }
+ let before = interfaceRotationDegrees()
+ guard try turn(to: deviceOrientation, hinge: hinge, tabletop: 0, reaching: { $0 != before }) else {
+ throw GuestAPIError.operationFailed("SpringBoard did not turn the interface")
+ }
+ }
+
+ /// Set the device orientation and wait up to 3 s for the interface to
+ /// reach `turned`. With CoreMotion's relay the host controls carry it
+ /// with the angle the hinge holds, and CoreMotion turns it into each
+ /// panel's. Otherwise the pose override takes it; only once the interface
+ /// has turned is it published (DeviceHub's stand-in reads it), and a
+ /// refused one is put back, since SpringBoard keeps it and later folds
+ /// carry it.
+ private static func turn(to deviceOrientation: Int32, hinge: Int32, tabletop: Int32,
+ reaching turned: (Int?) -> Bool) throws -> Bool {
+ let relayed = vp_core_motion_hinge()
+ if relayed, deviceOrientation == 2 {
+ throw GuestAPIError.invalidRequest("the host controls have no upside-down orientation")
+ }
+ let previous = (vp_device_pose_get()["device_orientation"] as? NSNumber)?.int32Value
+ if relayed {
+ guard let angle = settledFoldAngle(), vp_hinge_set(angle, deviceOrientation) else {
throw GuestAPIError.operationFailed("The virtual hinge did not take the orientation")
}
} else {
- guard vp_device_pose_set(orientation, hinge, tabletop) else {
+ guard vp_device_pose_set(deviceOrientation, hinge, tabletop) else {
throw GuestAPIError.operationFailed("SpringBoard refused the device pose")
}
}
- for _ in 0 ..< 30 where interfaceRotationDegrees() != degrees {
+ for _ in 0 ..< 30 where !turned(interfaceRotationDegrees()) {
usleep(100_000)
}
- guard interfaceRotationDegrees() == degrees else {
- throw GuestAPIError.operationFailed("The device did not apply the requested rotation.")
+ guard turned(interfaceRotationDegrees()) else {
+ if !relayed, let previous, (1 ... 6).contains(previous), previous != deviceOrientation {
+ _ = vp_device_pose_set(previous, hinge, tabletop)
+ }
+ return false
}
- var info = rotationInfo()
- info["requested"] = degrees
- return info
+ if !relayed { vp_device_orientation_publish(deviceOrientation) }
+ return true
}
/// The hinge state a settled angle reports: closed under 5°, open flat
diff --git a/VPhoneDaemon/Daemon/GuestDeviceHubControl.swift b/VPhoneDaemon/Daemon/GuestDeviceHubControl.swift
new file mode 100644
index 00000000..d2db72d8
--- /dev/null
+++ b/VPhoneDaemon/Daemon/GuestDeviceHubControl.swift
@@ -0,0 +1,64 @@
+import Foundation
+import VphonedNative
+
+/// Folds and turns an iPhone Duo guest as Xcode's DeviceHub asks
+/// (vphoned_devicehub.m decodes its controls). A closed / book / open button
+/// animates DeviceHub's hinge from the current angle to the target, sending a
+/// value every frame, and DeviceHub then waits for the device's hinge to
+/// agree. SpringBoard folds itself in one sweep, so a run of values is folded
+/// once it settles, to where it ended. The orientation picker sets the device
+/// orientation. Both go through the paths `display.posture` uses, so the host
+/// window, which polls the fold angle, follows too.
+enum GuestDeviceHubControl {
+ private final class Pending: @unchecked Sendable {
+ /// Owned by `queue`.
+ var generation = 0
+ }
+
+ private static let pending = Pending()
+ private static let queue = DispatchQueue(label: "vphoned.devicehub-fold", qos: .userInitiated)
+ /// Longer than DeviceHub's frame interval, short enough to feel direct.
+ private static let settle: DispatchTimeInterval = .milliseconds(200)
+ /// Apple's DeviceOrientation names, as the picker sends them.
+ private static let orientations: [String: Int32] = [
+ "portrait": 1, "portraitUpsideDown": 2, "landscapeLeft": 3, "landscapeRight": 4, "faceUp": 5, "faceDown": 6,
+ ]
+
+ static func startOnStartup() {
+ guard vp_devicehub_controls_start({ control in handle(control) }) else { return }
+ NSLog("vphoned: following DeviceHub's fold controls")
+ }
+
+ private static func handle(_ control: [AnyHashable: Any]) {
+ let value = control["value"]
+ switch control["source"] as? String {
+ case "hinge-slider-control":
+ guard let angle = (value as? NSNumber)?.doubleValue ?? (value as? String).flatMap(Double.init),
+ angle.isFinite
+ else { return }
+ queue.async {
+ pending.generation &+= 1
+ let generation = pending.generation
+ queue.asyncAfter(deadline: .now() + settle) {
+ guard pending.generation == generation else { return }
+ do {
+ try GuestAPI.foldFromDeviceHub(angle: angle)
+ } catch {
+ NSLog("vphoned: DeviceHub fold to %.0f° failed: %@", angle, "\(error)")
+ }
+ }
+ }
+ case "orientation-picker-control":
+ guard let name = value as? String, let orientation = orientations[name] else { return }
+ queue.async {
+ do {
+ try GuestAPI.orientFromDeviceHub(orientation)
+ } catch {
+ NSLog("vphoned: DeviceHub orientation %@ failed: %@", name, "\(error)")
+ }
+ }
+ default:
+ break
+ }
+ }
+}
diff --git a/VPhoneDaemon/Daemon/main.swift b/VPhoneDaemon/Daemon/main.swift
index 9ef8132a..5a2e5e6d 100644
--- a/VPhoneDaemon/Daemon/main.swift
+++ b/VPhoneDaemon/Daemon/main.swift
@@ -28,6 +28,7 @@ GuestVirtualAudioProduct.storeOnStartup()
// After SpringBoard has had time to come up, so the inner panel's layout
// matches the posture it was booted with.
GuestFoldPose.startOnStartup()
+GuestDeviceHubControl.startOnStartup()
vp_vcam_start()
GuestHomePodDisplay.startOnStartup()
// Multi-finger injection is resolved here so the first pinch is not the call
diff --git a/VPhoneDaemon/Native/Include/VphonedNative.h b/VPhoneDaemon/Native/Include/VphonedNative.h
index 4e537401..cf400a18 100644
--- a/VPhoneDaemon/Native/Include/VphonedNative.h
+++ b/VPhoneDaemon/Native/Include/VphonedNative.h
@@ -120,11 +120,6 @@ bool vp_screen_undim(void);
/// touch controller reports as a wake gesture.
void vp_tap_to_wake_start(void (* _Nonnull touched)(void));
bool vp_device_pose_set(int deviceOrientation, int hingeState, int tabletopPose);
-/// Whether this guest's CoreMotion has a foldable's angle and device-state
-/// capabilities (the foldable product-id). Then locationd relays the virtual
-/// hinge's host controls into CoreMotion and SpringBoard reads its pose from
-/// there; otherwise only the test-automation pose override reaches it.
-bool vp_core_motion_hinge(void);
/// Fold a foldable guest through SpringBoard's display tool service: sweep
/// its hinge pose to `position` (0 closed, 1 open flat) and swap displays on
/// the way. `durationSeconds` < 0 is the per-direction default, 0 an instant
@@ -135,6 +130,14 @@ bool vp_core_motion_hinge(void);
/// guest has no such service.
int vp_display_swap(double position, double durationSeconds, int deviceOrientation, int profileOverride,
double timeoutSeconds);
+/// Publish the device orientation (1 portrait … 4 landscape-right) for the
+/// device state DeviceHub reads (libdevicehubfix in dtdeviceinfod).
+void vp_device_orientation_publish(int deviceOrientation);
+/// Whether this guest's CoreMotion has a foldable's angle and device-state
+/// capabilities (the foldable product-id). Then locationd relays the virtual
+/// hinge's host controls into CoreMotion and SpringBoard reads its pose from
+/// there; otherwise only the test-automation pose override reaches it.
+bool vp_core_motion_hinge(void);
/// Ask launchd to shut the guest down and halt. Returns 0 once the request is
/// accepted, otherwise an errno value. Needs root.
@@ -215,6 +218,10 @@ BOOL vp_accelerometer_set_orientation(NSString * _Nonnull spec);
/// (degrees, closed 0) and whether the provider in backboardd is enumerated
/// and current.
NSDictionary * _Nonnull vp_hinge_get(void);
+/// On an iPhone Duo, hand every control Xcode's DeviceHub sends (a decoded
+/// dictionary with `source`, `type` and `value`) to `handler`, on a serial
+/// queue of its own. False on any other device or without the HID API.
+bool vp_devicehub_controls_start(void (^_Nonnull handler)(NSDictionary * _Nonnull control));
/// Every display-ish IOService object the guest published, with its small
/// properties: what the display stack bound, for the foldable display work.
NSArray * _Nonnull vp_display_probe(void);
diff --git a/VPhoneDaemon/Native/vphoned_devicehub.m b/VPhoneDaemon/Native/vphoned_devicehub.m
new file mode 100644
index 00000000..ce15effa
--- /dev/null
+++ b/VPhoneDaemon/Native/vphoned_devicehub.m
@@ -0,0 +1,89 @@
+/*
+ * vphoned_devicehub — the controls Xcode's DeviceHub sends a virtual iPhone
+ * Duo.
+ *
+ * DeviceHub's V68 controls (the closed / book / open buttons and their hinge
+ * animation, and the orientation picker) send a vendor-defined HID report
+ * (usage page 0xFF61, usage 0x5B) through CoreDevice. The DDI's dtuhidd
+ * replays it from a virtual service it creates, "CoreDevice avpCustom", as a
+ * vendor-defined event whose data is an IOKit binary-serialized dictionary:
+ *
+ * provider = com.apple.Virtualization.VirtualMachines
+ * source = hinge-slider-control, type = range, value = degrees
+ * source = orientation-picker-control, type = enum, value = portrait, ...
+ *
+ * One button press is a run of hinge values as DeviceHub animates from the
+ * current angle to the target. vphoned monitors the HID event system for
+ * these events and hands each dictionary to Swift.
+ */
+
+#import "Include/VphonedNative.h"
+
+#include <dlfcn.h>
+#include <string.h>
+#include <sys/sysctl.h>
+
+typedef struct __IOHIDEventSystemClient *VPHIDEventSystemClientRef;
+typedef struct __IOHIDEvent *VPHIDEventRef;
+typedef void (*VPHIDEventCallback)(void *target, void *refcon, void *sender, VPHIDEventRef event);
+
+static uint32_t (*vpEventType)(VPHIDEventRef);
+static CFIndex (*vpEventInteger)(VPHIDEventRef, uint32_t);
+static uint8_t *(*vpEventData)(VPHIDEventRef, uint32_t);
+static CFTypeRef (*vpUnserializeBinary)(const char *, size_t, CFAllocatorRef, CFOptionFlags, CFStringRef *);
+static void (^vpControlHandler)(NSDictionary *);
+
+static void vpDeviceHubEvent(void *target, void *refcon, void *sender, VPHIDEventRef event) {
+ // kIOHIDEventTypeVendorDefined; its fields are the type << 16 plus usage
+ // page 0, usage 1, version 2, data length 3, data 4.
+ static const uint32_t vendorDefined = 1, field = vendorDefined << 16;
+ if (!event || vpEventType(event) != vendorDefined || vpEventInteger(event, field) != 0xff61 ||
+ vpEventInteger(event, field | 1) != 0x5b)
+ return;
+ CFIndex length = vpEventInteger(event, field | 3);
+ uint8_t *data = vpEventData(event, field | 4);
+ if (!data || length <= 0) return;
+ @autoreleasepool {
+ id control = CFBridgingRelease(vpUnserializeBinary((const char *)data, (size_t)length, kCFAllocatorDefault, 0, NULL));
+ if ([control isKindOfClass:NSDictionary.class] &&
+ [control[@"provider"] isEqual:@"com.apple.Virtualization.VirtualMachines"])
+ vpControlHandler(control);
+ }
+}
+
+bool vp_devicehub_controls_start(void (^handler)(NSDictionary *control)) {
+ char product[64] = {0};
+ size_t size = sizeof(product);
+ if (sysctlbyname("hw.machine", product, &size, NULL, 0) != 0 || strcmp(product, "iPhone19,4") != 0) return false;
+ void *iokit = dlopen("/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_NOW);
+ VPHIDEventSystemClientRef (*create)(CFAllocatorRef, int, CFDictionaryRef) =
+ iokit ? dlsym(iokit, "IOHIDEventSystemClientCreateWithType") : NULL;
+ void (*registerCallback)(VPHIDEventSystemClientRef, VPHIDEventCallback, void *, void *) =
+ iokit ? dlsym(iokit, "IOHIDEventSystemClientRegisterEventCallback") : NULL;
+ void (*schedule)(VPHIDEventSystemClientRef, dispatch_queue_t) =
+ iokit ? dlsym(iokit, "IOHIDEventSystemClientScheduleWithDispatchQueue") : NULL;
+ vpEventType = iokit ? dlsym(iokit, "IOHIDEventGetType") : NULL;
+ vpEventInteger = iokit ? dlsym(iokit, "IOHIDEventGetIntegerValue") : NULL;
+ vpEventData = iokit ? dlsym(iokit, "IOHIDEventGetDataValue") : NULL;
+ vpUnserializeBinary = iokit ? dlsym(iokit, "IOCFUnserializeBinary") : NULL;
+ if (!create || !registerCallback || !schedule || !vpEventType || !vpEventInteger || !vpEventData ||
+ !vpUnserializeBinary)
+ return false;
+ // A monitor client (type 1), unmatched: dtuhidd creates the avpCustom
+ // service only when the first report arrives, and a client matched by its
+ // usage did not see that service's events.
+ VPHIDEventSystemClientRef client = create(kCFAllocatorDefault, 1, NULL);
+ if (!client) return false;
+ vpControlHandler = [handler copy];
+ registerCallback(client, vpDeviceHubEvent, NULL, NULL);
+ schedule(client, dispatch_queue_create("vphoned.devicehub-controls", DISPATCH_QUEUE_SERIAL));
+ return true;
+}
+
+void vp_device_orientation_publish(int deviceOrientation) {
+ // Beside the virtual hinge's newest sample, where the device state
+ // stand-in in dtdeviceinfod reads the hinge.
+ CFPreferencesSetValue(CFSTR("VPhoneDeviceOrientation"), (__bridge CFNumberRef)@(deviceOrientation),
+ CFSTR("com.apple.backboardd"), CFSTR("mobile"), kCFPreferencesAnyHost);
+ CFPreferencesSynchronize(CFSTR("com.apple.backboardd"), CFSTR("mobile"), kCFPreferencesAnyHost);
+}
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift
index ebbc0016..073c0307 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift
@@ -153,6 +153,9 @@ final class VPhoneGuestControl {
}
}
+ /// Folds this window asked for that have not answered yet.
+ @ObservationIgnored var foldRequestsInFlight = 0
+
@ObservationIgnored private var foldObservers: [(Double?, Double) -> Void] = []
@ObservationIgnored private var foldPositionObservers: [(VPhoneFoldPosition?) -> Void] = []
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlFold.swift b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlFold.swift
index 9b2ba2b7..11879a53 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlFold.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlFold.swift
@@ -16,6 +16,8 @@ extension VPhoneGuestControl {
if let duration {
params["duration"] = duration
}
+ foldRequestsInFlight += 1
+ defer { foldRequestsInFlight -= 1 }
let result = try await call("display.posture", params: params)
guard let angle = result.double("angle"), angle.isFinite, 0 ... 180 ~= angle,
let hinge = result.int("hinge"), 0 ... 4 ~= hinge
@@ -43,4 +45,16 @@ extension VPhoneGuestControl {
sweepMilliseconds: sweepMilliseconds,
)
}
+
+ /// The angle the guest's last fold settled at, which the orientation poll
+ /// reads (`display.orientation`'s `fold_angle`), so the window follows
+ /// folds it did not ask for, such as Xcode DeviceHub's. A fold this window
+ /// has in flight answers for itself; the guest publishes the angle only
+ /// once a fold has finished.
+ func followGuestFold(angle: Double) {
+ guard foldRequestsInFlight == 0, angle.isFinite, 0 ... 180 ~= angle, foldAngle != angle else { return }
+ foldSweepSeconds = 0
+ foldPosition = VPhoneFoldPosition.allCases.min { abs($0.angle - angle) < abs($1.angle - angle) }
+ foldAngle = angle
+ }
}
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift
index 608c19f0..d2fbb5fc 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift
@@ -296,8 +296,12 @@ class VPhoneVirtualMachineWindowController: NSObject, NSWindowDelegate {
orientationPollInFlight = true
Task {
defer { orientationPollInFlight = false }
- guard let result = try? await control.call("display.orientation"),
- !control.isChangingOrientation,
+ guard let result = try? await control.call("display.orientation") else { return }
+ // A foldable guest reports where its last fold settled.
+ if let foldAngle = (result["fold_angle"] as? NSNumber)?.doubleValue {
+ control.followGuestFold(angle: foldAngle)
+ }
+ guard !control.isChangingOrientation,
let degrees = (result["degrees"] as? NSNumber)?.intValue,
let orientation = VPhoneDisplayOrientation(degrees: degrees)
else { return }
diff --git a/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m b/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m
index 3158bcc6..b72e883e 100644
--- a/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m
+++ b/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m
@@ -109,10 +109,15 @@ static BOOL vpProviderIsRunning(void) {
// MARK: - The sample object
+// The angles are floats, as dtdeviceinfod's CMAngle_Bridge declares them
+// (Tf,R,N,V_angleDegrees): it reads s0, the low half of a double's d0, so a
+// double getter handed it 0° for every whole angle. Open and closed hid that
+// (their hinge states pin 180° and 0°); in book DeviceHub took the stream's
+// 0°, drew the device nearly closed and focused the cover.
typedef struct {
- double angle;
- double mechanical;
- double velocity;
+ float angle;
+ float mechanical;
+ float velocity;
double timestamp;
BOOL angleValid;
BOOL velocityValid;
@@ -147,9 +152,9 @@ static void vpRegisterAngleDataClass(void) {
VPAngleDataOffset = ivar_getOffset(class_getInstanceVariable(VPAngleDataClass, "fields"));
// The fields CMAngleManager_Bridge maps into DeviceHingeAngleSnapshot,
// with both spellings of the two flags.
- VP_SAMPLE_GETTER("angleDegrees", angle, "d16@0:8");
- VP_SAMPLE_GETTER("mechanicalAngleDegrees", mechanical, "d16@0:8");
- VP_SAMPLE_GETTER("velocityDegreesPerSeconds", velocity, "d16@0:8");
+ VP_SAMPLE_GETTER("angleDegrees", angle, "f16@0:8");
+ VP_SAMPLE_GETTER("mechanicalAngleDegrees", mechanical, "f16@0:8");
+ VP_SAMPLE_GETTER("velocityDegreesPerSeconds", velocity, "f16@0:8");
VP_SAMPLE_GETTER("timestamp", timestamp, "d16@0:8");
VP_SAMPLE_GETTER("isAngleValid", angleValid, "B16@0:8");
VP_SAMPLE_GETTER("angleValid", angleValid, "B16@0:8");
@@ -164,9 +169,9 @@ static id vpAngleDataFromSample(NSDictionary *latest) {
return nil;
id data = [VPAngleDataClass new];
VPAngleSampleFields *fields = (VPAngleSampleFields *)((char *)(__bridge void *)data + VPAngleDataOffset);
- fields->angle = [latest[@"angle"] doubleValue];
- fields->mechanical = [latest[@"mechanical_angle"] doubleValue];
- fields->velocity = [latest[@"velocity"] doubleValue];
+ fields->angle = [latest[@"angle"] floatValue];
+ fields->mechanical = [latest[@"mechanical_angle"] floatValue];
+ fields->velocity = [latest[@"velocity"] floatValue];
fields->timestamp = [latest[@"timestamp"] doubleValue];
fields->angleValid = latest[@"angle"] != nil;
fields->velocityValid = latest[@"velocity"] != nil;
@@ -344,9 +349,15 @@ typedef struct {
static VPDeviceState vpDeviceStateFromSample(NSDictionary *latest) {
long long hinge = [latest[@"state"] longLongValue];
+ // vphoned publishes the device orientation beside the sample (portrait
+ // until a rotation or DeviceHub's orientation picker sets one); the
+ // domain was just synchronized by vpLatestSample.
+ id published = CFBridgingRelease(CFPreferencesCopyValue(CFSTR("VPhoneDeviceOrientation"),
+ CFSTR("com.apple.backboardd"), CFSTR("mobile"), kCFPreferencesAnyHost));
+ long long orientation = [published isKindOfClass:NSNumber.class] ? [published longLongValue] : 1;
// The provider's state follows SpringBoard's table; open (4) is open
// flat to CoreMotion, which has no wider state.
- return (VPDeviceState){1, MIN(MAX(hinge, 0), 3), 0};
+ return (VPDeviceState){MIN(MAX(orientation, 1), 6), MIN(MAX(hinge, 0), 3), 0};
}
static id vpDeviceStateEvent(VPDeviceState state) {
@@ -452,12 +463,55 @@ static void vpInstallDeviceStateManagerStandIn(void) {
vpMotionLog(@"device state: CMDeviceStateManager surface not found, CoreDevice deviceMotionState stays off");
return;
}
+ // As for the angle manager: with the foldable's product-id locationd
+ // relays the virtual hinge into the real one.
+ if (((BOOL (*)(id, SEL))objc_msgSend)(manager, sel_registerName("isAvailable"))) {
+ vpMotionLog(@"device state: CoreMotion's own CMDeviceStateManager is available, no stand-in");
+ return;
+ }
vpOriginalStateIsAvailableIMP = method_setImplementation(available, (IMP)vpSwizzledStateIsAvailable);
method_setImplementation(start, (IMP)vpSwizzledStartStateUpdates);
method_setImplementation(stop, (IMP)vpSwizzledStopStateUpdates);
vpMotionLog(@"device state: stand-in installed");
}
+// MARK: - The inner display, as DeviceHub sees it
+//
+// DeviceHub draws a Duo's inner panel, and offers its pose controls, only for
+// an integrated display in DisplayInfo, which dtdeviceinfod builds from
+// CADisplay. The Duo's inner render display (libvphonefolddisplay) is a
+// virtual display at point scale 1 to every process but backboardd and
+// SpringBoard, where FoldDisplay presents it as the built-in 3x panel it
+// stands for; here it is presented the same way. DeviceHub then streams it
+// by display ID (libdevicehubfix.c answers that feature).
+static IMP vpOriginalDisplayType, vpOriginalPointScale;
+
+static BOOL vpIsInnerDisplay(id display) {
+ return [[display valueForKey:@"name"] isEqual:@"VPhone Duo Inner"];
+}
+
+static long long vpInnerDisplayType(id self, SEL selector) {
+ return vpIsInnerDisplay(self) ? 0 : ((long long (*)(id, SEL))vpOriginalDisplayType)(self, selector);
+}
+
+static unsigned long vpInnerPointScale(id self, SEL selector) {
+ return vpIsInnerDisplay(self) ? 3 : ((unsigned long (*)(id, SEL))vpOriginalPointScale)(self, selector);
+}
+
+static void vpInstallInnerDisplayPresentation(void) {
+ dlopen("/System/Library/Frameworks/QuartzCore.framework/QuartzCore", RTLD_LAZY | RTLD_LOCAL);
+ Class display = objc_getClass("CADisplay");
+ Method type = class_getInstanceMethod(display, sel_registerName("displayType"));
+ Method scale = class_getInstanceMethod(display, sel_registerName("pointScale"));
+ if (!type || !scale || strcmp(method_getTypeEncoding(type), "q16@0:8") != 0 ||
+ strcmp(method_getTypeEncoding(scale), "Q16@0:8") != 0) {
+ vpMotionLog(@"inner display: CADisplay ABI unavailable, DeviceHub sees it as virtual");
+ return;
+ }
+ vpOriginalDisplayType = method_setImplementation(type, (IMP)vpInnerDisplayType);
+ vpOriginalPointScale = method_setImplementation(scale, (IMP)vpInnerPointScale);
+}
+
// MARK: - Install
__attribute__((constructor)) static void vpInstallAngleManagerStandIn(void) {
@@ -465,6 +519,7 @@ __attribute__((constructor)) static void vpInstallAngleManagerStandIn(void) {
return;
dlopen("/System/Library/Frameworks/CoreMotion.framework/CoreMotion", RTLD_LAZY | RTLD_LOCAL);
vpInstallDeviceStateManagerStandIn();
+ vpInstallInnerDisplayPresentation();
Class manager = objc_getClass("CMAngleManager");
if (!manager) {
vpMotionLog(@"hinge manager: CMAngleManager not found, CoreDevice hingeAngle stays off");
diff --git a/VPhoneGuestComponents/DeviceHubFix/libdevicehubfix.c b/VPhoneGuestComponents/DeviceHubFix/libdevicehubfix.c
index fc5950e5..da1b37e1 100644
--- a/VPhoneGuestComponents/DeviceHubFix/libdevicehubfix.c
+++ b/VPhoneGuestComponents/DeviceHubFix/libdevicehubfix.c
@@ -50,10 +50,9 @@
// capture inside the guest, which does not ask either of them.
//
// The getter is interposed to answer with the features a Mac host offers
-// (primary display mirrored video, system audio and display information), and
-// `isCustomerRestricted`, which dtremotedisplayd also reads, answers no. The
-// host still intersects the answer with its own features, so asking for more
-// than the Mac can take changes nothing.
+// (primary display mirrored video, system audio and display information) plus
+// video by display ID, which an iPhone Duo's inner panel is streamed through,
+// and `isCustomerRestricted`, which dtremotedisplayd also reads, answers no.
//
// ## dtdeviceinfod: missing framebuffer mask
//
@@ -142,8 +141,10 @@
extern CFTypeRef MGCopyAnswer(CFStringRef key, CFDictionaryRef options);
// The features a Mac host reports for itself (raw 0x8c): primary display
-// mirrored output 0x4, system audio output 0x8, display information 0x80.
-#define VP_DEVICEHUB_FEATURES 0x8c
+// mirrored output 0x4, system audio output 0x8, display information 0x80;
+// and video output by display ID 0x100, which an iPhone Duo's inner panel
+// streams through (DeviceHub draws each integrated panel from its own display).
+#define VP_DEVICEHUB_FEATURES 0x18c
#define VP_STRINGIFY_(value) #value
#define VP_STRINGIFY(value) VP_STRINGIFY_(value)
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m
index 45fadd44..78b54828 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m
@@ -52,8 +52,8 @@ static void vpSetInnerDisplayProMotionMode(id display) {
return;
}
NSArray *colors = @[@{@"ID": @1, @"PixelEncoding": @0, @"Depth": @8, @"Colorimetry": @1, @"EOTF": @0, @"DynamicRange": @0}];
- NSArray *timings = @[@{@"ID": @1, @"Score": @1, @"HorizontalAttributes": @{@"Active": @2853},
- @"VerticalAttributes": @{@"Active": @2007, @"PreciseSyncRate": @(120 << 16)}}];
+ NSArray *timings = @[@{@"ID": @1, @"Score": @1, @"HorizontalAttributes": @{@"Active": @2007},
+ @"VerticalAttributes": @{@"Active": @2853, @"PreciseSyncRate": @(120 << 16)}}];
BOOL set = ((BOOL (*)(id, SEL, id, id))objc_msgSend)(display, setModes, colors, timings);
vpFoldDisplayLog([NSString stringWithFormat:@"inner display: 120 Hz mode %@", set ? @"set" : @"refused"]);
}
@@ -69,13 +69,15 @@ static BOOL vpAddInnerRenderDisplayToServer(id server) {
vpFoldDisplayLog(@"inner display: virtual display initializer ABI unavailable");
return NO;
}
- // The panel's native pixels, landscape: 951x669 points at 3x. Its
- // physical size, in inches, is what pixelsPerInch divides by; a
- // virtual display has none unless given one, and both panels share
- // the cover's 460 ppi pitch (MobileGestalt main-screen-pitch).
+ // The panel's native pixels, portrait as on hardware (669x951 points
+ // at 3x); its extended properties mount it at 270 degrees, so the
+ // landscape interface is drawn turned into it. Its physical size, in
+ // inches, is what pixelsPerInch divides by; a virtual display has
+ // none unless given one, and both panels share the cover's 460 ppi
+ // pitch (MobileGestalt main-screen-pitch).
id display = [(id<VPhoneInnerDisplayInitialization>)[cls alloc] initWithOptions:@{
- @"kCAVirtualDisplayWidth": @2853, @"kCAVirtualDisplayHeight": @2007,
- @"kCAVirtualDisplayPhysicalWidth": @(2853 / 460.0), @"kCAVirtualDisplayPhysicalHeight": @(2007 / 460.0),
+ @"kCAVirtualDisplayWidth": @2007, @"kCAVirtualDisplayHeight": @2853,
+ @"kCAVirtualDisplayPhysicalWidth": @(2007 / 460.0), @"kCAVirtualDisplayPhysicalHeight": @(2853 / 460.0),
@"kCAVirtualDisplayUpdateRate": @60, @"kCAVirtualDisplayName": vpInnerDisplayName,
}];
if (!display) { vpFoldDisplayLog(@"inner display: initializer returned nil"); return NO; }
@@ -166,12 +168,18 @@ static NSDictionary *vpGestaltDisplayProperties(NSNumber *surfaceType) {
static id vpSurfaceExtendedProperties(id self, SEL cmd) {
id properties = ((id (*)(id, SEL))vpOriginalExtendedProperties)(self, cmd);
id name = ((id (*)(id, SEL))objc_msgSend)(self, sel_registerName("deviceName"));
- NSNumber *surfaceType = [name isEqual:@"primary"] ? @1 : [name isEqual:vpInnerDisplayName] ? @2 : nil;
+ BOOL inner = [name isEqual:vpInnerDisplayName];
+ NSNumber *surfaceType = [name isEqual:@"primary"] ? @1 : inner ? @2 : nil;
if (!surfaceType || (properties && ![properties isKindOfClass:NSDictionary.class])) return properties;
NSMutableDictionary *derived = properties ? [properties mutableCopy] : [NSMutableDictionary dictionary];
- if ([surfaceType isEqual:@2])
+ if (inner)
[derived addEntriesFromDictionary:vpGestaltDisplayProperties(surfaceType) ?: @{}];
derived[@"DeviceSurfaceType"] = surfaceType;
+ derived[@"kMGQDeviceSurfaceType"] = surfaceType;
+ // The inner panel as Xcode 27.1's iPhone Duo simulator describes its
+ // second display.
+ if (inner) [derived addEntriesFromDictionary:@{@"DisplayRotation": @270, @"DisplayScale": @3,
+ @"ChromeIdentifier": @"com.apple.dt.devicekit.chrome.phone14", @"DeviceCornerRadius": @[@55, @55, @55, @55]}];
return [derived copy];
}
@@ -183,7 +191,8 @@ static id vpSurfaceExtendedProperties(id self, SEL cmd) {
// backboardd hit-tests touches on the inner display's own contexts.
// backboardd asks for a digitizer's display on every event and keeps
// digitizer state per display, so the state is created under the inner
-// display the first time it is missing there.
+// display the first time it is missing there. The inner display is portrait
+// like the panel, and the panel shows it unturned, so positions carry over.
static IMP vpOriginalDigitizerDisplayUUID, vpOriginalDigitizerState;
static BOOL vpLoggedDigitizerSwitch;
@@ -224,54 +233,6 @@ static id vpInnerDigitizerState(id self, SEL selector, id service) {
return state;
}
-// The inner panel is mounted at 270 degrees (device tree display1), so its
-// digitizer reports positions in the panel's portrait frame, and the panel
-// shows the inner display turned to match. This guest's single digitizer
-// reports positions on the portrait cover panel, which backboardd would
-// stretch onto the inner display's landscape space unturned; while the
-// inner display has the digitizer, each finger's normalized position is
-// turned by the mount first.
-typedef struct __IOHIDEvent *VPHIDEventRef;
-static IMP vpOriginalHandleDirectTouch;
-static CFArrayRef (*vpHIDEventChildren)(VPHIDEventRef);
-static uint32_t (*vpHIDEventType)(VPHIDEventRef);
-static double (*vpHIDEventGetFloat)(VPHIDEventRef, uint32_t);
-static void (*vpHIDEventSetFloat)(VPHIDEventRef, uint32_t, double);
-
-static void vpTurnDigitizerPosition(VPHIDEventRef event) {
- static const uint32_t digitizer = 11, x = 11 << 16, y = (11 << 16) | 1;
- if (vpHIDEventType(event) == digitizer) {
- double nx = vpHIDEventGetFloat(event, x), ny = vpHIDEventGetFloat(event, y);
- vpHIDEventSetFloat(event, x, 1 - ny);
- vpHIDEventSetFloat(event, y, nx);
- }
- CFArrayRef children = vpHIDEventChildren(event);
- for (CFIndex index = 0; children && index < CFArrayGetCount(children); index++)
- vpTurnDigitizerPosition((VPHIDEventRef)CFArrayGetValueAtIndex(children, index));
-}
-
-static void vpInnerHandleDirectTouch(id self, SEL selector, void *event, id service) {
- if (event && vpInnerPanelLit()) vpTurnDigitizerPosition((VPHIDEventRef)event);
- ((void (*)(id, SEL, void *, id))vpOriginalHandleDirectTouch)(self, selector, event, service);
-}
-
-static void vpInstallInnerDigitizerTurn(Class processor) {
- Method handle = class_getInstanceMethod(processor, sel_registerName("_handleDirectTouchEvent:service:"));
- const char *encoding = handle ? method_getTypeEncoding(handle) : "missing";
- vpHIDEventChildren = dlsym(RTLD_DEFAULT, "IOHIDEventGetChildren");
- vpHIDEventType = dlsym(RTLD_DEFAULT, "IOHIDEventGetType");
- vpHIDEventGetFloat = dlsym(RTLD_DEFAULT, "IOHIDEventGetFloatValue");
- vpHIDEventSetFloat = dlsym(RTLD_DEFAULT, "IOHIDEventSetFloatValue");
- size_t length = strlen(encoding);
- if (!vpHIDEventChildren || !vpHIDEventType || !vpHIDEventGetFloat || !vpHIDEventSetFloat ||
- strncmp(encoding, "v32@0:8", 7) != 0 || length < 3 || strcmp(encoding + length - 3, "@24") != 0) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: digitizer turn ABI unavailable (%s)", encoding]);
- return;
- }
- vpOriginalHandleDirectTouch = method_setImplementation(handle, (IMP)vpInnerHandleDirectTouch);
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: digitizer turn installed (%s)", encoding]);
-}
-
static void vpInstallInnerDigitizer(void) {
Class processor = objc_getClass("BKHIDDirectTouchEventProcessor");
Method uuid = class_getInstanceMethod(processor, sel_registerName("_queue_displayUUIDForDigitizerService:"));
@@ -287,65 +248,11 @@ static void vpInstallInnerDigitizer(void) {
vpOriginalDigitizerDisplayUUID = method_setImplementation(uuid, (IMP)vpInnerDigitizerDisplayUUID);
vpOriginalDigitizerState = method_setImplementation(state, (IMP)vpInnerDigitizerState);
vpFoldDisplayLog(@"inner display: digitizer routing installed");
- vpInstallInnerDigitizerTurn(processor);
-}
-
-// MARK: - mirroring
-
-// A mirror of the screen (Xcode's DeviceHub stream, AirPlay, recording) is a
-// clone of a display, and backboardd moves it to whichever display holds the
-// primary content: open, the inner render display. A clone is rotated upright
-// by its master's orientation, so it carried the inner display upright and
-// letterboxed. DeviceHub draws an open Duo's stream on the inner panel as
-// that panel's native framebuffer, portrait and mounted a quarter turn
-// (2007x2853 at 270 degrees), and turned the upright picture a quarter more.
-// The panel itself (LCD) is that framebuffer: open, SpringBoard shows the
-// inner display on it turned a quarter (FoldDisplayPanel.m). So every clone
-// stays on the panel, as the VM window shows it. A clone is removed from the
-// master that really holds it: CoreAnimation aborts on removing a clone from
-// a display it is not cloned from.
-static IMP vpOriginalAddClone, vpOriginalRemoveClone;
-
-static id vpPanelDisplay(void) {
- id server = ((id (*)(id, SEL))objc_msgSend)(objc_getClass("CAWindowServer"), sel_registerName("serverIfRunning"));
- for (id display in [server valueForKey:@"displays"] ?: @[])
- if ([[display valueForKey:@"displayId"] unsignedIntValue] == 1) return display;
- return nil;
-}
-
-static void vpPanelAddClone(id self, SEL selector, id clone, id options) {
- id panel = self == vpInnerRenderDisplay ? vpPanelDisplay() : nil;
- if (panel && clone != panel) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: %@ mirrors the panel instead", [clone valueForKey:@"name"]]);
- self = panel;
- }
- ((void (*)(id, SEL, id, id))vpOriginalAddClone)(self, selector, clone, options);
-}
-
-static void vpPanelRemoveClone(id self, SEL selector, id clone) {
- id master = [clone valueForKey:@"cloneMaster"];
- if (!master) return;
- ((void (*)(id, SEL, id))vpOriginalRemoveClone)(master, selector, clone);
-}
-
-static void vpInstallPanelMirroring(void) {
- Class display = objc_getClass("CAWindowServerDisplay");
- Method add = class_getInstanceMethod(display, sel_registerName("addClone:options:"));
- Method remove = class_getInstanceMethod(display, sel_registerName("removeClone:"));
- if (!add || !remove || strcmp(method_getTypeEncoding(add), "v32@0:8@16@24") != 0 ||
- strcmp(method_getTypeEncoding(remove), "v24@0:8@16") != 0 ||
- ![display instancesRespondToSelector:sel_registerName("cloneMaster")]) {
- vpFoldDisplayLog(@"inner display: clone ABI unavailable, mirrors follow the inner display");
- return;
- }
- vpOriginalAddClone = method_setImplementation(add, (IMP)vpPanelAddClone);
- vpOriginalRemoveClone = method_setImplementation(remove, (IMP)vpPanelRemoveClone);
}
// MARK: - installation
void vpInstallInnerRenderDisplay(void) {
- vpInstallPanelMirroring();
vpInstallInnerDigitizer();
Method extended = class_getInstanceMethod(objc_getClass("CAWindowServerDisplay"), sel_registerName("extendedProperties"));
if (extended && strcmp(method_getTypeEncoding(extended), "@16@0:8") == 0)
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
index 0153fb35..ff44e3f4 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
@@ -304,12 +304,12 @@ static void vpShowInnerDisplay(BOOL shown) {
}
}
if (!vpInnerPanelQueue) vpInnerPanelQueue = dispatch_queue_create("com.vphone.folddisplay.inner-panel", DISPATCH_QUEUE_SERIAL);
- // The inner display fills the panel, turned a quarter (-90 degrees)
- // when it reads landscape on the portrait panel. The panel is the
- // cover's, a little narrower than the inner display (1398x2034
- // against 2007x2853), so the fill is about 2% tighter across than
- // along; it leaves no bars, and the digitizer, which spans the panel,
- // maps onto the whole inner display as it is.
+ // The inner display is portrait like the panel and fills it as it is
+ // (one that read landscape would be turned a quarter, -90 degrees).
+ // The panel is the cover's, a little narrower than the inner display
+ // (1398x2034 against 2007x2853), so the fill is about 2% tighter
+ // across than along; it leaves no bars, and the digitizer, which
+ // spans the panel, maps onto the whole inner display as it is.
id rootLayer = vpReadObject(rootWindow, "layer");
CGRect panel = ((CGRect (*)(id, SEL))objc_msgSend)(rootLayer, sel_registerName("bounds"));
CGFloat pointScale = ((double (*)(id, SEL))objc_msgSend)(vpReadObject(rootWindow, "screen"), sel_registerName("scale"));
diff --git a/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m b/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
index 83b7f2fc..49679a8e 100644
--- a/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
+++ b/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
@@ -1,10 +1,11 @@
// The iPhone Duo's inner display. A real Duo drives two panels: the cover is
// Main (device tree display0) and the inner panel is a second built-in,
-// always-connected, landscape display mounted at 270 degrees (display1).
-// This guest has one portrait panel. backboardd publishes the inner panel as
-// a software render display, SpringBoard resolves the fold postures
-// (FoldingDual open, FullyClosed closed) for both displays natively, and the
-// lit display is shown on the one panel. See
+// always-connected display (display1), 2007x2853 mounted at 270 degrees so it
+// reads landscape. This guest has one portrait panel. backboardd publishes
+// the inner panel as a software render display shaped like the hardware one,
+// SpringBoard resolves the fold postures (FoldingDual open, FullyClosed
+// closed) for both displays natively, and the lit display is shown on the
+// one panel. See
// Research/Guest/iphone_duo_bringup.md.
#import "FoldDisplayPrivate.h"