Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Duo: keep dtdeviceinfod alive when DeviceHub reconnects

Jacky0017bb4156a0
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index 919c83de..ff47226f 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -5676,4 +5676,4 @@ The host VM view now derives its input geometry from the active Duo viewport (`a
> **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.
+> **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 skips `-[CMAngleManagerInternal stopAngleUpdatesPrivate]` (reached from `-[CMAngleManager dealloc]`, it asserts the real hinge notifier is available and aborted `dtdeviceinfod` whenever DeviceHub reconnected), its `minAngleDegrees`/`maxAngleDegrees` return floats, and its `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 e3935bd9..da4bcf73 100644
--- a/Research/Guest/devicehub_screen_viewing.md
+++ b/Research/Guest/devicehub_screen_viewing.md
@@ -638,6 +638,22 @@ 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.
+
+
+`dtdeviceinfod` aborted whenever it let a `CMAngleManager` go, as when
+DeviceHub quit or reconnected: `-[CMAngleManager dealloc]` stops
+CoreMotion's own manager, and `-[CMAngleManagerInternal
+stopAngleUpdatesPrivate]` asserts `CLAngleNotifier::isAvailable()`
+(`CMAngleManager.mm` line 214), which is false on a guest without the
+foldable product-id. The relaunched `dtdeviceinfod` left DeviceHub without
+the device state, and its fold controls stopped working until DeviceHub was
+restarted. The stand-in now skips that internal stop, since under it the
+real manager never started. Its `minAngleDegrees` and `maxAngleDegrees` also
+return floats, as declared. Six crash reports with the same stack were
+collected on 2026-10-29 and 2026-10-30. With the fix, `dtdeviceinfod` kept
+running through a DeviceHub quit and relaunch, and DeviceHub followed the
+guest to book and closed afterwards.
+
Restarting backboardd breaks `dtuhidd`'s HID connection and DeviceHub keeps
the dead one: restart DeviceHub after a respring.
diff --git a/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m b/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m
index b72e883e..3a264d44 100644
--- a/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m
+++ b/VPhoneGuestComponents/DeviceHubFix/VPCMAngleManager.m
@@ -280,8 +280,18 @@ static BOOL vpSwizzledIsAvailable(id self, SEL selector) {
return ((BOOL (*)(id, SEL))vpOriginalIsAvailableIMP)(self, selector);
}
-static double vpSwizzledMinAngle(id self, SEL selector) { return 0.0; }
-static double vpSwizzledMaxAngle(id self, SEL selector) { return 180.0; }
+// Floats, as CoreMotion declares them (`+ (float)minAngleDegrees`): a
+// double in d0 reads back as 0 from s0, the trap the sample fields hit.
+static float vpSwizzledMinAngle(id self, SEL selector) { return 0.0f; }
+static float vpSwizzledMaxAngle(id self, SEL selector) { return 180.0f; }
+
+// -[CMAngleManager dealloc] stops CoreMotion's own manager, and
+// -[CMAngleManagerInternal stopAngleUpdatesPrivate] asserts that the real
+// hinge notifier is available (CMAngleManager.mm line 214). Under the
+// stand-in that manager never started, so its stop is skipped: dtdeviceinfod
+// aborted every time it let a manager go, as when DeviceHub reconnected, and
+// DeviceHub lost the device state until it was restarted.
+static void vpSkippedInternalStop(id self, SEL selector) {}
static void vpSwizzledStartUpdates(id self, SEL selector, id queue, id handler) {
VPAngleSession *session = vpSession(self);
@@ -563,6 +573,10 @@ __attribute__((constructor)) static void vpInstallAngleManagerStandIn(void) {
vpOriginalStopIMP = method_getImplementation(stop);
method_setImplementation(stop, (IMP)vpSwizzledStopUpdates);
}
+ Method internalStop = class_getInstanceMethod(objc_getClass("CMAngleManagerInternal"),
+ sel_registerName("stopAngleUpdatesPrivate"));
+ if (internalStop && strcmp(method_getTypeEncoding(internalStop), "v16@0:8") == 0)
+ method_setImplementation(internalStop, (IMP)vpSkippedInternalStop);
Method active = class_getInstanceMethod(manager, sel_registerName("isAngleActive"));
if (active) {
vpOriginalActiveIMP = method_getImplementation(active);
@@ -580,8 +594,9 @@ __attribute__((constructor)) static void vpInstallAngleManagerStandIn(void) {
}
BOOL sampleReady = VPAngleDataClass != NULL;
- vpMotionLog(@"hinge manager: stand-in v6 installed (start=%@ setHandler=%@ stop=%@ active=%@ interval=%@ sample=%@ base=%@)",
+ vpMotionLog(@"hinge manager: stand-in v7 installed (start=%@ setHandler=%@ stop=%@ internalStop=%@ active=%@ interval=%@ sample=%@ base=%@)",
start ? @"yes" : @"MISSING", setHandler ? @"yes" : @"missing", stop ? @"yes" : @"missing",
+ internalStop ? @"yes" : @"MISSING",
active ? @"yes" : @"missing", getInterval ? @"yes" : @"missing",
sampleReady ? @"ready" : @"MISSING",
VPAngleDataClass ? class_getSuperclass(VPAngleDataClass) : nil);