Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Duo spike: let SpringBoard resolve the cover and inner displays natively

Jacky3d7da8390021
diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.md
index c9034c56..9c903d8d 100644
--- a/Research/Guest/iphone_duo_bringup.md
+++ b/Research/Guest/iphone_duo_bringup.md
@@ -4334,3 +4334,31 @@ For later: the inner panel's `Fold` region is `{0, 1335, 1878, 0}` in its
own pixels, which suggests a 1878-pixel-wide panel folding at row 1335;
this guest's 2007×2853 Main and the spike's 2853×2007 inner display were
not taken from the device tree.
+
+### SpringBoard's own posture logic drives both displays (2026-10-28 night)
+
+With the inner display published, backboardd now answers the device tree's
+roles through `extendedProperties` `DeviceSurfaceType`: the primary panel 1
+(`.cover`), the inner display 2 (`.inner`). FoldDisplay's SB-side
+`vpLogicalSurfaceType` and `vpSyncLogicalRoleResolver`, which forced Main
+to `.inner` for the single-display model, step aside while the inner display
+is requested. SB-main then reads surfaceType 1 and the inner scene 2.
+
+`-[SBDisplayContentModeCoordinator windowSceneDidConnect:]` is what calls
+`-[SBFDisplayContentModeResolver startResolvingContentModeOfDisplayForWindowScene:]`,
+and the inner display's bringup scene is never handed to it.
+`com.vphone.display.inner.resolve` hands it over (once; the resolver's
+`_displayProxies` is keyed by hardware identifier). The resolver then holds
+`legacyMain` (`.cover`) and the inner display (`.inner`), and the hinge
+picks the policy natively:
+
+| `display.posture` | Prevailing policy | Cover (Main) | Inner |
+|---|---|---|---|
+| `open` (hinge 3, 180°, `.openFlat`) | `FoldingDual`, primary on `.inner` | `.auxiliaryContent` | `.primaryContent` |
+| `closed` (hinge 1) | `FullyClosed` | `.primaryContent` | `.disabled` |
+
+Closed, the panel shows SpringBoard's real cover lock screen and the VM
+window is cover-sized. Open, the panel goes black at 0 fps: SpringBoard
+turns the cover display off, as on a real Duo, and on this guest the cover
+is Main, the only physical scanout, so the composited inner display has
+nowhere to appear. SpringBoard stayed up throughout.
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerDisplay.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerDisplay.m
index 68866e7b..ad8e3bd6 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerDisplay.m
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerDisplay.m
@@ -67,6 +67,15 @@ static void vpAddInnerRenderDisplay(unsigned int attempt) {
}
}
+// The surface type backboardd reports for a render display, from the
+// iPhone19,4 device tree: display0 (the primary, cover) 1, display1 (inner) 2.
+NSNumber *vpInnerDisplaySurfaceType(id deviceName) {
+ if (!vpInnerDisplayRequested()) return nil;
+ if ([deviceName isEqual:@"primary"]) return @1;
+ if ([deviceName isEqual:vpInnerDisplayName]) return @2;
+ return nil;
+}
+
void vpInstallInnerRenderDisplay(void) {
if (!vpInnerDisplayRequested()) return;
dispatch_async(dispatch_get_main_queue(), ^{ vpAddInnerRenderDisplay(0); });
@@ -274,6 +283,32 @@ void vpShowInnerDisplay(BOOL shown) {
}
}
+// MARK: - SpringBoard: content mode resolution
+
+// SpringBoard's display content mode coordinator starts resolving a window
+// scene's display when the scene connects to it; the inner display's scene
+// is never handed over. Hands it over and logs what the resolver makes of
+// the two panels.
+void vpResolveInnerDisplay(void) {
+ @try {
+ id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
+ id coordinator = vpReadObject(app, "displayContentModeCoordinator");
+ id innerScene = vpSpringBoardWindowScene(YES);
+ Method connect = class_getInstanceMethod(object_getClass(coordinator), sel_registerName("windowSceneDidConnect:"));
+ if (!coordinator || !innerScene || !connect || strcmp(method_getTypeEncoding(connect), "v24@0:8@16") != 0) {
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: resolve unavailable coordinator=%@ scene=%@", coordinator, innerScene]);
+ return;
+ }
+ if (![[vpReadObjectIvar(vpLogicalRoleResolver, "_displayProxies") allKeys] containsObject:
+ vpReadObject(vpReadObject(vpReadObject(vpReadObject(innerScene, "_FBSScene"), "settings"), "displayConfiguration"), "hardwareIdentifier")])
+ ((void (*)(id, SEL, id))objc_msgSend)(coordinator, sel_registerName("windowSceneDidConnect:"), innerScene);
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: resolve %@ -> %@",
+ vpReadObject(vpReadObject(innerScene, "_FBSScene"), "identifier"), vpLogicalRoleResolver]);
+ } @catch (NSException *exception) {
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: resolve exception %@", exception.reason]);
+ }
+}
+
// MARK: - Stage 1 test pattern
// A window on the inner display's scene with a clock that changes every
@@ -395,9 +430,18 @@ void vpInspectInnerDisplay(void) {
@catch (__unused NSException *exception) {}
id type = configuration && displayType ? displayType(configuration) : nil;
BOOL rotates = type && supports && deviceClass && lockRole && *lockRole ? supports(*lockRole, type, deviceClass()) : NO;
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: scene %@ %@ display=%@ bounds=%@ posterType=%@ dynamicRotation=%d",
+ NSMutableString *roles = [NSMutableString string];
+ for (NSString *key in @[@"type", @"connectionType", @"isUIKitMainLike", @"isAlwaysConnected", @"hardwareIdentifier"]) {
+ id value = nil;
+ @try { value = [configuration valueForKey:key]; } @catch (__unused NSException *exception) { value = @"-"; }
+ [roles appendFormat:@" %@=%@", key, value];
+ }
+ id surface = nil;
+ @try { surface = [scene valueForKey:@"surfaceType"]; } @catch (__unused NSException *exception) {}
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: scene %@ %@ display=%@ bounds=%@ posterType=%@ dynamicRotation=%d surfaceType=%@ delegate=%@%@",
NSStringFromClass([scene class]), vpReadObject(vpReadObject(scene, "_FBSScene"), "identifier"),
- vpReadObject(configuration, "identity"), [configuration valueForKey:@"bounds"], type, rotates]);
+ vpReadObject(configuration, "identity"), [configuration valueForKey:@"bounds"], type, rotates, surface,
+ NSStringFromClass([vpReadObject(scene, "delegate") class]), roles]);
}
} @catch (NSException *exception) {
vpFoldDisplayLog([NSString stringWithFormat:@"inner display: inspect exception %@", exception.reason]);
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPrivate.h b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPrivate.h
index fb900fbd..e9327f44 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPrivate.h
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPrivate.h
@@ -182,9 +182,11 @@ void vpVirtualDisplayExperiment(BOOL create);
// MARK: - inner display spike
BOOL vpInnerDisplayRequested(void);
+NSNumber *vpInnerDisplaySurfaceType(id deviceName);
void vpInstallInnerRenderDisplay(void);
void vpShowInnerDisplay(BOOL shown);
void vpToggleInnerPattern(void);
+void vpResolveInnerDisplay(void);
void vpInstallInnerDisplayAdapter(void);
void vpInspectInnerDisplay(void);
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplaySurfaceProbe.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplaySurfaceProbe.m
index 5d5990f3..49117c23 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplaySurfaceProbe.m
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplaySurfaceProbe.m
@@ -14,8 +14,17 @@ static atomic_uint vpSurfaceProbeLogCount;
// changes neither the framebuffer nor the number/identity of display sources.
id vpSurfaceExtendedProperties(id self, SEL cmd) {
id properties = ((id (*)(id, SEL))vpOriginalExtendedProperties)(self, cmd);
- if (!atomic_load_explicit(&vpInnerSurfaceProbeEnabled, memory_order_acquire)) return properties;
id name = ((id (*)(id, SEL))objc_msgSend)(self, sel_registerName("deviceName"));
+ // With the inner display published, the device tree's roles hold for
+ // good: the primary panel is the cover (display0, surface-type 1) and
+ // the inner panel is the second display (display1, surface-type 2).
+ NSNumber *role = vpInnerDisplaySurfaceType(name);
+ if (role && (!properties || [properties isKindOfClass:NSDictionary.class])) {
+ NSMutableDictionary *derived = properties ? [properties mutableCopy] : [NSMutableDictionary dictionary];
+ derived[@"DeviceSurfaceType"] = role;
+ return [derived copy];
+ }
+ if (!atomic_load_explicit(&vpInnerSurfaceProbeEnabled, memory_order_acquire)) return properties;
BOOL primary = [name isEqual:@"primary"];
BOOL cover = atomic_load_explicit(&vpCoverSurfaceProbeEnabled, memory_order_acquire) &&
[name isEqual:@"VPhone Cover Probe"];
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayViewport.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayViewport.m
index ed4fffbf..3d0cc0e3 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayViewport.m
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayViewport.m
@@ -112,6 +112,8 @@ void vpLogicalProjectionControl(NSInteger action) {
}
void vpSyncLogicalRoleResolver(void) {
+ // A published inner display gives the resolver both panels natively.
+ if (vpInnerDisplayRequested()) return;
@try {
id resolver = vpLogicalRoleResolver;
NSDictionary *proxies = vpReadObjectIvar(resolver, "_displayProxies");
@@ -399,7 +401,9 @@ void vpSetCoverViewport(BOOL enabled) {
// Scoped experiment: do not change CADisplay type or resolver source count.
NSInteger vpLogicalSurfaceType(id self, SEL selector) {
NSInteger native = ((NSInteger (*)(id, SEL))vpOriginalLogicalSurfaceType)(self, selector);
- if (vpReadingLogicalSurface || !vpAutomaticMainStatus) return native;
+ // A published inner display carries the roles natively (backboardd's
+ // DeviceSurfaceType, FoldDisplayInnerDisplay.m).
+ if (vpReadingLogicalSurface || !vpAutomaticMainStatus || vpInnerDisplayRequested()) return native;
vpReadingLogicalSurface = YES;
@try {
if (![vpReadObject(vpReadObject(self, "_FBSScene"), "identifier") isEqual:@"SB-main"]) return native;
diff --git a/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m b/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
index 2c355fd1..fc23a49f 100644
--- a/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
+++ b/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
@@ -172,6 +172,9 @@ static void vpRegisterSpringBoardNotifications(void) {
^(int token) { vpShowInnerDisplay(YES); });
notify_register_dispatch("com.vphone.display.inner.hide", &innerHideToken, dispatch_get_main_queue(),
^(int token) { vpShowInnerDisplay(NO); });
+ static int innerResolveToken;
+ notify_register_dispatch("com.vphone.display.inner.resolve", &innerResolveToken, dispatch_get_main_queue(),
+ ^(int token) { vpResolveInnerDisplay(); });
static int persistentCoverToken, persistentInnerToken;
notify_register_dispatch("com.vphone.display.viewport.apply.cover", &persistentCoverToken, dispatch_get_main_queue(),
^(int token) { vpSetPersistentViewport(YES); });