Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Duo: keep only the two-display path in FoldDisplay

Jacky31fecc2f10aa
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
index 3a6b36c3..4d84cb5e 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
@@ -537,9 +537,16 @@ public enum FirmwareGuestSystemPatchSet {
VPhonePatchDeclaration(
identifier: foldDisplay,
- title: "Foldable second-display identity",
+ title: "Foldable inner display",
summary: """
- Installs libvphonefolddisplay.dylib, loaded by SystemHook into SpringBoard. SpringBoard sizes its home grid from the display topology: with one always-connected display the grid keeps the outer panel's fit whatever the panel's pixel size, because the fold layouts key on +[FBDisplayManager alwaysConnectedIdentities].count >= 2 and the guest's paravirt GPU binds a single connector. The library pads a single answer with a copy of the real identity, so the count gates pass without inventing a display. Experimental: whether the grid then follows the posture is what this observes, and identity-keyed consumers may dedupe the copy. Foldable guests only.
+ Installs libvphonefolddisplay.dylib, loaded by SystemHook into backboardd and \
+ SpringBoard. A real iPhone Duo drives two panels: the cover is Main and the \
+ inner panel a second built-in, always-connected landscape display. backboardd \
+ publishes the inner panel as a software render display with the device tree's \
+ surface types and routes the one digitizer to whichever panel is lit; SpringBoard \
+ classifies it as built-in, resolves the fold postures for both displays natively \
+ and composites the inner display onto the guest's single panel while open. \
+ Experimental. Acts only on iPhone19,4.
""",
target: .guestFile(path: "/usr/lib/libvphonefolddisplay.dylib"),
applicability: VPhonePatchApplicability(iOSBase: .major(27)),
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayAdapter.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayAdapter.m
new file mode 100644
index 00000000..1dffd66c
--- /dev/null
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayAdapter.m
@@ -0,0 +1,219 @@
+// SpringBoard: how the system sees the inner display, and handing it to the
+// content mode resolver so the hinge can move content onto it.
+
+#import "FoldDisplayPrivate.h"
+
+// MARK: - the inner display and its scenes
+
+BOOL vpIsInnerDisplay(id display) {
+ @try {
+ for (NSString *key in @[@"name", @"deviceName"]) {
+ if ([display respondsToSelector:NSSelectorFromString(key)] &&
+ [[display valueForKey:key] isEqual:vpInnerDisplayName]) return YES;
+ }
+ } @catch (__unused NSException *exception) {
+ }
+ return NO;
+}
+
+BOOL vpSceneIsOnInnerDisplay(id scene) {
+ id configuration = vpReadObject(vpReadObject(vpReadObject(scene, "_FBSScene"), "settings"), "displayConfiguration");
+ id identity = vpReadObject(configuration, "identity");
+ return identity && ![[identity description] isEqual:@"Main"];
+}
+
+id vpSpringBoardWindowScene(BOOL inner) {
+ id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
+ for (id scene in [vpReadObject(app, "connectedScenes") allObjects] ?: @[])
+ if ([scene class] == objc_getClass("SBWindowScene") && vpSceneIsOnInnerDisplay(scene) == inner) return scene;
+ return nil;
+}
+
+// MARK: - classification
+
+// The inner panel is a built-in panel (CADisplay type 0) to everything that
+// asks: BacklightServices gives a backlight host only to built-in displays,
+// and every SpringBoard window scene needs one; SpringBoard's startup waits
+// for a scene on every built-in display. Only FrontBoard's configuration
+// classification sees type 4: in _FBSCADisplayToDisplayTypes that type is
+// always-connected without being UIKit-main-like, so only the real Main
+// claims the cloning source (claiming it twice is SpringBoard's "Cloning
+// source already exists" assertion).
+static IMP vpOriginalDisplayType, vpOriginalPointScale, vpOriginalExternal, vpOriginalConfigurationInit;
+static _Thread_local BOOL vpClassifyingConfiguration;
+static id vpInnerIdentity;
+
+static long long vpInnerDisplayType(id self, SEL selector) {
+ if (!vpIsInnerDisplay(self)) return ((long long (*)(id, SEL))vpOriginalDisplayType)(self, selector);
+ return vpClassifyingConfiguration ? 4 : 0;
+}
+
+static id vpInnerConfigurationInit(id self, SEL selector, id display, id original, BOOL isMain, BOOL assertIfInvalid) {
+ vpClassifyingConfiguration = YES;
+ id result = ((id (*)(id, SEL, id, id, BOOL, BOOL))vpOriginalConfigurationInit)(self, selector, display, original, isMain, assertIfInvalid);
+ vpClassifyingConfiguration = NO;
+ if (vpIsInnerDisplay(display) && !vpInnerIdentity) vpInnerIdentity = vpReadObject(result, "identity");
+ return result;
+}
+
+static NSUInteger vpInnerPointScale(id self, SEL selector) {
+ return vpIsInnerDisplay(self) ? 3 : ((NSUInteger (*)(id, SEL))vpOriginalPointScale)(self, selector);
+}
+
+static BOOL vpInnerExternal(id self, SEL selector) {
+ return vpIsInnerDisplay(self) ? NO : ((BOOL (*)(id, SEL))vpOriginalExternal)(self, selector);
+}
+
+static IMP vpReplaceDisplayGetter(const char *name, const char *encoding, IMP replacement) {
+ Method method = class_getInstanceMethod(objc_getClass("CADisplay"), sel_registerName(name));
+ if (!method || strcmp(method_getTypeEncoding(method), encoding) != 0) {
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: -[CADisplay %s] %s, expected %s", name,
+ method ? method_getTypeEncoding(method) : "missing", encoding]);
+ return NULL;
+ }
+ return method_setImplementation(method, replacement);
+}
+
+// MARK: - idiom
+
+// Applications take the scene's display identity from SpringBoard. UIKit
+// gives a screen the device idiom only when that identity is UIKit-main-like
+// and leaves it unspecified (-1) otherwise; UIKit's Swift idiom switches
+// (sheet presentation, scroll edge effects) trap on -1. The identity
+// SpringBoard keeps stays as classified, so only Main claims the cloning
+// source; the copy an application decodes says main-like.
+static IMP vpOriginalIdentityEncode;
+
+static void vpInnerIdentityEncode(id self, SEL selector, xpc_object_t dictionary) {
+ ((void (*)(id, SEL, xpc_object_t))vpOriginalIdentityEncode)(self, selector, dictionary);
+ if (dictionary && vpInnerIdentity && [self isEqual:vpInnerIdentity])
+ xpc_dictionary_set_bool(dictionary, "mainLike", true);
+}
+
+static void vpInstallInnerIdentityEncode(void) {
+ Method encode = class_getInstanceMethod(objc_getClass("FBSDisplayIdentity"), sel_registerName("encodeWithXPCDictionary:"));
+ if (!encode || strcmp(method_getTypeEncoding(encode), "v24@0:8@16") != 0) {
+ vpFoldDisplayLog(@"inner display: identity encoding ABI unavailable");
+ return;
+ }
+ vpOriginalIdentityEncode = method_setImplementation(encode, (IMP)vpInnerIdentityEncode);
+}
+
+// SpringBoard's own screens follow the same rule: UIScreen takes the device
+// idiom only for a UIKit-main-like screen and leaves every other non-car
+// screen unspecified (-1); UIKit's Swift idiom switch (ScrollEdgeEffectView)
+// traps on -1 during posture changes. The inner panel is a built-in phone
+// panel, so its screen takes the device idiom too.
+static IMP vpOriginalUpdateScreenIdiom;
+
+static void vpInnerUpdateScreenIdiom(id self, SEL selector) {
+ ((void (*)(id, SEL))vpOriginalUpdateScreenIdiom)(self, selector);
+ id identity = vpReadObject(vpReadObject(self, "displayConfiguration"), "identity");
+ if (!identity || [[identity description] isEqual:@"Main"]) return;
+ if (((long long (*)(id, SEL))objc_msgSend)(self, sel_registerName("_userInterfaceIdiom")) != -1) return;
+ long long idiom = ((long long (*)(id, SEL))objc_msgSend)(vpReadObject(objc_getClass("UIDevice"), "currentDevice"),
+ sel_registerName("userInterfaceIdiom"));
+ ((void (*)(id, SEL, long long))objc_msgSend)(self, sel_registerName("_setUserInterfaceIdiom:"), idiom);
+}
+
+static void vpInstallInnerScreenIdiom(void) {
+ Class screen = objc_getClass("UIScreen");
+ Method update = class_getInstanceMethod(screen, sel_registerName("_updateUserInterfaceIdiom"));
+ Method set = class_getInstanceMethod(screen, sel_registerName("_setUserInterfaceIdiom:"));
+ Method get = class_getInstanceMethod(screen, sel_registerName("_userInterfaceIdiom"));
+ if (!update || !set || !get || strcmp(method_getTypeEncoding(update), "v16@0:8") != 0 ||
+ strcmp(method_getTypeEncoding(set), "v24@0:8q16") != 0 || strcmp(method_getTypeEncoding(get), "q16@0:8") != 0) {
+ vpFoldDisplayLog(@"inner display: screen idiom ABI unavailable");
+ return;
+ }
+ vpOriginalUpdateScreenIdiom = method_setImplementation(update, (IMP)vpInnerUpdateScreenIdiom);
+}
+
+// MARK: - 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, so the hinge could not move content to it. The
+// resolver is recorded as it starts resolving Main, and the inner scene is
+// handed over once it and the resolver both exist (the resolver keys its
+// display proxies by hardware identifier, so this runs once per
+// SpringBoard).
+static IMP vpOriginalStartResolvingDisplay;
+static __weak id vpContentModeResolver;
+
+static void vpRecordContentModeResolver(id self, SEL selector, id proxy) {
+ ((void (*)(id, SEL, id))vpOriginalStartResolvingDisplay)(self, selector, proxy);
+ vpContentModeResolver = self;
+}
+
+// Whether the inner display is resolved, handing it over first if needed.
+static BOOL vpHandOverInnerDisplay(void) {
+ id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
+ id coordinator = vpReadObject(app, "displayContentModeCoordinator");
+ id innerScene = vpSpringBoardWindowScene(YES);
+ id resolver = vpContentModeResolver;
+ Method connect = class_getInstanceMethod(object_getClass(coordinator), sel_registerName("windowSceneDidConnect:"));
+ if (!coordinator || !innerScene || !resolver || !connect || strcmp(method_getTypeEncoding(connect), "v24@0:8@16") != 0)
+ return NO;
+ id identifier = vpReadObject(vpReadObject(vpReadObject(vpReadObject(innerScene, "_FBSScene"), "settings"),
+ "displayConfiguration"), "hardwareIdentifier");
+ if ([[vpReadObjectIvar(resolver, "_displayProxies") allKeys] containsObject:identifier]) return YES;
+ ((void (*)(id, SEL, id))objc_msgSend)(coordinator, sel_registerName("windowSceneDidConnect:"), innerScene);
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: handed %@ to the content mode resolver: %@",
+ vpReadObject(vpReadObject(innerScene, "_FBSScene"), "identifier"), resolver]);
+ return [[vpReadObjectIvar(resolver, "_displayProxies") allKeys] containsObject:identifier];
+}
+
+// From SpringBoard's start, until the inner display is resolved.
+static void vpWatchInnerDisplayResolution(void) {
+ static dispatch_source_t timer;
+ static unsigned int attempts;
+ timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
+ dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), NSEC_PER_SEC, NSEC_PER_SEC / 10);
+ dispatch_source_set_event_handler(timer, ^{
+ BOOL resolved = NO;
+ @try { resolved = vpHandOverInnerDisplay(); } @catch (__unused NSException *exception) {}
+ if (resolved || ++attempts >= 600) {
+ dispatch_source_cancel(timer);
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: resolution watch done resolved=%d after %u s", resolved, attempts]);
+ }
+ });
+ dispatch_resume(timer);
+}
+
+static void vpInstallContentModeResolution(void) {
+ Method start = class_getInstanceMethod(objc_getClass("SBFDisplayContentModeResolver"),
+ sel_registerName("_startResolvingContentModeOfDisplay:"));
+ if (!start || strcmp(method_getTypeEncoding(start), "v24@0:8@16") != 0) {
+ vpFoldDisplayLog(@"inner display: content mode resolver ABI unavailable");
+ return;
+ }
+ vpOriginalStartResolvingDisplay = method_setImplementation(start, (IMP)vpRecordContentModeResolver);
+ vpWatchInnerDisplayResolution();
+}
+
+// MARK: - installation
+
+// Installed before SpringBoard's display monitor reads the render displays.
+// CADisplay has no always-connected getter; FrontBoard derives that from
+// the type.
+void vpInstallInnerDisplayAdapter(void) {
+ vpInstallInnerScreenIdiom();
+ vpInstallInnerIdentityEncode();
+ // Type 0 without the FrontBoard scope is a second UIKit-main-like
+ // display, so no scope means no adapter.
+ Method configurationInit = class_getInstanceMethod(objc_getClass("FBSDisplayConfiguration"),
+ sel_registerName("_initWithImmutableDisplay:originalDisplay:isMainDisplay:assertIfInvalid:"));
+ const char *encoding = configurationInit ? method_getTypeEncoding(configurationInit) : "missing";
+ if (strcmp(encoding, "@40@0:8@16@24B32B36") != 0) {
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: configuration initializer %s, adapter off", encoding]);
+ return;
+ }
+ vpOriginalConfigurationInit = method_setImplementation(configurationInit, (IMP)vpInnerConfigurationInit);
+ vpOriginalDisplayType = vpReplaceDisplayGetter("displayType", "q16@0:8", (IMP)vpInnerDisplayType);
+ vpOriginalPointScale = vpReplaceDisplayGetter("pointScale", "Q16@0:8", (IMP)vpInnerPointScale);
+ vpOriginalExternal = vpReplaceDisplayGetter("isExternal", "B16@0:8", (IMP)vpInnerExternal);
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: adapter type=%d scale=%d external=%d",
+ vpOriginalDisplayType != NULL, vpOriginalPointScale != NULL, vpOriginalExternal != NULL]);
+ vpInstallContentModeResolution();
+}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m
new file mode 100644
index 00000000..28519db9
--- /dev/null
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m
@@ -0,0 +1,238 @@
+// backboardd: the inner panel's render display, the surface types the device
+// tree gives both panels, and the one digitizer routed to whichever is lit.
+
+#import "FoldDisplayPrivate.h"
+
+static id vpInnerRenderDisplay;
+
+// MARK: - the render display
+
+@protocol VPhoneInnerDisplayInitialization
+- (instancetype)initWithOptions:(NSDictionary *)options;
+@end
+
+// Tags a render display with the BKS bit the guest itself describes as
+// `unknown`. FrontBoard drops an untagged source unless it is always
+// connected; this tag is what makes it publish one.
+static void vpTagUnknownDisplay(id display) {
+ NSString *(*describe)(NSUInteger) = dlsym(RTLD_DEFAULT, "NSStringFromBKSDisplayTags");
+ SEL setter = sel_registerName("setTag:");
+ Method method = class_getInstanceMethod(object_getClass(display), setter);
+ if (!describe || !method || strcmp(method_getTypeEncoding(method), "v24@0:8q16") != 0) {
+ vpFoldDisplayLog(@"inner display: tag unavailable");
+ return;
+ }
+ NSUInteger unknown = 0;
+ for (unsigned int bit = 0; bit < 24; bit++) {
+ NSUInteger candidate = (NSUInteger)1 << bit;
+ NSString *label = describe(candidate);
+ if (!label || [label rangeOfString:@"unknown" options:NSCaseInsensitiveSearch].location == NSNotFound) continue;
+ if (unknown) { vpFoldDisplayLog(@"inner display: ambiguous unknown tag bit"); return; }
+ unknown = candidate;
+ }
+ if (!unknown) { vpFoldDisplayLog(@"inner display: no unknown tag bit"); return; }
+ ((void (*)(id, SEL, NSInteger))objc_msgSend)(display, setter, (NSInteger)unknown);
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: tag %@ (%lu)", describe(unknown), (unsigned long)unknown]);
+}
+
+// Adds the inner panel's render display to a render server, once. It is
+// never removed: FrontBoard keeps identities for the life of the monitor.
+static BOOL vpAddInnerRenderDisplayToServer(id server) {
+ if (vpInnerRenderDisplay || !server) return NO;
+ @try {
+ Class cls = objc_getClass("CAWindowServerVirtualDisplay");
+ Method initializer = class_getInstanceMethod(cls, sel_registerName("initWithOptions:"));
+ if (!initializer || strcmp(method_getTypeEncoding(initializer), "@24@0:8@16") != 0) {
+ vpFoldDisplayLog(@"inner display: virtual display initializer ABI unavailable");
+ return NO;
+ }
+ // The panel's native pixels, landscape: 951x669 points at 3x.
+ id display = [(id<VPhoneInnerDisplayInitialization>)[cls alloc] initWithOptions:@{
+ @"kCAVirtualDisplayWidth": @2853, @"kCAVirtualDisplayHeight": @2007,
+ @"kCAVirtualDisplayUpdateRate": @60, @"kCAVirtualDisplayName": vpInnerDisplayName,
+ }];
+ if (!display) { vpFoldDisplayLog(@"inner display: initializer returned nil"); return NO; }
+ ((void (*)(id, SEL, id))objc_msgSend)(server, sel_registerName("addDisplay:"), display);
+ SEL setEnabled = sel_registerName("setEnabled:");
+ Method enable = class_getInstanceMethod(object_getClass(display), setEnabled);
+ if (enable && strcmp(method_getTypeEncoding(enable), "v20@0:8B16") == 0)
+ ((void (*)(id, SEL, BOOL))objc_msgSend)(display, setEnabled, YES);
+ vpTagUnknownDisplay(display);
+ vpInnerRenderDisplay = display;
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: render display added %@ uniqueId=%@", display,
+ [display respondsToSelector:sel_registerName("uniqueId")] ? [display valueForKey:@"uniqueId"] : @"-"]);
+ return YES;
+ } @catch (NSException *exception) {
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: render display exception %@", exception.reason]);
+ }
+ return NO;
+}
+
+// QuartzCore's shared_server_init creates the CAWindowServer (_init), finds
+// the hardware displays (_detectDisplays), configures them, and only then
+// registers the render server's name (CA::Render::Server::register_name),
+// which is when SpringBoard and every other client can connect and read the
+// display inventory. Adding the inner display after the server runs lands
+// after that first read: FrontBoard's display monitor, BacklightServices'
+// backlight hosts and SpringBoard's embedded-scene gate all missed it until
+// SpringBoard restarted. Adding it from _detectDisplays puts it in the
+// inventory before any client exists.
+static IMP vpOriginalDetectDisplays;
+
+static void vpDetectDisplaysWithInner(id self, SEL selector) {
+ ((void (*)(id, SEL))vpOriginalDetectDisplays)(self, selector);
+ if (vpAddInnerRenderDisplayToServer(self))
+ vpFoldDisplayLog(@"inner display: added during render server display detection");
+}
+
+// The fallback for a render server that was already running when this
+// library loaded: add the display once the server answers.
+static void vpAddInnerRenderDisplay(unsigned int attempt) {
+ if (vpInnerRenderDisplay) return;
+ id server = ((id (*)(id, SEL))objc_msgSend)(objc_getClass("CAWindowServer"), sel_registerName("serverIfRunning"));
+ if (server)
+ vpAddInnerRenderDisplayToServer(server);
+ else if (attempt < 30)
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), dispatch_get_main_queue(),
+ ^{ vpAddInnerRenderDisplay(attempt + 1); });
+ else
+ vpFoldDisplayLog(@"inner display: render server never ran");
+}
+
+// MARK: - surface types
+
+// backboardd's BKSDisplayTraits.surfaceType comes from DeviceSurfaceType in
+// a render display's extendedProperties. The iPhone19,4 device tree gives
+// display0 (the primary, the cover) surface type 1 and display1 (the inner
+// panel) 2; SpringBoard's fold policies pick their panels by these.
+static IMP vpOriginalExtendedProperties;
+
+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;
+ if (!surfaceType || (properties && ![properties isKindOfClass:NSDictionary.class])) return properties;
+ NSMutableDictionary *derived = properties ? [properties mutableCopy] : [NSMutableDictionary dictionary];
+ derived[@"DeviceSurfaceType"] = surfaceType;
+ return [derived copy];
+}
+
+// MARK: - one digitizer for two panels
+
+// A real Duo has a digitizer per panel; this guest has one, bound to the
+// primary display (an empty display UUID). While the inner display is lit
+// (the device is open) that digitizer belongs to the inner display, so
+// 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.
+static IMP vpOriginalDigitizerDisplayUUID, vpOriginalDigitizerState;
+static BOOL vpLoggedDigitizerSwitch;
+
+static BOOL vpInnerPanelLit(void) {
+ id inner = vpInnerRenderDisplay;
+ return inner && [[inner valueForKey:@"enabled"] boolValue] && ![[inner valueForKey:@"isBlanked"] boolValue];
+}
+
+static id vpInnerDigitizerDisplayUUID(id self, SEL selector, id service) {
+ id uuid = ((id (*)(id, SEL, id))vpOriginalDigitizerDisplayUUID)(self, selector, service);
+ if ([uuid length] || !vpInnerPanelLit()) return uuid;
+ id inner = [vpInnerRenderDisplay valueForKey:@"uniqueId"];
+ return [inner length] ? inner : uuid;
+}
+
+static id vpInnerDigitizerState(id self, SEL selector, id service) {
+ id state = ((id (*)(id, SEL, id))vpOriginalDigitizerState)(self, selector, service);
+ if (state || !vpInnerPanelLit()) return state;
+ ((id (*)(id, SEL, id))objc_msgSend)(self, sel_registerName("_queue_addDigitizerStateForService:"), service);
+ state = ((id (*)(id, SEL, id))vpOriginalDigitizerState)(self, selector, service);
+ if (!vpLoggedDigitizerSwitch) {
+ vpLoggedDigitizerSwitch = YES;
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: digitizer %@ now on %@ (state %@)",
+ service, [vpInnerRenderDisplay valueForKey:@"uniqueId"], state]);
+ }
+ 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:"));
+ Method state = class_getInstanceMethod(processor, sel_registerName("_queue_digitizerStateForService:"));
+ Method add = class_getInstanceMethod(processor, sel_registerName("_queue_addDigitizerStateForService:"));
+ const char *encodings[] = {uuid ? method_getTypeEncoding(uuid) : "missing", state ? method_getTypeEncoding(state) : "missing",
+ add ? method_getTypeEncoding(add) : "missing"};
+ if (strcmp(encodings[0], "@24@0:8@16") != 0 || strcmp(encodings[1], "@24@0:8@16") != 0 || strcmp(encodings[2], "@24@0:8@16") != 0) {
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: digitizer ABI unavailable (%s, %s, %s)",
+ encodings[0], encodings[1], encodings[2]]);
+ return;
+ }
+ vpOriginalDigitizerDisplayUUID = method_setImplementation(uuid, (IMP)vpInnerDigitizerDisplayUUID);
+ vpOriginalDigitizerState = method_setImplementation(state, (IMP)vpInnerDigitizerState);
+ vpFoldDisplayLog(@"inner display: digitizer routing installed");
+ vpInstallInnerDigitizerTurn(processor);
+}
+
+// MARK: - installation
+
+void vpInstallInnerRenderDisplay(void) {
+ vpInstallInnerDigitizer();
+ Method extended = class_getInstanceMethod(objc_getClass("CAWindowServerDisplay"), sel_registerName("extendedProperties"));
+ if (extended && strcmp(method_getTypeEncoding(extended), "@16@0:8") == 0)
+ vpOriginalExtendedProperties = method_setImplementation(extended, (IMP)vpSurfaceExtendedProperties);
+ else
+ vpFoldDisplayLog(@"inner display: surface type ABI unavailable");
+ Method detect = class_getInstanceMethod(objc_getClass("CAWindowServer"), sel_registerName("_detectDisplays"));
+ if (detect && strcmp(method_getTypeEncoding(detect), "v16@0:8") == 0)
+ vpOriginalDetectDisplays = method_setImplementation(detect, (IMP)vpDetectDisplaysWithInner);
+ else
+ vpFoldDisplayLog(@"inner display: render server display detection ABI unavailable");
+ dispatch_async(dispatch_get_main_queue(), ^{ vpAddInnerRenderDisplay(0); });
+}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayDiagnostics.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayDiagnostics.m
deleted file mode 100644
index 7bef993d..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayDiagnostics.m
+++ /dev/null
@@ -1,860 +0,0 @@
-// Read-only inspection dumps behind the com.vphone.display.*inspect
-// notifications.
-
-#import "FoldDisplayPrivate.h"
-
-// MARK: - system UI and home-screen family
-
-void vpInspectDuoSystemUI(void) {
- @try {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- NSUInteger found = 0;
- for (id window in vpReadObject(app, "windows")) {
- NSMutableArray *pending = [NSMutableArray arrayWithObject:window];
- while (pending.count) {
- id view = pending.lastObject;
- [pending removeLastObject];
- if ([NSStringFromClass([view class]) isEqualToString:@"UICoverSheetButton"]) {
- id content = vpReadObjectIvar(view, "_contentView");
- id image = vpReadObjectIvar(view, "_image");
- id selected = vpReadObjectIvar(view, "_selectedImage");
- vpFoldDisplayLog([NSString stringWithFormat:@"cover sheet native bounds: button=%@ frame=%@ bounds=%@ contentFrame=%@ contentBounds=%@ imageSize=%@ selectedImageSize=%@ edgeInsets=%@",
- NSStringFromClass([view class]), [view valueForKey:@"frame"], [view valueForKey:@"bounds"],
- [content valueForKey:@"frame"], [content valueForKey:@"bounds"], [image valueForKey:@"size"],
- [selected valueForKey:@"size"], [view valueForKey:@"edgeInsets"]]);
- found++;
- }
- for (id child in [view valueForKey:@"subviews"] ?: @[]) [pending addObject:child];
- }
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"Duo system UI inventory: coverSheetButtons=%lu", (unsigned long)found]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"Duo system UI inventory exception: %@", exception.reason]);
- }
-}
-void vpInspectStatusProvider(void) { vpFoldDisplayLog(@"status provider inspection requested"); }
-void vpPulseInputTrace(void) { vpFoldDisplayLog(@"input trace pulse requested"); }
-void vpRestoreInputTrace(void) { vpFoldDisplayLog(@"input trace restore requested"); }
-
-void vpInspectHomeScreenType(void) {
- void *home = dlopen("/System/Library/PrivateFrameworks/SpringBoardHome.framework/SpringBoardHome", RTLD_LAZY | RTLD_LOCAL);
- NSUInteger (*current)(void) = dlsym(home, "SBHScreenTypeForCurrentDevice");
- NSUInteger (*forScreen)(id) = dlsym(home, "SBHScreenTypeForScreen");
- NSString *(*name)(NSUInteger) = dlsym(home, "SBHStringForScreenType");
- NSUInteger (*forContexts)(id, id) = dlsym(home, "SBHScreenTypeForDeviceAndDisplayContexts");
- // Independent native providers only. Compare actual family metrics;
- // never install a provider or change the active icon model/layout.
- Class providerClass = objc_getClass("SBHDefaultIconListLayoutProvider");
- SEL initializerSelector = sel_registerName("initWithScreenType:layoutOptions:");
- Method initializer = class_getInstanceMethod(providerClass, initializerSelector);
- if (initializer && strcmp(method_getTypeEncoding(initializer), "@32@0:8Q16Q24") == 0) {
- @try {
- NSUInteger options = 0;
- SEL optionsSelector = sel_registerName("defaultLayoutOptions");
- if ([providerClass respondsToSelector:optionsSelector])
- options = ((NSUInteger (*)(id, SEL))objc_msgSend)(providerClass, optionsSelector);
- for (NSNumber *family in @[@23, @31, @32]) {
- id provider = ((id (*)(id, SEL, NSUInteger, NSUInteger))objc_msgSend)(
- [providerClass alloc], initializerSelector, family.unsignedIntegerValue, options);
- for (NSString *symbol in @[@"SBIconLocationRoot", @"SBIconLocationRootWithWidgets"]) {
- NSString *__unsafe_unretained *address = (NSString *__unsafe_unretained *)dlsym(home, symbol.UTF8String);
- NSString *location = address ? *address : nil;
- if (![location isKindOfClass:NSString.class]) continue;
- id layout = ((id (*)(id, SEL, id))objc_msgSend)(provider, sel_registerName("layoutForIconLocation:"), location);
- id configuration = vpReadObject(layout, "layoutConfiguration");
- NSMutableDictionary *metrics = [NSMutableDictionary dictionary];
- for (NSString *key in @[@"numberOfPortraitColumns", @"numberOfPortraitRows", @"numberOfLandscapeColumns", @"numberOfLandscapeRows",
- @"portraitListSizeForIconSpacingCalculation", @"landscapeListSizeForIconSpacingCalculation",
- @"portraitLayoutInsets", @"landscapeLayoutInsets"])
- if ([configuration respondsToSelector:NSSelectorFromString(key)])
- metrics[key] = [[configuration valueForKey:key] description] ?: NSNull.null;
- vpFoldDisplayLog([NSString stringWithFormat:@"native family layout preview: type=%@ options=%lu location=%@ %@",
- family, (unsigned long)options, location, metrics]);
- }
- }
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"native family layout preview exception: %@", exception.reason]);
- }
- }
- Class screenClass = objc_getClass("UIScreen");
- if (current && forScreen && name && screenClass) {
- id screen = ((id (*)(id, SEL))objc_msgSend)(screenClass, sel_registerName("mainScreen"));
- NSUInteger globalType = current(), screenType = forScreen(screen);
- vpFoldDisplayLog([NSString stringWithFormat:@"home screen type: current=%lu %@ screen=%lu %@",
- (unsigned long)globalType, name(globalType), (unsigned long)screenType, name(screenType)]);
- id traits = ((id (*)(id, SEL))objc_msgSend)(screen, sel_registerName("traitCollection"));
- SEL artworkGetter = sel_registerName("valueForNSIntegerTrait:");
- Class artwork = objc_getClass("UITraitArtworkSubtype");
- NSMethodSignature *signature = [traits methodSignatureForSelector:artworkGetter];
- if (artwork && signature.numberOfArguments == 3 && signature.methodReturnType[0] == 'q') {
- NSInteger subtype = ((NSInteger (*)(id, SEL, Class))objc_msgSend)(traits, artworkGetter, artwork);
- vpFoldDisplayLog([NSString stringWithFormat:@"home screen artwork subtype: %ld", (long)subtype]);
- }
- Class platformClass = objc_getClass("BSPlatform");
- if ([platformClass respondsToSelector:sel_registerName("sharedInstance")]) {
- id platform = ((id (*)(id, SEL))objc_msgSend)(platformClass, sel_registerName("sharedInstance"));
- vpFoldDisplayLog([NSString stringWithFormat:@"home platform: class=%@ homeButton=%@",
- [platform valueForKey:@"deviceClass"], [platform valueForKey:@"homeButtonType"]]);
- }
- // Classify copies of the native contexts only. This tests whether
- // missing artwork metadata explains the fallback family without
- // modifying a screen, scene or global device context.
- Class deviceContextClass = objc_getClass("UISDeviceContext");
- Class displayContextClass = objc_getClass("UISDisplayContext");
- SEL defaultDevice = sel_registerName("sb_defaultContext");
- SEL defaultDisplay = sel_registerName("sb_defaultContextForDisplayConfiguration:");
- if (forContexts && [deviceContextClass respondsToSelector:defaultDevice] &&
- [displayContextClass respondsToSelector:defaultDisplay]) {
- @try {
- id deviceContext = ((id (*)(id, SEL))objc_msgSend)(deviceContextClass, defaultDevice);
- id configuration = ((id (*)(id, SEL))objc_msgSend)(objc_getClass("FBDisplayManager"), sel_registerName("mainConfiguration"));
- id displayContext = ((id (*)(id, SEL, id))objc_msgSend)(displayContextClass, defaultDisplay, configuration);
- id copy = [displayContext mutableCopy];
- SEL setArtwork = sel_registerName("setArtworkSubtype:");
- Method setter = class_getInstanceMethod(object_getClass(copy), setArtwork);
- if (copy && copy != displayContext && setter && strcmp(method_getTypeEncoding(setter), "v24@0:8Q16") == 0) {
- id cachedConfiguration = ((id (*)(id, SEL))objc_msgSend)(displayContext, sel_registerName("displayConfiguration"));
- CGRect cachedBounds = ((CGRect (*)(id, SEL))objc_msgSend)(cachedConfiguration, sel_registerName("bounds"));
- vpFoldDisplayLog([NSString stringWithFormat:@"native family context: cached configuration %s %gx%g",
- object_getClassName(cachedConfiguration), cachedBounds.size.width, cachedBounds.size.height]);
- for (NSNumber *candidate in @[@0, @2034, @2853, @2796]) {
- ((void (*)(id, SEL, NSUInteger))objc_msgSend)(copy, setArtwork, candidate.unsignedIntegerValue);
- NSUInteger type = forContexts(deviceContext, copy);
- vpFoldDisplayLog([NSString stringWithFormat:@"native family preview: artwork=%@ type=%lu %@",
- candidate, (unsigned long)type, name(type)]);
- }
- ((void (*)(id, SEL, NSUInteger))objc_msgSend)(copy, setArtwork, 0);
- id sourceMode = ((id (*)(id, SEL))objc_msgSend)(configuration, sel_registerName("currentMode"));
- CGFloat scale = ((CGFloat (*)(id, SEL))objc_msgSend)(sourceMode, sel_registerName("pointScale"));
- const CGSize candidateSizes[] = {{678, 951}, {669, 951}, {466, 678}};
- for (NSUInteger index = 0; index < sizeof(candidateSizes) / sizeof(candidateSizes[0]); index++) {
- CGSize size = candidateSizes[index];
- id virtualMode = [(id<VPhoneDisplayModeCopying>)sourceMode _copyWithOverrideSize:size scale:scale];
- id preview = [(id<VPhoneDisplayProjectionCopying>)configuration copyWithOverrideMode:virtualMode];
- ((void (*)(id, SEL, id))objc_msgSend)(copy, sel_registerName("setDisplayConfiguration:"), preview);
- NSUInteger type = forContexts(deviceContext, copy);
- vpFoldDisplayLog([NSString stringWithFormat:@"native family geometry preview: %gx%g type=%lu %@",
- size.width, size.height, (unsigned long)type, name(type)]);
- }
- }
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"native family preview exception: %@", exception.reason]);
- }
- }
- }
- Class cls = objc_getClass("SBIconListGridLayoutConfiguration");
- unsigned int count = 0;
- Method *methods = class_copyMethodList(cls, &count);
- for (unsigned int i = 0; i < count; i++) {
- const char *selector = sel_getName(method_getName(methods[i]));
- if (strstr(selector, "init") || strstr(selector, "creen") || strstr(selector, "ize") || strstr(selector, "ayout"))
- vpFoldDisplayLog([NSString stringWithFormat:@"grid method: %s types: %s", selector, method_getTypeEncoding(methods[i])]);
- }
- free(methods);
- for (NSString *className in @[@"SBHDefaultIconListLayoutProvider", @"SBHCustomIconListLayoutProvider",
- @"SBHMappedIconListLayoutProvider", @"SBHAdjustableRootIconListLayoutProvider",
- @"SBHIconManager", @"SBIconController"]) {
- Class provider = objc_getClass(className.UTF8String);
- for (int meta = 0; meta < 2; meta++) {
- unsigned int n = 0;
- Method *list = class_copyMethodList(meta ? object_getClass(provider) : provider, &n);
- for (unsigned int i = 0; i < n; i++) {
- const char *selector = sel_getName(method_getName(list[i]));
- if (([className isEqualToString:@"SBHIconManager"] || [className isEqualToString:@"SBIconController"]) &&
- !strstr(selector, "ayout") && !strstr(selector, "hared") && !strstr(selector, "conManager")) continue;
- vpFoldDisplayLog([NSString stringWithFormat:@"provider %@ %c%s types: %s", className,
- meta ? '+' : '-', selector, method_getTypeEncoding(list[i])]);
- }
- free(list);
- }
- }
-}
-
-// MARK: - SB-main scene snapshot
-
-// One bounded JSON line: do not format the arbiter, class inventories or
-// controller/model descriptions on SpringBoard's main queue during tests.
-void vpSnapshotMainScene(void) {
- CFAbsoluteTime started = CFAbsoluteTimeGetCurrent();
- @try {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id scene = vpReadObject(app, "activeDisplayWindowScene") ?: vpReadObject(app, "embeddedDisplayWindowScene");
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- id screen = vpReadObject(scene, "screen");
- NSMutableDictionary *snapshot = [NSMutableDictionary dictionaryWithDictionary:@{
- @"pid": @(getpid()), @"time": @(started),
- @"viewportGeneration": @(atomic_load_explicit(&vpViewportRequestGeneration, memory_order_relaxed)),
- @"configurationBounds": vpSnapshotRect(configuration, "bounds"),
- @"scene": vpReadObject(vpReadObject(scene, "_FBSScene"), "identifier") ?: NSNull.null,
- @"coordinateBounds": vpSnapshotRect(vpReadObject(scene, "coordinateSpace"), "bounds"),
- @"screenBounds": vpSnapshotRect(screen, "bounds"),
- @"screenNativeBounds": vpSnapshotRect(screen, "nativeBounds"),
- }];
- id pipeline = vpReadObject(scene, "traitsPipelineManager");
- id snapshotIdentity = vpReadObject(configuration, "identity");
- for (NSString *key in @[@"isMainDisplay", @"isMainRootDisplay", @"isRootIdentity", @"isUIKitMainLike", @"isAlwaysConnected"])
- snapshot[[@"identity." stringByAppendingString:key]] = [snapshotIdentity valueForKey:key] ?: NSNull.null;
- for (NSString *key in @[@"isMainDisplayWindowScene", @"isLegacyMainEmbeddedScene"])
- snapshot[[@"scene." stringByAppendingString:key]] = vpReadBoolValue(scene, key.UTF8String) ?: NSNull.null;
- id statusManager = vpReadObject(scene, "statusBarManager");
- snapshot[@"statusManagerClass"] = statusManager ? NSStringFromClass(object_getClass(statusManager)) : NSNull.null;
- snapshot[@"statusManagerEmbedded"] = vpReadBoolValue(statusManager, "_isEmbeddedDisplay") ?: NSNull.null;
- snapshot[@"statusManagerHidden"] = vpReadBoolValue(statusManager, "isStatusBarHidden") ?: NSNull.null;
- snapshot[@"screenUserInterfaceIdiom"] = [screen valueForKey:@"_userInterfaceIdiom"] ?: NSNull.null;
- snapshot[@"screenTraitUserInterfaceIdiom"] = [vpReadObject(screen, "traitCollection") valueForKey:@"userInterfaceIdiom"] ?: NSNull.null;
- id uiConfiguration = vpReadObject(scene, "_sbDisplayConfiguration");
- id clientIdentity = vpReadObject(scene, "_fbsDisplayIdentity");
- snapshot[@"uiConfigurationIdentifier"] = vpReadObject(vpReadObject(uiConfiguration, "identity"), "uniqueIdentifier") ?: NSNull.null;
- snapshot[@"clientDisplayIdentifier"] = vpReadObject(clientIdentity, "uniqueIdentifier") ?: NSNull.null;
- snapshot[@"clientDisplayType"] = [clientIdentity valueForKey:@"type"] ?: NSNull.null;
- id serverSettingsForSnapshot = nil;
- for (id serverScene in vpRootServerScenes(app))
- if ([vpReadObject(serverScene, "identifier") isEqual:@"SB-main"]) { serverSettingsForSnapshot = vpReadObject(serverScene, "uiSettings"); break; }
- snapshot[@"serverHostedIdentifier"] = vpReadObject(vpReadObject(vpReadObject(serverSettingsForSnapshot, "sb_hostedDisplayConfiguration"), "identity"), "uniqueIdentifier") ?: NSNull.null;
- snapshot[@"serverDisplayIdentifier"] = vpReadObject(vpReadObject(serverSettingsForSnapshot, "displayIdentity"), "uniqueIdentifier") ?: NSNull.null;
- snapshot[@"connectedDisplayCount"] = @([vpReadObject(vpReadObject(objc_getClass("FBDisplayManager"), "sharedInstance"), "alwaysConnectedIdentities") count]);
- snapshot[@"caDisplayObjectCount"] = @([vpReadObject(objc_getClass("CADisplay"), "displays") count]);
- snapshot[@"sceneScreenType"] = [scene valueForKey:@"sbhScreenType"] ?: NSNull.null;
- void *home = dlopen("/System/Library/PrivateFrameworks/SpringBoardHome.framework/SpringBoardHome", RTLD_LAZY | RTLD_LOCAL);
- NSUInteger (*globalFamily)(void) = dlsym(home, "SBHScreenTypeForCurrentDevice");
- NSUInteger (*screenFamily)(id) = dlsym(home, "SBHScreenTypeForScreen");
- if (globalFamily) snapshot[@"globalScreenType"] = @(globalFamily());
- if (screenFamily) snapshot[@"screenScreenType"] = @(screenFamily(screen));
- id geometry = vpReadObject(scene, "effectiveGeometry");
- if ([geometry respondsToSelector:sel_registerName("interfaceOrientation")])
- snapshot[@"effectiveGeometryOrientation"] = [geometry valueForKey:@"interfaceOrientation"];
- for (NSString *name in @[@"systemSpaceOrientationForDeviceOrientation:", @"deviceOrientationForSystemSpaceOrientation:"]) {
- SEL selector = NSSelectorFromString(name);
- Method method = class_getInstanceMethod(object_getClass(scene), selector);
- if (method && strcmp(method_getTypeEncoding(method), "q24@0:8q16") == 0) {
- NSMutableArray *mapping = [NSMutableArray array];
- for (NSInteger direction = 1; direction <= 4; direction++)
- [mapping addObject:@(((NSInteger (*)(id, SEL, NSInteger))objc_msgSend)(scene, selector, direction))];
- snapshot[name] = mapping;
- }
- }
- snapshot[@"providerDirections"] = vpSnapshotPoseDirections(vpReadObjectIvar(pipeline, "_devicePoseProvider"));
- for (NSString *name in @[@"_settingUpPipeline", @"_arbiterRunningUpdatesCount", @"_isCoversheetPresented", @"_isContinuousFoldSettleWindowActive", @"_continuousFoldHolderCount",
- @"_continuousFoldPinnedDeviceOrientation", @"_isDevicePoseOverridingOrientationLock"])
- snapshot[name] = vpSnapshotScalarIvar(pipeline, name.UTF8String) ?: NSNull.null;
- for (NSString *name in @[@"activeInterfaceOrientation", @"statusBarOrientationForEmbeddedDisplay", @"statusBarOrientation"])
- if ([app respondsToSelector:NSSelectorFromString(name)])
- snapshot[[@"application." stringByAppendingString:name]] = [app valueForKey:name];
- id deferrals = vpReadObjectIvar(pipeline, "_deviceOrientationUpdateDeferralManager");
- SEL deferred = sel_registerName("isCurrentlyDeferringOrientationUpdatesForWindowScene:");
- Method deferredMethod = class_getInstanceMethod(object_getClass(deferrals), deferred);
- if (deferredMethod && strcmp(method_getTypeEncoding(deferredMethod), "B24@0:8@16") == 0)
- snapshot[@"deferringOrientation"] = @(((BOOL (*)(id, SEL, id))objc_msgSend)(deferrals, deferred, scene));
- for (NSString *getter in @[@"_effectiveUISettings", @"_effectiveUIClientSettings"]) {
- id settings = vpReadObject(scene, getter.UTF8String);
- if ([settings respondsToSelector:sel_registerName("interfaceOrientation")])
- snapshot[getter] = [settings valueForKey:@"interfaceOrientation"];
- }
- for (NSString *name in @[@"interfaceOrientation", @"surfaceType"])
- if ([scene respondsToSelector:NSSelectorFromString(name)]) snapshot[name] = [scene valueForKey:name];
- for (NSString *name in @[@"systemArbitratedDeviceOrientation", @"systemArbitratedInterfaceOrientation", @"continuousFoldPinnedInterfaceOrientation"])
- if ([pipeline respondsToSelector:NSSelectorFromString(name)]) snapshot[name] = [pipeline valueForKey:name];
- NSMutableArray *roots = [NSMutableArray array];
- for (id root in vpRootServerScenes(app)) {
- id settings = vpReadObject(root, "uiSettings");
- [roots addObject:@{@"identifier": vpReadObject(root, "identifier") ?: NSNull.null,
- @"orientation": [settings valueForKey:@"interfaceOrientation"] ?: NSNull.null,
- @"frame": vpSnapshotRect(settings, "frame")}];
- }
- snapshot[@"roots"] = roots;
- NSMutableArray *windows = [NSMutableArray array];
- for (id window in vpReadObject(scene, "windows")) {
- id controller = vpReadObject(window, "rootViewController");
- NSMutableDictionary *row = [NSMutableDictionary dictionaryWithDictionary:@{
- @"class": NSStringFromClass(object_getClass(window)),
- @"frame": vpSnapshotRect(window, "frame"), @"bounds": vpSnapshotRect(window, "bounds"),
- @"hidden": [window valueForKey:@"hidden"], @"orientation": [window valueForKey:@"interfaceOrientation"],
- @"rootClass": controller ? NSStringFromClass(object_getClass(controller)) : NSNull.null,
- @"rootFrame": vpSnapshotRect(vpReadObject(controller, "viewIfLoaded"), "frame"),
- }];
- for (NSString *name in @[@"orientation", @"effectiveOrientation", @"supportedInterfaceOrientations"])
- if ([controller respondsToSelector:NSSelectorFromString(name)])
- row[[@"controller." stringByAppendingString:name]] = [controller valueForKey:name];
- for (NSString *name in @[@"orientation", @"_sbStatusBarWindowShouldRotate", @"_sbStatusBarWindowSupportedOrientations"]) {
- Method method = class_getInstanceMethod(object_getClass(window), NSSelectorFromString(name));
- char *type = method ? method_copyReturnType(method) : NULL;
- if (type && (strcmp(type, "q") == 0 || strcmp(type, "Q") == 0 || strcmp(type, "B") == 0))
- row[[@"native." stringByAppendingString:name]] = [window valueForKey:name];
- free(type);
- }
- [windows addObject:row];
- if (windows.count == 32) break;
- }
- snapshot[@"windows"] = windows;
- snapshot[@"elapsedMs"] = @((CFAbsoluteTimeGetCurrent() - started) * 1000);
- NSData *data = [NSJSONSerialization dataWithJSONObject:snapshot options:0 error:NULL];
- if (data) vpFoldDisplayLog([@"snapshot " stringByAppendingString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"snapshot exception: %@", exception.reason]);
- }
-}
-
-// MARK: - device-determined configuration
-
-// Reads the scalar state of a live SBSDeviceDeterminedConfiguration and probes
-// its pure class-mapping helpers, so the profile-selection inputs (base class,
-// distinguishers, subtype) and the base->effective mapping are both recorded
-// from evidence. Every selector is guarded; setters are never touched.
-void vpDumpDeviceConfiguration(id config) {
- if (!config) { vpFoldDisplayLog(@"live device configuration: nil"); return; }
- vpFoldDisplayLog([NSString stringWithFormat:@"live device configuration: %@", [config description]]);
- struct { const char *name; } qNames[] = {
- {"effectiveDeviceClass"}, {"baseDeviceClass"}, {"baseClass"}, {"distinguishers"},
- {"effectiveDeviceGrouping"}, {"baseDeviceGrouping"}, {"_fallbackEffectiveClass"},
- };
- for (size_t i = 0; i < sizeof(qNames) / sizeof(qNames[0]); i++) {
- SEL selector = sel_registerName(qNames[i].name);
- if (![config respondsToSelector:selector]) continue;
- @try {
- unsigned long long value = ((unsigned long long (*)(id, SEL))objc_msgSend)(config, selector);
- vpFoldDisplayLog([NSString stringWithFormat:@"device configuration %s = %llu", qNames[i].name, value]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"device configuration %s exception: %@", qNames[i].name, exception.reason]);
- }
- }
- const char *iNames[] = {"idiom"};
- for (size_t i = 0; i < 1; i++) {
- SEL selector = sel_registerName(iNames[i]);
- if ([config respondsToSelector:selector]) {
- @try {
- long value = ((long (*)(id, SEL))objc_msgSend)(config, selector);
- vpFoldDisplayLog([NSString stringWithFormat:@"device configuration %s = %ld", iNames[i], value]);
- } @catch (NSException *exception) { }
- }
- }
- const char *qReaderNames[] = {"homeButton", "_deviceSubtype", "_zoomModeDirection"};
- for (size_t i = 0; i < 3; i++) {
- SEL selector = sel_registerName(qReaderNames[i]);
- if (![config respondsToSelector:selector]) continue;
- @try {
- long long value = ((long long (*)(id, SEL))objc_msgSend)(config, selector);
- vpFoldDisplayLog([NSString stringWithFormat:@"device configuration %s = %lld", qReaderNames[i], value]);
- } @catch (NSException *exception) { }
- }
- const char *dNames[] = {"_nativeScale", "_currentScale"};
- for (size_t i = 0; i < 2; i++) {
- SEL selector = sel_registerName(dNames[i]);
- if (![config respondsToSelector:selector]) continue;
- @try {
- double value = ((double (*)(id, SEL))objc_msgSend)(config, selector);
- vpFoldDisplayLog([NSString stringWithFormat:@"device configuration %s = %.6g", dNames[i], value]);
- } @catch (NSException *exception) { }
- }
- SEL sizeSelector = sel_registerName("_effectiveDeviceClassForScreenSize:");
- if ([config respondsToSelector:sizeSelector]) {
- CGSize sizes[] = { CGSizeMake(669, 951), CGSizeMake(951, 669), CGSizeMake(466, 678), CGSizeMake(428, 926) };
- for (size_t i = 0; i < 4; i++) {
- @try {
- unsigned long long value = ((unsigned long long (*)(id, SEL, CGSize))objc_msgSend)(config, sizeSelector, sizes[i]);
- vpFoldDisplayLog([NSString stringWithFormat:@"device configuration effectiveDeviceClassForSize {%.0f,%.0f} = %llu", sizes[i].width, sizes[i].height, value]);
- } @catch (NSException *exception) { }
- }
- }
- SEL baseSelector = sel_registerName("_classForBase:zoom:");
- if ([config respondsToSelector:baseSelector]) {
- for (unsigned long long base = 0; base <= 20; base++) {
- @try {
- unsigned long long value = ((unsigned long long (*)(id, SEL, unsigned long long, long long))objc_msgSend)(config, baseSelector, base, 0);
- vpFoldDisplayLog([NSString stringWithFormat:@"device configuration classForBase %llu zoom0 = %llu", base, value]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"device configuration classForBase %llu exception: %@", base, exception.reason]);
- break;
- }
- }
- }
-}
-
-// The determined configuration's constructor, swizzled at load so every
-// construction in SpringBoard logs its hardware inputs and one instance is
-// kept for on-demand mapping probes. No object-graph walking: the round-5
-// crawl crashed SpringBoard on an unsafe-unretained ivar.
-typedef id (*vpConfigInitIMP)(id, SEL, unsigned long long, CGSize, int, long long,
- unsigned long long, long long, CGRect, double, double);
-static vpConfigInitIMP vpOriginalConfigInit;
-id vpStashedConfig;
-static NSUInteger vpConfigInitLogs;
-
-static id vpConfigInitReplacement(id self, SEL cmd, unsigned long long baseDevice, CGSize deviceSize, int idiom,
- long long homeButton, unsigned long long distinguishers, long long deviceSubtype,
- CGRect nativeBounds, double nativeScale, double currentScale) {
- id result = vpOriginalConfigInit(self, cmd, baseDevice, deviceSize, idiom, homeButton, distinguishers,
- deviceSubtype, nativeBounds, nativeScale, currentScale);
- if (vpConfigInitLogs < 8) {
- vpConfigInitLogs++;
- // Identify the construction callsite so the hardware-input source can
- // be corrected rather than guessed.
- Dl_info info = {0};
- void *frame0 = __builtin_return_address(0);
- void *frame1 = __builtin_frame_address(0) ? *(void **)__builtin_frame_address(0) : NULL;
- void *caller1 = frame1 ? *(void **)((char *)frame1 + 8) : NULL;
- dladdr(frame0, &info);
- // Raw pointers too: the shared-cache slide plus this file offset turns
- // the redacted callsite into a decodable static address.
- vpFoldDisplayLog([NSString stringWithFormat:@"config init frame0=%p fbase=%p fname=%s",
- frame0, info.dli_fbase, info.dli_fname ?: "?"]);
- NSString *site1 = @"?";
- if (caller1) {
- Dl_info info1 = {0};
- dladdr(caller1, &info1);
- vpFoldDisplayLog([NSString stringWithFormat:@"config init frame1=%p fbase=%p",
- caller1, info1.dli_fbase]);
- site1 = [NSString stringWithFormat:@"%p", caller1];
- }
- vpFoldDisplayLog([NSString stringWithFormat:
- @"config init: base=%llu size={%.0f,%.0f} idiom=%d home=%lld distinguishers=0x%llx subtype=%lld "
- "native={{%.0f,%.0f},{%.0f,%.0f}} scale=%.4g/%.4g callsite=%@ <- %@ -> %@",
- baseDevice, deviceSize.width, deviceSize.height, idiom, homeButton, distinguishers, deviceSubtype,
- nativeBounds.origin.x, nativeBounds.origin.y, nativeBounds.size.width, nativeBounds.size.height,
- nativeScale, currentScale, [NSString stringWithFormat:@"%p", frame0], site1,
- result ? [result description] : @"nil"]);
- }
- if (result) {
- vpStashedConfig = result;
- }
- return result;
-}
-
-void vpInstallConfigInitSwizzle(void) {
- Class cls = objc_getClass("SBSDeviceDeterminedConfiguration");
- SEL selector = sel_registerName(
- "initMatchingBaseDevice:deviceSize:deviceIdiom:homeButton:distinguishers:deviceSubtype:nativeBounds:nativeScale:currentScale:");
- Method method = cls ? class_getInstanceMethod(cls, selector) : NULL;
- if (!method) { vpFoldDisplayLog(@"config init swizzle: method absent"); return; }
- vpOriginalConfigInit = (vpConfigInitIMP)method_getImplementation(method);
- method_setImplementation(method, (IMP)vpConfigInitReplacement);
- vpFoldDisplayLog(@"config init swizzle: installed");
-}
-
-// Logs who feeds the effective device class into the CoverSheet layout
-// controller, and with which value. The numeric override file that once
-// forced a candidate class is gone with the experiment sweep; only the
-// capped diagnostic log remains.
-static void (*vpOriginalSetEffectiveClass)(id, SEL, unsigned long long);
-static NSUInteger vpSetEffectiveClassLogs;
-
-static void vpSetEffectiveClassReplacement(id self, SEL cmd, unsigned long long value) {
- if (vpSetEffectiveClassLogs < 8) {
- vpSetEffectiveClassLogs++;
- Dl_info info = {0};
- void *frame0 = __builtin_return_address(0);
- dladdr(frame0, &info);
- vpFoldDisplayLog([NSString stringWithFormat:@"layout setEffectiveDeviceClass %llu on %s from %p fbase=%p",
- value, object_getClassName(self), frame0, info.dli_fbase]);
- }
- vpOriginalSetEffectiveClass(self, cmd, value);
-}
-
-void vpInstallLayoutClassSwizzle(void) {
- Class cls = objc_getClass("CSProminentLayoutController");
- Method method = cls ? class_getInstanceMethod(cls, sel_registerName("setEffectiveDeviceClass:")) : NULL;
- if (!method) { vpFoldDisplayLog(@"layout class swizzle: method absent"); return; }
- vpOriginalSetEffectiveClass = (void (*)(id, SEL, unsigned long long))method_getImplementation(method);
- method_setImplementation(method, (IMP)vpSetEffectiveClassReplacement);
- vpFoldDisplayLog(@"layout class swizzle: installed");
-}
-
-__attribute__((unused)) static void vpDumpClassSurface(const char *className, NSString *label) {
- Class cls = objc_getClass(className);
- if (!cls) { vpFoldDisplayLog([NSString stringWithFormat:@"%@ class %s absent", label, className]); return; }
- for (Class walk = cls; walk && walk != objc_getClass("UIView"); walk = class_getSuperclass(walk)) {
- unsigned int count = 0;
- Method *methods = class_copyMethodList(walk, &count);
- vpFoldDisplayLog([NSString stringWithFormat:@"%@ surface %s: %u methods (super=%s)", label,
- class_getName(walk), count, class_getName(class_getSuperclass(walk))]);
- for (unsigned int i = 0; i < count; i++)
- vpFoldDisplayLog([NSString stringWithFormat:@"%@ method[%u] %s %s", label, i,
- sel_getName(method_getName(methods[i])), method_getTypeEncoding(methods[i])]);
- free(methods);
- unsigned int icount = 0;
- Ivar *ivars = class_copyIvarList(walk, &icount);
- for (unsigned int i = 0; i < icount; i++)
- vpFoldDisplayLog([NSString stringWithFormat:@"%@ ivardecl[%u] %s %s", label, i,
- ivar_getName(ivars[i]), ivar_getTypeEncoding(ivars[i]) ?: "?"]);
- free(ivars);
- }
-}
-
-// MARK: - windows and presentation
-
-// Full window inventory with two subview levels: identifies which window or
-// view owns any on-screen black band in landscape.
-void vpInspectAllWindows(void) {
- @try {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- for (id window in vpReadObject(app, "windows")) {
- vpFoldDisplayLog([NSString stringWithFormat:@"window: class=%@ frame=%@ level=%@ hidden=%@",
- NSStringFromClass([window class]), [window valueForKey:@"frame"],
- [window valueForKey:@"windowLevel"], [window valueForKey:@"hidden"]]);
- BOOL deep = [NSStringFromClass([window class]) containsString:@"HomeScreen"] ||
- [NSStringFromClass([window class]) containsString:@"Wallpaper"];
- for (id child in [window valueForKey:@"subviews"] ?: @[]) {
- vpFoldDisplayLog([NSString stringWithFormat:@"window sub: class=%@ frame=%@ alpha=%@ hidden=%@",
- NSStringFromClass([child class]), [child valueForKey:@"frame"],
- [child valueForKey:@"alpha"], [child valueForKey:@"hidden"]]);
- if (deep)
- vpDumpWallpaperTree(child, 3);
- else
- for (id grandchild in [child valueForKey:@"subviews"] ?: @[])
- vpFoldDisplayLog([NSString stringWithFormat:@"window sub2: class=%@ frame=%@ alpha=%@ hidden=%@",
- NSStringFromClass([grandchild class]), [grandchild valueForKey:@"frame"],
- [grandchild valueForKey:@"alpha"], [grandchild valueForKey:@"hidden"]]);
- }
- }
- // The device-class selection surfaces and singleton probes were
- // captured in the round-4 dump; the live values now come from the
- // quick-action ivar crawl.
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"window inventory exception: %@", exception.reason]);
- }
-}
-
-// Lights the Lock Screen without the Home press icli's wake falls back to,
-// so the locked wallpaper and quick actions can be captured lit.
-void vpUndimScreenOnly(void) {
- void *handle = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_NOW);
- void (*undim)(void) = handle ? dlsym(handle, "SBSUndimScreen") : NULL;
- if (!undim) { vpFoldDisplayLog(@"screen undim: SBSUndimScreen absent"); return; }
- undim();
- vpFoldDisplayLog(@"screen undim: requested");
-}
-
-void vpInspectNativePresentation(void) {
- @try {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id scene = vpReadObject(app, "activeDisplayWindowScene") ?: vpReadObject(app, "embeddedDisplayWindowScene");
- id wallpaper = vpReadObject(scene, "wallpaperController");
- id presenter = vpReadObjectIvar(wallpaper, "_wallpaperPresenter");
- id presenterView = vpReadObject(presenter, "viewIfLoaded");
- vpDumpWallpaperTree(presenterView, 0);
- vpDumpObjectIvars(wallpaper, @"wallpaper controller", 96);
- vpDumpObjectIvars(presenter, @"wallpaper presenter", 96);
- // The presenter hosts the wallpaper through a remote CAContext; its
- // full description carries the scale/scene fields a short dump cuts,
- // and the overlay/transfer containers may hold the clip geometry.
- vpFoldDisplayLog([NSString stringWithFormat:@"presenter full: %@", [presenter description]]);
- // The inner poster controller composes portrait while the wallpaper
- // controller is landscape; find its orientation-control surface.
- for (NSString *className in @[@"PBUIPosterViewController", @"PBUIPosterWallpaperViewController",
- @"PBUIPosterLockViewController", @"PBUIWallpaperView"]) {
- Class cls = objc_getClass(className.UTF8String);
- if (!cls) { vpFoldDisplayLog([NSString stringWithFormat:@"poster class %@ absent", className]); continue; }
- unsigned int methodCount = 0;
- Method *methods = class_copyMethodList(cls, &methodCount);
- for (unsigned int i = 0; i < methodCount; i++) {
- const char *name = sel_getName(method_getName(methods[i]));
- if (strstr(name, "rientation") || strstr(name, "andscape") || strstr(name, "ontentMode") || strstr(name, "ize")) {
- vpFoldDisplayLog([NSString stringWithFormat:@"poster surface %@ method %s %s", className, name,
- method_getTypeEncoding(methods[i])]);
- }
- }
- free(methods);
- }
- for (NSString *containerKey in @[@"_wallpaperOverlayContainerView", @"_transferContainerView"]) {
- id container = vpReadObjectIvar(wallpaper, containerKey.UTF8String);
- vpFoldDisplayLog([NSString stringWithFormat:@"container %@: %@", containerKey, container ? [container description] : @"nil"]);
- vpDumpWallpaperTree(container, 1);
- }
- id rootController = vpReadObjectIvar(wallpaper, "_rootWallpaperViewController");
- vpDumpObjectIvars(rootController, @"wallpaper root", 64);
- id manager = vpReadObject(scene, "statusBarManager");
- id sceneBar = vpReadObject(manager, "statusBar");
- id mainBar = vpReadObject(app, "statusBarForEmbeddedDisplay");
- NSMutableArray *bars = [NSMutableArray array];
- for (id bar in @[sceneBar ?: NSNull.null, mainBar ?: NSNull.null]) {
- if (bar == NSNull.null) { [bars addObject:NSNull.null]; continue; }
- id provider = vpReadObject(bar, "inProcessStateProvider");
- NSMutableDictionary *row = [@{@"bar": [NSString stringWithFormat:@"%p %s", bar, object_getClassName(bar)],
- @"provider": provider ? [NSString stringWithFormat:@"%p %s", provider, object_getClassName(provider)] : (id)NSNull.null,
- @"server": [vpReadObject(bar, "statusBarServer") description] ?: (id)NSNull.null,
- @"bounds": vpSnapshotRect(bar, "bounds")} mutableCopy];
- for (NSString *key in @[@"timeCloaked", @"allButBatteryCloaked", @"telephonyAndBluetoothCloaked"]) {
- Ivar ivar = class_getInstanceVariable(object_getClass(provider), [[@"_" stringByAppendingString:key] UTF8String]);
- if (ivar && strcmp(ivar_getTypeEncoding(ivar), "B") == 0) row[key] = [provider valueForKey:key] ?: NSNull.null;
- }
- row[@"serverUpdatesDisabled"] = vpReadBoolValue(bar, "serverUpdatesDisabled") ?: (id)NSNull.null;
- row[@"homeItemsDisabled"] = vpReadBoolValue(bar, "homeItemsDisabled") ?: (id)NSNull.null;
- id renderer = vpReadObject(bar, "statusBar");
- for (NSString *key in @[@"currentData", @"currentAggregatedData", @"additionalDataDelegate"]) {
- NSString *description = [vpReadObject(renderer, key.UTF8String) description];
- row[key] = description ? [description substringToIndex:MIN(description.length, 6000)] : (id)NSNull.null;
- }
- row[@"enabledParts"] = vpReadObjectIvar(bar, "_enabledPartIdentifiers") ?: (id)NSNull.null;
- row[@"disabledParts"] = vpReadObjectIvar(bar, "_disabledPartIdentifiers") ?: (id)NSNull.null;
-
- id serverClient = vpReadObject(vpReadObject(bar, "statusBarServer"), "statusBar");
- row[@"serverClient"] = serverClient ? [NSString stringWithFormat:@"%p %s", serverClient, object_getClassName(serverClient)] : (id)NSNull.null;
- for (NSString *key in @[@"registered", @"foreground", @"hidden"]) {
- Ivar ivar = class_getInstanceVariable(object_getClass(bar), [[@"_" stringByAppendingString:key] UTF8String]);
- if (ivar && strcmp(ivar_getTypeEncoding(ivar), "B") == 0) row[key] = [bar valueForKey:key] ?: NSNull.null;
- }
-
- [bars addObject:row];
- }
- NSMutableDictionary *wall = [NSMutableDictionary dictionary];
- for (NSString *key in @[@"activeVariant", @"activeOrientationSource", @"activeInterfaceOrientationSourcesDescriptions", @"isWallpaperRequired", @"_isTraitsArbiterWallpaperActive"])
- if ([wallpaper respondsToSelector:NSSelectorFromString(key)]) wall[key] = [[wallpaper valueForKey:key] description] ?: NSNull.null;
- for (NSString *key in @[@"_wallpaperWindow", @"_wallpaperContainerView", @"_wallpaperPresenter", @"_rootWallpaperViewController"]) {
- id object = vpReadObjectIvar(wallpaper, key.UTF8String);
- wall[key] = object ? @{@"class": NSStringFromClass(object_getClass(object)),
- @"frame": vpSnapshotRect(object, "frame"), @"bounds": vpSnapshotRect(object, "bounds"),
- @"hidden": vpReadBoolValue(object, "isHidden") ?: (id)NSNull.null} : (id)NSNull.null;
- }
- id wallpaperWindow = vpReadObjectIvar(wallpaper, "_wallpaperWindow");
- id participant = vpReadObject(wallpaperWindow, "sb_traitsParticipant");
- wall[@"participant"] = [participant description] ?: (id)NSNull.null;
- for (NSString *key in @[@"role", @"settings", @"preferences"])
- wall[[@"participant." stringByAppendingString:key]] = [vpReadObject(participant, key.UTF8String) description] ?: (id)NSNull.null;
- id delegate = vpReadObject(scene, "_abstractWindowSceneDelegate");
- wall[@"delegateClass"] = delegate ? NSStringFromClass(object_getClass(delegate)) : (id)NSNull.null;
- wall[@"individuallyManagedRoles"] = [vpReadObject(object_getClass(delegate), "_individuallyManagedRoles") description] ?: (id)NSNull.null;
- id __unsafe_unretained *roleAddress = (id __unsafe_unretained *)dlsym(RTLD_DEFAULT, "SBTraitsParticipantRoleWallpaper");
- SEL manages = sel_registerName("_shouldManageParticipantWithRole:");
- Method managesMethod = class_getInstanceMethod(object_getClass(delegate), manages);
- if (roleAddress && *roleAddress && managesMethod && strcmp(method_getTypeEncoding(managesMethod), "B24@0:8@16") == 0)
- wall[@"delegateManagesWallpaper"] = @(((BOOL (*)(id, SEL, id))objc_msgSend)(delegate, manages, *roleAddress));
- for (NSString *key in @[@"_wallpaperPresenter", @"_rootWallpaperViewController"]) {
- id view = vpReadObject(vpReadObjectIvar(wallpaper, key.UTF8String), "viewIfLoaded");
- wall[[key stringByAppendingString:@".view"]] = view ? @{
- @"class": NSStringFromClass(object_getClass(view)), @"frame": vpSnapshotRect(view, "frame"),
- @"bounds": vpSnapshotRect(view, "bounds"), @"hidden": vpReadBoolValue(view, "isHidden") ?: (id)NSNull.null,
- @"alpha": [view valueForKey:@"alpha"] ?: (id)NSNull.null} : (id)NSNull.null;
- }
- id mainProvider = vpReadObject(app, "mainStatusBarStateProvider");
- id aggregator = vpReadObject(app, "statusBarStateAggregator");
- NSMutableDictionary *source = [NSMutableDictionary dictionary];
- for (NSString *key in @[@"timeCloaked", @"allButBatteryCloaked", @"telephonyAndBluetoothCloaked"]) {
- Ivar ivar = class_getInstanceVariable(object_getClass(mainProvider), [[@"_" stringByAppendingString:key] UTF8String]);
- if (ivar && strcmp(ivar_getTypeEncoding(ivar), "B") == 0) source[key] = [mainProvider valueForKey:key] ?: NSNull.null;
- }
- for (NSString *key in @[@"_dateTimeProvider", @"_dateTimeProviderToken", @"_timeItemDateFormatter", @"_shortTimeItemDateFormatter", @"_timeItemTimeString"])
- source[key] = [vpReadObjectIvar(aggregator, key.UTF8String) description] ?: (id)NSNull.null;
- source[@"nativeDate"] = [vpReadObject(vpReadObjectIvar(aggregator, "_dateTimeProvider"), "date") description] ?: (id)NSNull.null;
- for (NSString *key in @[@"_timeItemDateFormatter", @"_shortTimeItemDateFormatter"]) {
- id formatter = vpReadObjectIvar(aggregator, key.UTF8String);
- if ([formatter isKindOfClass:NSDateFormatter.class]) {
- NSDateFormatter *native = formatter;
- source[[key stringByAppendingString:@"Config"]] = @{
- @"format": native.dateFormat ?: (id)NSNull.null,
- @"dateStyle": @(native.dateStyle), @"timeStyle": @(native.timeStyle),
-@"locale": native.locale.localeIdentifier ?: (id)NSNull.null,
- @"nativeFormattedDate": [native stringFromDate:vpReadObject(vpReadObjectIvar(aggregator, "_dateTimeProvider"), "date")] ?: (id)NSNull.null};
- }
- }
- NSDictionary *record = @{@"scene": vpReadObject(vpReadObject(scene, "_FBSScene"), "identifier") ?: (id)NSNull.null,
- @"barsSceneThenEmbedded": bars, @"wallpaper": wall, @"mainStateSource": source};
- NSData *data = [NSJSONSerialization dataWithJSONObject:record options:0 error:NULL];
- if (data) vpFoldDisplayLog([@"native presentation " stringByAppendingString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"native presentation exception: %@", exception.reason]);
- }
-}
-
-// MARK: - display state
-
-void vpInspectDisplayState(void) {
- @try {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id provider = vpReadObject(app, "devicePoseProvider");
- id coordinator = vpReadObject(app, "displayContentModeCoordinator");
- for (id scene in vpRootServerScenes(app)) {
- id settings = vpReadObject(scene, "uiSettings") ?: vpReadObject(scene, "settings");
- NSMutableDictionary *fields = [NSMutableDictionary dictionary];
- for (NSString *property in @[@"frame", @"interfaceOrientation"]) {
- @try {
- if ([settings respondsToSelector:NSSelectorFromString(property)])
- fields[property] = [settings valueForKey:property] ?: NSNull.null;
- } @catch (NSException *exception) { fields[property] = exception.reason ?: @"unavailable"; }
- }
- @try {
- fields[@"hostedDisplayConfiguration"] = vpReadObject(settings, "sb_hostedDisplayConfiguration") ?: NSNull.null;
- } @catch (NSException *exception) { fields[@"hostedDisplayConfiguration"] = exception.reason ?: @"unavailable"; }
- vpFoldDisplayLog([NSString stringWithFormat:@"root server scene: %@ class=%s settings=%s %@",
- vpReadObject(scene, "identifier"), object_getClassName(scene), object_getClassName(settings), fields]);
- }
- id resolver = vpReadObjectIvar(coordinator, "_resolver");
- vpFoldDisplayLog([NSString stringWithFormat:@"display resolver: %@", resolver]);
- for (NSString *name in @[@"_policies", @"_resolution", @"_displayProxies"])
- vpFoldDisplayLog([NSString stringWithFormat:@"display resolver %@: %@", name,
- vpReadObjectIvar(resolver, name.UTF8String)]);
- Class cover = objc_getClass("SBCoverDisplayConfigurationTransformer");
- NSMutableDictionary *coverState = [NSMutableDictionary dictionary];
- for (NSString *name in @[@"activeTransformMode", @"appliedCoverInsets", @"rotationAngle", @"scaleX", @"scaleY",
- @"transformedDisplayConfigurationHardwareIdentifier", @"insetDisplayConfigurationHardwareIdentifier"])
- if ([cover respondsToSelector:NSSelectorFromString(name)])
- coverState[name] = [cover valueForKey:name] ?: NSNull.null;
- vpFoldDisplayLog([NSString stringWithFormat:@"cover transform state: %@", coverState]);
- vpFoldDisplayLog([NSString stringWithFormat:@"display state logical projection enabled=%d", atomic_load_explicit(&vpLogicalProjectionEnabled, memory_order_acquire)]);
- vpFoldDisplayLog([NSString stringWithFormat:@"display state: app=%s poseProvider=%@ coordinator=%@",
- object_getClassName(app), provider, coordinator]);
- id monitor = vpReadObject(objc_getClass("FBDisplayManager"), "sharedInstance");
- NSMutableArray *compatibilitySourceFlags = [NSMutableArray array];
- for (id source in vpReadObject(monitor, "_sortedSources"))
- [compatibilitySourceFlags addObject:[source valueForKey:@"updatable"] ?: NSNull.null];
- vpFoldDisplayLog([NSString stringWithFormat:@"compatibility monitor source updatable=%@", compatibilitySourceFlags]);
- NSArray *observedMonitors;
- @synchronized (vpObservedDisplayMonitors) {
- observedMonitors = vpObservedDisplayMonitors.allObjects;
- }
- for (id observed in observedMonitors) {
- id transformer = vpReadObject(observed, "transformer");
- NSMutableArray *sourceFlags = [NSMutableArray array];
- for (id source in vpReadObject(observed, "_sortedSources"))
- [sourceFlags addObject:[source valueForKey:@"updatable"] ?: NSNull.null];
- vpFoldDisplayLog([NSString stringWithFormat:@"observed monitor: %s %p transformer=%s %p updatable=%@",
- object_getClassName(observed), (__bridge void *)observed,
- transformer ? object_getClassName(transformer) : "none", (__bridge void *)transformer, sourceFlags]);
- }
- id mainConfiguration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- id caDisplay = vpReadObject(mainConfiguration, "CADisplay");
- id uuid = vpReadObject(caDisplay, "uniqueId");
- id service = vpReadObject(objc_getClass("BKSDisplayService"), "sharedInstance");
- SEL traitsSelector = sel_registerName("traitsForDisplayUUID:");
- if ([service respondsToSelector:traitsSelector]) {
- id traits = ((id (*)(id, SEL, id))objc_msgSend)(service, traitsSelector, uuid);
- vpFoldDisplayLog([NSString stringWithFormat:@"display native traits uuid=%@: %@", uuid, traits]);
- Class displayClass = objc_getClass("CADisplay");
- // New untagged software displays do not refresh every client's
- // inventory automatically. Invalidate only this read cache.
- SEL refresh = sel_registerName("updateDisplays");
- if ([displayClass respondsToSelector:refresh])
- ((void (*)(id, SEL))objc_msgSend)(displayClass, refresh);
- id displays = vpReadObject(displayClass, "displays");
- for (id display in displays) {
- id displayName = vpReadObject(display, "deviceName");
- if (![displayName isEqual:@"VPhone Cover Probe"]) continue;
- id displayUUID = vpReadObject(display, "uniqueId");
- if (!displayUUID) continue;
- id displayTraits = ((id (*)(id, SEL, id))objc_msgSend)(service, traitsSelector, displayUUID);
- vpFoldDisplayLog([NSString stringWithFormat:@"display native software traits name=%@ uuid=%@: %@",
- displayName, displayUUID, displayTraits]);
- }
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"display state monitor=%@ transformer=%@ observedTransformer=%@",
- monitor, vpReadObject(monitor, "transformer"), vpObservedConfigurationTransformer]);
- id connected = vpReadObject(monitor, "connectedIdentities");
- id permanent = vpReadObject(monitor, "alwaysConnectedIdentities");
- vpFoldDisplayLog([NSString stringWithFormat:@"display state monitor connected=%@ always=%@", connected, permanent]);
- for (id identity in connected) {
- NSMutableDictionary *fields = [NSMutableDictionary dictionary];
- for (NSString *key in @[@"displayID", @"type", @"connectionType", @"isAlwaysConnected", @"isUIKitMainLike",
- @"isExternal", @"isVirtualized", @"uniqueIdentifier"]) {
- if ([identity respondsToSelector:NSSelectorFromString(key)]) fields[key] = [identity valueForKey:key] ?: NSNull.null;
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"display identity fields: %@", fields]);
- }
- NSArray *sources = vpReadObject(monitor, "_sortedSources");
- vpFoldDisplayLog([NSString stringWithFormat:@"display state sources: %@", sources]);
- static BOOL sourceMethodsLogged;
- if (!sourceMethodsLogged && sources.count) {
- sourceMethodsLogged = YES;
- Class sourceClass = object_getClass(sources.firstObject);
- for (unsigned int level = 0; sourceClass && level < 2; level++, sourceClass = class_getSuperclass(sourceClass)) {
- unsigned int count = 0;
- Method *methods = class_copyMethodList(sourceClass, &count);
- for (unsigned int i = 0; i < count; i++) {
- const char *selector = sel_getName(method_getName(methods[i]));
- if (strstr(selector, "ransform") || strstr(selector, "pdate") || strstr(selector, "onfiguration"))
- vpFoldDisplayLog([NSString stringWithFormat:@"display source method %@ %s types: %s",
- NSStringFromClass(sourceClass), selector, method_getTypeEncoding(methods[i])]);
- }
- free(methods);
- }
- }
- // Legacy Main can display the home screen while the fold coordinator
- // has no selected primary scene. Inspect SpringBoard's actual scene
- // accessors as well; a nil coordinator entry is not an absent UI.
- for (NSString *key in @[@"primaryWindowScene", @"activeWindowScene", @"embeddedDisplayWindowScene",
- @"activeDisplayWindowScene", @"currentTransitionContext"]) {
- id owner = [key hasSuffix:@"DisplayWindowScene"] ? app : coordinator;
- id value = vpReadObject(owner, key.UTF8String);
- vpFoldDisplayLog([NSString stringWithFormat:@"display state %@: %@", key, value]);
- if ([key hasSuffix:@"WindowScene"] && value) {
- for (NSString *property in @[@"displayConfiguration", @"displayConfigurationContext", @"displayIdentity", @"screen", @"traitCollection"])
- vpFoldDisplayLog([NSString stringWithFormat:@"display scene %@: %@", property,
- vpReadObject(value, property.UTF8String)]);
- id coordinateSpace = vpReadObject(value, "coordinateSpace");
- if ([coordinateSpace respondsToSelector:sel_registerName("bounds")])
- vpFoldDisplayLog([NSString stringWithFormat:@"display scene coordinate bounds: %@",
- [coordinateSpace valueForKey:@"bounds"]]);
- id screen = vpReadObject(value, "screen");
- id pipeline = vpReadObject(value, "traitsPipelineManager");
- NSMutableDictionary *pipelineState = [NSMutableDictionary dictionary];
- pipelineState[@"sceneSurfaceType"] = [value valueForKey:@"surfaceType"] ?: NSNull.null;
- pipelineState[@"nativeOrientationState"] = vpReadObject(pipeline, "_orientationStateDescription") ?: NSNull.null;
- id arbiter = vpReadObject(value, "traitsArbiter");
- pipelineState[@"arbiter"] = arbiter ?: NSNull.null;
- pipelineState[@"arbiterDetails"] = vpReadMultilineDescription(arbiter) ?: NSNull.null;
- for (NSString *stage in @[@"inputsValidationStage", @"orientationResolutionStage"])
- pipelineState[stage] = vpReadMultilineDescription(vpReadObject(arbiter, stage.UTF8String)) ?: NSNull.null;
- for (NSString *property in @[@"supportsLiveDeviceRotation", @"systemArbitratedDeviceOrientation",
- @"systemArbitratedInterfaceOrientation", @"continuousFoldPinnedInterfaceOrientation",
- @"lastNonFlatDeviceOrientation", @"inputs"])
- if ([pipeline respondsToSelector:NSSelectorFromString(property)])
- pipelineState[property] = [pipeline valueForKey:property] ?: NSNull.null;
- vpFoldDisplayLog([NSString stringWithFormat:@"display pipeline state %s: %@", object_getClassName(pipeline), pipelineState]);
- static BOOL arbiterMethodsLogged;
- if (arbiter && !arbiterMethodsLogged) {
- arbiterMethodsLogged = YES;
- unsigned int count = 0;
- Method *methods = class_copyMethodList(object_getClass(arbiter), &count);
- for (unsigned int i = 0; i < count; i++) {
- const char *name = sel_getName(method_getName(methods[i]));
- if (strstr(name, "tage") || strstr(name, "articipant") || strstr(name, "esolved") || strstr(name, "escription"))
- vpFoldDisplayLog([NSString stringWithFormat:@"arbiter method %s %s types: %s", object_getClassName(arbiter), name, method_getTypeEncoding(methods[i])]);
- }
- free(methods);
- }
- NSMutableDictionary *screenBounds = [NSMutableDictionary dictionary];
- for (NSString *property in @[@"_referenceBounds", @"_unjailedReferenceBounds", @"_mainSceneReferenceBounds", @"nativeBounds"])
- screenBounds[property] = vpReadRectValue(screen, property.UTF8String) ?: NSNull.null;
- vpFoldDisplayLog([NSString stringWithFormat:@"display screen geometry: %@", screenBounds]);
- NSUInteger visibleWindowCount = 0;
- for (id window in vpReadObject(value, "windows")) {
- if (![[window valueForKey:@"hidden"] boolValue] && visibleWindowCount++ < 8) {
- vpFoldDisplayLog([NSString stringWithFormat:@"display visible window %s frame=%@ bounds=%@",
- object_getClassName(window), [window valueForKey:@"frame"], [window valueForKey:@"bounds"]]);
- NSMutableDictionary *policy = [NSMutableDictionary dictionary];
- for (NSString *property in @[@"_shouldResizeWithScene", @"_isHostedInAnotherProcess", @"_isSceneSized", @"resizesToFullScreen"])
- policy[property] = vpReadBoolValue(window, property.UTF8String) ?: NSNull.null;
- policy[@"classTransformRotationsEnabled"] = vpReadBoolValue(object_getClass(window), "_transformLayerRotationsAreEnabled") ?: NSNull.null;
- policy[@"sceneBoundsInWindowOrientation"] = vpReadRectValue(window, "_sceneBoundsInWindowOrientation") ?: NSNull.null;
- id controller = vpReadObject(window, "rootViewController");
- id view = vpReadObject(controller, "viewIfLoaded");
- policy[@"rootController"] = controller ? NSStringFromClass([controller class]) : @"none";
- policy[@"rootViewFrame"] = vpReadRectValue(view, "frame") ?: NSNull.null;
- policy[@"rootViewBounds"] = vpReadRectValue(view, "bounds") ?: NSNull.null;
- policy[@"windowTransform"] = [window valueForKey:@"transform"] ?: NSNull.null;
- policy[@"rootViewTransform"] = view ? [view valueForKey:@"transform"] : NSNull.null;
- policy[@"interfaceOrientation"] = [window valueForKey:@"interfaceOrientation"] ?: NSNull.null;
- vpFoldDisplayLog([NSString stringWithFormat:@"display window resize policy %s: %@", object_getClassName(window), policy]);
- // Read-only: separate UIKit scene orientation from the
- // home controller's native orientation/layout caches.
- NSMutableDictionary *controllerState = [NSMutableDictionary dictionary];
- for (NSString *property in @[@"orientation", @"effectiveOrientation", @"supportedInterfaceOrientations"])
- if ([controller respondsToSelector:NSSelectorFromString(property)])
- controllerState[property] = [controller valueForKey:property] ?: NSNull.null;
- id manager = vpReadObjectIvar(controller, "_iconManager");
- id folder = vpReadObject(manager, "rootFolderController");
- controllerState[@"iconManager"] = manager ?: NSNull.null;
- controllerState[@"folderController"] = folder ?: NSNull.null;
- controllerState[@"contentView"] = vpReadObjectIvar(controller, "_iconContentView") ?: NSNull.null;
- vpFoldDisplayLog([NSString stringWithFormat:@"display controller layout %s: %@", object_getClassName(controller), controllerState]);
- }
- }
- SEL mode = sel_registerName("displayContentModeForWindowScene:");
- Method method = class_getInstanceMethod(object_getClass(coordinator), mode);
- if (method && strcmp(method_getTypeEncoding(method), "q24@0:8@16") == 0) {
- NSInteger selected = ((NSInteger (*)(id, SEL, id))objc_msgSend)(coordinator, mode, value);
- vpFoldDisplayLog([NSString stringWithFormat:@"display state %@ mode=%ld", key, (long)selected]);
- }
- }
- }
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"display state inspection exception: %@", exception.reason]);
- }
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerBoot.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerBoot.m
deleted file mode 100644
index 79cf8abb..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerBoot.m
+++ /dev/null
@@ -1,33 +0,0 @@
-// backboardd: the inner display from the render server's first moment.
-//
-// QuartzCore's shared_server_init creates the CAWindowServer (_init), finds
-// the hardware displays (_detectDisplays), configures them, and only then
-// registers the render server's name (CA::Render::Server::register_name),
-// which is when SpringBoard and every other client can connect and read the
-// display inventory. Adding the inner display after the server runs (a
-// main-queue retry on +[CAWindowServer serverIfRunning]) lands after that
-// first read: FrontBoard's display monitor, BacklightServices' backlight
-// hosts and SpringBoard's embedded-scene gate all missed it until
-// SpringBoard restarted. Adding it from _detectDisplays puts it in the
-// inventory before any client exists. The server-ready retry in
-// FoldDisplayInnerDisplay.m stays as the fallback for a server that was
-// already running when this library loaded.
-
-#import "FoldDisplayPrivate.h"
-
-static IMP vpOriginalDetectDisplays;
-
-static void vpDetectDisplaysWithInner(id self, SEL selector) {
- ((void (*)(id, SEL))vpOriginalDetectDisplays)(self, selector);
- if (vpAddInnerRenderDisplayToServer(self))
- vpFoldDisplayLog(@"inner display: added during render server display detection");
-}
-
-void vpInstallInnerBootDisplay(void) {
- Method detect = class_getInstanceMethod(objc_getClass("CAWindowServer"), sel_registerName("_detectDisplays"));
- if (!detect || strcmp(method_getTypeEncoding(detect), "v16@0:8") != 0) {
- vpFoldDisplayLog(@"inner display: render server display detection ABI unavailable");
- return;
- }
- vpOriginalDetectDisplays = method_setImplementation(detect, (IMP)vpDetectDisplaysWithInner);
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerDisplay.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerDisplay.m
deleted file mode 100644
index a8943a7c..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerDisplay.m
+++ /dev/null
@@ -1,855 +0,0 @@
-// Spike: the Duo inner panel as a display of its own. A real iPhone Duo has a
-// cover main display and a non-main, always-connected, landscape-native inner
-// panel, which PosterKit classifies as auxiliary. This guest has one portrait
-// main display. Here backboardd adds a software render display for the inner
-// panel, and SpringBoard describes it as a built-in panel everywhere except
-// FrontBoard's classification, which sees CADisplay type 4: in
-// _FBSCADisplayToDisplayTypes that type is always-connected without being
-// UIKit-main-like, so only the real Main claims the cloning source (claiming
-// it twice is SpringBoard's "Cloning source already exists" assertion).
-//
-// Opt-in while the spike runs: both processes act only while
-// /var/mobile/Library/Caches/vphone-duo-inner-display exists. Remove the
-// file and restart backboardd and SpringBoard to return to the baseline.
-
-#import "FoldDisplayPrivate.h"
-
-static NSString *const vpInnerDisplayName = @"VPhone Duo Inner";
-static const char *vpInnerDisplayMarker = "/var/mobile/Library/Caches/vphone-duo-inner-display";
-static id vpInnerRenderDisplay;
-static BOOL vpIsInnerDisplay(id display);
-static void vpWatchInnerDisplayResolution(void);
-
-BOOL vpInnerDisplayRequested(void) {
- return access(vpInnerDisplayMarker, F_OK) == 0;
-}
-
-// MARK: - backboardd: the render display
-
-@protocol VPhoneInnerDisplayInitialization
-- (instancetype)initWithOptions:(NSDictionary *)options;
-@end
-
-// Adds the inner panel's render display to a render server, once. It is
-// never removed: FrontBoard keeps identities for the life of the monitor.
-// Normally called from the server's display detection (FoldDisplayInnerBoot.m),
-// so the display exists before any client reads the inventory.
-BOOL vpAddInnerRenderDisplayToServer(id server) {
- if (vpInnerRenderDisplay || !server) return NO;
- @try {
- Class cls = objc_getClass("CAWindowServerVirtualDisplay");
- Method initializer = class_getInstanceMethod(cls, sel_registerName("initWithOptions:"));
- if (!initializer || strcmp(method_getTypeEncoding(initializer), "@24@0:8@16") != 0) {
- vpFoldDisplayLog(@"inner display: virtual display initializer ABI unavailable");
- return NO;
- }
- // The panel's native pixels, landscape: 951x669 points at 3x.
- id display = [(id<VPhoneInnerDisplayInitialization>)[cls alloc] initWithOptions:@{
- @"kCAVirtualDisplayWidth": @2853, @"kCAVirtualDisplayHeight": @2007,
- @"kCAVirtualDisplayUpdateRate": @60, @"kCAVirtualDisplayName": vpInnerDisplayName,
- }];
- if (!display) { vpFoldDisplayLog(@"inner display: initializer returned nil"); return NO; }
- ((void (*)(id, SEL, id))objc_msgSend)(server, sel_registerName("addDisplay:"), display);
- SEL setEnabled = sel_registerName("setEnabled:");
- Method enable = class_getInstanceMethod(object_getClass(display), setEnabled);
- if (enable && strcmp(method_getTypeEncoding(enable), "v20@0:8B16") == 0)
- ((void (*)(id, SEL, BOOL))objc_msgSend)(display, setEnabled, YES);
- vpTagUnknownDisplay(display);
- vpInnerRenderDisplay = display;
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: render display added %@ uniqueId=%@", display,
- [display respondsToSelector:sel_registerName("uniqueId")] ? [display valueForKey:@"uniqueId"] : @"-"]);
- vpInspectRenderDisplays();
- return YES;
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: render display exception %@", exception.reason]);
- }
- return NO;
-}
-
-// The fallback for a render server that was already running when this
-// library loaded: add the display once the server answers.
-static void vpAddInnerRenderDisplay(unsigned int attempt) {
- if (vpInnerRenderDisplay) return;
- id server = ((id (*)(id, SEL))objc_msgSend)(objc_getClass("CAWindowServer"), sel_registerName("serverIfRunning"));
- if (server)
- vpAddInnerRenderDisplayToServer(server);
- else if (attempt < 30)
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), dispatch_get_main_queue(),
- ^{ vpAddInnerRenderDisplay(attempt + 1); });
- else
- vpFoldDisplayLog(@"inner display: render server never ran");
-}
-
-// 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;
-}
-
-// MARK: - backboardd: one digitizer for two panels
-
-// A real Duo has a digitizer per panel; this guest has one, bound to the
-// primary display (an empty display UUID). While the inner display is lit
-// (the device is open) that digitizer belongs to the inner display, so
-// 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.
-static IMP vpOriginalDigitizerDisplayUUID, vpOriginalDigitizerState;
-static BOOL vpLoggedDigitizerSwitch;
-
-static BOOL vpInnerPanelLit(void) {
- id inner = vpInnerRenderDisplay;
- return inner && [[inner valueForKey:@"enabled"] boolValue] && ![[inner valueForKey:@"isBlanked"] boolValue];
-}
-
-static id vpInnerDigitizerDisplayUUID(id self, SEL selector, id service) {
- id uuid = ((id (*)(id, SEL, id))vpOriginalDigitizerDisplayUUID)(self, selector, service);
- if ([uuid length] || !vpInnerPanelLit()) return uuid;
- id inner = [vpInnerRenderDisplay valueForKey:@"uniqueId"];
- return [inner length] ? inner : uuid;
-}
-
-static id vpInnerDigitizerState(id self, SEL selector, id service) {
- id state = ((id (*)(id, SEL, id))vpOriginalDigitizerState)(self, selector, service);
- if (state || !vpInnerPanelLit()) return state;
- ((id (*)(id, SEL, id))objc_msgSend)(self, sel_registerName("_queue_addDigitizerStateForService:"), service);
- state = ((id (*)(id, SEL, id))vpOriginalDigitizerState)(self, selector, service);
- if (!vpLoggedDigitizerSwitch) {
- vpLoggedDigitizerSwitch = YES;
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: digitizer %@ now on %@ (state %@)",
- service, [vpInnerRenderDisplay valueForKey:@"uniqueId"], state]);
- }
- 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:"));
- Method state = class_getInstanceMethod(processor, sel_registerName("_queue_digitizerStateForService:"));
- Method add = class_getInstanceMethod(processor, sel_registerName("_queue_addDigitizerStateForService:"));
- const char *encodings[] = {uuid ? method_getTypeEncoding(uuid) : "missing", state ? method_getTypeEncoding(state) : "missing",
- add ? method_getTypeEncoding(add) : "missing"};
- if (strcmp(encodings[0], "@24@0:8@16") != 0 || strcmp(encodings[1], "@24@0:8@16") != 0 || strcmp(encodings[2], "@24@0:8@16") != 0) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: digitizer ABI unavailable (%s, %s, %s)",
- encodings[0], encodings[1], encodings[2]]);
- return;
- }
- vpOriginalDigitizerDisplayUUID = method_setImplementation(uuid, (IMP)vpInnerDigitizerDisplayUUID);
- vpOriginalDigitizerState = method_setImplementation(state, (IMP)vpInnerDigitizerState);
- vpFoldDisplayLog(@"inner display: digitizer routing installed");
- vpInstallInnerDigitizerTurn(processor);
-}
-
-// MARK: - SpringBoard: one scanout for two panels
-
-// SpringBoard powers each panel through its CADisplayStateControl (state 1
-// on, 0 off): open, the cover (primary, display 1) goes off and the inner
-// display on; closed, the reverse. On this guest the primary is the only
-// scanout, and open it has to show the inner display, which SpringBoard
-// composites onto it (vpShowInnerDisplay). So the primary is kept on while
-// either panel wants it; a screen-off turns both off. Closing does not turn
-// the inner display off, so the inner display is lit only while the cover is
-// not: the cover wins the shared panel. The compositor and backboardd's touch
-// routing follow the inner display's applied state.
-static IMP vpOriginalTransitionDisplayState;
-static id vpPrimaryStateControl, vpInnerStateControl;
-static long long vpPrimaryWantedState = 1, vpPrimaryAppliedState = 1, vpInnerWantedState, vpInnerAppliedState = -1;
-
-static unsigned int vpStateControlDisplayId(id control) {
- Ivar ivar = class_getInstanceVariable(object_getClass(control), "_display_id");
- if (!ivar || strcmp(ivar_getTypeEncoding(ivar), "I") != 0) return 0;
- return *(unsigned int *)((uint8_t *)(__bridge void *)control + ivar_getOffset(ivar));
-}
-
-static void vpApplyPanelState(id control, long long state, long long *applied, id completion) {
- if (!control || (state == *applied && !completion)) return;
- *applied = state;
- ((void (*)(id, SEL, long long, id))vpOriginalTransitionDisplayState)(control,
- sel_registerName("transitionToDisplayState:withCompletion:"), state, completion);
-}
-
-static void vpApplyPanelStates(id primaryCompletion, id innerCompletion) {
- vpApplyPanelState(vpPrimaryStateControl, vpPrimaryWantedState || vpInnerWantedState ? 1 : 0,
- &vpPrimaryAppliedState, primaryCompletion);
- long long inner = vpInnerWantedState && !vpPrimaryWantedState ? 1 : 0;
- BOOL changed = inner != vpInnerAppliedState;
- vpApplyPanelState(vpInnerStateControl, inner, &vpInnerAppliedState, innerCompletion);
- if (changed && vpInnerStateControl) dispatch_async(dispatch_get_main_queue(), ^{ vpShowInnerDisplay(inner != 0); });
-}
-
-// SpringBoard asks for a transition only when it wants a state the panel is
-// not in; after a SpringBoard restart the inner display may already be lit and
-// is never asked about. So until it is, its wanted state is the state it has.
-static void vpAdoptInnerStateControl(void) {
- if (vpInnerStateControl) return;
- for (id display in vpReadObject(objc_getClass("CADisplay"), "displays") ?: @[]) {
- if (!vpIsInnerDisplay(display)) continue;
- id control = vpReadObject(display, "stateControl");
- Method current = class_getInstanceMethod(object_getClass(control), sel_registerName("displayState"));
- if (!current || strcmp(method_getTypeEncoding(current), "q16@0:8") != 0) return;
- vpInnerWantedState = vpInnerAppliedState =
- ((long long (*)(id, SEL))objc_msgSend)(control, sel_registerName("displayState")) != 0;
- vpInnerStateControl = control;
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: adopted state %lld", vpInnerWantedState]);
- if (vpInnerWantedState) dispatch_async(dispatch_get_main_queue(), ^{ vpShowInnerDisplay(YES); });
- return;
- }
-}
-
-static void vpSharedScanoutTransition(id self, SEL selector, long long state, id completion) {
- unsigned int displayId = vpStateControlDisplayId(self);
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: display %u wants state %lld", displayId, state]);
- if (displayId == 1) {
- vpAdoptInnerStateControl();
- vpPrimaryStateControl = self;
- vpPrimaryWantedState = state;
- vpApplyPanelStates(completion, nil);
- return;
- }
- id innerDisplay = nil;
- for (id display in vpReadObject(objc_getClass("CADisplay"), "displays") ?: @[])
- if ([[display valueForKey:@"displayId"] unsignedIntValue] == displayId && vpIsInnerDisplay(display)) innerDisplay = display;
- if (!innerDisplay) {
- ((void (*)(id, SEL, long long, id))vpOriginalTransitionDisplayState)(self, selector, state, completion);
- return;
- }
- vpInnerStateControl = self;
- vpInnerWantedState = state;
- vpApplyPanelStates(nil, completion);
-}
-
-static void vpInstallSharedScanout(void) {
- Method transition = class_getInstanceMethod(objc_getClass("CADisplayStateControl"),
- sel_registerName("transitionToDisplayState:withCompletion:"));
- const char *encoding = transition ? method_getTypeEncoding(transition) : "missing";
- Ivar displayId = class_getInstanceVariable(objc_getClass("CADisplayStateControl"), "_display_id");
- if (strcmp(encoding, "v32@0:8q16@?24") != 0 || !displayId || strcmp(ivar_getTypeEncoding(displayId), "I") != 0) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: shared scanout ABI unavailable (%s)", encoding]);
- return;
- }
- vpOriginalTransitionDisplayState = method_setImplementation(transition, (IMP)vpSharedScanoutTransition);
- vpFoldDisplayLog(@"inner display: shared scanout installed");
-}
-
-// Each render display's power and blanking, as backboardd holds them.
-void vpLogRenderDisplayState(void) {
- @try {
- id server = ((id (*)(id, SEL))objc_msgSend)(objc_getClass("CAWindowServer"), sel_registerName("serverIfRunning"));
- for (id display in ((id (*)(id, SEL))objc_msgSend)(server, sel_registerName("displays"))) {
- if (![[display valueForKey:@"enabled"] boolValue] && ![[display valueForKey:@"deviceName"] isEqual:@"primary"] &&
- display != vpInnerRenderDisplay) continue;
- NSMutableString *state = [NSMutableString stringWithFormat:@"inner display: server %@", [display valueForKey:@"deviceName"]];
- for (NSString *key in @[@"enabled", @"isBlanked", @"disablesUpdates", @"brightness"])
- [state appendFormat:@" %@=%@", key, [display respondsToSelector:NSSelectorFromString(key)] ? [display valueForKey:key] : @"-"];
- vpFoldDisplayLog(state);
- }
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: server state exception %@", exception.reason]);
- }
-}
-
-void vpInstallInnerRenderDisplay(void) {
- if (!vpInnerDisplayRequested()) return;
- vpInstallInnerDigitizer();
- vpInstallInnerBootDisplay();
- dispatch_async(dispatch_get_main_queue(), ^{ vpAddInnerRenderDisplay(0); });
-}
-
-// MARK: - SpringBoard: how the system sees it
-
-// The inner panel is a built-in panel (CADisplay type 0) to everything that
-// asks: BacklightServices gives a backlight host only to built-in displays,
-// and every SpringBoard window scene needs one; SpringBoard's startup waits
-// for a scene on every built-in display. Only FrontBoard's configuration
-// classification sees type 4, which there is always-connected without being
-// UIKit-main-like, so only the real Main claims the cloning source.
-static IMP vpOriginalDisplayType, vpOriginalPointScale, vpOriginalExternal, vpOriginalConfigurationInit;
-static _Thread_local BOOL vpClassifyingConfiguration;
-static id vpInnerIdentity;
-
-static BOOL vpIsInnerDisplay(id display) {
- @try {
- for (NSString *key in @[@"name", @"deviceName"]) {
- if ([display respondsToSelector:NSSelectorFromString(key)] &&
- [[display valueForKey:key] isEqual:vpInnerDisplayName]) return YES;
- }
- } @catch (__unused NSException *exception) {
- }
- return NO;
-}
-
-static long long vpInnerDisplayType(id self, SEL selector) {
- if (!vpIsInnerDisplay(self)) return ((long long (*)(id, SEL))vpOriginalDisplayType)(self, selector);
- return vpClassifyingConfiguration ? 4 : 0;
-}
-
-static id vpInnerConfigurationInit(id self, SEL selector, id display, id original, BOOL isMain, BOOL assertIfInvalid) {
- vpClassifyingConfiguration = YES;
- id result = ((id (*)(id, SEL, id, id, BOOL, BOOL))vpOriginalConfigurationInit)(self, selector, display, original, isMain, assertIfInvalid);
- vpClassifyingConfiguration = NO;
- if (vpIsInnerDisplay(display) && !vpInnerIdentity) vpInnerIdentity = vpReadObject(result, "identity");
- return result;
-}
-
-// Applications take the scene's display identity from SpringBoard. UIKit
-// gives a screen the device idiom only when that identity is UIKit-main-like
-// and leaves it unspecified (-1) otherwise; UIKit's Swift idiom switches
-// (sheet presentation, scroll edge effects) trap on -1. The identity
-// SpringBoard keeps stays as classified, so only Main claims the cloning
-// source; the copy an application decodes says main-like.
-static IMP vpOriginalIdentityEncode;
-
-static void vpInnerIdentityEncode(id self, SEL selector, xpc_object_t dictionary) {
- ((void (*)(id, SEL, xpc_object_t))vpOriginalIdentityEncode)(self, selector, dictionary);
- if (dictionary && vpInnerIdentity && [self isEqual:vpInnerIdentity])
- xpc_dictionary_set_bool(dictionary, "mainLike", true);
-}
-
-static void vpInstallInnerIdentityEncode(void) {
- Method encode = class_getInstanceMethod(objc_getClass("FBSDisplayIdentity"), sel_registerName("encodeWithXPCDictionary:"));
- if (!encode || strcmp(method_getTypeEncoding(encode), "v24@0:8@16") != 0) {
- vpFoldDisplayLog(@"inner display: identity encoding ABI unavailable");
- return;
- }
- vpOriginalIdentityEncode = method_setImplementation(encode, (IMP)vpInnerIdentityEncode);
-}
-
-static NSUInteger vpInnerPointScale(id self, SEL selector) {
- return vpIsInnerDisplay(self) ? 3 : ((NSUInteger (*)(id, SEL))vpOriginalPointScale)(self, selector);
-}
-
-static BOOL vpInnerExternal(id self, SEL selector) {
- return vpIsInnerDisplay(self) ? NO : ((BOOL (*)(id, SEL))vpOriginalExternal)(self, selector);
-}
-
-// UIScreen takes the device idiom only for a UIKit-main-like screen and
-// leaves every other non-car screen unspecified (-1); UIKit's Swift idiom
-// switch (ScrollEdgeEffectView) traps on -1. The inner panel is a built-in
-// phone panel, so its screen takes the device idiom too.
-static IMP vpOriginalUpdateScreenIdiom;
-
-static void vpInnerUpdateScreenIdiom(id self, SEL selector) {
- ((void (*)(id, SEL))vpOriginalUpdateScreenIdiom)(self, selector);
- id identity = vpReadObject(vpReadObject(self, "displayConfiguration"), "identity");
- if (!identity || [[identity description] isEqual:@"Main"]) return;
- if (((long long (*)(id, SEL))objc_msgSend)(self, sel_registerName("_userInterfaceIdiom")) != -1) return;
- long long idiom = ((long long (*)(id, SEL))objc_msgSend)(vpReadObject(objc_getClass("UIDevice"), "currentDevice"),
- sel_registerName("userInterfaceIdiom"));
- ((void (*)(id, SEL, long long))objc_msgSend)(self, sel_registerName("_setUserInterfaceIdiom:"), idiom);
-}
-
-static void vpInstallInnerScreenIdiom(void) {
- Class screen = objc_getClass("UIScreen");
- Method update = class_getInstanceMethod(screen, sel_registerName("_updateUserInterfaceIdiom"));
- Method set = class_getInstanceMethod(screen, sel_registerName("_setUserInterfaceIdiom:"));
- Method get = class_getInstanceMethod(screen, sel_registerName("_userInterfaceIdiom"));
- if (!update || !set || !get || strcmp(method_getTypeEncoding(update), "v16@0:8") != 0 ||
- strcmp(method_getTypeEncoding(set), "v24@0:8q16") != 0 || strcmp(method_getTypeEncoding(get), "q16@0:8") != 0) {
- vpFoldDisplayLog(@"inner display: screen idiom ABI unavailable");
- return;
- }
- vpOriginalUpdateScreenIdiom = method_setImplementation(update, (IMP)vpInnerUpdateScreenIdiom);
-}
-
-static IMP vpReplaceDisplayGetter(const char *name, const char *encoding, IMP replacement) {
- Method method = class_getInstanceMethod(objc_getClass("CADisplay"), sel_registerName(name));
- if (!method || strcmp(method_getTypeEncoding(method), encoding) != 0) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: -[CADisplay %s] %s, expected %s", name,
- method ? method_getTypeEncoding(method) : "missing", encoding]);
- return NULL;
- }
- return method_setImplementation(method, replacement);
-}
-
-// Installed before SpringBoard's display monitor reads the render displays.
-// CADisplay has no always-connected getter; FrontBoard derives that from
-// the type.
-void vpInstallInnerDisplayAdapter(void) {
- if (!vpInnerDisplayRequested()) return;
- vpInstallSharedScanout();
- vpInstallInnerScreenIdiom();
- vpInstallInnerIdentityEncode();
- // Type 0 without the FrontBoard scope is a second UIKit-main-like
- // display, so no scope means no adapter.
- Method configurationInit = class_getInstanceMethod(objc_getClass("FBSDisplayConfiguration"),
- sel_registerName("_initWithImmutableDisplay:originalDisplay:isMainDisplay:assertIfInvalid:"));
- const char *encoding = configurationInit ? method_getTypeEncoding(configurationInit) : "missing";
- if (strcmp(encoding, "@40@0:8@16@24B32B36") != 0) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: configuration initializer %s, adapter off", encoding]);
- return;
- }
- vpOriginalConfigurationInit = method_setImplementation(configurationInit, (IMP)vpInnerConfigurationInit);
- vpOriginalDisplayType = vpReplaceDisplayGetter("displayType", "q16@0:8", (IMP)vpInnerDisplayType);
- vpOriginalPointScale = vpReplaceDisplayGetter("pointScale", "Q16@0:8", (IMP)vpInnerPointScale);
- vpOriginalExternal = vpReplaceDisplayGetter("isExternal", "B16@0:8", (IMP)vpInnerExternal);
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: adapter type=%d scale=%d external=%d",
- vpOriginalDisplayType != NULL, vpOriginalPointScale != NULL, vpOriginalExternal != NULL]);
- vpWatchInnerDisplayResolution();
-}
-
-// MARK: - SpringBoard: the inner display's scenes
-
-static BOOL vpSceneIsOnInnerDisplay(id scene) {
- id configuration = vpReadObject(vpReadObject(vpReadObject(scene, "_FBSScene"), "settings"), "displayConfiguration");
- id identity = vpReadObject(configuration, "identity");
- return identity && ![[identity description] isEqual:@"Main"];
-}
-
-// The SpringBoard window scene (not an aperture subclass) on the inner
-// display, or on Main.
-static id vpSpringBoardWindowScene(BOOL inner) {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- for (id scene in [vpReadObject(app, "connectedScenes") allObjects] ?: @[])
- if ([scene class] == objc_getClass("SBWindowScene") && vpSceneIsOnInnerDisplay(scene) == inner) return scene;
- return nil;
-}
-
-// MARK: - SpringBoard: the panel shows the inner display
-
-// The render server's own clone of a display (addClone:options:) never
-// reaches this guest's paravirtual panel, so SpringBoard composites
-// instead: a render context ordered onto the primary display above
-// everything hosts every window of the inner display's scenes by render
-// context (CALayerHost, as scene hosting does). It is not a window of
-// SB-main, because open, SpringBoard gives the cover (Main) auxiliary
-// content and takes its scene's windows off screen. Touches on the hosted
-// windows reach their owners through backboardd's render-tree hit test.
-//
-// The render server redraws a display for commits to its own contexts only;
-// a commit by an inner-display context (an application changing its pixels)
-// leaves the hosting primary display on its last frame. So while shown, a
-// layer over the whole panel changes once per primary frame: its background
-// alternates between two clear colors, which damages every pixel without
-// a visible change. (An opacity flip on the container does the same, but
-// below 1 the container renders offscreen as a group, and hosted secure
-// windows come out as grey blocks on those frames.)
-static id vpInnerHostContext, vpInnerHostContainer, vpInnerHostDamage, vpInnerHostRefresh;
-static dispatch_source_t vpInnerHostTimer;
-
-@interface VPhoneInnerHostRefresh : NSObject
-@end
-
-@implementation VPhoneInnerHostRefresh
-- (void)refresh:(id)link {
- static CGColorRef clear, faint;
- static BOOL flip;
- if (!clear) {
- clear = CGColorCreateSRGB(0, 0, 0, 0);
- faint = CGColorCreateSRGB(1, 1, 1, 0);
- }
- flip = !flip;
- Class transaction = objc_getClass("CATransaction");
- ((void (*)(id, SEL))objc_msgSend)(transaction, sel_registerName("begin"));
- ((void (*)(id, SEL, BOOL))objc_msgSend)(transaction, sel_registerName("setDisableActions:"), YES);
- ((void (*)(id, SEL, CGColorRef))objc_msgSend)(vpInnerHostDamage, sel_registerName("setBackgroundColor:"), flip ? faint : clear);
- ((void (*)(id, SEL))objc_msgSend)(transaction, sel_registerName("commit"));
-}
-@end
-static NSMutableDictionary<NSNumber *, id> *vpInnerHostLayers;
-static CGSize vpInnerHostPanel;
-
-static id vpPrimaryCADisplay(void) {
- for (id display in vpReadObject(objc_getClass("CADisplay"), "displays") ?: @[])
- if ([[display valueForKey:@"deviceName"] isEqual:@"primary"]) return display;
- return nil;
-}
-
-// A display-level context works in the panel's pixels: the root covers them,
-// and the inner display's points are fitted onto the panel's points,
-// turned a quarter (-90 degrees) if it reads landscape on the portrait
-// panel, centered, shrunk only if it does not fit.
-static void vpFitInnerHosts(CGRect inner) {
- id primary = vpPrimaryCADisplay();
- CGRect pixels = ((CGRect (*)(id, SEL))objc_msgSend)(primary, sel_registerName("bounds"));
- double pointScale = [[primary valueForKey:@"pointScale"] doubleValue] ?: 1;
- CGSize panel = CGSizeMake(pixels.size.width / pointScale, pixels.size.height / pointScale);
- if (CGSizeEqualToSize(panel, vpInnerHostPanel)) return;
- vpInnerHostPanel = panel;
- id root = vpReadObject(vpInnerHostContext, "layer");
- ((void (*)(id, SEL, CGRect))objc_msgSend)(root, sel_registerName("setFrame:"), (CGRect){CGPointZero, pixels.size});
- ((void (*)(id, SEL, CGRect))objc_msgSend)(vpInnerHostDamage, sel_registerName("setFrame:"), (CGRect){CGPointZero, pixels.size});
- BOOL turned = inner.size.width > inner.size.height;
- CGSize upright = turned ? CGSizeMake(inner.size.height, inner.size.width) : inner.size;
- CGFloat scale = MIN(1, MIN(panel.width / upright.width, panel.height / upright.height));
- CGAffineTransform transform = CGAffineTransformMakeScale(scale * pointScale, scale * pointScale);
- if (turned) transform = CGAffineTransformRotate(transform, -M_PI_2);
- id container = vpInnerHostContainer;
- ((void (*)(id, SEL, CGRect))objc_msgSend)(container, sel_registerName("setBounds:"), (CGRect){CGPointZero, inner.size});
- ((void (*)(id, SEL, CGPoint))objc_msgSend)(container, sel_registerName("setPosition:"), CGPointMake(CGRectGetMidX(pixels), CGRectGetMidY(pixels)));
- ((void (*)(id, SEL, CGAffineTransform))objc_msgSend)(container, sel_registerName("setAffineTransform:"), transform);
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: fitted panel=%@ inner=%@ turned=%d scale=%.3f",
- vpSizeText(panel), vpSizeText(inner.size), turned, scale]);
-}
-
-static void vpSyncInnerHosts(void) {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id innerScene = vpSpringBoardWindowScene(YES);
- if (innerScene)
- vpFitInnerHosts(((CGRect (*)(id, SEL))objc_msgSend)(vpReadObject(innerScene, "coordinateSpace"), sel_registerName("bounds")));
- NSMutableArray *windows = [NSMutableArray array];
- for (id scene in [vpReadObject(app, "connectedScenes") allObjects] ?: @[])
- if ([scene isKindOfClass:objc_getClass("UIWindowScene")] && vpSceneIsOnInnerDisplay(scene))
- for (id window in vpReadObject(scene, "windows") ?: @[])
- if (![[window valueForKey:@"hidden"] boolValue]) [windows addObject:window];
- [windows sortUsingComparator:^NSComparisonResult(id a, id b) {
- return [[a valueForKey:@"windowLevel"] compare:[b valueForKey:@"windowLevel"]];
- }];
- NSMutableSet *live = [NSMutableSet set];
- SEL contextIdSelector = sel_registerName("_contextId");
- for (NSUInteger index = 0; index < windows.count; index++) {
- id window = windows[index];
- if (![window respondsToSelector:contextIdSelector]) continue;
- unsigned int contextId = ((unsigned int (*)(id, SEL))objc_msgSend)(window, contextIdSelector);
- if (!contextId) continue;
- NSNumber *key = @(contextId);
- [live addObject:key];
- id host = vpInnerHostLayers[key];
- if (!host) {
- host = [objc_getClass("CALayerHost") new];
- ((void (*)(id, SEL, unsigned int))objc_msgSend)(host, sel_registerName("setContextId:"), contextId);
- ((void (*)(id, SEL, id))objc_msgSend)(vpInnerHostContainer, sel_registerName("addSublayer:"), host);
- vpInnerHostLayers[key] = host;
- }
- ((void (*)(id, SEL, CGRect))objc_msgSend)(host, sel_registerName("setFrame:"),
- ((CGRect (*)(id, SEL))objc_msgSend)(window, sel_registerName("frame")));
- ((void (*)(id, SEL, double))objc_msgSend)(host, sel_registerName("setZPosition:"), index);
- }
- for (NSNumber *key in vpInnerHostLayers.allKeys) {
- if ([live containsObject:key]) continue;
- ((void (*)(id, SEL))objc_msgSend)(vpInnerHostLayers[key], sel_registerName("removeFromSuperlayer"));
- [vpInnerHostLayers removeObjectForKey:key];
- }
-}
-
-void vpShowInnerDisplay(BOOL shown) {
- @try {
- if (!shown) {
- if (!vpInnerHostContext) return;
- dispatch_source_cancel(vpInnerHostTimer);
- vpInnerHostTimer = nil;
- ((void (*)(id, SEL))objc_msgSend)(vpInnerHostRefresh, sel_registerName("invalidate"));
- vpInnerHostRefresh = nil;
- ((void (*)(id, SEL))objc_msgSend)(vpInnerHostContext, sel_registerName("invalidate"));
- vpInnerHostContext = vpInnerHostContainer = vpInnerHostDamage = nil;
- vpInnerHostLayers = nil;
- vpInnerHostPanel = CGSizeZero;
- vpFoldDisplayLog(@"inner display: shown=0");
- return;
- }
- if (vpInnerHostContext) return;
- id primary = vpPrimaryCADisplay();
- NSString *__unsafe_unretained *displayable = (NSString *__unsafe_unretained *)dlsym(RTLD_DEFAULT, "kCAContextDisplayable");
- NSString *__unsafe_unretained *displayIdKey = (NSString *__unsafe_unretained *)dlsym(RTLD_DEFAULT, "kCAContextDisplayId");
- Method hostContext = class_getInstanceMethod(objc_getClass("CALayerHost"), sel_registerName("setContextId:"));
- Method level = class_getInstanceMethod(objc_getClass("CAContext"), sel_registerName("setLevel:"));
- if (!primary || !displayable || !displayIdKey || !hostContext || !level ||
- strcmp(method_getTypeEncoding(hostContext), "v20@0:8I16") != 0 || strcmp(method_getTypeEncoding(level), "v20@0:8f16") != 0) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: show unavailable primary=%d keys=%d host=%s level=%s",
- primary != nil, displayable && displayIdKey, hostContext ? method_getTypeEncoding(hostContext) : "missing",
- level ? method_getTypeEncoding(level) : "missing"]);
- return;
- }
- id context = ((id (*)(id, SEL, id))objc_msgSend)(objc_getClass("CAContext"), sel_registerName("remoteContextWithOptions:"),
- @{*displayable: @YES, *displayIdKey: [primary valueForKey:@"displayId"]});
- id root = [objc_getClass("CALayer") new];
- ((void (*)(id, SEL, CGColorRef))objc_msgSend)(root, sel_registerName("setBackgroundColor:"),
- ((CGColorRef (*)(id, SEL))objc_msgSend)(vpReadObject(objc_getClass("UIColor"), "blackColor"), sel_registerName("CGColor")));
- id container = [objc_getClass("CALayer") new];
- ((void (*)(id, SEL, id))objc_msgSend)(root, sel_registerName("addSublayer:"), container);
- id damage = [objc_getClass("CALayer") new];
- ((void (*)(id, SEL, id))objc_msgSend)(root, sel_registerName("addSublayer:"), damage);
- vpInnerHostDamage = damage;
- ((void (*)(id, SEL, id))objc_msgSend)(context, sel_registerName("setLayer:"), root);
- ((void (*)(id, SEL, float))objc_msgSend)(context, sel_registerName("setLevel:"), 1.0e9f);
- vpInnerHostContext = context;
- vpInnerHostContainer = container;
- vpInnerHostLayers = [NSMutableDictionary dictionary];
- vpInnerHostPanel = CGSizeZero;
- vpSyncInnerHosts();
- vpInnerHostTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
- dispatch_source_set_timer(vpInnerHostTimer, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 4), NSEC_PER_SEC / 4, NSEC_PER_SEC / 20);
- dispatch_source_set_event_handler(vpInnerHostTimer, ^{ vpSyncInnerHosts(); });
- dispatch_resume(vpInnerHostTimer);
- vpInnerHostRefresh = ((id (*)(id, SEL, id, SEL))objc_msgSend)(objc_getClass("CADisplayLink"),
- sel_registerName("displayLinkWithTarget:selector:"), [VPhoneInnerHostRefresh new], @selector(refresh:));
- ((void (*)(id, SEL, id, id))objc_msgSend)(vpInnerHostRefresh, sel_registerName("addToRunLoop:forMode:"),
- NSRunLoop.mainRunLoop, NSRunLoopCommonModes);
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: shown=1 context=%@ hosts=%lu",
- [context valueForKey:@"contextId"], (unsigned long)vpInnerHostLayers.count]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: show exception %@", exception.reason]);
- }
-}
-
-// 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, so the hinge could not move content to it. Hands it
-// over once the scene and the resolver both exist (the resolver keys its
-// display proxies by hardware identifier, so this runs once per
-// SpringBoard), and reports whether the inner display is resolved.
-static BOOL vpHandOverInnerDisplay(void) {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id coordinator = vpReadObject(app, "displayContentModeCoordinator");
- id innerScene = vpSpringBoardWindowScene(YES);
- id resolver = vpLogicalRoleResolver;
- Method connect = class_getInstanceMethod(object_getClass(coordinator), sel_registerName("windowSceneDidConnect:"));
- if (!coordinator || !innerScene || !resolver || !connect || strcmp(method_getTypeEncoding(connect), "v24@0:8@16") != 0)
- return NO;
- id identifier = vpReadObject(vpReadObject(vpReadObject(vpReadObject(innerScene, "_FBSScene"), "settings"),
- "displayConfiguration"), "hardwareIdentifier");
- if ([[vpReadObjectIvar(resolver, "_displayProxies") allKeys] containsObject:identifier]) return YES;
- ((void (*)(id, SEL, id))objc_msgSend)(coordinator, sel_registerName("windowSceneDidConnect:"), innerScene);
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: handed %@ to the content mode resolver: %@",
- vpReadObject(vpReadObject(innerScene, "_FBSScene"), "identifier"), resolver]);
- return [[vpReadObjectIvar(resolver, "_displayProxies") allKeys] containsObject:identifier];
-}
-
-void vpResolveInnerDisplay(void) {
- @try {
- if (!vpHandOverInnerDisplay()) vpFoldDisplayLog(@"inner display: resolve not ready");
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: resolve exception %@", exception.reason]);
- }
-}
-
-// From SpringBoard's start, until the inner display is resolved.
-static void vpWatchInnerDisplayResolution(void) {
- static dispatch_source_t timer;
- static unsigned int attempts;
- timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
- dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), NSEC_PER_SEC, NSEC_PER_SEC / 10);
- dispatch_source_set_event_handler(timer, ^{
- BOOL resolved = NO;
- @try { resolved = vpHandOverInnerDisplay(); } @catch (__unused NSException *exception) {}
- if (resolved || ++attempts >= 600) {
- dispatch_source_cancel(timer);
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: resolution watch done resolved=%d after %u s", resolved, attempts]);
- }
- });
- dispatch_resume(timer);
-}
-
-// MARK: - Stage 1 test pattern
-
-// A window on the inner display's scene with a clock that changes every
-// second, so a frame reaching the panel can be told from a stale one, and a
-// tap count, so a touch reaching the inner display can be told too.
-static id vpInnerPatternWindow;
-static dispatch_source_t vpInnerPatternTimer;
-static unsigned int vpInnerPatternTaps;
-
-@interface VPhoneInnerPatternTapTarget : NSObject
-@end
-
-@implementation VPhoneInnerPatternTapTarget
-- (void)tapped:(id)recognizer {
- vpInnerPatternTaps++;
- CGPoint point = ((CGPoint (*)(id, SEL, id))objc_msgSend)(recognizer, sel_registerName("locationInView:"), nil);
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: pattern tap %u at {%.1f, %.1f}", vpInnerPatternTaps, point.x, point.y]);
-}
-@end
-
-static VPhoneInnerPatternTapTarget *vpInnerPatternTapTarget;
-
-void vpToggleInnerPattern(void) {
- @try {
- if (vpInnerPatternWindow) {
- dispatch_source_cancel(vpInnerPatternTimer);
- vpInnerPatternTimer = nil;
- ((void (*)(id, SEL, BOOL))objc_msgSend)(vpInnerPatternWindow, sel_registerName("setHidden:"), YES);
- vpInnerPatternWindow = nil;
- vpFoldDisplayLog(@"inner display: pattern removed");
- return;
- }
- id innerScene = vpSpringBoardWindowScene(YES);
- if (!innerScene) { vpFoldDisplayLog(@"inner display: pattern has no inner window scene"); return; }
- CGRect bounds = ((CGRect (*)(id, SEL))objc_msgSend)(vpReadObject(innerScene, "coordinateSpace"), sel_registerName("bounds"));
- id window = ((id (*)(id, SEL, id))objc_msgSend)([objc_getClass("UIWindow") alloc],
- sel_registerName("initWithWindowScene:"), innerScene);
- ((void (*)(id, SEL, CGRect))objc_msgSend)(window, sel_registerName("setFrame:"), bounds);
- ((void (*)(id, SEL, double))objc_msgSend)(window, sel_registerName("setWindowLevel:"), 10000000.0);
- ((void (*)(id, SEL, id))objc_msgSend)(window, sel_registerName("setBackgroundColor:"),
- vpReadObject(objc_getClass("UIColor"), "systemTealColor"));
- id label = ((id (*)(id, SEL, CGRect))objc_msgSend)([objc_getClass("UILabel") alloc],
- sel_registerName("initWithFrame:"), CGRectInset(bounds, 40, 40));
- ((void (*)(id, SEL, long long))objc_msgSend)(label, sel_registerName("setNumberOfLines:"), 0);
- ((void (*)(id, SEL, long long))objc_msgSend)(label, sel_registerName("setTextAlignment:"), 1);
- ((void (*)(id, SEL, id))objc_msgSend)(label, sel_registerName("setFont:"),
- ((id (*)(id, SEL, double))objc_msgSend)(objc_getClass("UIFont"), sel_registerName("boldSystemFontOfSize:"), 64));
- ((void (*)(id, SEL, id))objc_msgSend)(window, sel_registerName("addSubview:"), label);
- vpInnerPatternTapTarget = vpInnerPatternTapTarget ?: [VPhoneInnerPatternTapTarget new];
- id tap = ((id (*)(id, SEL, id, SEL))objc_msgSend)([objc_getClass("UITapGestureRecognizer") alloc],
- sel_registerName("initWithTarget:action:"), vpInnerPatternTapTarget, @selector(tapped:));
- ((void (*)(id, SEL, id))objc_msgSend)(window, sel_registerName("addGestureRecognizer:"), tap);
- ((void (*)(id, SEL, BOOL))objc_msgSend)(window, sel_registerName("setHidden:"), NO);
- vpInnerPatternWindow = window;
- NSString *size = [NSString stringWithFormat:@"%.0fx%.0f", bounds.size.width, bounds.size.height];
- vpInnerPatternTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
- dispatch_source_set_timer(vpInnerPatternTimer, DISPATCH_TIME_NOW, NSEC_PER_SEC, NSEC_PER_SEC / 10);
- dispatch_source_set_event_handler(vpInnerPatternTimer, ^{
- NSString *time = [NSDateFormatter localizedStringFromDate:NSDate.date dateStyle:NSDateFormatterNoStyle
- timeStyle:NSDateFormatterMediumStyle];
- ((void (*)(id, SEL, id))objc_msgSend)(label, sel_registerName("setText:"),
- [NSString stringWithFormat:@"INNER %@\n%@\ntaps %u", size, time, vpInnerPatternTaps]);
- });
- dispatch_resume(vpInnerPatternTimer);
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: pattern on %@ bounds=%@",
- vpReadObject(vpReadObject(innerScene, "_FBSScene"), "identifier"), size]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: pattern exception %@", exception.reason]);
- }
-}
-
-// MARK: - Stage 0 report
-
-// The spike's pass criteria, read live: the always-connected identities,
-// the window scenes and their displays, and PosterKit's own rotation answer
-// for each display's configuration.
-void vpInspectInnerDisplay(void) {
- @try {
- // The render displays as this process sees them, through the adapter.
- for (id display in vpReadObject(objc_getClass("CADisplay"), "displays") ?: @[]) {
- NSMutableString *line = [NSMutableString stringWithString:@"inner display: CADisplay"];
- for (NSString *key in @[@"name", @"deviceName", @"displayId", @"displayType", @"tag", @"pointScale", @"isExternal", @"bounds"]) {
- id value = nil;
- @try { value = [display valueForKey:key]; } @catch (__unused NSException *exception) {}
- [line appendFormat:@" %@=%@", key, value];
- }
- [line appendFormat:@" modes=%lu", (unsigned long)[vpReadObject(display, "availableModes") count]];
- // backboardd's traits for the panel. Its surfaceType comes from
- // DeviceSurfaceType in the display's extendedProperties, which
- // FoldDisplaySurfaceProbe.m supplies on this guest.
- id service = vpReadObject(objc_getClass("BKSDisplayService"), "sharedInstance");
- SEL traitsSelector = sel_registerName("traitsForDisplayUUID:");
- id uuid = vpReadObject(display, "uniqueId");
- if (uuid && [service respondsToSelector:traitsSelector])
- [line appendFormat:@" traits=%@", ((id (*)(id, SEL, id))objc_msgSend)(service, traitsSelector, uuid)];
- vpFoldDisplayLog(line);
- }
- Class manager = objc_getClass("FBDisplayManager");
- id instance = vpReadObject(manager, "sharedInstance");
- for (NSString *key in @[@"connectedIdentities", @"alwaysConnectedIdentities"]) {
- id value = nil;
- @try { value = [instance valueForKey:key]; } @catch (__unused NSException *exception) {}
- if (!value && [manager respondsToSelector:NSSelectorFromString(key)]) value = [manager valueForKey:key];
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: %@ = %@", key, value]);
- }
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- BOOL (*supports)(id, id, NSInteger) = dlsym(RTLD_DEFAULT, "PFContextSupportsDynamicRotation");
- id (*displayType)(id) = dlsym(RTLD_DEFAULT, "PRDisplayTypeFromFBSDisplayConfiguration");
- NSInteger (*deviceClass)(void) = dlsym(RTLD_DEFAULT, "PFCurrentDeviceClass");
- id __unsafe_unretained *lockRole = (id __unsafe_unretained *)dlsym(RTLD_DEFAULT, "PFPosterRoleLockScreen");
- // PosterKit's class 1 is iPad; an iPhone (MG DeviceClassNumber 1)
- // is class 0, where only an auxiliary display rotates its poster.
- if (deviceClass && supports && lockRole && *lockRole)
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: PFCurrentDeviceClass=%ld embedded-as-class-1=%d",
- (long)deviceClass(), supports(*lockRole, @"DISPLAY_TYPE_EMBEDDED", 1)]);
- // Each scene's status bar windows (frame, provider, the status bar's
- // own frame) and its screen's inputs to the native provider lookup.
- for (id scene in [vpReadObject(app, "connectedScenes") allObjects] ?: @[]) {
- id screen = vpReadObject(scene, "screen");
- NSMutableString *line = [NSMutableString stringWithFormat:@"inner display: screen of %@",
- vpReadObject(vpReadObject(scene, "_FBSScene"), "identifier")];
- for (NSString *key in @[@"_nativeDisplayBounds", @"_exclusionArea", @"_displayCornerRadius", @"_referenceBounds"]) {
- id value = nil;
- @try { value = [screen valueForKey:key]; } @catch (__unused NSException *exception) { value = @"-"; }
- [line appendFormat:@" %@=%@", key, value];
- }
- for (id window in vpReadObject(scene, "windows") ?: @[]) {
- if (![NSStringFromClass([window class]) containsString:@"StatusBar"]) continue;
- id statusBar = nil;
- NSMutableArray *pending = [NSMutableArray arrayWithObject:window];
- while (pending.count && !statusBar) {
- id view = pending.lastObject;
- [pending removeLastObject];
- if ([view isKindOfClass:objc_getClass("STUIStatusBar")]) statusBar = view;
- else [pending addObjectsFromArray:[view valueForKey:@"subviews"] ?: @[]];
- }
- CGRect bounds = statusBar ? ((CGRect (*)(id, SEL))objc_msgSend)(statusBar, sel_registerName("bounds")) : CGRectZero;
- id hit = statusBar ? ((id (*)(id, SEL, CGPoint, id))objc_msgSend)(statusBar, sel_registerName("hitTest:withEvent:"),
- CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)), nil) : nil;
- [line appendFormat:@" | %@ frame=%@ STUIStatusBar=%@ provider=%@ middleHit=%@", NSStringFromClass([window class]),
- [window valueForKey:@"frame"], statusBar ? [statusBar valueForKey:@"frame"] : @"-",
- statusBar ? [statusBar valueForKey:@"_visualProviderClassName"] : @"-", NSStringFromClass([hit class])];
- }
- vpFoldDisplayLog(line);
- }
- for (id scene in [vpReadObject(app, "connectedScenes") allObjects] ?: @[]) {
- id configuration = nil;
- @try { configuration = vpReadObject(vpReadObject(scene, "_FBSScene"), "settings"); configuration = vpReadObject(configuration, "displayConfiguration"); }
- @catch (__unused NSException *exception) {}
- id type = configuration && displayType ? displayType(configuration) : nil;
- BOOL rotates = type && supports && deviceClass && lockRole && *lockRole ? supports(*lockRole, type, deviceClass()) : NO;
- 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=%@ idiom=%@ screenIdiom=%@%@",
- NSStringFromClass([scene class]), vpReadObject(vpReadObject(scene, "_FBSScene"), "identifier"),
- vpReadObject(configuration, "identity"), [configuration valueForKey:@"bounds"], type, rotates, surface,
- NSStringFromClass([vpReadObject(scene, "delegate") class]),
- [vpReadObject(scene, "traitCollection") valueForKey:@"userInterfaceIdiom"],
- [vpReadObject(vpReadObject(scene, "screen"), "traitCollection") valueForKey:@"userInterfaceIdiom"], roles]);
- }
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner display: inspect exception %@", exception.reason]);
- }
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerTouch.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerTouch.m
deleted file mode 100644
index e7ae25a0..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayInnerTouch.m
+++ /dev/null
@@ -1,66 +0,0 @@
-// Spike: touches on the inner display reach its windows.
-//
-// backboardd routes the digitizer to the inner display while it is lit and
-// its hit test names the inner window (FoldDisplayInnerDisplay.m). SpringBoard
-// then sends the touch to a _UISystemGestureWindow first, and when that
-// releases it, UIKit looks for the touch's window with
-// -[UIWindow _targetWindowForPathIndex:atPoint:scenePointZ:forEvent:windowServerHitTestWindow:]:
-// it hit-tests the point against the visible windows of the hit window's
-// scene (+[UIWindow _hitTestToPoint:scenePointZ:forEvent:windowServerHitTestWindow:]).
-// The answer was nil ("Unexpected nil window in latent system gesture client
-// update", "to windows: 0"): the point is in the receiving window's space, a
-// window of Main, and the inner scene's space is a different screen's.
-//
-// The compositor shows the inner scene's points one to one on the panel, so
-// a point on Main's fixed coordinate space is the same point in the inner
-// scene. When the native answer is nil for a hit window on the inner display,
-// the point is taken through Main's fixed space and hit-tested again.
-
-#import "FoldDisplayPrivate.h"
-
-static IMP vpOriginalTargetWindow;
-static unsigned int vpTouchLogCount;
-
-static BOOL vpWindowIsOnInnerDisplay(id window) {
- id scene = vpReadObject(window, "windowScene");
- id configuration = vpReadObject(vpReadObject(vpReadObject(scene, "_FBSScene"), "settings"), "displayConfiguration");
- id identity = vpReadObject(configuration, "identity");
- return identity && ![[identity description] isEqual:@"Main"];
-}
-
-static id vpInnerTargetWindow(id self, SEL selector, NSInteger pathIndex, CGPoint point, double z, id event, id hitWindow) {
- id target = ((id (*)(id, SEL, NSInteger, CGPoint, double, id, id))vpOriginalTargetWindow)(self, selector, pathIndex, point, z, event, hitWindow);
- if (target || !hitWindow || !vpWindowIsOnInnerDisplay(hitWindow)) return target;
- @try {
- id fixed = vpReadObject(vpReadObject(self, "screen"), "fixedCoordinateSpace");
- CGPoint mapped = fixed ? ((CGPoint (*)(id, SEL, CGPoint, id))objc_msgSend)(self,
- sel_registerName("convertPoint:toCoordinateSpace:"), point, fixed) : point;
- target = ((id (*)(id, SEL, CGPoint, double, id, id))objc_msgSend)(objc_getClass("UIWindow"),
- sel_registerName("_hitTestToPoint:scenePointZ:forEvent:windowServerHitTestWindow:"), mapped, z, event, hitWindow);
- if (vpTouchLogCount++ < 24)
- vpFoldDisplayLog([NSString stringWithFormat:@"inner touch: receiver %@ point {%.1f, %.1f} -> {%.1f, %.1f} hit %@ -> %@",
- NSStringFromClass([self class]), point.x, point.y, mapped.x, mapped.y,
- NSStringFromClass([hitWindow class]), target ? NSStringFromClass([target class]) : @"nil"]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner touch: exception %@", exception.reason]);
- }
- return target;
-}
-
-void vpInstallInnerTouch(void) {
- if (!vpInnerDisplayRequested()) return;
- Method target = class_getInstanceMethod(objc_getClass("UIWindow"),
- sel_registerName("_targetWindowForPathIndex:atPoint:scenePointZ:forEvent:windowServerHitTestWindow:"));
- Method hitTest = class_getClassMethod(objc_getClass("UIWindow"),
- sel_registerName("_hitTestToPoint:scenePointZ:forEvent:windowServerHitTestWindow:"));
- const char *targetEncoding = target ? method_getTypeEncoding(target) : "missing";
- const char *hitTestEncoding = hitTest ? method_getTypeEncoding(hitTest) : "missing";
- if (strcmp(targetEncoding, "@64@0:8q16{CGPoint=dd}24d40@48@56") != 0 ||
- strcmp(hitTestEncoding, "@56@0:8{CGPoint=dd}16d32@40@48") != 0) {
- vpFoldDisplayLog([NSString stringWithFormat:@"inner touch: target window ABI unavailable (%s, %s)",
- targetEncoding, hitTestEncoding]);
- return;
- }
- vpOriginalTargetWindow = method_setImplementation(target, (IMP)vpInnerTargetWindow);
- vpFoldDisplayLog(@"inner touch: target window adapter installed");
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayOrientation.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayOrientation.m
deleted file mode 100644
index d1c8d4fe..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayOrientation.m
+++ /dev/null
@@ -1,575 +0,0 @@
-// Interface orientation: root scene orientation, arbitration and actuation
-// refresh, scene geometry requests, and the backboardd and embedded
-// orientation probes.
-
-#import "FoldDisplayPrivate.h"
-
-static NSMutableDictionary<NSString *, NSDictionary *> *vpSavedSceneOrientations;
-static atomic_uint vpSceneOrientationPulseGeneration;
-static __weak id vpGeometryRequestScene;
-static NSInteger vpGeometryRequestOriginal;
-static NSInteger vpGeometryRequestTarget;
-static atomic_uint vpGeometryRequestGeneration;
-static __weak id vpOrientationEventsManager;
-static BOOL vpOriginalOrientationEventsEnabled;
-static atomic_uint vpOrientationEventsGeneration;
-static IMP vpOriginalTollFreeOrientationConversion;
-static __weak id vpCanonicalOrientationScene;
-static atomic_uint vpCanonicalOrientationGeneration;
-static __weak id vpEmbeddedOrientationApplication;
-static __weak id vpEmbeddedOrientationScene;
-static NSInteger vpEmbeddedOrientationOriginal, vpEmbeddedOrientationPublished;
-static atomic_uint vpEmbeddedOrientationGeneration;
-
-@protocol VPhoneGeometryPreferencesInitializing
-- (instancetype)initWithInterfaceOrientations:(NSUInteger)orientations;
-@end
-
-// MARK: - root scene orientation
-
-void vpProbeUnknownDisplayPolicy(BOOL restore) {
- static BOOL saved = NO, original = NO;
- @try {
- id monitor = vpReadObject(objc_getClass("FBDisplayManager"), "sharedInstance");
- SEL getter = sel_registerName("allowsUnknownDisplays");
- SEL setter = sel_registerName("setAllowsUnknownDisplays:");
- Method method = class_getInstanceMethod(object_getClass(monitor), setter);
- if (![monitor respondsToSelector:getter] || !method ||
- strcmp(method_getTypeEncoding(method), "v20@0:8B16") != 0) {
- vpFoldDisplayLog(@"unknown display policy: unavailable");
- return;
- }
- if (!saved) {
- original = ((BOOL (*)(id, SEL))objc_msgSend)(monitor, getter);
- saved = YES;
- }
- ((void (*)(id, SEL, BOOL))objc_msgSend)(monitor, setter, restore ? original : YES);
- BOOL actual = ((BOOL (*)(id, SEL))objc_msgSend)(monitor, getter);
- vpFoldDisplayLog([NSString stringWithFormat:@"unknown display policy: original=%d actual=%d restore=%d",
- original, actual, restore]);
- vpSnapshotMainScene();
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"unknown display policy exception: %@", exception.reason]);
- }
-}
-
-static void vpSetRootSceneOrientation(id scene, NSInteger orientation, NSNumber *expected, unsigned int generation) {
- SEL update = sel_registerName("updateUISettingsWithBlock:");
- Method method = class_getInstanceMethod(object_getClass(scene), update);
- if (!method || strcmp(method_getTypeEncoding(method), "v24@0:8@?16") != 0) {
- vpFoldDisplayLog(@"root orientation: settings-update ABI unavailable"); return;
- }
- ((void (*)(id, SEL, id))objc_msgSend)(scene, update, ^(id settings) {
- @try {
- if (generation != atomic_load_explicit(&vpSceneOrientationPulseGeneration, memory_order_acquire) ||
- ![[settings valueForKey:@"interfaceOrientation"] isEqual:expected]) return;
- SEL setter = sel_registerName("setInterfaceOrientation:");
- NSMethodSignature *signature = [settings methodSignatureForSelector:setter];
- if (!signature || signature.numberOfArguments != 3 || signature.methodReturnType[0] != 'v' ||
- strcmp([signature getArgumentTypeAtIndex:2], "q") != 0) return;
- ((void (*)(id, SEL, NSInteger))objc_msgSend)(settings, setter, orientation);
- vpFoldDisplayLog([NSString stringWithFormat:@"root orientation: %@ submitted=%ld frame=%@ generation=%u",
- vpReadObject(scene, "identifier"), (long)orientation, vpReadRectValue(settings, "frame"), generation]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"root orientation transaction exception: %@", exception.reason]);
- }
- });
-}
-
-static void vpRestoreRootSceneOrientationsAttempt(unsigned int generation, unsigned int attempt) {
- if (generation != atomic_load_explicit(&vpSceneOrientationPulseGeneration, memory_order_acquire) ||
- !vpSavedSceneOrientations.count) return;
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- NSMutableSet *present = [NSMutableSet set];
- for (id scene in vpRootServerScenes(app)) {
- @try {
- NSString *identifier = vpReadObject(scene, "identifier");
- NSDictionary *saved = vpSavedSceneOrientations[identifier];
- if (!saved) continue;
- [present addObject:identifier];
- // A reconstructed scene with the same identifier owns new state.
- // Never replay an old instance's saved orientation into it.
- if ([saved[@"scope"] anyObject] != scene) {
- [vpSavedSceneOrientations removeObjectForKey:identifier];
- vpFoldDisplayLog(@"root orientation: old scene scope ended");
- continue;
- }
- NSNumber *current = [vpReadObject(scene, "uiSettings") valueForKey:@"interfaceOrientation"];
- if (![current isKindOfClass:NSNumber.class]) continue;
- if ([current isEqual:saved[@"original"]] || ![current isEqual:saved[@"published"]]) {
- [vpSavedSceneOrientations removeObjectForKey:identifier];
- vpFoldDisplayLog([NSString stringWithFormat:@"root orientation: %@ %@",
- identifier, [current isEqual:saved[@"original"]] ? @"restoration verified" : @"newer setting preserved"]);
- continue;
- }
- vpSetRootSceneOrientation(scene, [saved[@"original"] integerValue], saved[@"published"], generation);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"root orientation restore exception: %@", exception.reason]);
- }
- }
- for (NSString *identifier in [vpSavedSceneOrientations.allKeys copy]) {
- // A temporary profile lookup miss is not proof of scene removal.
- // Keep a live scene's checkpoint for retry; only a cleared weak
- // reference establishes that the original scope has ended.
- if (![present containsObject:identifier] && ![vpSavedSceneOrientations[identifier][@"scope"] anyObject]) {
- [vpSavedSceneOrientations removeObjectForKey:identifier];
- vpFoldDisplayLog([NSString stringWithFormat:@"root orientation: %@ scene removed", identifier]);
- }
- }
- if (vpSavedSceneOrientations.count && attempt < 3) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- vpRestoreRootSceneOrientationsAttempt(generation, attempt + 1);
- });
- } else if (vpSavedSceneOrientations.count) {
- // Keep the checkpoint for an explicit restore retry; submission is
- // not readback proof and must not discard failed cleanup state.
- vpFoldDisplayLog([NSString stringWithFormat:@"root orientation: restoration pending for %lu scene(s)",
- (unsigned long)vpSavedSceneOrientations.count]);
- }
-}
-
-void vpRestoreRootSceneOrientations(void) {
- // Cancel delayed publication blocks before starting restoration.
- unsigned int generation = atomic_fetch_add_explicit(&vpSceneOrientationPulseGeneration, 1, memory_order_acq_rel) + 1;
- vpRestoreRootSceneOrientationsAttempt(generation, 0);
-}
-
-// Default-off pulse: publish the existing native arbitration result through
-// the common root scene contract. No window transform/frame or app mask is
-// supplied. Restoration starts after ten seconds and keeps a checkpoint
-// until readback proves restoration or a newer setting supersedes it.
-void vpSyncRootSceneOrientation(void) {
- @try {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id windowScene = vpMainInnerWindowScene();
- if (!windowScene) {
- vpFoldDisplayLog(@"root orientation: pulse refused outside the real Main inner scene");
- return;
- }
- id pipeline = vpReadObject(windowScene, "traitsPipelineManager");
- NSInteger orientation = [[pipeline valueForKey:@"systemArbitratedInterfaceOrientation"] integerValue];
- if (orientation < 1 || orientation > 4) return;
- NSString *identifier = vpReadObject(vpReadObject(windowScene, "_FBSScene"), "identifier");
- if (!identifier) return;
- if (!vpSavedSceneOrientations) vpSavedSceneOrientations = [NSMutableDictionary dictionary];
- unsigned int generation = atomic_fetch_add_explicit(&vpSceneOrientationPulseGeneration, 1, memory_order_acq_rel) + 1;
- for (id scene in vpRootServerScenes(app)) {
- if (![vpReadObject(scene, "identifier") isEqual:identifier]) continue;
- id settings = vpReadObject(scene, "uiSettings");
- id uiIdentity = vpReadObject(windowScene, "_fbsDisplayIdentity") ?: vpReadObject(windowScene, "displayIdentity");
- if (![vpReadObject(vpReadObject(settings, "sb_hostedDisplayConfiguration"), "identity") isEqual:uiIdentity]) continue;
- NSNumber *previous = [settings valueForKey:@"interfaceOrientation"];
- if (![previous isKindOfClass:NSNumber.class] || previous.integerValue < 1 || previous.integerValue > 4) continue;
- if (previous.integerValue == orientation) {
- vpFoldDisplayLog(@"root orientation: scene settings already match native arbitration");
- continue;
- }
- NSDictionary *saved = vpSavedSceneOrientations[identifier];
- BOOL sameScope = [saved[@"scope"] anyObject] == scene;
- NSHashTable *scope = sameScope ? saved[@"scope"] : [NSHashTable weakObjectsHashTable];
- if (!sameScope) [scope addObject:scene];
- vpSavedSceneOrientations[identifier] = @{
- @"original": sameScope ? saved[@"original"] : previous,
- @"published": @(orientation), @"scope": scope,
- };
- vpFoldDisplayLog([NSString stringWithFormat:@"root orientation: pulse %@ previous=%@ native=%ld",
- identifier, previous, (long)orientation]);
- vpSetRootSceneOrientation(scene, orientation, previous, generation);
- }
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- if (generation == atomic_load_explicit(&vpSceneOrientationPulseGeneration, memory_order_acquire))
- vpRestoreRootSceneOrientations();
- });
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"root orientation pulse exception: %@", exception.reason]);
- }
-}
-
-// MARK: - arbitration scene
-
-id vpMainInnerWindowScene(void) {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id scene = vpReadObject(app, "activeDisplayWindowScene") ?: vpUIConfigWindowScene;
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- id identity = vpReadObject(configuration, "identity");
- id uiIdentity = vpReadObject(scene, "_fbsDisplayIdentity") ?: vpReadObject(scene, "displayIdentity");
- BOOL realMain = [uiIdentity isEqual:identity];
- // The only accepted alias is our currently leased UI identity, parented
- // by the unchanged real Main. Do not admit arbitrary external scenes.
- BOOL ownedAlias = scene == vpUIConfigWindowScene && vpUIConfigPublished &&
- [uiIdentity isEqual:vpReadObject(vpUIConfigPublished, "identity")] &&
- [vpReadObject(uiIdentity, "rootIdentity") isEqual:identity] &&
- vpReadObject(vpUIConfigPublished, "CADisplay") == vpReadObject(configuration, "CADisplay");
- if (![[scene valueForKey:@"surfaceType"] isEqual:@2] ||
- !(realMain || ownedAlias) ||
- ![[identity valueForKey:@"isMainRootDisplay"] boolValue]) return nil;
- return scene;
-}
-
-// The orientation machinery must also run while the persistent viewport
-// holds the cover mode: the active scene is the same SB-main scene under
-// the cover identity, and a fold transition must not strand the interface
-// at the direction the mode swap computed with the previous panel's pose
-// (observed: closed computed landscape from the inner portrait pose and
-// nothing re-arbitrated it). Accept the active scene only while the
-// persistent viewport is live and it carries the current Main identity.
-id vpOrientationArbitrationScene(void) {
- id inner = vpMainInnerWindowScene();
- if (inner) return inner;
- if (!vpPersistentViewport) return nil;
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id scene = vpReadObject(app, "activeDisplayWindowScene");
- if (!scene) return nil;
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- id identity = vpReadObject(configuration, "identity");
- id uiIdentity = vpReadObject(scene, "_fbsDisplayIdentity") ?: vpReadObject(scene, "displayIdentity");
- if (!identity || ![uiIdentity isEqual:identity]) return nil;
- return scene;
-}
-
-// MARK: - scene geometry requests
-
-static void vpRequestSceneGeometry(id scene, NSInteger orientation) {
- @try {
- if (!scene || orientation < 1 || orientation > 4) return;
- Class preferencesClass = objc_getClass("UIWindowSceneGeometryPreferencesIOS");
- SEL initializer = sel_registerName("initWithInterfaceOrientations:");
- SEL request = sel_registerName("requestGeometryUpdateWithPreferences:errorHandler:");
- Method initMethod = class_getInstanceMethod(preferencesClass, initializer);
- Method requestMethod = class_getInstanceMethod(object_getClass(scene), request);
- if (!initMethod || strcmp(method_getTypeEncoding(initMethod), "@24@0:8Q16") != 0 ||
- !requestMethod || strcmp(method_getTypeEncoding(requestMethod), "v32@0:8@16@?24") != 0) {
- vpFoldDisplayLog(@"scene geometry request: native API ABI unavailable");
- return;
- }
- // Public iOS geometry API, verified against the local iOS 27.1 SDK.
- // UIKit chooses from supported orientations; this does not change
- // any application's mask or directly rotate a window/layer.
- id preferences = [(id<VPhoneGeometryPreferencesInitializing>)[preferencesClass alloc]
- initWithInterfaceOrientations:1UL << orientation];
- ((void (*)(id, SEL, id, id))objc_msgSend)(scene, request, preferences, ^(NSError *error) {
- vpFoldDisplayLog([NSString stringWithFormat:@"scene geometry request: error %@/%ld %@",
- error.domain, (long)error.code, error.localizedDescription]);
- });
- vpFoldDisplayLog([NSString stringWithFormat:@"scene geometry request: submitted orientation=%ld", (long)orientation]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"scene geometry request exception: %@", exception.reason]);
- }
-}
-
-void vpRestoreSceneGeometryRequest(void) {
- atomic_fetch_add_explicit(&vpGeometryRequestGeneration, 1, memory_order_acq_rel);
- id scene = vpGeometryRequestScene;
- vpGeometryRequestScene = nil;
- if (!scene || scene != vpMainInnerWindowScene()) return;
- NSInteger current = [[scene valueForKey:@"interfaceOrientation"] integerValue];
- if (current == vpGeometryRequestTarget || current == vpGeometryRequestOriginal)
- vpRequestSceneGeometry(scene, vpGeometryRequestOriginal);
- else vpFoldDisplayLog(@"scene geometry request: newer direction preserved");
-}
-
-void vpProbeSceneGeometryRequest(void) {
- @try {
- id scene = vpMainInnerWindowScene();
- if (!scene) { vpFoldDisplayLog(@"scene geometry request: refused outside Main inner"); return; }
- vpRestoreSceneGeometryRequest();
- NSInteger original = [[scene valueForKey:@"interfaceOrientation"] integerValue];
- NSInteger target = [[vpReadObject(scene, "traitsPipelineManager") valueForKey:@"systemArbitratedInterfaceOrientation"] integerValue];
- if (original < 1 || original > 4 || target < 1 || target > 4) return;
- vpGeometryRequestScene = scene;
- vpGeometryRequestOriginal = original;
- vpGeometryRequestTarget = target;
- unsigned int generation = atomic_fetch_add_explicit(&vpGeometryRequestGeneration, 1, memory_order_acq_rel) + 1;
- vpRequestSceneGeometry(scene, target);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- if (generation == atomic_load_explicit(&vpGeometryRequestGeneration, memory_order_acquire))
- vpRestoreSceneGeometryRequest();
- });
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"scene geometry probe exception: %@", exception.reason]);
- }
-}
-
-// MARK: - native inputs, arbitration and actuation
-
-void vpRefreshNativeOrientationInputs(BOOL rereadPose) {
- @try {
- id scene = vpOrientationArbitrationScene();
- if (!scene) { vpFoldDisplayLog(@"orientation refresh: refused outside Main inner"); return; }
- id pipeline = vpReadObject(scene, "traitsPipelineManager");
- SEL selector = sel_registerName(rereadPose ? "_updateDeviceOrientationAnimated:forReason:" : "_noteInputsNeedUpdateAnimated:reason:");
- Method method = class_getInstanceMethod(object_getClass(pipeline), selector);
- if (!method || strcmp(method_getTypeEncoding(method), "v28@0:8B16@20") != 0) {
- vpFoldDisplayLog(@"orientation refresh: native API ABI unavailable");
- return;
- }
- ((void (*)(id, SEL, BOOL, id))objc_msgSend)(pipeline, selector, NO, @"vphone settled pose/input refresh");
- vpFoldDisplayLog([NSString stringWithFormat:@"orientation refresh: native %@ requested", rereadPose ? @"pose" : @"inputs"]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"orientation refresh exception: %@", exception.reason]);
- }
-}
-
-void vpForceNativeOrientationResolution(void) {
- @try {
- id scene = vpOrientationArbitrationScene();
- if (!scene) { vpFoldDisplayLog(@"orientation arbitration: refused outside Main inner"); return; }
- id arbiter = vpReadObject(scene, "traitsArbiter");
- SEL factory = sel_registerName("_defaultUpdateContextWithReason:animatable:");
- SEL mark = sel_registerName("setNeedsUpdateArbitrationWithContext:");
- SEL update = sel_registerName("updateArbitrationIfNeeded");
- Method fm = class_getInstanceMethod(object_getClass(arbiter), factory);
- Method mm = class_getInstanceMethod(object_getClass(arbiter), mark);
- Method um = class_getInstanceMethod(object_getClass(arbiter), update);
- if (!fm || strcmp(method_getTypeEncoding(fm), "@28@0:8@16B24") != 0 ||
- !mm || strcmp(method_getTypeEncoding(mm), "v24@0:8@16") != 0 ||
- !um || strcmp(method_getTypeEncoding(um), "v16@0:8") != 0) {
- vpFoldDisplayLog(@"orientation arbitration: native context API unavailable"); return;
- }
- id context = ((id (*)(id, SEL, id, BOOL))objc_msgSend)(arbiter, factory, @"vphone coherent orientation resolution", NO);
- SEL force = sel_registerName("setForceOrientationResolution:");
- Method forceMethod = class_getInstanceMethod(object_getClass(context), force);
- if (!forceMethod || strcmp(method_getTypeEncoding(forceMethod), "v20@0:8B16") != 0) return;
- ((void (*)(id, SEL, BOOL))objc_msgSend)(context, force, YES);
- ((void (*)(id, SEL, id))objc_msgSend)(arbiter, mark, context);
- ((void (*)(id, SEL))objc_msgSend)(arbiter, update);
- vpFoldDisplayLog(@"orientation arbitration: native force-resolution context submitted");
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"orientation arbitration exception: %@", exception.reason]);
- }
-}
-
-// Real inner panels use a rotated mounting convention. The single Main VM
-// retains the portrait framebuffer. Use the native paired conversion branch
-// for one explicitly scoped experiment; never write individual window angles.
-static BOOL vpCanonicalOrientationConversion(id self, SEL selector) {
- if (self == vpCanonicalOrientationScene && [[self valueForKey:@"surfaceType"] isEqual:@2]) return YES;
- return ((BOOL (*)(id, SEL))vpOriginalTollFreeOrientationConversion)(self, selector);
-}
-
-void vpSetCanonicalOrientationProbe(BOOL enabled) {
- @try {
- id scene = enabled ? vpMainInnerWindowScene() : vpCanonicalOrientationScene;
- if (enabled && !scene) { vpFoldDisplayLog(@"canonical orientation: refused outside Main inner"); return; }
- if (enabled) {
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- if (![vpSnapshotRect(configuration, "bounds") isEqual:@[@0, @0, @678, @951]]) {
- vpFoldDisplayLog(@"canonical orientation: refused unexpected panel bounds"); return;
- }
- if (!vpOriginalTollFreeOrientationConversion) {
- Method method = class_getInstanceMethod(object_getClass(scene), sel_registerName("_hasTollFreeDeviceAndInterfaceOrientationConversion"));
- if (!method || strcmp(method_getTypeEncoding(method), "B16@0:8") != 0) return;
- vpOriginalTollFreeOrientationConversion = method_setImplementation(method, (IMP)vpCanonicalOrientationConversion);
- }
- }
- unsigned int generation = atomic_fetch_add_explicit(&vpCanonicalOrientationGeneration, 1, memory_order_acq_rel) + 1;
- vpCanonicalOrientationScene = enabled ? scene : nil;
- vpFoldDisplayLog([NSString stringWithFormat:@"canonical orientation: %@ generation=%u", enabled ? @"enabled" : @"restored", generation]);
- if (scene == vpMainInnerWindowScene()) vpForceNativeOrientationResolution();
- if (enabled) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- if (generation == atomic_load_explicit(&vpCanonicalOrientationGeneration, memory_order_acquire))
- vpSetCanonicalOrientationProbe(NO);
- });
- } @catch (NSException *exception) {
- vpCanonicalOrientationScene = nil;
- vpFoldDisplayLog([NSString stringWithFormat:@"canonical orientation exception: %@", exception.reason]);
- }
-}
-
-void vpRefreshNativeOrientationActuation(void) {
- @try {
- id scene = vpOrientationArbitrationScene();
- if (!scene) { vpFoldDisplayLog(@"orientation actuation: refused outside Main inner"); return; }
- // The bridge must exist before the first rotation the wallpaper
- // follows; installing on every actuation keeps it armed across
- // wallpaper controller re-creation.
- vpInstallWallpaperOrientationBridge();
- NSInteger direction = [[vpReadObject(scene, "traitsPipelineManager") valueForKey:@"systemArbitratedInterfaceOrientation"] integerValue];
- // The cover presentation is portrait-native, but the single-scene
- // emulation's arbiter carries the direction the mode swap computed
- // from the inner panel's rotated pose and no input channel reopens
- // it (pose, pose-refresh, arbitration, accelerometer all verified
- // portrait while the pipeline stays landscape). Complete the same
- // native callback chain with the cover's native direction instead
- // of the latched one.
- if (scene != vpMainInnerWindowScene()) {
- if (direction != 1) vpFoldDisplayLog([NSString stringWithFormat:
- @"orientation actuation: cover direction %ld overridden to portrait", (long)direction]);
- direction = 1;
- }
- if (direction < 1 || direction > 4) return;
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- SEL selector = sel_registerName("_notePipelineManagerChangedInterfaceOrientation:onWindowScene:duration:force:logMessage:");
- Method method = class_getInstanceMethod(object_getClass(app), selector);
- if (!method || strcmp(method_getTypeEncoding(method), "v52@0:8q16@24d32B40@44") != 0) return;
- // Replay the existing shared native pipeline callback with its own
- // resolved direction; no status-window setter or custom mask is used.
- ((void (*)(id, SEL, NSInteger, id, CGFloat, BOOL, id))objc_msgSend)(app, selector,
- direction, scene, 0, YES, @"vphone native orientation actuation refresh");
- vpFoldDisplayLog([NSString stringWithFormat:@"orientation actuation: native callback direction=%ld", (long)direction]);
- // The Main mode keeps portrait dimensions on this platform, so a
- // rotation also needs UIKit to re-deliver the scene's coordinate
- // space; otherwise the portrait layout renders sideways inside the
- // rotated framebuffer. The public geometry request for the actuated
- // direction makes the space swap (951x669) and the icon family and
- // windows re-flow.
- vpRequestSceneGeometry(scene, direction);
- vpScheduleQuickActionGlyphScale();
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"orientation actuation exception: %@", exception.reason]);
- }
-}
-
-// MARK: - embedded orientation probe
-
-void vpRestoreEmbeddedOrientation(void) {
- atomic_fetch_add_explicit(&vpEmbeddedOrientationGeneration, 1, memory_order_acq_rel);
- id app = vpEmbeddedOrientationApplication;
- id scene = vpEmbeddedOrientationScene;
- if (!app || scene != vpMainInnerWindowScene()) {
- vpEmbeddedOrientationApplication = nil;
- vpEmbeddedOrientationScene = nil;
- return;
- }
- @try {
- NSInteger current = [[app valueForKey:@"statusBarOrientationForEmbeddedDisplay"] integerValue];
- if (current != vpEmbeddedOrientationPublished) {
- vpEmbeddedOrientationApplication = nil;
- vpEmbeddedOrientationScene = nil;
- vpFoldDisplayLog(@"embedded orientation: newer native value preserved"); return;
- }
- ((void (*)(id, SEL, NSInteger, BOOL))objc_msgSend)(app,
- sel_registerName("setStatusBarOrientation:forEmbeddedDisplayAnimated:"), vpEmbeddedOrientationOriginal, NO);
- NSInteger readback = [[app valueForKey:@"statusBarOrientationForEmbeddedDisplay"] integerValue];
- if (readback == vpEmbeddedOrientationOriginal) {
- vpEmbeddedOrientationApplication = nil;
- vpEmbeddedOrientationScene = nil;
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"embedded orientation: restore original=%ld readback=%ld verified=%d",
- (long)vpEmbeddedOrientationOriginal, (long)readback, readback == vpEmbeddedOrientationOriginal]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"embedded orientation restore exception: %@", exception.reason]);
- }
-}
-
-void vpProbeEmbeddedOrientation(void) {
- @try {
- vpRestoreEmbeddedOrientation();
- if (vpEmbeddedOrientationApplication) {
- vpFoldDisplayLog(@"embedded orientation: prior restoration pending"); return;
- }
- id scene = vpMainInnerWindowScene();
- if (!scene) { vpFoldDisplayLog(@"embedded orientation: refused outside Main inner"); return; }
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- NSInteger target = [[vpReadObject(scene, "traitsPipelineManager") valueForKey:@"systemArbitratedInterfaceOrientation"] integerValue];
- NSInteger original = [[app valueForKey:@"statusBarOrientationForEmbeddedDisplay"] integerValue];
- SEL setter = sel_registerName("setStatusBarOrientation:forEmbeddedDisplayAnimated:");
- Method method = class_getInstanceMethod(object_getClass(app), setter);
- if (!method || strcmp(method_getTypeEncoding(method), "v28@0:8q16B24") != 0 ||
- original < 1 || original > 4 || target < 1 || target > 4 || original == target) return;
- vpEmbeddedOrientationApplication = app;
- vpEmbeddedOrientationScene = scene;
- vpEmbeddedOrientationOriginal = original;
- vpEmbeddedOrientationPublished = target;
- unsigned int generation = atomic_fetch_add_explicit(&vpEmbeddedOrientationGeneration, 1, memory_order_acq_rel) + 1;
- // Synchronize the native embedded-display direction slot with the
- // existing arbiter output. No individual window receives a direction.
- ((void (*)(id, SEL, NSInteger, BOOL))objc_msgSend)(app, setter, target, NO);
- vpFoldDisplayLog([NSString stringWithFormat:@"embedded orientation: pulse %ld -> %ld readback=%@",
- (long)original, (long)target, [app valueForKey:@"statusBarOrientationForEmbeddedDisplay"]]);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- if (generation == atomic_load_explicit(&vpEmbeddedOrientationGeneration, memory_order_acquire))
- vpRestoreEmbeddedOrientation();
- });
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"embedded orientation pulse exception: %@", exception.reason]);
- }
-}
-
-// MARK: - backboardd orientation events
-
-static id vpBackboardOrientationManager(void) {
- return vpReadObject(objc_getClass("BKOrientationManager"), "sharedInstance");
-}
-
-static void vpSnapshotBackboardOrientationNow(void) {
- @try {
- id manager = vpBackboardOrientationManager();
- NSMutableDictionary *snapshot = [NSMutableDictionary dictionaryWithDictionary:@{
- @"pid": @(getpid()), @"time": @(CFAbsoluteTimeGetCurrent())}];
- for (NSString *key in @[@"isOrientationEventsEnabled", @"isDeviceOrientationLocked"])
- snapshot[key] = vpReadBoolValue(manager, key.UTF8String) ?: NSNull.null;
- for (NSString *key in @[@"currentRawDeviceOrientation", @"effectiveDeviceOrientation", @"currentUserInterfaceOrientation", @"lastEffectiveInterfaceOrientation"]) {
- SEL getter = NSSelectorFromString(key);
- NSMethodSignature *signature = [manager methodSignatureForSelector:getter];
- if (signature.numberOfArguments == 2 && strcmp(signature.methodReturnType, "q") == 0)
- snapshot[key] = @(((NSInteger (*)(id, SEL))objc_msgSend)(manager, getter));
- }
- id display = vpReadObject(objc_getClass("CADisplay"), "mainDisplay");
- if (!display) for (id candidate in vpReadObject(objc_getClass("CADisplay"), "displays"))
- if ([vpReadObject(candidate, "deviceName") isEqual:@"primary"]) { display = candidate; break; }
- SEL supports = sel_registerName("displaySupportsRotation:");
- Method method = class_getInstanceMethod(object_getClass(manager), supports);
- if (display && method && strcmp(method_getTypeEncoding(method), "B24@0:8@16") == 0)
- snapshot[@"primarySupportsRotation"] = @(((BOOL (*)(id, SEL, id))objc_msgSend)(manager, supports, display));
- NSData *data = [NSJSONSerialization dataWithJSONObject:snapshot options:0 error:NULL];
- if (data) vpFoldDisplayLog([@"backboard orientation " stringByAppendingString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"backboard orientation snapshot exception: %@", exception.reason]);
- }
-}
-
-void vpSnapshotBackboardOrientation(void) {
- // Native getters synchronize with the orientation manager and may query
- // CoreAnimation. Keep the backboardd main run loop free while observing.
- dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
- vpSnapshotBackboardOrientationNow();
- });
-}
-
-void vpRestoreBackboardOrientationEvents(void) {
- @try {
- atomic_fetch_add_explicit(&vpOrientationEventsGeneration, 1, memory_order_acq_rel);
- id manager = vpOrientationEventsManager;
- if (!manager || manager != vpBackboardOrientationManager()) { vpOrientationEventsManager = nil; return; }
- SEL setter = sel_registerName("setOrientationEventsEnabled:");
- Method method = class_getInstanceMethod(object_getClass(manager), setter);
- if (!method || strcmp(method_getTypeEncoding(method), "v20@0:8B16") != 0) return;
- ((void (*)(id, SEL, BOOL))objc_msgSend)(manager, setter, vpOriginalOrientationEventsEnabled);
- vpOrientationEventsManager = nil;
- vpSnapshotBackboardOrientation();
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"backboard orientation events restore exception: %@", exception.reason]);
- }
-}
-
-void vpProbeBackboardOrientationEvents(void) {
- @try {
- if (!atomic_load_explicit(&vpInnerSurfaceProbeEnabled, memory_order_acquire) || atomic_load_explicit(&vpPrimarySurfaceType, memory_order_acquire) != 2) {
- vpFoldDisplayLog(@"backboard orientation events: refused outside inner metadata probe"); return;
- }
- if (vpOrientationEventsManager) vpRestoreBackboardOrientationEvents();
- id manager = vpBackboardOrientationManager();
- NSNumber *enabled = vpReadBoolValue(manager, "isOrientationEventsEnabled");
- SEL setter = sel_registerName("setOrientationEventsEnabled:");
- Method method = class_getInstanceMethod(object_getClass(manager), setter);
- if (!enabled || !method || strcmp(method_getTypeEncoding(method), "v20@0:8B16") != 0) return;
- if (enabled.boolValue) {
- vpFoldDisplayLog(@"backboard orientation events: already enabled, no mutation");
- vpSnapshotBackboardOrientation();
- return;
- }
- vpOrientationEventsManager = manager;
- vpOriginalOrientationEventsEnabled = enabled.boolValue;
- ((void (*)(id, SEL, BOOL))objc_msgSend)(manager, setter, YES);
- vpFoldDisplayLog([NSString stringWithFormat:@"backboard orientation events: temporary enable, original=%@", enabled]);
- vpSnapshotBackboardOrientation();
- unsigned int generation = atomic_fetch_add_explicit(&vpOrientationEventsGeneration, 1, memory_order_acq_rel) + 1;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- if (generation == atomic_load_explicit(&vpOrientationEventsGeneration, memory_order_acquire))
- vpRestoreBackboardOrientationEvents();
- });
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"backboard orientation events exception: %@", exception.reason]);
- }
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayOrientationMap.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayOrientationMap.m
deleted file mode 100644
index e6542c3b..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayOrientationMap.m
+++ /dev/null
@@ -1,100 +0,0 @@
-// The orientation map vphoned polls (vphone-display-orientation-map.json): the
-// scene's native mounting tables and the current viewport.
-
-#import "FoldDisplayPrivate.h"
-
-// The SB-main orientation map is the contract vphoned's Duo rotation and
-// posture paths poll (vp_display_orientation_mapping). Publish the live
-// scene geometry on demand, at startup, and after each viewport change;
-// without this file the daemon sees "map unavailable" and refuses every
-// posture/rotation settle.
-void vpExportNativeOrientationMapping(void) {
- vpFoldDisplayLog(@"native orientation mapping export requested");
- @try {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- if (!app) return;
- id scene = vpReadObject(app, "activeDisplayWindowScene") ?: vpReadObject(app, "embeddedDisplayWindowScene");
- if (!scene) return;
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- if (!configuration) return;
- id screen = vpReadObject(scene, "screen");
- double scale = 3;
- @try {
- id scaleValue = screen ? [screen valueForKey:@"scale"] : nil;
- if ([scaleValue respondsToSelector:@selector(doubleValue)]) scale = [scaleValue doubleValue];
- } @catch (NSException *exception) { }
- long long interfaceOrientation = 1;
- SEL orientationSelector = sel_registerName("interfaceOrientation");
- if ([scene respondsToSelector:orientationSelector])
- interfaceOrientation = ((long long (*)(id, SEL))objc_msgSend)(scene, orientationSelector);
- unsigned long long surfaceType = 0;
- SEL surfaceSelector = sel_registerName("sbhScreenType");
- if ([scene respondsToSelector:surfaceSelector])
- surfaceType = ((unsigned long long (*)(id, SEL))objc_msgSend)(scene, surfaceSelector);
- // The daemon resolves interface requests through the device table;
- // the native scene owns the real inverse mounting map (the Duo inner
- // panel mounts rotated, measured [3,4,2,1] on iPhone19,4). The
- // identity table stays only as the fallback for a scene without the
- // conversion selectors.
- NSMutableArray *deviceOrientations = [NSMutableArray arrayWithArray:@[@1, @2, @3, @4]];
- NSMutableArray *systemSpaceOrientations = [NSMutableArray arrayWithArray:@[@1, @2, @3, @4]];
- for (NSString *name in @[@"deviceOrientationForSystemSpaceOrientation:", @"systemSpaceOrientationForDeviceOrientation:"]) {
- SEL selector = NSSelectorFromString(name);
- Method method = class_getInstanceMethod(object_getClass(scene), selector);
- if (!method || strcmp(method_getTypeEncoding(method), "q24@0:8q16") != 0) continue;
- NSMutableArray *table = [NSMutableArray arrayWithCapacity:4];
- for (NSInteger direction = 1; direction <= 4; direction++)
- [table addObject:@(((NSInteger (*)(id, SEL, NSInteger))objc_msgSend)(scene, selector, direction))];
- if (![[NSSet setWithArray:table] isEqualToSet:[NSSet setWithArray:@[@1, @2, @3, @4]]]) {
- vpFoldDisplayLog([NSString stringWithFormat:@"native orientation mapping export: %@ returned non-permutation %@; keeping fallback", name, table]);
- continue;
- }
- if ([name hasPrefix:@"deviceOrientation"]) deviceOrientations = table;
- else systemSpaceOrientations = table;
- }
- NSDictionary *map = @{
- @"version": @1,
- @"scene": @"SB-main",
- @"pid": @(getpid()),
- @"generatedUptime": @(NSProcessInfo.processInfo.systemUptime),
- @"available": @YES,
- @"persistentViewport": @(vpPersistentViewport ? YES : NO),
- @"deviceOrientations": deviceOrientations,
- @"systemSpaceOrientations": systemSpaceOrientations,
- @"scale": @(scale),
- @"surfaceType": @(surfaceType),
- @"viewportGeneration": @(atomic_load_explicit(&vpViewportRequestGeneration, memory_order_relaxed)),
- @"interfaceOrientation": @(interfaceOrientation),
- @"configurationBounds": vpSnapshotRect(configuration, "bounds"),
- @"coordinateBounds": vpSnapshotRect(vpReadObject(scene, "coordinateSpace"), "bounds") ?: NSNull.null,
- @"bounds": vpSnapshotRect(configuration, "bounds"),
- };
- NSData *data = [NSJSONSerialization dataWithJSONObject:map options:0 error:NULL];
- if (![data writeToFile:@"/var/mobile/Library/Caches/vphone-display-orientation-map.json" atomically:YES]) {
- vpFoldDisplayLog(@"native orientation mapping export: write failed");
- return;
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"native orientation mapping export: generation=%u bounds=%@ interface=%lld persistent=%d",
- atomic_load_explicit(&vpViewportRequestGeneration, memory_order_relaxed),
- map[@"configurationBounds"], interfaceOrientation, vpPersistentViewport ? 1 : 0]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"native orientation mapping export exception: %@", exception.reason]);
- }
-}
-
-id vpSnapshotPoseDirections(id provider) {
- SEL selector = sel_registerName("currentPose");
- NSMethodSignature *signature = [provider methodSignatureForSelector:selector];
- // The shipped SBF pose begins with three native q orientations. Match
- // the runtime aggregate ABI, rather than declaring a guessed C struct.
- if (!signature || signature.numberOfArguments != 2 || signature.methodReturnLength < 24 ||
- signature.methodReturnLength > 1024 || strncmp(signature.methodReturnType, "{?=qqq", 6) != 0) return NSNull.null;
- NSMutableData *bytes = [NSMutableData dataWithLength:signature.methodReturnLength];
- NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
- invocation.target = provider;
- invocation.selector = selector;
- [invocation invoke];
- [invocation getReturnValue:bytes.mutableBytes];
- int64_t directions[3]; memcpy(directions, bytes.bytes, sizeof(directions));
- return @[@(directions[0]), @(directions[1]), @(directions[2])];
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
new file mode 100644
index 00000000..b7628535
--- /dev/null
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
@@ -0,0 +1,275 @@
+// SpringBoard: one physical panel for two displays. The cover and the inner
+// display share this guest's only scanout, the primary; open, SpringBoard
+// composites the inner display onto it.
+
+#import "FoldDisplayPrivate.h"
+
+static void vpShowInnerDisplay(BOOL shown);
+
+// MARK: - power
+
+// SpringBoard powers each panel through its CADisplayStateControl (state 1
+// on, 0 off): open, the cover (primary, display 1) goes off and the inner
+// display on; closed, the reverse. On this guest the primary is the only
+// scanout, and open it has to show the inner display, which SpringBoard
+// composites onto it (vpShowInnerDisplay). So the primary is kept on while
+// either panel wants it; a screen-off turns both off. Closing does not turn
+// the inner display off, so the inner display is lit only while the cover is
+// not: the cover wins the shared panel. The compositor and backboardd's touch
+// routing follow the inner display's applied state.
+static IMP vpOriginalTransitionDisplayState;
+static id vpPrimaryStateControl, vpInnerStateControl;
+static long long vpPrimaryWantedState = 1, vpPrimaryAppliedState = 1, vpInnerWantedState, vpInnerAppliedState = -1;
+
+static unsigned int vpStateControlDisplayId(id control) {
+ Ivar ivar = class_getInstanceVariable(object_getClass(control), "_display_id");
+ if (!ivar || strcmp(ivar_getTypeEncoding(ivar), "I") != 0) return 0;
+ return *(unsigned int *)((uint8_t *)(__bridge void *)control + ivar_getOffset(ivar));
+}
+
+static void vpApplyPanelState(id control, long long state, long long *applied, id completion) {
+ if (!control || (state == *applied && !completion)) return;
+ *applied = state;
+ ((void (*)(id, SEL, long long, id))vpOriginalTransitionDisplayState)(control,
+ sel_registerName("transitionToDisplayState:withCompletion:"), state, completion);
+}
+
+static void vpApplyPanelStates(id primaryCompletion, id innerCompletion) {
+ vpApplyPanelState(vpPrimaryStateControl, vpPrimaryWantedState || vpInnerWantedState ? 1 : 0,
+ &vpPrimaryAppliedState, primaryCompletion);
+ long long inner = vpInnerWantedState && !vpPrimaryWantedState ? 1 : 0;
+ BOOL changed = inner != vpInnerAppliedState;
+ vpApplyPanelState(vpInnerStateControl, inner, &vpInnerAppliedState, innerCompletion);
+ if (changed && vpInnerStateControl) dispatch_async(dispatch_get_main_queue(), ^{ vpShowInnerDisplay(inner != 0); });
+}
+
+// SpringBoard asks for a transition only when it wants a state the panel is
+// not in; after a SpringBoard restart the inner display may already be lit and
+// is never asked about. So until it is, its wanted state is the state it has.
+static void vpAdoptInnerStateControl(void) {
+ if (vpInnerStateControl) return;
+ for (id display in vpReadObject(objc_getClass("CADisplay"), "displays") ?: @[]) {
+ if (!vpIsInnerDisplay(display)) continue;
+ id control = vpReadObject(display, "stateControl");
+ Method current = class_getInstanceMethod(object_getClass(control), sel_registerName("displayState"));
+ if (!current || strcmp(method_getTypeEncoding(current), "q16@0:8") != 0) return;
+ vpInnerWantedState = vpInnerAppliedState =
+ ((long long (*)(id, SEL))objc_msgSend)(control, sel_registerName("displayState")) != 0;
+ vpInnerStateControl = control;
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: adopted state %lld", vpInnerWantedState]);
+ if (vpInnerWantedState) dispatch_async(dispatch_get_main_queue(), ^{ vpShowInnerDisplay(YES); });
+ return;
+ }
+}
+
+static void vpSharedScanoutTransition(id self, SEL selector, long long state, id completion) {
+ unsigned int displayId = vpStateControlDisplayId(self);
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: display %u wants state %lld", displayId, state]);
+ if (displayId == 1) {
+ vpAdoptInnerStateControl();
+ vpPrimaryStateControl = self;
+ vpPrimaryWantedState = state;
+ vpApplyPanelStates(completion, nil);
+ return;
+ }
+ id innerDisplay = nil;
+ for (id display in vpReadObject(objc_getClass("CADisplay"), "displays") ?: @[])
+ if ([[display valueForKey:@"displayId"] unsignedIntValue] == displayId && vpIsInnerDisplay(display)) innerDisplay = display;
+ if (!innerDisplay) {
+ ((void (*)(id, SEL, long long, id))vpOriginalTransitionDisplayState)(self, selector, state, completion);
+ return;
+ }
+ vpInnerStateControl = self;
+ vpInnerWantedState = state;
+ vpApplyPanelStates(nil, completion);
+}
+
+void vpInstallSharedPanel(void) {
+ Method transition = class_getInstanceMethod(objc_getClass("CADisplayStateControl"),
+ sel_registerName("transitionToDisplayState:withCompletion:"));
+ const char *encoding = transition ? method_getTypeEncoding(transition) : "missing";
+ Ivar displayId = class_getInstanceVariable(objc_getClass("CADisplayStateControl"), "_display_id");
+ if (strcmp(encoding, "v32@0:8q16@?24") != 0 || !displayId || strcmp(ivar_getTypeEncoding(displayId), "I") != 0) {
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: shared scanout ABI unavailable (%s)", encoding]);
+ return;
+ }
+ vpOriginalTransitionDisplayState = method_setImplementation(transition, (IMP)vpSharedScanoutTransition);
+ vpFoldDisplayLog(@"inner display: shared scanout installed");
+}
+
+// MARK: - compositing
+
+// The render server's own clone of a display (addClone:options:) never
+// reaches this guest's paravirtual panel, so SpringBoard composites
+// instead: a render context ordered onto the primary display above
+// everything hosts every window of the inner display's scenes by render
+// context (CALayerHost, as scene hosting does). It is not a window of
+// SB-main, because open, SpringBoard gives the cover (Main) auxiliary
+// content and takes its scene's windows off screen. Touches on the hosted
+// windows reach their owners through backboardd's render-tree hit test.
+//
+// The render server redraws a display for commits to its own contexts only;
+// a commit by an inner-display context (an application changing its pixels)
+// leaves the hosting primary display on its last frame. So while shown, a
+// layer over the whole panel changes once per primary frame: its background
+// alternates between two clear colors, which damages every pixel without
+// a visible change. (An opacity flip on the container does the same, but
+// below 1 the container renders offscreen as a group, and hosted secure
+// windows come out as grey blocks on those frames.)
+static id vpInnerHostContext, vpInnerHostContainer, vpInnerHostDamage, vpInnerHostRefresh;
+static dispatch_source_t vpInnerHostTimer;
+static NSMutableDictionary<NSNumber *, id> *vpInnerHostLayers;
+static CGSize vpInnerHostPanel;
+
+@interface VPhoneInnerHostRefresh : NSObject
+@end
+
+@implementation VPhoneInnerHostRefresh
+- (void)refresh:(id)link {
+ static CGColorRef clear, faint;
+ static BOOL flip;
+ if (!clear) {
+ clear = CGColorCreateSRGB(0, 0, 0, 0);
+ faint = CGColorCreateSRGB(1, 1, 1, 0);
+ }
+ flip = !flip;
+ Class transaction = objc_getClass("CATransaction");
+ ((void (*)(id, SEL))objc_msgSend)(transaction, sel_registerName("begin"));
+ ((void (*)(id, SEL, BOOL))objc_msgSend)(transaction, sel_registerName("setDisableActions:"), YES);
+ ((void (*)(id, SEL, CGColorRef))objc_msgSend)(vpInnerHostDamage, sel_registerName("setBackgroundColor:"), flip ? faint : clear);
+ ((void (*)(id, SEL))objc_msgSend)(transaction, sel_registerName("commit"));
+}
+@end
+
+static id vpPrimaryCADisplay(void) {
+ for (id display in vpReadObject(objc_getClass("CADisplay"), "displays") ?: @[])
+ if ([[display valueForKey:@"deviceName"] isEqual:@"primary"]) return display;
+ return nil;
+}
+
+// A display-level context works in the panel's pixels: the root covers them,
+// and the inner display's points are fitted onto the panel's points,
+// turned a quarter (-90 degrees) if it reads landscape on the portrait
+// panel, centered, shrunk only if it does not fit.
+static void vpFitInnerHosts(CGRect inner) {
+ id primary = vpPrimaryCADisplay();
+ CGRect pixels = ((CGRect (*)(id, SEL))objc_msgSend)(primary, sel_registerName("bounds"));
+ double pointScale = [[primary valueForKey:@"pointScale"] doubleValue] ?: 1;
+ CGSize panel = CGSizeMake(pixels.size.width / pointScale, pixels.size.height / pointScale);
+ if (CGSizeEqualToSize(panel, vpInnerHostPanel)) return;
+ vpInnerHostPanel = panel;
+ id root = vpReadObject(vpInnerHostContext, "layer");
+ ((void (*)(id, SEL, CGRect))objc_msgSend)(root, sel_registerName("setFrame:"), (CGRect){CGPointZero, pixels.size});
+ ((void (*)(id, SEL, CGRect))objc_msgSend)(vpInnerHostDamage, sel_registerName("setFrame:"), (CGRect){CGPointZero, pixels.size});
+ BOOL turned = inner.size.width > inner.size.height;
+ CGSize upright = turned ? CGSizeMake(inner.size.height, inner.size.width) : inner.size;
+ CGFloat scale = MIN(1, MIN(panel.width / upright.width, panel.height / upright.height));
+ CGAffineTransform transform = CGAffineTransformMakeScale(scale * pointScale, scale * pointScale);
+ if (turned) transform = CGAffineTransformRotate(transform, -M_PI_2);
+ id container = vpInnerHostContainer;
+ ((void (*)(id, SEL, CGRect))objc_msgSend)(container, sel_registerName("setBounds:"), (CGRect){CGPointZero, inner.size});
+ ((void (*)(id, SEL, CGPoint))objc_msgSend)(container, sel_registerName("setPosition:"), CGPointMake(CGRectGetMidX(pixels), CGRectGetMidY(pixels)));
+ ((void (*)(id, SEL, CGAffineTransform))objc_msgSend)(container, sel_registerName("setAffineTransform:"), transform);
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: fitted panel={%.0f, %.0f} inner={%.0f, %.0f} turned=%d scale=%.3f",
+ panel.width, panel.height, inner.size.width, inner.size.height, turned, scale]);
+}
+
+static void vpSyncInnerHosts(void) {
+ id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
+ id innerScene = vpSpringBoardWindowScene(YES);
+ if (innerScene)
+ vpFitInnerHosts(((CGRect (*)(id, SEL))objc_msgSend)(vpReadObject(innerScene, "coordinateSpace"), sel_registerName("bounds")));
+ NSMutableArray *windows = [NSMutableArray array];
+ for (id scene in [vpReadObject(app, "connectedScenes") allObjects] ?: @[])
+ if ([scene isKindOfClass:objc_getClass("UIWindowScene")] && vpSceneIsOnInnerDisplay(scene))
+ for (id window in vpReadObject(scene, "windows") ?: @[])
+ if (![[window valueForKey:@"hidden"] boolValue]) [windows addObject:window];
+ [windows sortUsingComparator:^NSComparisonResult(id a, id b) {
+ return [[a valueForKey:@"windowLevel"] compare:[b valueForKey:@"windowLevel"]];
+ }];
+ NSMutableSet *live = [NSMutableSet set];
+ SEL contextIdSelector = sel_registerName("_contextId");
+ for (NSUInteger index = 0; index < windows.count; index++) {
+ id window = windows[index];
+ if (![window respondsToSelector:contextIdSelector]) continue;
+ unsigned int contextId = ((unsigned int (*)(id, SEL))objc_msgSend)(window, contextIdSelector);
+ if (!contextId) continue;
+ NSNumber *key = @(contextId);
+ [live addObject:key];
+ id host = vpInnerHostLayers[key];
+ if (!host) {
+ host = [objc_getClass("CALayerHost") new];
+ ((void (*)(id, SEL, unsigned int))objc_msgSend)(host, sel_registerName("setContextId:"), contextId);
+ ((void (*)(id, SEL, id))objc_msgSend)(vpInnerHostContainer, sel_registerName("addSublayer:"), host);
+ vpInnerHostLayers[key] = host;
+ }
+ ((void (*)(id, SEL, CGRect))objc_msgSend)(host, sel_registerName("setFrame:"),
+ ((CGRect (*)(id, SEL))objc_msgSend)(window, sel_registerName("frame")));
+ ((void (*)(id, SEL, double))objc_msgSend)(host, sel_registerName("setZPosition:"), index);
+ }
+ for (NSNumber *key in vpInnerHostLayers.allKeys) {
+ if ([live containsObject:key]) continue;
+ ((void (*)(id, SEL))objc_msgSend)(vpInnerHostLayers[key], sel_registerName("removeFromSuperlayer"));
+ [vpInnerHostLayers removeObjectForKey:key];
+ }
+}
+
+static void vpShowInnerDisplay(BOOL shown) {
+ @try {
+ if (!shown) {
+ if (!vpInnerHostContext) return;
+ dispatch_source_cancel(vpInnerHostTimer);
+ vpInnerHostTimer = nil;
+ ((void (*)(id, SEL))objc_msgSend)(vpInnerHostRefresh, sel_registerName("invalidate"));
+ vpInnerHostRefresh = nil;
+ ((void (*)(id, SEL))objc_msgSend)(vpInnerHostContext, sel_registerName("invalidate"));
+ vpInnerHostContext = vpInnerHostContainer = vpInnerHostDamage = nil;
+ vpInnerHostLayers = nil;
+ vpInnerHostPanel = CGSizeZero;
+ vpFoldDisplayLog(@"inner display: shown=0");
+ return;
+ }
+ if (vpInnerHostContext) return;
+ id primary = vpPrimaryCADisplay();
+ NSString *__unsafe_unretained *displayable = (NSString *__unsafe_unretained *)dlsym(RTLD_DEFAULT, "kCAContextDisplayable");
+ NSString *__unsafe_unretained *displayIdKey = (NSString *__unsafe_unretained *)dlsym(RTLD_DEFAULT, "kCAContextDisplayId");
+ Method hostContext = class_getInstanceMethod(objc_getClass("CALayerHost"), sel_registerName("setContextId:"));
+ Method level = class_getInstanceMethod(objc_getClass("CAContext"), sel_registerName("setLevel:"));
+ if (!primary || !displayable || !displayIdKey || !hostContext || !level ||
+ strcmp(method_getTypeEncoding(hostContext), "v20@0:8I16") != 0 || strcmp(method_getTypeEncoding(level), "v20@0:8f16") != 0) {
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: show unavailable primary=%d keys=%d host=%s level=%s",
+ primary != nil, displayable && displayIdKey, hostContext ? method_getTypeEncoding(hostContext) : "missing",
+ level ? method_getTypeEncoding(level) : "missing"]);
+ return;
+ }
+ id context = ((id (*)(id, SEL, id))objc_msgSend)(objc_getClass("CAContext"), sel_registerName("remoteContextWithOptions:"),
+ @{*displayable: @YES, *displayIdKey: [primary valueForKey:@"displayId"]});
+ id root = [objc_getClass("CALayer") new];
+ ((void (*)(id, SEL, CGColorRef))objc_msgSend)(root, sel_registerName("setBackgroundColor:"),
+ ((CGColorRef (*)(id, SEL))objc_msgSend)(vpReadObject(objc_getClass("UIColor"), "blackColor"), sel_registerName("CGColor")));
+ id container = [objc_getClass("CALayer") new];
+ ((void (*)(id, SEL, id))objc_msgSend)(root, sel_registerName("addSublayer:"), container);
+ id damage = [objc_getClass("CALayer") new];
+ ((void (*)(id, SEL, id))objc_msgSend)(root, sel_registerName("addSublayer:"), damage);
+ vpInnerHostDamage = damage;
+ ((void (*)(id, SEL, id))objc_msgSend)(context, sel_registerName("setLayer:"), root);
+ ((void (*)(id, SEL, float))objc_msgSend)(context, sel_registerName("setLevel:"), 1.0e9f);
+ vpInnerHostContext = context;
+ vpInnerHostContainer = container;
+ vpInnerHostLayers = [NSMutableDictionary dictionary];
+ vpInnerHostPanel = CGSizeZero;
+ vpSyncInnerHosts();
+ vpInnerHostTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
+ dispatch_source_set_timer(vpInnerHostTimer, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 4), NSEC_PER_SEC / 4, NSEC_PER_SEC / 20);
+ dispatch_source_set_event_handler(vpInnerHostTimer, ^{ vpSyncInnerHosts(); });
+ dispatch_resume(vpInnerHostTimer);
+ vpInnerHostRefresh = ((id (*)(id, SEL, id, SEL))objc_msgSend)(objc_getClass("CADisplayLink"),
+ sel_registerName("displayLinkWithTarget:selector:"), [VPhoneInnerHostRefresh new], @selector(refresh:));
+ ((void (*)(id, SEL, id, id))objc_msgSend)(vpInnerHostRefresh, sel_registerName("addToRunLoop:forMode:"),
+ NSRunLoop.mainRunLoop, NSRunLoopCommonModes);
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: shown=1 context=%@ hosts=%lu",
+ [context valueForKey:@"contextId"], (unsigned long)vpInnerHostLayers.count]);
+ } @catch (NSException *exception) {
+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: show exception %@", exception.reason]);
+ }
+}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPipeline.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPipeline.m
deleted file mode 100644
index 67090070..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPipeline.m
+++ /dev/null
@@ -1,415 +0,0 @@
-// SpringBoard's display configuration pipeline: the main-configuration
-// transformer hook, display-monitor observation, and the logged identity and
-// configuration getters.
-
-#import "FoldDisplayPrivate.h"
-
-static IMP vpOriginalAlwaysConnected;
-static IMP vpOriginalTransform;
-static atomic_uint vpTransformLogCount;
-static atomic_uint vpConfigurationLogCount;
-atomic_bool vpLogicalProjectionEnabled;
-__weak id vpLogicalRoleResolver;
-IMP vpOriginalStartResolvingDisplay;
-
-// Bumped on every hooked SBMainDisplayConfigurationTransformer call so the
-// invalidation pulse can prove the pipeline actually re-ran.
-static atomic_uint vpPulseTransformCount;
-
-__weak id vpObservedConfigurationTransformer;
-
-NSHashTable *vpObservedDisplayMonitors;
-static IMP vpOriginalPublicMonitorInit;
-static IMP vpOriginalCompletionMonitorInit;
-
-// MARK: - transform refresh
-
-// Re-runs the Main configuration transform through the observed display
-// monitors, or through the FBDisplayManager compatibility monitor when none
-// was observed. It changes no display identity or framebuffer itself.
-void vpRefreshMainTransform(void) {
- NSUInteger refreshed = 0;
- @synchronized (vpObservedDisplayMonitors) {
- for (id monitor in vpObservedDisplayMonitors) {
- SEL update = sel_registerName("updateConfigurationWithCompletion:");
- if (![monitor respondsToSelector:update]) continue;
- @try { ((void (*)(id, SEL, id))objc_msgSend)(monitor, update, ^(id error) { (void)error; }); refreshed++; }
- @catch (NSException *exception) { vpFoldDisplayLog([NSString stringWithFormat:@"transform refresh exception: %@", exception.reason]); }
- }
- }
- // This SpringBoard build creates no FBSDisplayMonitor through the
- // observed initializers, but the FBDisplayManager compatibility monitor
- // owns the same configuration pipeline (it holds the transformer whose
- // cover override the flag above arms). The 3803cc4d invalidation pulse
- // drove the cover switch through updateTransformsWithCompletion:; the
- // selector table of that shipped dylib names it, the rewritten source
- // had lost it.
- if (refreshed == 0) {
- id manager = vpReadObject(objc_getClass("FBDisplayManager"), "sharedInstance");
- SEL transforms = sel_registerName("updateTransformsWithCompletion:");
- Method pulse = manager ? class_getInstanceMethod(object_getClass(manager), transforms) : NULL;
- if (pulse) {
- vpFoldDisplayLog([NSString stringWithFormat:@"invalidation pulse: selector ABI %s", method_getTypeEncoding(pulse)]);
- if (strcmp(method_getTypeEncoding(pulse), "v24@0:8@?16") == 0) {
- @try {
- // The Main source sits out the transform pipeline until
- // its updatable flag is set; the 3803cc4d pulse flipped
- // it for the duration of one update and restored it in
- // the completion.
- NSMutableArray *flippedSources = [NSMutableArray array];
- static BOOL sourceFlagInventoried;
- for (id source in vpReadObject(manager, "_sortedSources")) {
- NSNumber *updatable = nil;
- @try { updatable = [source valueForKey:@"updatable"]; } @catch (NSException *exception) { }
- if (!updatable || updatable.boolValue) continue;
- SEL setUpdatable = sel_registerName("setUpdatable:");
- Method setter = class_getInstanceMethod(object_getClass(source), setUpdatable);
- if (!sourceFlagInventoried) {
- sourceFlagInventoried = YES;
- vpFoldDisplayLog([NSString stringWithFormat:@"invalidation pulse: source class %s updatable-getter %@ setter %@",
- object_getClassName(source),
- [source methodSignatureForSelector:sel_registerName("updatable")],
- setter ? [NSString stringWithFormat:@"%s", method_getTypeEncoding(setter)] : @"absent"]);
- }
- const char *setterABI = setter ? method_getTypeEncoding(setter) : NULL;
- if (setterABI && strcmp(setterABI, "v20@0:8B16") == 0)
- ((void (*)(id, SEL, BOOL))objc_msgSend)(source, setUpdatable, YES);
- else if (setterABI && strcmp(setterABI, "v20@0:8q16") == 0)
- ((void (*)(id, SEL, long))objc_msgSend)(source, setUpdatable, 1L);
- else {
- // No usable setter: the 3803cc4d pulse worked, so
- // the flag must be settable another way. Try the
- // instance variable directly by offset.
- Ivar flag = class_getInstanceVariable(object_getClass(source), "_updatable");
- if (!flag) flag = class_getInstanceVariable(object_getClass(source), "updatable");
- const char *flagType = flag ? ivar_getTypeEncoding(flag) : NULL;
- if (flag && flagType && (flagType[0] == 'B' || flagType[0] == 'c' || flagType[0] == 'q' || flagType[0] == 'i')) {
- *(BOOL *)((char *)(__bridge void *)source + ivar_getOffset(flag)) = YES;
- [flippedSources addObject:source];
- vpFoldDisplayLog([NSString stringWithFormat:@"invalidation pulse: source %s flag ivar %s set", object_getClassName(source), flagType]);
- continue;
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"invalidation pulse: native source flag ABI unavailable (%s setter %s ivar %s)",
- object_getClassName(source), setterABI ? setterABI : "absent", flagType ?: "absent"]);
- continue;
- }
- [flippedSources addObject:source];
- vpFoldDisplayLog([NSString stringWithFormat:@"invalidation pulse: prior updatable=%d", updatable.boolValue]);
- }
- unsigned int before = atomic_load_explicit(&vpPulseTransformCount, memory_order_relaxed);
- ((void (*)(id, SEL, id))objc_msgSend)(manager, transforms, ^(id unused) {
- (void)unused;
- for (id source in flippedSources) {
- SEL setUpdatable = sel_registerName("setUpdatable:");
- Method setter = class_getInstanceMethod(object_getClass(source), setUpdatable);
- const char *setterABI = setter ? method_getTypeEncoding(setter) : NULL;
- if (setterABI && strcmp(setterABI, "v20@0:8B16") == 0)
- ((void (*)(id, SEL, BOOL))objc_msgSend)(source, setUpdatable, NO);
- else if (setterABI && strcmp(setterABI, "v20@0:8q16") == 0)
- ((void (*)(id, SEL, long))objc_msgSend)(source, setUpdatable, 0L);
- else {
- Ivar flag = class_getInstanceVariable(object_getClass(source), "_updatable");
- if (!flag) flag = class_getInstanceVariable(object_getClass(source), "updatable");
- const char *flagType = flag ? ivar_getTypeEncoding(flag) : NULL;
- if (flag && flagType && (flagType[0] == 'B' || flagType[0] == 'c' || flagType[0] == 'q' || flagType[0] == 'i'))
- *(BOOL *)((char *)(__bridge void *)source + ivar_getOffset(flag)) = NO;
- }
- }
- if (flippedSources.count) vpFoldDisplayLog(@"invalidation pulse: native flag restored");
- unsigned int after = atomic_load_explicit(&vpPulseTransformCount, memory_order_relaxed);
- vpFoldDisplayLog([NSString stringWithFormat:@"invalidation pulse: transform calls %u -> %u", before, after]);
- });
- refreshed++;
- vpFoldDisplayLog(@"invalidation pulse: updateTransformsWithCompletion requested");
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"invalidation pulse exception: %@", exception.reason]);
- }
- }
- } else {
- // One-shot inventory of the manager's own pipeline methods, so a
- // renamed selector is visible without another build cycle.
- static BOOL inventoried;
- if (!inventoried) {
- inventoried = YES;
- unsigned int count = 0;
- Class managerClass = object_getClass(manager);
- for (unsigned int level = 0; managerClass && level < 3; level++, managerClass = class_getSuperclass(managerClass)) {
- Method *methods = class_copyMethodList(managerClass, &count);
- for (unsigned int i = 0; i < count; i++) {
- const char *selector = sel_getName(method_getName(methods[i]));
- if (strstr(selector, "pdate") || strstr(selector, "ransform") || strstr(selector, "onfiguration"))
- vpFoldDisplayLog([NSString stringWithFormat:@"invalidation pulse: manager method %s %s",
- selector, method_getTypeEncoding(methods[i])]);
- }
- free(methods);
- }
- }
- vpFoldDisplayLog(@"transform refresh: no observed monitors and the manager lacks both update selectors");
- }
- }
-}
-
-// MARK: - monitor and configuration observation
-
-BOOL vpIsDuoInnerBounds(id configuration) {
- SEL selector = sel_registerName("bounds");
- NSMethodSignature *signature = [configuration methodSignatureForSelector:selector];
- if (signature.methodReturnLength != sizeof(CGRect)) return NO;
- CGRect bounds = ((CGRect (*)(id, SEL))objc_msgSend)(configuration, selector);
- // Native size is the acceptance target. Retain the earlier explicit
- // research viewport so its saved restoration controls remain usable.
- return CGRectEqualToRect(bounds, CGRectMake(0, 0, 669, 951)) ||
- CGRectEqualToRect(bounds, CGRectMake(0, 0, 678, 951));
-}
-
-static void vpRememberDisplayMonitor(id monitor, id transformer) {
- if (!monitor) return;
- @synchronized (vpObservedDisplayMonitors) {
- [vpObservedDisplayMonitors addObject:monitor];
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"monitor init: %s %p transformer=%s %p",
- object_getClassName(monitor), (__bridge void *)monitor,
- transformer ? object_getClassName(transformer) : "none", (__bridge void *)transformer]);
-}
-
-static id vpObservePublicMonitorInit(id self, SEL cmd, id transformer) {
- id monitor = ((id (*)(id, SEL, id))vpOriginalPublicMonitorInit)(self, cmd, transformer);
- vpRememberDisplayMonitor(monitor, transformer);
- return monitor;
-}
-
-static id vpObserveCompletionMonitorInit(id self, SEL cmd, id completion) {
- id monitor = ((id (*)(id, SEL, id))vpOriginalCompletionMonitorInit)(self, cmd, completion);
- vpRememberDisplayMonitor(monitor, nil);
- return monitor;
-}
-
-// Transform one native root into distinct logical configurations. The native
-// builder preserves root linkage; no render mode or identity array is forged.
-static id vpLoggedTransform(id self, SEL _cmd, id configuration) {
- vpObservedConfigurationTransformer = self;
- atomic_fetch_add_explicit(&vpPulseTransformCount, 1, memory_order_relaxed);
- id result = ((id (*)(id, SEL, id))vpOriginalTransform)(self, _cmd, configuration);
- if (atomic_load_explicit(&vpCoverViewportEnabled, memory_order_acquire) &&
- [result isKindOfClass:NSSet.class] && [result count] == 1) {
- id candidate = [result anyObject];
- id identity = ((id (*)(id, SEL))objc_msgSend)(candidate, sel_registerName("identity"));
- if ([identity respondsToSelector:sel_registerName("isMainRootDisplay")] &&
- ((BOOL (*)(id, SEL))objc_msgSend)(identity, sel_registerName("isMainRootDisplay"))) {
- CGRect bounds = ((CGRect (*)(id, SEL))objc_msgSend)(candidate, sel_registerName("bounds"));
- CGSize cover = bounds.size.width > bounds.size.height ? CGSizeMake(678, 466) : CGSizeMake(466, 678);
- if (cover.width <= bounds.size.width && cover.height <= bounds.size.height) {
- id mode = ((id (*)(id, SEL))objc_msgSend)(candidate, sel_registerName("currentMode"));
- SEL modeCopy = sel_registerName("_copyWithOverrideSize:scale:");
- SEL configurationCopy = sel_registerName("copyWithOverrideMode:");
- Method modeMethod = class_getInstanceMethod(object_getClass(mode), modeCopy);
- Method configurationMethod = class_getInstanceMethod(object_getClass(candidate), configurationCopy);
- if (!modeMethod || !configurationMethod ||
- strcmp(method_getTypeEncoding(modeMethod), "@40@0:8{CGSize=dd}16d32") != 0 ||
- strcmp(method_getTypeEncoding(configurationMethod), "@24@0:8@16") != 0) {
- vpFoldDisplayLog(@"single viewport: complete effective-mode copy ABI unavailable");
- return result;
- }
- CGFloat scale = ((CGFloat (*)(id, SEL))objc_msgSend)(mode, sel_registerName("pointScale"));
- // These are FBS frontend descriptors. The underlying CADisplay
- // and its hardware mode remain the original objects.
- id coverMode = [(id<VPhoneDisplayModeCopying>)mode _copyWithOverrideSize:cover scale:scale];
- id bounded = [(id<VPhoneDisplayProjectionCopying>)candidate copyWithOverrideMode:coverMode];
- id boundedIdentity = ((id (*)(id, SEL))objc_msgSend)(bounded, sel_registerName("identity"));
- if (bounded && [boundedIdentity isEqual:identity]) {
- result = [NSSet setWithObject:bounded];
- vpFoldDisplayLog([NSString stringWithFormat:@"single viewport: native Main cover configuration %@", bounded]);
- // The publish races any same-run adoption steps: schedule
- // them for after this transform returns, once per
- // generation, so the recompute sees the landed bounds.
- dispatch_async(dispatch_get_main_queue(), ^{ vpScheduleViewportAdoption(); });
- }
- }
- }
- }
- if (atomic_load_explicit(&vpLogicalProjectionEnabled, memory_order_acquire))
- vpFoldDisplayLog([NSString stringWithFormat:@"logical transform called: self=%@ resultClass=%@", self, NSStringFromClass([result class])]);
- // Never expand this set: the native SBFBSDisplayTransformer contract is
- // exactly one effective configuration per source. Derived identities
- // are previewed off to the side until singleton replacement is proven.
- if (atomic_fetch_add_explicit(&vpTransformLogCount, 1, memory_order_relaxed) < 8)
- vpFoldDisplayLog([NSString stringWithFormat:@"transform input=%@ output=%@", configuration, result]);
- return result;
-}
-
-static NSArray *vpObservedAlwaysConnected(id self, SEL _cmd) {
- NSArray *identities = ((NSArray *(*)(id, SEL))vpOriginalAlwaysConnected)(self, _cmd);
- vpFoldDisplayLog([NSString stringWithFormat:@"observed %s count=%lu", sel_getName(_cmd), (unsigned long)identities.count]);
- return identities;
-}
-
-// The measured main configuration is already 678x951. Keep bounded evidence
-// here while investigating how that configuration reaches scene traits.
-static IMP vpOriginalMainConfiguration;
-
-static id vpLoggedMainConfiguration(id self, SEL _cmd) {
- id (*original)(id, SEL) = (id (*)(id, SEL))vpOriginalMainConfiguration;
- id configuration = original(self, _cmd);
- if (atomic_fetch_add_explicit(&vpConfigurationLogCount, 1, memory_order_relaxed) < 8)
- vpFoldDisplayLog([NSString stringWithFormat:@"mainConfiguration -> %@", configuration]);
- return configuration;
-}
-
-static IMP vpOriginalMainIdentity;
-
-static id vpLoggedMainIdentity(id self, SEL _cmd) {
- id (*original)(id, SEL) = (id (*)(id, SEL))vpOriginalMainIdentity;
- id identity = original(self, _cmd);
- vpFoldDisplayLog([NSString stringWithFormat:@"mainIdentity -> %@", identity]);
- return identity;
-}
-
-// Observe the native monitor inventory. A count readback alone does not
-// establish which native condition selects a home layout family.
-static IMP vpOriginalMonitorIdentities;
-
-static NSArray *vpObservedMonitorIdentities(id self, SEL _cmd) {
- NSArray *identities = ((NSArray *(*)(id, SEL))vpOriginalMonitorIdentities)(self, _cmd);
- vpFoldDisplayLog([NSString stringWithFormat:@"observed %s count=%lu", sel_getName(_cmd), (unsigned long)identities.count]);
- return identities;
-}
-
-// Observe configuration counts; never invent a second hardware identity.
-static IMP vpOriginalLockConfigurations;
-
-static NSArray *vpObservedLockConfigurations(id self, SEL _cmd) {
- NSArray *configurations = ((NSArray *(*)(id, SEL))vpOriginalLockConfigurations)(self, _cmd);
- vpFoldDisplayLog([NSString stringWithFormat:@"observed %s count=%lu", sel_getName(_cmd), (unsigned long)configurations.count]);
- return configurations;
-}
-
-// This initializer was not called in the baseline. Preserve its input exactly
-// if a different display transition eventually exercises it.
-static IMP vpOriginalMonitorInit;
-
-static id vpObservedMonitorInit(id self, SEL _cmd,
- NSArray *displays, id mainDisplay,
- id bookendObserver, id transformer) {
- id (*original)(id, SEL, NSArray *, id, id, id) = (id (*)(id, SEL, NSArray *, id, id, id))vpOriginalMonitorInit;
- return original(self, _cmd, displays, mainDisplay, bookendObserver, transformer);
-}
-
-// MARK: - single inner readiness
-
-// One physical panel can expose only the active fold surface. Test the
-// content-readiness boundary without promoting a virtual CADisplay, adding
-// a source, or bypassing the native one-result transformer invariant.
-// This hook is installed only for an explicitly consumed startup flag.
-void vpResolveSingleInnerDisplay(id self, SEL cmd, id proxy) {
- ((void (*)(id, SEL, id))vpOriginalStartResolvingDisplay)(self, cmd, proxy);
- if (vpLogicalRoleExperiment) {
- vpLogicalRoleResolver = self;
- vpSyncLogicalRoleResolver();
- return;
- }
- @try {
- NSDictionary *proxies = vpReadObjectIvar(self, "_displayProxies");
- if (proxies.count != 1 || proxies.allValues.firstObject != proxy ||
- [[self valueForKey:@"isReadyToResolve"] boolValue] ||
- [[proxy valueForKey:@"isExternal"] boolValue] ||
- [[proxy valueForKey:@"surfaceType"] integerValue] != 2) return;
- id monitor = vpReadObject(objc_getClass("FBDisplayManager"), "sharedInstance");
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- id identity = vpReadObject(configuration, "identity");
- NSSet *connected = vpReadObject(monitor, "connectedIdentities");
- if (connected.count != 1 || ![connected containsObject:identity] ||
- ![[identity valueForKey:@"isMainRootDisplay"] boolValue]) return;
- Ivar ready = class_getInstanceVariable(object_getClass(self), "_isReadyToResolve");
- SEL update = sel_registerName("_updateResolvedContentModesForDisplays");
- Method method = class_getInstanceMethod(object_getClass(self), update);
- if (!ready || strcmp(ivar_getTypeEncoding(ready), "B") != 0 ||
- !method || strcmp(method_getTypeEncoding(method), "v16@0:8") != 0) return;
- [self setValue:@YES forKey:@"isReadyToResolve"];
- vpFoldDisplayLog(@"single inner readiness: one real Main, one nonexternal inner proxy; native content resolution requested");
- ((void (*)(id, SEL))objc_msgSend)(self, update);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"single inner readiness exception: %@", exception.reason]);
- }
-}
-
-// MARK: - installation
-
-// Installed last in the constructor: an early return here leaves the
-// monitor half of the observation idle and nothing after it unset.
-void vpInstallDisplayPipelineObservation(void) {
- Class transformer = objc_getClass("SBMainDisplayConfigurationTransformer");
- Method transform = class_getInstanceMethod(transformer, sel_registerName("transformDisplayConfiguration:"));
- if (transform && strcmp(method_getTypeEncoding(transform), "@24@0:8@16") == 0) {
- vpOriginalTransform = method_setImplementation(transform, (IMP)vpLoggedTransform);
- vpFoldDisplayLog(@"transform probe installed");
- } else {
- vpFoldDisplayLog([NSString stringWithFormat:@"transform probe unavailable: %s",
- transform ? method_getTypeEncoding(transform) : "missing"]);
- }
- dlopen("/System/Library/PrivateFrameworks/FrontBoard.framework/FrontBoard",
- RTLD_LAZY | RTLD_LOCAL);
- Class manager = objc_getClass("FBDisplayManager");
- Method alwaysConnected = manager
- ? class_getClassMethod(manager, sel_registerName("alwaysConnectedIdentities"))
- : NULL;
- if (!alwaysConnected) {
- vpFoldDisplayLog(@"FBDisplayManager alwaysConnectedIdentities missing — idle");
- return;
- }
- vpOriginalAlwaysConnected = method_getImplementation(alwaysConnected);
- method_setImplementation(alwaysConnected, (IMP)vpObservedAlwaysConnected);
- vpFoldDisplayLog(@"observation installed over +alwaysConnectedIdentities");
-
- dlopen("/System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices",
- RTLD_LAZY | RTLD_LOCAL);
- Class monitor = objc_getClass("FBSDisplayMonitor");
- Method publicInit = class_getInstanceMethod(monitor, sel_registerName("initWithTransformer:"));
- if (publicInit && strcmp(method_getTypeEncoding(publicInit), "@24@0:8@16") == 0)
- vpOriginalPublicMonitorInit = method_setImplementation(publicInit, (IMP)vpObservePublicMonitorInit);
- Method completionInit = class_getInstanceMethod(monitor, sel_registerName("initWithInitializationCompletion:"));
- if (completionInit && strcmp(method_getTypeEncoding(completionInit), "@24@0:8@?16") == 0)
- vpOriginalCompletionMonitorInit = method_setImplementation(completionInit, (IMP)vpObserveCompletionMonitorInit);
- Method monitorInit = monitor
- ? class_getInstanceMethod(monitor,
- sel_registerName("_initWithDisplays:mainDisplay:bookendObserver:transformer:"))
- : NULL;
- if (!monitorInit) {
- vpFoldDisplayLog(@"FBSDisplayMonitor init missing — monitor half idle");
- return;
- }
- vpOriginalMonitorInit = method_getImplementation(monitorInit);
- method_setImplementation(monitorInit, (IMP)vpObservedMonitorInit);
- vpFoldDisplayLog(@"observation installed over _initWithDisplays:mainDisplay:bookendObserver:transformer:");
-
- Method identities = class_getInstanceMethod(monitor, sel_registerName("alwaysConnectedIdentities"));
- if (identities) {
- vpOriginalMonitorIdentities = method_getImplementation(identities);
- method_setImplementation(identities, (IMP)vpObservedMonitorIdentities);
- vpFoldDisplayLog(@"observation installed over -[FBSDisplayMonitor alwaysConnectedIdentities]");
- } else {
- vpFoldDisplayLog(@"FBSDisplayMonitor alwaysConnectedIdentities missing");
- }
- for (NSString *name in @[@"mainConfiguration", @"mainIdentity"]) {
- SEL selector = sel_registerName(name.UTF8String);
- Method method = class_getClassMethod(manager, selector);
- if (!method) {
- vpFoldDisplayLog([NSString stringWithFormat:@"FBDisplayManager %@ missing", name]);
- continue;
- }
- if (selector == sel_registerName("mainConfiguration")) {
- vpOriginalMainConfiguration = method_getImplementation(method);
- method_setImplementation(method, (IMP)vpLoggedMainConfiguration);
- } else {
- vpOriginalMainIdentity = method_getImplementation(method);
- method_setImplementation(method, (IMP)vpLoggedMainIdentity);
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"log installed over +[%@ %@]",
- NSStringFromClass(manager), name]);
- }
- Method configurations = class_getInstanceMethod(monitor, sel_registerName("_lock_alwaysConnectedConfigurations"));
- if (configurations) {
- vpOriginalLockConfigurations = method_getImplementation(configurations);
- method_setImplementation(configurations, (IMP)vpObservedLockConfigurations);
- vpFoldDisplayLog(@"observation installed over _lock_alwaysConnectedConfigurations");
- }
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPrivate.h b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPrivate.h
index ab26c576..fff3f000 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPrivate.h
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPrivate.h
@@ -1,10 +1,8 @@
#ifndef FOLD_DISPLAY_PRIVATE_H
#define FOLD_DISPLAY_PRIVATE_H
-// Shared by every libvphonefolddisplay translation unit: the state and
-// helpers one section owns and another reads, grouped by the file that
-// defines them (FoldDisplay<Section>.m; the constructor's state lives in
-// libvphonefolddisplay.m). State used by one file stays static there.
+// Shared by every libvphonefolddisplay translation unit, grouped by the file
+// that defines each declaration. State used by one file stays static there.
//
// Everything declared between the visibility pragmas is internal to the
// dylib: it links across files but stays out of the export table.
@@ -13,211 +11,42 @@
#import <CoreGraphics/CoreGraphics.h>
#import <objc/runtime.h>
#import <objc/message.h>
-#include "../MISFix/MISFixDetour.h"
#include <dlfcn.h>
+#include <fcntl.h>
#include <string.h>
-#include <stdatomic.h>
-#include <notify.h>
-#include <xpc/xpc.h>
-#include <sys/stat.h>
#include <sys/sysctl.h>
#include <unistd.h>
-#include <stdio.h>
+#include <xpc/xpc.h>
#pragma GCC visibility push(hidden)
-// MARK: - typed selector declarations
-@protocol VPhoneDisplayProjectionCopying
-- (instancetype)copyWithOverrideBounds:(CGRect)bounds;
-- (instancetype)copyWithOverrideMode:(id)mode;
-@end
-@protocol VPhoneDisplayModeCopying
-- (instancetype)_copyWithOverrideSize:(CGSize)size scale:(CGFloat)scale;
-@end
-
-// MARK: - logging and object readers
+// MARK: - FoldDisplaySupport.m
+extern NSString *const vpInnerDisplayName;
void vpFoldDisplayLog(NSString *line);
-BOOL vpConsumeDisplayExperimentFlag(const char *flag);
id vpReadObject(id object, const char *name);
-id vpReadMultilineDescription(id object);
id vpReadObjectIvar(id object, const char *name);
-id vpRootServerScenes(id app);
-NSNumber *vpReadBoolValue(id object, const char *name);
-NSValue *vpReadRectValue(id object, const char *name);
-id vpSnapshotRect(id object, const char *name);
-NSNumber *vpSnapshotScalarIvar(id object, const char *name);
-NSString *vpDescribeLayerContents(id contents);
-void vpDumpObjectIvars(id object, NSString *label, NSUInteger limit);
-NSString *vpSizeText(CGSize size);
-
-// MARK: - display configuration pipeline
-
-extern atomic_bool vpLogicalProjectionEnabled;
-extern __weak id vpLogicalRoleResolver;
-extern IMP vpOriginalStartResolvingDisplay;
-extern __weak id vpObservedConfigurationTransformer;
-extern NSHashTable *vpObservedDisplayMonitors;
-void vpRefreshMainTransform(void);
-BOOL vpIsDuoInnerBounds(id configuration);
-void vpResolveSingleInnerDisplay(id self, SEL cmd, id proxy);
-void vpInstallDisplayPipelineObservation(void);
-
-// MARK: - logical viewport
-
-extern atomic_bool vpCoverViewportEnabled;
-extern BOOL vpPersistentViewport;
-extern IMP vpOriginalLogicalSurfaceType;
-extern atomic_uint vpViewportRequestGeneration;
-extern atomic_bool vpNativeGeometryRefreshEnabled;
-extern atomic_bool vpSceneResizePropagationEnabled;
-extern IMP vpOriginalSBWindowResizePolicy;
-extern NSMutableDictionary<NSString *, NSNumber *> *vpResizedSceneGenerations;
-void vpScheduleViewportAdoption(void);
-void vpLogicalProjectionControl(NSInteger action);
-void vpSyncLogicalRoleResolver(void);
-BOOL vpAllowScopedMainWindowResize(id self, SEL cmd);
-void vpObserveSceneGeometry(id self, SEL cmd, id windowScene, id previousSpace, NSInteger previousOrientation, id previousTraits);
-void vpProcessViewportWorkspaceRequest(BOOL submit);
-void vpSetCoverViewport(BOOL enabled);
-NSInteger vpLogicalSurfaceType(id self, SEL selector);
-void vpSetPersistentViewport(BOOL cover);
-// MARK: - home-screen family
+// MARK: - FoldDisplayBackboard.m
-extern IMP vpOriginalSceneScreenType;
-NSUInteger vpNativeInnerSceneFamily(id self, SEL selector);
-void vpInstallSharedInnerFamily(void);
-void vpInstallViewportFamilyLookup(void);
-
-// MARK: - orientation map
-
-void vpExportNativeOrientationMapping(void);
-id vpSnapshotPoseDirections(id provider);
-
-// MARK: - interface orientation
-
-void vpProbeUnknownDisplayPolicy(BOOL restore);
-void vpRestoreRootSceneOrientations(void);
-void vpSyncRootSceneOrientation(void);
-id vpMainInnerWindowScene(void);
-id vpOrientationArbitrationScene(void);
-void vpRestoreSceneGeometryRequest(void);
-void vpProbeSceneGeometryRequest(void);
-void vpRefreshNativeOrientationInputs(BOOL rereadPose);
-void vpForceNativeOrientationResolution(void);
-void vpSetCanonicalOrientationProbe(BOOL enabled);
-void vpRefreshNativeOrientationActuation(void);
-void vpRestoreEmbeddedOrientation(void);
-void vpProbeEmbeddedOrientation(void);
-void vpSnapshotBackboardOrientation(void);
-void vpRestoreBackboardOrientationEvents(void);
-void vpProbeBackboardOrientationEvents(void);
-
-// MARK: - status bar
-
-extern BOOL vpLogicalRoleExperiment;
-extern IMP vpOriginalTimeItemUpdate;
-extern IMP vpOriginalMachClockTick, vpOriginalMachClockObserve;
-extern atomic_bool vpStatusProfileLookupEnabled;
-extern _Thread_local void *vpStatusProfileConstructionScene;
-void vpRefreshNativeStatusRegistration(void);
-void vpMachClockTick(id self, SEL selector);
-id vpMachClockObserve(id self, SEL selector, id handler);
-void vpObserveNativeTimeUpdate(id self, SEL selector, id date);
-void vpRefreshNativeClockSource(void);
-BOOL vpIsSingleMainStatusScene(id scene, BOOL constructing);
-void vpInstallSceneStatusPolicy(void);
-void vpInstallMainStatusLookup(void);
-void vpInstallDualStatusLookup(void);
-void vpRefreshMainStatusRenderer(void);
-void vpRestoreMainStatusProfile(void);
-void vpPulseMainStatusProfile(void);
-void vpResetManagedStatusProvider(void);
-void vpRestoreStatusProfileLookup(void);
-void vpPulseStatusProfileLookup(void);
-
-// MARK: - UIKit configuration and traits
-
-extern __weak id vpUIConfigWindowScene;
-extern id vpUIConfigPublished;
-void vpPreviewNonEmbeddedUIConfiguration(void);
-void vpSyncUIScreenTraits(void);
-void vpRefreshUIStatusComponent(void);
-void vpRestoreUIConfiguration(void);
-void vpActivateUIConfiguration(void);
-void vpPulseUIConfiguration(BOOL nonEmbedded);
-void vpPreviewUISceneConfiguration(void);
-
-// MARK: - wallpaper
-
-void vpPulseNativeWallpaperOrientation(void);
-void vpDumpWallpaperTree(id view, NSUInteger depth);
-void vpSyncWallpaperSceneHosts(void);
-BOOL vpInstallWallpaperOrientationBridge(void);
-void vpInstallWallpaperTraitsExperiment(void);
-void vpInstallLandscapeWallpaperGateDetour(void);
-
-// MARK: - quick actions
-
-void vpInspectQuickActions(void);
-void vpApplyQuickActionGlyphScale(void);
-void vpScheduleQuickActionGlyphScale(void);
-
-// MARK: - backboardd surface probe
-
-extern IMP vpOriginalExtendedProperties;
-extern atomic_bool vpInnerSurfaceProbeEnabled;
-extern atomic_uint vpPrimarySurfaceType;
-id vpSurfaceExtendedProperties(id self, SEL cmd);
-void vpBeginSurfaceProbe(unsigned int surfaceType, BOOL pair);
-
-// MARK: - virtual display
-
-void vpInspectServerClass(void);
-void vpInspectRenderDisplays(void);
-void vpEnableVirtualDisplayProbe(void);
-BOOL vpTagUnknownDisplay(id display);
-void vpTagVirtualDisplayProbe(void);
-void vpVirtualDisplayExperiment(BOOL create);
+void vpInstallInnerRenderDisplay(void);
-// MARK: - inner display spike
+// MARK: - FoldDisplayAdapter.m
-BOOL vpInnerDisplayRequested(void);
-NSNumber *vpInnerDisplaySurfaceType(id deviceName);
-void vpInstallInnerRenderDisplay(void);
-BOOL vpAddInnerRenderDisplayToServer(id server);
-void vpInstallInnerBootDisplay(void);
-void vpLogRenderDisplayState(void);
-void vpShowInnerDisplay(BOOL shown);
-void vpToggleInnerPattern(void);
-void vpResolveInnerDisplay(void);
+BOOL vpIsInnerDisplay(id display);
+BOOL vpSceneIsOnInnerDisplay(id scene);
+/// The SpringBoard window scene (not an aperture subclass) on the inner
+/// display, or on Main.
+id vpSpringBoardWindowScene(BOOL inner);
void vpInstallInnerDisplayAdapter(void);
-void vpInstallInnerTouch(void);
-void vpInspectInnerDisplay(void);
-// MARK: - diagnostics
+// MARK: - FoldDisplayPanel.m
-extern id vpStashedConfig;
-void vpInspectDuoSystemUI(void);
-void vpInspectStatusProvider(void);
-void vpPulseInputTrace(void);
-void vpRestoreInputTrace(void);
-void vpInspectHomeScreenType(void);
-void vpSnapshotMainScene(void);
-void vpDumpDeviceConfiguration(id config);
-void vpInstallConfigInitSwizzle(void);
-void vpInstallLayoutClassSwizzle(void);
-void vpInspectAllWindows(void);
-void vpUndimScreenOnly(void);
-void vpInspectNativePresentation(void);
-void vpInspectDisplayState(void);
+void vpInstallSharedPanel(void);
-// MARK: - constructor state (libvphonefolddisplay.m)
+// MARK: - FoldDisplayStatusBar.m
-extern atomic_bool vpCoordinateRootSceneFrame;
-extern IMP vpOriginalSceneGeometryCallback;
-extern BOOL vpAutomaticMainStatus;
+void vpInstallDualStatusLookup(void);
#pragma GCC visibility pop
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayQuickActions.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayQuickActions.m
deleted file mode 100644
index ad8176f8..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayQuickActions.m
+++ /dev/null
@@ -1,204 +0,0 @@
-// Lock-screen quick action buttons: inspection and glyph scaling.
-
-#import "FoldDisplayPrivate.h"
-
-// MARK: - inspection
-
-// Lock-screen quick-action diagnostics: locate live CSQuickAction* views,
-// record their geometry, traits and raw ivar state, and dump the native
-// class surfaces so the profile selection can be read from evidence.
-void vpInspectQuickActions(void) {
- @try {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id device = vpReadObject(objc_getClass("UIDevice"), "currentDevice");
- vpFoldDisplayLog([NSString stringWithFormat:@"quick action device: model=%@ name=%@ idiom=%ld orientation=%ld",
- [device valueForKey:@"model"], [device valueForKey:@"name"],
- (long)((NSInteger (*)(id, SEL))objc_msgSend)(device, sel_registerName("userInterfaceIdiom")),
- (long)((NSInteger (*)(id, SEL))objc_msgSend)(device, sel_registerName("orientation"))]);
- NSUInteger found = 0;
- for (id window in vpReadObject(app, "windows")) {
- NSMutableArray *pending = [NSMutableArray arrayWithObject:window];
- while (pending.count) {
- id view = pending.lastObject;
- [pending removeLastObject];
- NSString *className = NSStringFromClass([view class]);
- BOOL quickAction = [className containsString:@"QuickAction"];
- BOOL prominent = [className containsString:@"Prominent"];
- if ((quickAction || prominent) && found < 10) {
- found++;
- vpFoldDisplayLog([NSString stringWithFormat:@"quick action view: class=%@ frame=%@ alpha=%@ hidden=%@",
- className, [view valueForKey:@"frame"], [view valueForKey:@"alpha"], [view valueForKey:@"hidden"]]);
- vpDumpObjectIvars(view, @"quick action instance", 48);
- if ([className isEqualToString:@"CSQuickActionImageGlyphView"]) {
- // The glyph's geometry chain: the size the button's
- // layout set, the symbol's own size, the container
- // the scale lives on, and the size that reaches the
- // window.
- id superview = [view valueForKey:@"superview"];
- CGRect bounds = ((CGRect (*)(id, SEL))objc_msgSend)(view, sel_registerName("bounds"));
- CGRect onScreen = ((CGRect (*)(id, SEL, CGRect, id))objc_msgSend)(view,
- sel_registerName("convertRect:toView:"), bounds, nil);
- vpFoldDisplayLog([NSString stringWithFormat:@"quick action glyph: bounds=%@ transform=%@ image=%@ window={%.1f, %.1f} container=%@ %@ subviews=%lu sublayerTransform=%@",
- vpSizeText(bounds.size), [view valueForKey:@"transform"],
- [vpReadObjectIvar(view, "_image") valueForKey:@"size"],
- onScreen.size.width, onScreen.size.height,
- NSStringFromClass([superview class]), [superview valueForKey:@"bounds"],
- (unsigned long)[[superview valueForKey:@"subviews"] count],
- [[superview valueForKey:@"layer"] valueForKey:@"sublayerTransform"]]);
- }
- if ([className isEqualToString:@"CSQuickActionsButton"]) {
- // Read-only computed getters; they reveal which metric
- // row the native layout resolved for this instance.
- // These selectors belong to the button, not the glyph.
- SEL sizeSelector = sel_registerName("iconImageSize");
- SEL frameSelector = sel_registerName("iconImageFrame");
- SEL diameterSelector = sel_registerName("buttonDiameter");
- if ([view respondsToSelector:sizeSelector]) {
- CGSize size = ((CGSize (*)(id, SEL))objc_msgSend)(view, sizeSelector);
- vpFoldDisplayLog([NSString stringWithFormat:@"quick action computed: iconImageSize={%g, %g}", size.width, size.height]);
- }
- if ([view respondsToSelector:frameSelector]) {
- CGRect rect = ((CGRect (*)(id, SEL))objc_msgSend)(view, frameSelector);
- vpFoldDisplayLog([NSString stringWithFormat:@"quick action computed: iconImageFrame={{%g, %g}, {%g, %g}}",
- rect.origin.x, rect.origin.y, rect.size.width, rect.size.height]);
- }
- if ([view respondsToSelector:diameterSelector]) {
- double diameter = ((double (*)(id, SEL))objc_msgSend)(view, diameterSelector);
- vpFoldDisplayLog([NSString stringWithFormat:@"quick action computed: buttonDiameter=%.6g", diameter]);
- }
- }
- if ([className isEqualToString:@"CSQuickActionsView"]) {
- vpDumpObjectIvars(vpReadObjectIvar(view, "_quickActionsSettings"), @"quick action settings", 96);
- vpDumpObjectIvars(vpReadObjectIvar(view, "_buttonContainerView"), @"quick action buttons container", 48);
- }
- }
- for (id child in [view valueForKey:@"subviews"] ?: @[]) [pending addObject:child];
- }
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"quick action inventory: views=%lu", (unsigned long)found]);
- // The layout controller, its adaptive time context, and the determined
- // configuration hang off the quick-action objects' ivar graph.
- if (vpStashedConfig) {
- vpDumpDeviceConfiguration(vpStashedConfig);
- } else {
- vpFoldDisplayLog(@"live device configuration: not constructed yet");
- }
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"quick action exception: %@", exception.reason]);
- }
-}
-
-// MARK: - glyph scale
-
-// The Duo cover sheet lays the glyphs out at 20x37pt (flashlight) and
-// 35x26pt (camera) inside a 48pt icon; a real iPhone Duo's landscape lock
-// screen draws them at about 15x27pt and 23x17pt in the same 48pt icon.
-// Those are 0.75 and 0.66 of the layout sizes, one factor within the
-// measurement, so both glyphs take vpQuickActionGlyphScale and keep the
-// per-symbol proportions the native layout gives them (the user's earlier
-// visual check had settled on 0.68).
-//
-// The lever is the glyph's transform, but the button lays the glyph out with
-// setFrame:, which on a transformed view grows the bounds until the visual
-// frame is the native size again. Whether a glyph looked scaled depended on
-// whether a layout pass followed the walk. Each glyph therefore moves to a
-// runtime subclass (as KVO does) whose setFrame: sets center and bounds from
-// the layout rect, so the transform survives every later pass. The glyph
-// class's own method list is never written: its image's method pages are
-// read-only and method_setImplementation there faults (round-12/13).
-static double const vpQuickActionGlyphScale = 0.70;
-static atomic_uint vpQuickActionScaleGeneration;
-static Class vpQuickActionGlyphSubclass;
-static IMP vpQuickActionGlyphSetFrame;
-
-static void vpQuickActionGlyphSetFrameReplacement(id self, SEL selector, CGRect frame) {
- CGAffineTransform transform = ((CGAffineTransform (*)(id, SEL))objc_msgSend)(self, sel_registerName("transform"));
- if (CGAffineTransformIsIdentity(transform)) {
- ((void (*)(id, SEL, CGRect))vpQuickActionGlyphSetFrame)(self, selector, frame);
- return;
- }
- CGRect bounds = ((CGRect (*)(id, SEL))objc_msgSend)(self, sel_registerName("bounds"));
- bounds.size = frame.size;
- ((void (*)(id, SEL, CGRect))objc_msgSend)(self, sel_registerName("setBounds:"), bounds);
- ((void (*)(id, SEL, CGPoint))objc_msgSend)(self, sel_registerName("setCenter:"),
- CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame)));
-}
-
-static Class vpQuickActionGlyphReportedClass(id self, SEL selector) {
- return class_getSuperclass(object_getClass(self));
-}
-
-// Moves one glyph to the layout-preserving subclass. Refuses a glyph whose
-// class is already someone else's subclass (a KVO observer, say).
-static BOOL vpAdoptQuickActionGlyph(id view, Class glyphClass) {
- Class current = object_getClass(view);
- if (current == vpQuickActionGlyphSubclass && current) return YES;
- if (current != glyphClass) return NO;
- if (!vpQuickActionGlyphSubclass) {
- SEL setFrame = sel_registerName("setFrame:");
- Method method = class_getInstanceMethod(glyphClass, setFrame);
- if (!method) return NO;
- Class subclass = objc_allocateClassPair(glyphClass, "VPhoneQuickActionGlyphView", 0);
- if (!subclass) return NO;
- vpQuickActionGlyphSetFrame = method_getImplementation(method);
- class_addMethod(subclass, setFrame, (IMP)vpQuickActionGlyphSetFrameReplacement, method_getTypeEncoding(method));
- class_addMethod(subclass, sel_registerName("class"), (IMP)vpQuickActionGlyphReportedClass, "#16@0:8");
- objc_registerClassPair(subclass);
- vpQuickActionGlyphSubclass = subclass;
- }
- object_setClass(view, vpQuickActionGlyphSubclass);
- return YES;
-}
-
-void vpApplyQuickActionGlyphScale(void) {
- @try {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- Class glyphClass = objc_getClass("CSQuickActionImageGlyphView");
- if (!app || !glyphClass) return;
- NSUInteger touched = 0, rescaled = 0, refused = 0;
- for (id window in vpReadObject(app, "windows")) {
- NSMutableArray *pending = [NSMutableArray arrayWithObject:window];
- while (pending.count) {
- id view = pending.lastObject;
- [pending removeLastObject];
- for (id child in [view valueForKey:@"subviews"] ?: @[]) [pending addObject:child];
- if (![view isKindOfClass:glyphClass]) continue;
- touched++;
- // The subclass keeps bounds equal to the layout size, so the
- // transform alone sets the drawn size.
- if (!vpAdoptQuickActionGlyph(view, glyphClass)) { refused++; continue; }
- CGRect bounds = ((CGRect (*)(id, SEL))objc_msgSend)(view, sel_registerName("bounds"));
- // Not laid out yet; a later pass catches it.
- if (bounds.size.width < 1 || bounds.size.height < 1) continue;
- double scale = vpQuickActionGlyphScale;
- CGAffineTransform current = ((CGAffineTransform (*)(id, SEL))objc_msgSend)(view, sel_registerName("transform"));
- if (fabs(current.a - scale) < 0.001 && fabs(current.d - scale) < 0.001 && current.b == 0 && current.c == 0) continue;
- ((void (*)(id, SEL, CGAffineTransform))objc_msgSend)(view, sel_registerName("setTransform:"),
- CGAffineTransformMakeScale(scale, scale));
- rescaled++;
- }
- }
- if (rescaled || refused)
- vpFoldDisplayLog([NSString stringWithFormat:@"quick action glyph scale: %lu of %lu views rescaled, %lu refused",
- (unsigned long)rescaled, (unsigned long)touched, (unsigned long)refused]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"quick action glyph scale exception: %@", exception.reason]);
- }
-}
-
-// The native orientation callback starts a new CoverSheet layout; its glyph
-// views can be rebuilt after the callback returns. Apply on the next main-queue
-// turn and at two short settling points, while coalescing stale rotation
-// schedules. Repeated passes are no-ops once a glyph carries its scale.
-void vpScheduleQuickActionGlyphScale(void) {
- if (!vpAutomaticMainStatus) return;
- unsigned int generation = atomic_fetch_add_explicit(&vpQuickActionScaleGeneration, 1, memory_order_acq_rel) + 1;
- const double delays[] = {0.0, 0.12, 0.4};
- for (NSUInteger index = 0; index < sizeof(delays) / sizeof(delays[0]); ++index) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delays[index] * NSEC_PER_SEC)),
- dispatch_get_main_queue(), ^{
- if (generation != atomic_load_explicit(&vpQuickActionScaleGeneration, memory_order_acquire)) return;
- vpApplyQuickActionGlyphScale();
- });
- }
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayScreenFamily.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayScreenFamily.m
deleted file mode 100644
index 1e53af09..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayScreenFamily.m
+++ /dev/null
@@ -1,158 +0,0 @@
-// Home-screen family classification: the inner scene's native family and the
-// viewport-scoped family lookups.
-
-#import "FoldDisplayPrivate.h"
-
-IMP vpOriginalSceneScreenType;
-static NSUInteger vpInnerNativeScreenType;
-static atomic_uint vpInnerFamilyLogCount;
-static void *vpOriginalSharedFamilyClassifier;
-static void *vpOriginalViewportScreenFamily, *vpOriginalViewportGlobalFamily;
-static _Thread_local BOOL vpViewportFamilyLookupActive;
-static _Thread_local unsigned int vpGlobalFamilyDepth;
-static atomic_uint vpGlobalFamilyTraceCount;
-static atomic_uint vpSharedFamilyLogCount;
-
-// Classify a distinct reference context; never publish its 669pt geometry.
-// This tests the shared scene family decision used by system consumers,
-// including the native status-bar rotation gate, rather than one provider.
-NSUInteger vpNativeInnerSceneFamily(id self, SEL selector) {
- NSUInteger original = ((NSUInteger (*)(id, SEL))vpOriginalSceneScreenType)(self, selector);
- @try {
- if (![[self valueForKey:@"surfaceType"] isEqual:@2]) return original;
- id identity = vpReadObject(self, "displayIdentity");
- // SBWindowScene has no displayConfiguration on this build. Resolve
- // Main through FrontBoard and verify its identity before using it.
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- if (![[identity valueForKey:@"isMainRootDisplay"] boolValue] ||
- ![identity isEqual:vpReadObject(configuration, "identity")]) return original;
- CGRect bounds = ((CGRect (*)(id, SEL))objc_msgSend)(configuration, sel_registerName("bounds"));
- if (!CGSizeEqualToSize(bounds.size, CGSizeMake(678, 951))) return original;
- if (!vpInnerNativeScreenType) {
- void *home = dlopen("/System/Library/PrivateFrameworks/SpringBoardHome.framework/SpringBoardHome", RTLD_LAZY | RTLD_LOCAL);
- NSUInteger (*classify)(id, id) = dlsym(home, "SBHScreenTypeForDeviceAndDisplayContexts");
- id device = vpReadObject(objc_getClass("UISDeviceContext"), "sb_defaultContext");
- id display = vpReadObject(self, "_sbDisplayContext");
- id copy = [display mutableCopy];
- Method setter = class_getInstanceMethod(object_getClass(copy), sel_registerName("setDisplayConfiguration:"));
- if (!classify || !device || !copy || copy == display || !setter ||
- strcmp(method_getTypeEncoding(setter), "v24@0:8@16") != 0) return original;
- id mode = vpReadObject(configuration, "currentMode");
- CGFloat scale = ((CGFloat (*)(id, SEL))objc_msgSend)(mode, sel_registerName("pointScale"));
- id referenceMode = [(id<VPhoneDisplayModeCopying>)mode _copyWithOverrideSize:CGSizeMake(669, 951) scale:scale];
- id reference = [(id<VPhoneDisplayProjectionCopying>)configuration copyWithOverrideMode:referenceMode];
- ((void (*)(id, SEL, id))objc_msgSend)(copy, sel_registerName("setDisplayConfiguration:"), reference);
- NSUInteger candidate = classify(device, copy);
- if (candidate != 32) return original;
- vpInnerNativeScreenType = candidate;
- }
- if (atomic_fetch_add_explicit(&vpInnerFamilyLogCount, 1, memory_order_relaxed) < 4)
- vpFoldDisplayLog([NSString stringWithFormat:@"shared scene family: native reference=%lu original=%lu actual=%gx%g",
- (unsigned long)vpInnerNativeScreenType, (unsigned long)original, bounds.size.width, bounds.size.height]);
- return vpInnerNativeScreenType;
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"shared scene family exception: %@", exception.reason]);
- return original;
- }
-}
-
-static NSUInteger vpSharedInnerFamily(uintptr_t a, uintptr_t b, uintptr_t c, CGRect bounds,
- CGFloat scale, CGFloat referenceScale) {
- // The native common helper receives x0..x2 plus the CGRect HFA in
- // d0..d3 and two scalars in d4/d5. Both exported context and screen
- // classifiers use this helper; hooking their wrapper misses UIScreen.
- NSUInteger (*original)(uintptr_t, uintptr_t, uintptr_t, CGRect, CGFloat, CGFloat) = vpOriginalSharedFamilyClassifier;
- NSUInteger native = original(a, b, c, bounds, scale, referenceScale);
- @try {
- if (!CGSizeEqualToSize(bounds.size, CGSizeMake(678, 951))) return native;
- CGRect reference = bounds;
- reference.size.width = 669;
- NSUInteger family = original(a, b, c, reference, scale, referenceScale);
- if (family != 32) return native;
- if (atomic_fetch_add_explicit(&vpSharedFamilyLogCount, 1, memory_order_relaxed) < 6)
- vpFoldDisplayLog([NSString stringWithFormat:@"shared classifier: native=%lu reference=%lu actual=%gx%g",
- (unsigned long)native, (unsigned long)family, bounds.size.width, bounds.size.height]);
- return family;
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"shared classifier exception: %@", exception.reason]);
- return native;
- }
-}
-
-void vpInstallSharedInnerFamily(void) {
- void *home = dlopen("/System/Library/PrivateFrameworks/SpringBoardHome.framework/SpringBoardHome", RTLD_LAZY | RTLD_LOCAL);
- void *target = dlsym(home, "_SBHScreenTypeLookupCommon");
- MISFixDetourResult (*install)(const char *, void *, void *, void **) = dlsym(RTLD_DEFAULT, "MISFixDetour");
- if (!target || !install) { vpFoldDisplayLog(@"shared classifier: existing detour API unavailable"); return; }
- // The existing constructor-only detour checks relocation and readback,
- // uses process-private COW cache pages, and publishes the trampoline
- // before its jump. Nothing in the on-disk cache or other processes changes.
- MISFixDetourResult result = install("Duo shared screen classifier", target, (void *)vpSharedInnerFamily,
- &vpOriginalSharedFamilyClassifier);
- vpFoldDisplayLog([NSString stringWithFormat:@"shared classifier: constructor detour result=%d", result]);
-}
-
-// The physical screen's family caches are boot-scoped. During an explicit
-// same-Main viewport lease, ask the native context classifier about the
-// currently published scene instead; do not overwrite dispatch_once state
-// or associated objects, and never affect another screen.
-static NSUInteger vpViewportFamily(id requestedScreen, NSUInteger fallback) {
- if (!atomic_load_explicit(&vpCoverViewportEnabled, memory_order_acquire) ||
- ![NSThread isMainThread] || vpViewportFamilyLookupActive) return fallback;
- vpViewportFamilyLookupActive = YES;
- @try {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id scene = vpReadObject(app, "embeddedDisplayWindowScene");
- id screen = vpReadObject(scene, "screen");
- id root = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- if (!scene || (requestedScreen && requestedScreen != screen) ||
- ![vpReadObject(vpReadObject(scene, "_FBSScene"), "identifier") isEqual:@"SB-main"] ||
- ![vpReadObject(screen, "displayIdentity") isEqual:vpReadObject(root, "identity")]) return fallback;
- id context = vpReadObject(scene, "_sbDisplayContext");
- id device = vpReadObject(objc_getClass("UISDeviceContext"), "sb_defaultContext");
- NSUInteger (*classify)(id, id) = dlsym(RTLD_DEFAULT, "SBHScreenTypeForDeviceAndDisplayContexts");
- if (!context || !device || !classify) return fallback;
- NSUInteger result = classify(device, context);
- return (result == 31 || result == 32) ? result : fallback;
- } @catch (NSException *exception) {
- return fallback;
- } @finally { vpViewportFamilyLookupActive = NO; }
-}
-
-static NSUInteger vpViewportScreenFamily(id screen) {
- return vpViewportFamily(screen, ((NSUInteger (*)(id))vpOriginalViewportScreenFamily)(screen));
-}
-// No Foundation formatting here: classification can be called while native
-// once-initializers are holding locks. Bounded raw records also survive a
-// blocked main queue and identify which side of the trampoline was reached.
-static void vpTraceGlobalFamily(const char *phase, unsigned int sequence, NSUInteger value, void *caller) {
- if (sequence >= 24) return;
- int fd = open("/var/mobile/Library/Caches/vphone-duo-family-trace.log",
- O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC | O_NOFOLLOW, 0644);
- if (fd < 0) return;
- char line[512];
- int length = snprintf(line, sizeof(line), "pid=%d seq=%u depth=%u phase=%s value=%lu caller=%p",
- getpid(), sequence, vpGlobalFamilyDepth, phase, (unsigned long)value, caller);
- if (length > 0 && length < (int)sizeof(line) - 1) { line[length++] = '\n'; write(fd, line, (size_t)length); }
- close(fd);
-}
-static NSUInteger vpViewportGlobalFamily(void) {
- unsigned int sequence = atomic_fetch_add_explicit(&vpGlobalFamilyTraceCount, 1, memory_order_relaxed);
- ++vpGlobalFamilyDepth;
- vpTraceGlobalFamily("enter-original", sequence, 0, __builtin_return_address(0));
- NSUInteger original = ((NSUInteger (*)(void))vpOriginalViewportGlobalFamily)();
- vpTraceGlobalFamily("returned-original", sequence, original, __builtin_return_address(0));
- NSUInteger result = vpViewportFamily(nil, original);
- vpTraceGlobalFamily("returned-context", sequence, result, __builtin_return_address(0));
- --vpGlobalFamilyDepth;
- return result;
-}
-void vpInstallViewportFamilyLookup(void) {
- MISFixDetourResult (*install)(const char *, void *, void *, void **) = dlsym(RTLD_DEFAULT, "MISFixDetour");
- void *screen = dlsym(RTLD_DEFAULT, "SBHScreenTypeForScreen");
- void *global = dlsym(RTLD_DEFAULT, "SBHScreenTypeForCurrentDevice");
- if (!install || !screen || !global) return;
- MISFixDetourResult a = install("Duo viewport screen family", screen, (void *)vpViewportScreenFamily, &vpOriginalViewportScreenFamily);
- MISFixDetourResult b = install("Duo viewport global family", global, (void *)vpViewportGlobalFamily, &vpOriginalViewportGlobalFamily);
- vpFoldDisplayLog([NSString stringWithFormat:@"viewport native family: screen=%d global=%d", a, b]);
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayStatusBar.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayStatusBar.m
index 7995a16e..469acb3b 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayStatusBar.m
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayStatusBar.m
@@ -1,187 +1,10 @@
-// Status bar: native status registration, the clock source, the scene status
-// policy, and the visual provider profile lookup.
+// SpringBoard: each screen's status bar provider, chosen for its own panel.
#import "FoldDisplayPrivate.h"
+#include "../MISFix/MISFixDetour.h"
-BOOL vpLogicalRoleExperiment;
-static IMP vpOriginalSceneIsMain, vpOriginalStatusManagerInit, vpOriginalStatusManagerEmbedded;
-static _Thread_local void *vpStatusManagerInitializingScene;
-static _Thread_local BOOL vpStatusManagerMainQueryConsumed;
-IMP vpOriginalTimeItemUpdate;
-IMP vpOriginalMachClockTick, vpOriginalMachClockObserve;
-static atomic_uint vpClockReferenceFallbackCount;
-static atomic_uint vpTimeItemTraceCount;
-static _Atomic(IMP) vpOriginalStatusProfileFactories[4];
-atomic_bool vpStatusProfileLookupEnabled;
-static unsigned int vpStatusProfileGeneration;
-static unsigned int vpStatusProfileCallCount;
-_Thread_local void *vpStatusProfileConstructionScene;
-static _Thread_local unsigned int vpStatusProfileFactoryDepth;
-static __weak id vpStatusProfileScene;
-static void *vpOriginalMainStatusClassLookup;
-static atomic_bool vpMainStatusProfileEnabled;
-static unsigned int vpMainStatusProfileGeneration, vpMainStatusProfileLogCount;
-static __weak id vpMainStatusProfileScene;
-static Class vpMainStatusOriginalProviderClass;
-
-// MARK: - status registration and clock
-
-void vpRefreshNativeStatusRegistration(void) {
- if (!vpLogicalRoleExperiment) return;
- id scene = vpMainInnerWindowScene();
- id bar = vpReadObject(vpReadObject(scene, "statusBarManager"), "statusBar");
- if (!bar || vpReadBoolValue(bar, "serverUpdatesDisabled").boolValue || vpReadBoolValue(bar, "isHidden").boolValue) return;
- SEL toggle = sel_registerName("setServerUpdatesDisabled:");
- SEL update = sel_registerName("forceUpdateData:");
- Method tm = class_getInstanceMethod(object_getClass(bar), toggle);
- Method um = class_getInstanceMethod(object_getClass(bar), update);
- if (!tm || !um || strcmp(method_getTypeEncoding(tm), "v20@0:8B16") != 0 ||
- strcmp(method_getTypeEncoding(um), "v20@0:8B16") != 0) return;
- @try {
- ((void (*)(id, SEL, BOOL))objc_msgSend)(bar, toggle, YES);
- } @finally {
- ((void (*)(id, SEL, BOOL))objc_msgSend)(bar, toggle, NO);
- }
- ((void (*)(id, SEL, BOOL))objc_msgSend)(bar, update, YES);
- vpFoldDisplayLog(@"native status registration: visible scene client re-registered and requested native data");
-}
-
-// Native minute scheduling already supports a nil reference view (zero
-// frame-phase adjustment). A detached but alive view instead follows the
-// nonnil path and divides by its absent screen's0 FPS. Use the native nil
-// branch only while the reference cannot supply a valid screen cadence.
-static id vpWithUsableClockReference(id provider, id (^operation)(void)) {
- Ivar ivar = class_getInstanceVariable(object_getClass(provider), "_referenceView");
- if (!vpLogicalRoleExperiment || ![NSThread isMainThread] || !ivar || ivar_getTypeEncoding(ivar)[0] != '@') return operation();
- id reference = vpReadObjectIvar(provider, "_referenceView");
- id screen = vpReadObject(vpReadObject(vpReadObject(reference, "window"), "windowScene"), "screen");
- NSMethodSignature *fpsSignature = [screen methodSignatureForSelector:sel_registerName("maximumFramesPerSecond")];
- NSInteger fps = 0;
- if (fpsSignature && fpsSignature.numberOfArguments == 2 &&
- (fpsSignature.methodReturnType[0] == 'q' || fpsSignature.methodReturnType[0] == 'Q'))
- fps = ((NSInteger (*)(id, SEL))objc_msgSend)(screen, sel_registerName("maximumFramesPerSecond"));
- if (!reference || fps > 0) return operation();
- // initWithReferenceView: uses objc_storeWeak for this slot. The runtime
- // setter preserves known weak memory management (objc/runtime.h).
- object_setIvar(provider, ivar, nil);
- @try {
- if (atomic_fetch_add_explicit(&vpClockReferenceFallbackCount, 1, memory_order_relaxed) < 4)
- vpFoldDisplayLog([NSString stringWithFormat:@"native clock reference fallback: class=%s screen=%p fps=%ld", object_getClassName(reference), screen, (long)fps]);
- return operation();
- } @finally {
- if (!object_getIvar(provider, ivar)) object_setIvar(provider, ivar, reference);
- }
-}
-void vpMachClockTick(id self, SEL selector) {
- vpWithUsableClockReference(self, ^id {
- ((void (*)(id, SEL))vpOriginalMachClockTick)(self, selector);
- // A once-a-minute bounded walk re-scales glyph instances that a
- // lock-screen rebuild created at the native factor.
- if (vpAutomaticMainStatus) vpApplyQuickActionGlyphScale();
- return nil;
- });
-}
-id vpMachClockObserve(id self, SEL selector, id handler) {
- return vpWithUsableClockReference(self, ^id {
- return ((id (*)(id, SEL, id))vpOriginalMachClockObserve)(self, selector, handler);
- });
-}
-
-void vpObserveNativeTimeUpdate(id self, SEL selector, id date) {
- unsigned int count = atomic_fetch_add_explicit(&vpTimeItemTraceCount, 1, memory_order_relaxed);
- NSString *before = count < 20 ? [vpReadObjectIvar(self, "_timeItemTimeString") copy] : nil;
- ((void (*)(id, SEL, id))vpOriginalTimeItemUpdate)(self, selector, date);
- if (count < 20) {
- id current = vpReadObject(vpReadObjectIvar(self, "_dateTimeProvider"), "date");
- id provider = vpReadObjectIvar(self, "_dateTimeProvider");
- id underlying = vpReadObjectIvar(provider, "_underlyingProvider");
- NSString *interval = [date isKindOfClass:NSDate.class] ? [NSString stringWithFormat:@"%.17g", [(NSDate *)date timeIntervalSinceReferenceDate]] : @"not-date";
- vpFoldDisplayLog([NSString stringWithFormat:@"native clock update: input=%@ class=%s interval=%@ current=%@ underlying=%s underlyingDate=%@ before=%@ after=%@ caller=%p",
- date, date ? object_getClassName(date) : "nil", interval, current,
- underlying ? object_getClassName(underlying) : "nil", vpReadObject(underlying, "date"), before,
- vpReadObjectIvar(self, "_timeItemTimeString"), __builtin_return_address(0)]);
- }
-}
-
-void vpRefreshNativeClockSource(void) {
- if (!vpLogicalRoleExperiment) return;
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id aggregator = vpReadObject(app, "statusBarStateAggregator");
- SEL refresh = sel_registerName("_restartTimeItemTimer");
- Method method = class_getInstanceMethod(object_getClass(aggregator), refresh);
- if (!method || strcmp(method_getTypeEncoding(method), "v16@0:8") != 0) return;
- ((void (*)(id, SEL))objc_msgSend)(aggregator, refresh);
- vpFoldDisplayLog(@"native clock source: native time-item subscription restarted");
-}
-
-// MARK: - scene status policy
-
-BOOL vpIsSingleMainStatusScene(id scene, BOOL constructing) {
- if (![vpReadObject(vpReadObject(scene, "_FBSScene"), "identifier") isEqual:@"SB-main"]) return NO;
- NSInteger surface = [[scene valueForKey:@"surfaceType"] integerValue];
- // During UIKit status-manager construction SB's surface property may
- // still be default. This path is armed only for the explicit inner boot.
- if (surface != 2 && !(constructing && surface == 0)) return NO;
- id identity = vpReadObject(scene, "_fbsDisplayIdentity") ?: vpReadObject(scene, "displayIdentity");
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- return [[identity valueForKey:@"isMainRootDisplay"] boolValue] &&
- [identity isEqual:vpReadObject(configuration, "identity")] &&
- [vpSnapshotRect(configuration, "bounds") isEqual:@[@0, @0, @669, @951]];
-}
-
-static BOOL vpSceneMainDuringStatusConstruction(id self, SEL selector) {
-if ((__bridge void *)self == vpStatusManagerInitializingScene && !vpStatusManagerMainQueryConsumed) {
- vpStatusManagerMainQueryConsumed = YES;
- vpFoldDisplayLog([NSString stringWithFormat:@"scene status construction: single Main query redirected caller=%p", __builtin_return_address(0)]);
- return NO;
- }
- return ((BOOL (*)(id, SEL))vpOriginalSceneIsMain)(self, selector);
-}
-
-static id vpConstructSceneStatusManager(id self, SEL selector, id scene) {
- void *previous = vpStatusManagerInitializingScene;
- BOOL previousConsumed = vpStatusManagerMainQueryConsumed;
- @try {
- vpFoldDisplayLog([NSString stringWithFormat:@"scene status construction: scene=%@ identity=%@ surface=%@",
- vpReadObject(vpReadObject(scene, "_FBSScene"), "identifier"),
- vpReadObject(scene, "_fbsDisplayIdentity"), [scene valueForKey:@"surfaceType"]]);
- if (vpIsSingleMainStatusScene(scene, YES)) {
- vpStatusManagerInitializingScene = (__bridge void *)scene;
- vpStatusManagerMainQueryConsumed = NO;
- vpFoldDisplayLog(@"scene status policy: native per-scene construction for Main inner");
- }
- return ((id (*)(id, SEL, id))vpOriginalStatusManagerInit)(self, selector, scene);
- } @finally { vpStatusManagerInitializingScene = previous; vpStatusManagerMainQueryConsumed = previousConsumed; }
-}
-
-static BOOL vpSceneStatusUsesEmbeddedLegacySlot(id self, SEL selector) {
- if (vpIsSingleMainStatusScene(vpReadObjectIvar(self, "_windowScene"), NO)) return NO;
- return ((BOOL (*)(id, SEL))vpOriginalStatusManagerEmbedded)(self, selector);
-}
-
-void vpInstallSceneStatusPolicy(void) {
- Class sceneClass = objc_getClass("SBWindowScene");
- Class managerClass = objc_getClass("SBWindowSceneStatusBarManager");
- SEL mainSelector = sel_registerName("isMainDisplayWindowScene");
- Method main = class_getInstanceMethod(sceneClass, mainSelector);
- Method init = class_getInstanceMethod(managerClass, sel_registerName("initWithScene:"));
- Method embedded = class_getInstanceMethod(managerClass, sel_registerName("_isEmbeddedDisplay"));
- if (!main || strcmp(method_getTypeEncoding(main), "B16@0:8") != 0 ||
- !init || strcmp(method_getTypeEncoding(init), "@24@0:8@16") != 0 ||
- !embedded || strcmp(method_getTypeEncoding(embedded), "B16@0:8") != 0) {
- vpFoldDisplayLog(@"scene status policy: native ABI unavailable"); return;
- }
- vpOriginalSceneIsMain = method_getImplementation(main);
- // Add an override to SBWindowScene itself if the method is inherited;
- // never replace UIWindowScene's implementation for all scene classes.
- if (!class_addMethod(sceneClass, mainSelector, (IMP)vpSceneMainDuringStatusConstruction, method_getTypeEncoding(main)))
- method_setImplementation(main, (IMP)vpSceneMainDuringStatusConstruction);
- vpOriginalStatusManagerInit = method_setImplementation(init, (IMP)vpConstructSceneStatusManager);
- vpOriginalStatusManagerEmbedded = method_setImplementation(embedded, (IMP)vpSceneStatusUsesEmbeddedLegacySlot);
- vpFoldDisplayLog(@"scene status policy: one-instance native per-scene adapter installed");
-}
-
-// MARK: - Main status profile
+static void *vpOriginalStatusClassLookup;
+static unsigned int vpStatusLookupLogCount;
// Used only as an argument to the native, read-only provider factory. Never
// register this proxy with UIKit or publish its reference bounds to a scene.
@@ -189,12 +12,11 @@ void vpInstallSceneStatusPolicy(void) {
@property(nonatomic, strong) id source;
@property(nonatomic, strong) id previewExclusion;
@property(nonatomic) CGRect referenceBounds;
-@property(nonatomic) BOOL skipEmbeddedCache;
@end
@implementation VPhoneStatusScreenPreview
- (CGRect)_nativeDisplayBounds { return self.referenceBounds; }
- (id)_exclusionArea { return self.previewExclusion ?: vpReadObject(self.source, "_exclusionArea"); }
-- (BOOL)_isEmbeddedScreen { return self.skipEmbeddedCache ? NO : vpReadBoolValue(self.source, "_isEmbeddedScreen").boolValue; }
+- (BOOL)_isEmbeddedScreen { return NO; }
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector { return [self.source methodSignatureForSelector:selector]; }
- (void)forwardInvocation:(NSInvocation *)invocation { [invocation invokeWithTarget:self.source]; }
- (BOOL)respondsToSelector:(SEL)selector {
@@ -210,7 +32,7 @@ void vpInstallSceneStatusPolicy(void) {
// would otherwise pick a generic island provider. Nil unless the factory
// itself selects the profile.
static Class vpDuoPanelStatusClass(id screen, id info, BOOL inner) {
- Class (*original)(id, id) = vpOriginalMainStatusClassLookup;
+ Class (*original)(id, id) = vpOriginalStatusClassLookup;
Class profile = objc_getClass(inner ? "STUIStatusBarVisualProvider_AxisAlignableSplit2007" :
"STUIStatusBarVisualProvider_AxisAlignableSplitV68Cover");
SEL notchSelector = sel_registerName("notchSize");
@@ -225,41 +47,22 @@ static Class vpDuoPanelStatusClass(id screen, id info, BOOL inner) {
VPhoneStatusScreenPreview *preview = [VPhoneStatusScreenPreview alloc];
preview.source = screen;
preview.referenceBounds = inner ? CGRectMake(0, 0, 2007, 2853) : CGRectMake(0, 0, 1398, 2034);
- preview.skipEmbeddedCache = YES;
preview.previewExclusion = ((id (*)(id, SEL, CGRect))objc_msgSend)([shapeClass alloc], initializer,
CGRectMake(0, 0, notch.width, notch.height));
Class selected = original(preview, info);
return selected == profile ? selected : Nil;
}
-static Class vpMainStatusClassLookup(id screen, id info) {
- Class (*original)(id, id) = vpOriginalMainStatusClassLookup;
- if (!vpMainStatusProfileEnabled || ![NSThread isMainThread]) return original(screen, info);
- id root = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- id identity = vpReadObject(screen, "displayIdentity");
- NSArray *bounds = vpSnapshotRect(root, "bounds");
- BOOL inner = [bounds isEqual:@[@0, @0, @669, @951]];
- BOOL cover = [bounds isEqual:@[@0, @0, @466, @678]];
- if (![identity isEqual:vpReadObject(root, "identity")] ||
- screen != vpReadObject(vpMainStatusProfileScene, "screen") ||
- !(inner || cover)) return original(screen, info);
- Class selected = vpDuoPanelStatusClass(screen, info, inner);
- if (!selected) return original(screen, info);
- if (vpMainStatusProfileLogCount++ < 8)
- vpFoldDisplayLog([NSString stringWithFormat:@"Main status profile: native %@ lookup accepted; original data/screen/identity retained", inner ? @"inner" : @"cover"]);
- return selected;
-}
-
-// With the inner display published each screen is one panel: the inner
-// display's screen is the inner panel and Main's is the cover.
+// Each screen is one panel: the inner display's screen is the inner panel
+// and Main's is the cover.
static Class vpDualStatusClassLookup(id screen, id info) {
- Class (*original)(id, id) = vpOriginalMainStatusClassLookup;
+ Class (*original)(id, id) = vpOriginalStatusClassLookup;
if (![NSThread isMainThread]) return original(screen, info);
id identity = vpReadObject(vpReadObject(screen, "displayConfiguration"), "identity");
if (!identity) return original(screen, info);
BOOL inner = ![[identity description] isEqual:@"Main"];
Class selected = vpDuoPanelStatusClass(screen, info, inner);
- if (vpMainStatusProfileLogCount++ < 8)
+ if (vpStatusLookupLogCount++ < 8)
vpFoldDisplayLog([NSString stringWithFormat:@"status bar: %@ screen takes %@", inner ? @"inner" : @"cover",
selected ? NSStringFromClass(selected) : @"the native provider"]);
return selected ?: original(screen, info);
@@ -270,203 +73,6 @@ void vpInstallDualStatusLookup(void) {
MISFixDetourResult (*install)(const char *, void *, void *, void **) = dlsym(RTLD_DEFAULT, "MISFixDetour");
if (!target || !install) { vpFoldDisplayLog(@"status bar: native lookup/detour API unavailable"); return; }
MISFixDetourResult result = install("Duo per-panel status profile", target, (void *)vpDualStatusClassLookup,
- &vpOriginalMainStatusClassLookup);
+ &vpOriginalStatusClassLookup);
vpFoldDisplayLog([NSString stringWithFormat:@"status bar: per-panel lookup detour result=%d", result]);
}
-
-void vpInstallMainStatusLookup(void) {
- void *target = dlsym(RTLD_DEFAULT, "STUIStatusBarGetVisualProviderClassForScreen");
- MISFixDetourResult (*install)(const char *, void *, void *, void **) = dlsym(RTLD_DEFAULT, "MISFixDetour");
- if (!target || !install) { vpFoldDisplayLog(@"Main status profile: native lookup/detour API unavailable"); return; }
- MISFixDetourResult result = install("Duo Main native status profile", target, (void *)vpMainStatusClassLookup,
- &vpOriginalMainStatusClassLookup);
- vpFoldDisplayLog([NSString stringWithFormat:@"Main status profile: constructor detour result=%d", result]);
-}
-
-void vpRefreshMainStatusRenderer(void) {
- id scene = vpMainStatusProfileScene;
- if (!scene) return;
- id wrapper = vpReadObject(vpReadObject(scene, "statusBarManager"), "statusBar");
- id renderer = vpReadObject(wrapper, "statusBar");
- // resetVisualProvider resets region/item/alpha dictionaries only. Clear
- // the native class cache (never assign a replacement class), then use
- // the native full reconstruction that releases provider/foreground.
- Method clear = class_getInstanceMethod(object_getClass(renderer), sel_registerName("_setVisualProviderClass:"));
- if (clear && strcmp(method_getTypeEncoding(clear), "v24@0:8#16") == 0)
- ((void (*)(id, SEL, Class))objc_msgSend)(renderer, sel_registerName("_setVisualProviderClass:"), Nil);
- for (NSString *name in @[@"reinitializeStatusBar", @"setNeedsLayout", @"layoutIfNeeded"]) {
- SEL selector = NSSelectorFromString(name);
- Method method = class_getInstanceMethod(object_getClass(renderer), selector);
- if (method && strcmp(method_getTypeEncoding(method), "v16@0:8") == 0)
- ((void (*)(id, SEL))objc_msgSend)(renderer, selector);
- }
- Method data = class_getInstanceMethod(object_getClass(wrapper), sel_registerName("forceUpdateData:"));
- if (data && strcmp(method_getTypeEncoding(data), "v20@0:8B16") == 0)
- ((void (*)(id, SEL, BOOL))objc_msgSend)(wrapper, sel_registerName("forceUpdateData:"), YES);
- Method force = class_getInstanceMethod(object_getClass(wrapper), sel_registerName("forceUpdate:"));
- if (force && strcmp(method_getTypeEncoding(force), "v20@0:8B16") == 0)
- ((void (*)(id, SEL, BOOL))objc_msgSend)(wrapper, sel_registerName("forceUpdate:"), YES);
-}
-
-void vpRestoreMainStatusProfile(void) {
- if (vpAutomaticMainStatus) { vpRefreshMainStatusRenderer(); return; }
- if (!vpMainStatusProfileEnabled && !vpMainStatusProfileScene) return;
- vpMainStatusProfileEnabled = NO;
- vpMainStatusProfileGeneration++;
- if (!vpMainStatusProfileScene) { vpMainStatusOriginalProviderClass = Nil; return; }
- vpRefreshMainStatusRenderer();
- id wrapper = vpReadObject(vpReadObject(vpMainStatusProfileScene, "statusBarManager"), "statusBar");
- Class current = object_getClass(vpReadObject(vpReadObject(wrapper, "statusBar"), "visualProvider"));
- if (vpMainStatusOriginalProviderClass && current != vpMainStatusOriginalProviderClass) {
- vpFoldDisplayLog(@"Main status profile: provider restoration pending; checkpoint retained"); return;
- }
- vpMainStatusProfileScene = nil;
- vpMainStatusOriginalProviderClass = Nil;
- vpFoldDisplayLog(@"Main status profile: native lookup behavior restored");
-}
-
-void vpPulseMainStatusProfile(void) {
- if (!vpOriginalMainStatusClassLookup || vpUIConfigPublished) return;
- if (vpMainStatusProfileScene) {
- id wrapper = vpReadObject(vpReadObject(vpMainStatusProfileScene, "statusBarManager"), "statusBar");
- if (!vpReadObject(vpReadObject(wrapper, "statusBar"), "currentData")) vpRefreshMainStatusRenderer();
- return;
- }
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id scene = vpReadObject(app, "activeDisplayWindowScene") ?: vpReadObject(app, "embeddedDisplayWindowScene");
- id identity = vpReadObject(scene, "_fbsDisplayIdentity");
- id root = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- NSArray *bounds = vpSnapshotRect(root, "bounds");
- if (!scene || ![[identity valueForKey:@"isMainDisplay"] boolValue] ||
- ![identity isEqual:vpReadObject(root, "identity")] ||
- ![vpReadObject(vpReadObject(scene, "_FBSScene"), "identifier") isEqual:@"SB-main"] ||
- (!([bounds isEqual:@[@0, @0, @669, @951]]) && !([bounds isEqual:@[@0, @0, @466, @678]]))) return;
- vpMainStatusProfileScene = scene;
- id wrapper = vpReadObject(vpReadObject(scene, "statusBarManager"), "statusBar");
- vpMainStatusOriginalProviderClass = object_getClass(vpReadObject(vpReadObject(wrapper, "statusBar"), "visualProvider"));
- vpMainStatusProfileLogCount = 0;
- vpMainStatusProfileEnabled = YES;
- unsigned int generation = ++vpMainStatusProfileGeneration;
- vpFoldDisplayLog(vpAutomaticMainStatus ? @"Main status profile: persistent native Duo profile enabled" :
- @"Main status profile: eight-second native metadata lookup lease; no UI identity migration");
- vpRefreshMainStatusRenderer();
- if (vpAutomaticMainStatus) return;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 8 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- if (generation == vpMainStatusProfileGeneration) vpRestoreMainStatusProfile();
- });
-}
-
-// MARK: - visual provider profile lookup
-
-static Class vpStatusProfileFactoryAtIndex(NSUInteger index, id self, SEL selector, id screen, id info) {
- Class (*original)(id, SEL, id, id) = (void *)vpOriginalStatusProfileFactories[index];
- // This is a reference-metric lookup only. Native provider construction
- // continues with its real screen; no UIView geometry/provider class is set.
- if (!vpStatusProfileLookupEnabled || ![NSThread isMainThread] || vpStatusProfileFactoryDepth)
- return original(self, selector, screen, info);
- BOOL ownedConstruction = vpStatusProfileConstructionScene == (__bridge void *)vpStatusProfileScene;
- BOOL sameScreen = screen == vpReadObject(vpStatusProfileScene, "screen");
- if (vpStatusProfileCallCount++ < 12)
- vpFoldDisplayLog([NSString stringWithFormat:@"status profile factory call: class=%@ sameScreen=%d ownedConstruction=%d",
- NSStringFromClass(self), sameScreen, ownedConstruction]);
- if (!vpUIConfigPublished || vpStatusProfileScene != vpUIConfigWindowScene ||
- !(sameScreen || ownedConstruction) || vpMainInnerWindowScene() != vpStatusProfileScene)
- return original(self, selector, screen, info);
- Class profile = objc_getClass("STUIStatusBarVisualProvider_AxisAlignableSplit2007");
- SEL notchSelector = sel_registerName("notchSize");
- NSMethodSignature *notchSignature = [profile methodSignatureForSelector:notchSelector];
- if (notchSignature.methodReturnLength != sizeof(CGSize)) return original(self, selector, screen, info);
- CGSize notch = ((CGSize (*)(id, SEL))objc_msgSend)(profile, notchSelector);
- if (notch.width <= 0 || notch.height <= 0) return original(self, selector, screen, info);
- Class shapeClass = objc_getClass("UISDisplaySingleRectShape");
- SEL initializer = sel_registerName("initWithRect:");
- NSMethodSignature *shapeSignature = [shapeClass instanceMethodSignatureForSelector:initializer];
- if (shapeSignature.numberOfArguments != 3 ||
- strcmp([shapeSignature getArgumentTypeAtIndex:2], "{CGRect={CGPoint=dd}{CGSize=dd}}") != 0)
- return original(self, selector, screen, info);
- VPhoneStatusScreenPreview *preview = [VPhoneStatusScreenPreview alloc];
- preview.source = screen;
- preview.referenceBounds = CGRectMake(0, 0, 2007, 2853);
- preview.previewExclusion = ((id (*)(id, SEL, CGRect))objc_msgSend)([shapeClass alloc], initializer,
- CGRectMake(0, 0, notch.width, notch.height));
- Class selected = Nil;
- vpStatusProfileFactoryDepth++;
- @try { selected = original(self, selector, preview, info); }
- @finally { vpStatusProfileFactoryDepth--; }
- // The native factory, not a returned constant, must accept this profile.
- if (selected != profile) return original(self, selector, screen, info);
- if (vpStatusProfileCallCount++ < 20)
- vpFoldDisplayLog(@"status profile lookup: native factory accepted inner reference metrics; real screen retained");
- return selected;
-}
-
-static Class vpStatusProfileFactoryIOS(id self, SEL selector, id screen, id info) { return vpStatusProfileFactoryAtIndex(0, self, selector, screen, info); }
-static Class vpStatusProfileFactoryPhone(id self, SEL selector, id screen, id info) { return vpStatusProfileFactoryAtIndex(1, self, selector, screen, info); }
-static Class vpStatusProfileFactorySplit(id self, SEL selector, id screen, id info) { return vpStatusProfileFactoryAtIndex(2, self, selector, screen, info); }
-static Class vpStatusProfileFactoryAxis(id self, SEL selector, id screen, id info) { return vpStatusProfileFactoryAtIndex(3, self, selector, screen, info); }
-static const char *vpStatusProfileFactoryClasses[] = {"STUIStatusBarVisualProvider_iOS", "STUIStatusBarVisualProvider_Phone",
- "STUIStatusBarVisualProvider_Split", "STUIStatusBarVisualProvider_AxisAlignableSplit"};
-static IMP vpStatusProfileFactoryReplacements[] = {(IMP)vpStatusProfileFactoryIOS, (IMP)vpStatusProfileFactoryPhone,
- (IMP)vpStatusProfileFactorySplit, (IMP)vpStatusProfileFactoryAxis};
-
-void vpResetManagedStatusProvider(void) {
- id scene = vpStatusProfileScene;
- if (!scene || scene != vpUIConfigWindowScene) return;
- id renderer = vpReadObject(vpReadObject(vpReadObject(scene, "statusBarManager"), "statusBar"), "statusBar");
- SEL reset = sel_registerName("resetVisualProvider");
- Method method = class_getInstanceMethod(object_getClass(renderer), reset);
- void *previousScope = vpStatusProfileConstructionScene;
- @try {
- if (vpStatusProfileLookupEnabled) vpStatusProfileConstructionScene = (__bridge void *)scene;
- if (method && strcmp(method_getTypeEncoding(method), "v16@0:8") == 0)
- ((void (*)(id, SEL))objc_msgSend)(renderer, reset);
- for (NSString *name in @[@"setNeedsLayout", @"layoutIfNeeded"])
- if ([renderer respondsToSelector:NSSelectorFromString(name)]) ((void (*)(id, SEL))objc_msgSend)(renderer, NSSelectorFromString(name));
- } @finally { vpStatusProfileConstructionScene = previousScope; }
-}
-
-void vpRestoreStatusProfileLookup(void) {
- if (!vpStatusProfileLookupEnabled) return;
- vpStatusProfileLookupEnabled = NO;
- vpStatusProfileGeneration++;
- for (NSUInteger index = 0; index < 4; index++) {
- Method method = class_getClassMethod(objc_getClass(vpStatusProfileFactoryClasses[index]),
- sel_registerName("visualProviderSubclassForScreen:visualProviderInfo:"));
- if (method && vpOriginalStatusProfileFactories[index] && method_getImplementation(method) == vpStatusProfileFactoryReplacements[index])
- method_setImplementation(method, vpOriginalStatusProfileFactories[index]);
- }
- vpResetManagedStatusProvider();
- vpStatusProfileScene = nil;
- vpFoldDisplayLog(@"status profile lookup: original factory restored");
-}
-
-void vpPulseStatusProfileLookup(void) {
- // Single-display only: a published inner display has its own status bar.
- if (vpInnerDisplayRequested()) return;
- @try {
- if (vpStatusProfileLookupEnabled || !vpUIConfigPublished || vpMainInnerWindowScene() != vpUIConfigWindowScene) return;
- Method methods[4];
- for (NSUInteger index = 0; index < 4; index++) {
- methods[index] = class_getClassMethod(objc_getClass(vpStatusProfileFactoryClasses[index]),
- sel_registerName("visualProviderSubclassForScreen:visualProviderInfo:"));
- if (!methods[index] || strcmp(method_getTypeEncoding(methods[index]), "#32@0:8@16@24") != 0) return;
- }
- vpStatusProfileScene = vpUIConfigWindowScene;
- vpStatusProfileCallCount = 0;
- // Publish all original call targets before any replacement can run,
- // including a concurrent factory call that will take the native path.
- for (NSUInteger index = 0; index < 4; index++)
- vpOriginalStatusProfileFactories[index] = method_getImplementation(methods[index]);
- for (NSUInteger index = 0; index < 4; index++)
- method_setImplementation(methods[index], vpStatusProfileFactoryReplacements[index]);
- vpStatusProfileLookupEnabled = YES;
- unsigned int generation = ++vpStatusProfileGeneration;
- vpFoldDisplayLog(@"status profile lookup: eight-second owned UI reference-metric lease");
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 8 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- if (generation == vpStatusProfileGeneration) vpRestoreStatusProfileLookup();
- });
- } @catch (NSException *exception) {
- vpRestoreStatusProfileLookup();
- vpFoldDisplayLog([NSString stringWithFormat:@"status profile lookup exception: %@", exception.reason]);
- }
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplaySupport.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplaySupport.m
index a12adaa1..215fcbc0 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplaySupport.m
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplaySupport.m
@@ -1,33 +1,22 @@
-// Logging, the one-shot experiment flags, and the KVC and ivar readers
-// every other section reads SpringBoard and FrontBoard objects through.
+// The log, the inner display's name, and the KVC and ivar readers every
+// section reads backboardd, SpringBoard and FrontBoard objects through.
#import "FoldDisplayPrivate.h"
+NSString *const vpInnerDisplayName = @"VPhone Duo Inner";
+
void vpFoldDisplayLog(NSString *line) {
- int fd = open("/var/mobile/Library/Caches/vphone-folddisplay.log",
- O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0666);
+ int fd = open("/var/mobile/Library/Caches/vphone-folddisplay.log", O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0666);
if (fd < 0)
return;
- NSString *stamp = [NSDateFormatter localizedStringFromDate:NSDate.date
- dateStyle:NSDateFormatterNoStyle
- timeStyle:NSDateFormatterMediumStyle];
- NSString *row = [NSString stringWithFormat:@"%@ %@\n", stamp, line];
- const char *bytes = row.UTF8String;
+ NSString *stamp = [NSDateFormatter localizedStringFromDate:NSDate.date dateStyle:NSDateFormatterNoStyle
+ timeStyle:NSDateFormatterMediumStyle];
+ const char *bytes = [NSString stringWithFormat:@"%@ %@\n", stamp, line].UTF8String;
if (bytes)
write(fd, bytes, strlen(bytes));
close(fd);
}
-BOOL vpConsumeDisplayExperimentFlag(const char *flag) {
- int fd = open(flag, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
- if (fd < 0) return NO;
- char value = 0;
- ssize_t length = read(fd, &value, 1);
- close(fd);
- unlink(flag);
- return length == 1 && value == '1';
-}
-
id vpReadObject(id object, const char *name) {
SEL selector = sel_registerName(name);
NSMethodSignature *signature = [object methodSignatureForSelector:selector];
@@ -35,158 +24,8 @@ id vpReadObject(id object, const char *name) {
return ((id (*)(id, SEL))objc_msgSend)(object, selector);
}
-id vpReadMultilineDescription(id object) {
- SEL selector = sel_registerName("descriptionWithMultilinePrefix:");
- Method method = class_getInstanceMethod(object_getClass(object), selector);
- if (!method || strcmp(method_getTypeEncoding(method), "@24@0:8@16") != 0) return nil;
- return ((id (*)(id, SEL, id))objc_msgSend)(object, selector, @"");
-}
-
id vpReadObjectIvar(id object, const char *name) {
Ivar ivar = class_getInstanceVariable(object_getClass(object), name);
const char *type = ivar ? ivar_getTypeEncoding(ivar) : NULL;
return type && type[0] == '@' ? object_getIvar(object, ivar) : nil;
}
-
-id vpRootServerScenes(id app) {
- return vpReadObject(vpReadObject(app, "displayProfileManager"), "fbScenes");
-}
-
-NSNumber *vpReadBoolValue(id object, const char *name) {
- SEL selector = sel_registerName(name);
- NSMethodSignature *signature = [object methodSignatureForSelector:selector];
- if (!signature || signature.numberOfArguments != 2 ||
- (signature.methodReturnType[0] != 'B' && signature.methodReturnType[0] != 'c')) return nil;
- return @(((BOOL (*)(id, SEL))objc_msgSend)(object, selector));
-}
-
-NSValue *vpReadRectValue(id object, const char *name) {
- SEL selector = sel_registerName(name);
- NSMethodSignature *signature = [object methodSignatureForSelector:selector];
- if (!signature || signature.numberOfArguments != 2 ||
- strcmp(signature.methodReturnType, "{CGRect={CGPoint=dd}{CGSize=dd}}") != 0) return nil;
- CGRect value = ((CGRect (*)(id, SEL))objc_msgSend)(object, selector);
- return [NSValue value:&value withObjCType:@encode(CGRect)];
-}
-
-id vpSnapshotRect(id object, const char *name) {
- NSValue *value = vpReadRectValue(object, name);
- if (!value) return NSNull.null;
- CGRect rect;
- [value getValue:&rect size:sizeof(rect)];
- return @[@(rect.origin.x), @(rect.origin.y), @(rect.size.width), @(rect.size.height)];
-}
-
-NSNumber *vpSnapshotScalarIvar(id object, const char *name) {
- Ivar ivar = class_getInstanceVariable(object_getClass(object), name);
- const char *type = ivar ? ivar_getTypeEncoding(ivar) : NULL;
- if (!type) return nil;
- const void *address = (const char *)(__bridge void *)object + ivar_getOffset(ivar);
- if (strcmp(type, "B") == 0 || strcmp(type, "c") == 0) {
- uint8_t value; memcpy(&value, address, sizeof(value)); return @(value != 0);
- }
- if (strcmp(type, "q") == 0) { int64_t value; memcpy(&value, address, sizeof(value)); return @(value); }
- if (strcmp(type, "Q") == 0) { uint64_t value; memcpy(&value, address, sizeof(value)); return @(value); }
- return nil;
-}
-
-NSString *vpDescribeLayerContents(id contents) {
- if (!contents) return @"nil";
- @try {
- if (CFGetTypeID((CFTypeRef)contents) == CGImageGetTypeID()) {
- CGImageRef image = (CGImageRef)(__bridge void *)contents;
- return [NSString stringWithFormat:@"image %zux%zu", CGImageGetWidth(image), CGImageGetHeight(image)];
- }
- } @catch (NSException *exception) { }
- NSString *text = [contents description];
- if (text.length > 60) text = [text substringToIndex:60];
- return [NSString stringWithFormat:@"%s %@", object_getClassName(contents), text];
-}
-
-// Reads one ivar by its type encoding so numeric and struct state appear
-// without calling arbitrary getters. Unknown layouts stay "?"; nothing is
-// synthesized.
-static NSString *vpFormatIvarValue(id object, Ivar ivar) {
- const char *type = ivar_getTypeEncoding(ivar);
- if (!type) return @"?";
- void *ptr = (void *)((char *)(__bridge void *)object + ivar_getOffset(ivar));
- switch (type[0]) {
- case 'd': return [NSString stringWithFormat:@"%.6g", *(double *)ptr];
- case 'f': return [NSString stringWithFormat:@"%.6g", (double)*(float *)ptr];
- case 'B': return *(BOOL *)ptr ? @"YES" : @"NO";
- case 'c': return @(*(int8_t *)ptr).stringValue;
- case 'C': return @(*(uint8_t *)ptr).stringValue;
- case 's': return @(*(int16_t *)ptr).stringValue;
- case 'S': return @(*(uint16_t *)ptr).stringValue;
- case 'i': case 'l': return @(*(int32_t *)ptr).stringValue;
- case 'I': case 'L': return @(*(uint32_t *)ptr).stringValue;
- case 'q': return @(*(int64_t *)ptr).stringValue;
- case 'Q': return @(*(uint64_t *)ptr).stringValue;
- case '@': {
- id value = object_getIvar(object, ivar);
- if (!value) return @"nil";
- if ([value isKindOfClass:NSNumber.class]) return [NSString stringWithFormat:@"@ %@", value];
- if ([value isKindOfClass:NSString.class] || [value isKindOfClass:NSValue.class])
- return [NSString stringWithFormat:@"%s %@", object_getClassName(value), value];
- NSString *text = [value description];
- if (text.length > 90) text = [text substringToIndex:90];
- return [NSString stringWithFormat:@"%s %@", object_getClassName(value), text];
- }
- case '{': {
- if (strncmp(type, "{CGRect", 6) == 0) {
- CGRect rect = *(CGRect *)ptr;
- return [NSString stringWithFormat:@"{{%g, %g}, {%g, %g}}", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height];
- }
- if (strncmp(type, "{CGSize", 6) == 0) {
- CGSize size = *(CGSize *)ptr;
- return [NSString stringWithFormat:@"{%g, %g}", size.width, size.height];
- }
- if (strncmp(type, "{CGPoint", 7) == 0) {
- CGPoint point = *(CGPoint *)ptr;
- return [NSString stringWithFormat:@"{%g, %g}", point.x, point.y];
- }
- if (strncmp(type, "{UIEdgeInsets", 13) == 0) {
- // {top,left,bottom,right} as four CGFloats; a local layout so
- // UIKit is not a dependency of this dylib.
- const CGFloat *edges = (const CGFloat *)ptr;
- return [NSString stringWithFormat:@"insets{%g,%g,%g,%g}", edges[0], edges[1], edges[2], edges[3]];
- }
- if (strncmp(type, "{CGAffineTransform", 18) == 0) {
- CGAffineTransform transform = *(CGAffineTransform *)ptr;
- return [NSString stringWithFormat:@"transform{%g,%g,%g,%g,%g,%g}", transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty];
- }
- return @"{struct}";
- }
- case '^': return [NSString stringWithFormat:@"%p", *(void **)ptr];
- default: return @"?";
- }
-}
-
-void vpDumpObjectIvars(id object, NSString *label, NSUInteger limit) {
- if (!object) { vpFoldDisplayLog([NSString stringWithFormat:@"%@ ivars: nil", label]); return; }
- Class cls = object_getClass(object);
- unsigned int count = 0;
- Ivar *ivars = class_copyIvarList(cls, &count);
- vpFoldDisplayLog([NSString stringWithFormat:@"%@ ivars: class=%s count=%u", label, class_getName(cls), count]);
- for (unsigned int i = 0; i < count && i < limit; i++) {
- @try {
- vpFoldDisplayLog([NSString stringWithFormat:@"%@ ivar[%u] %s (%s) = %@", label, i,
- ivar_getName(ivars[i]), ivar_getTypeEncoding(ivars[i]) ?: "?",
- vpFormatIvarValue(object, ivars[i])]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"%@ ivar[%u] %s exception: %@", label, i,
- ivar_getName(ivars[i]), exception.reason]);
- }
- }
- free(ivars);
-}
-
-// The poster extension's hosted scene presentation views keep their portrait
-// 669x951 bounds inside the landscape wallpaper tree. Renderer host nodes are
-// resized to the wallpaper presenter's current bounds; the PosterBoard
-// floating editor keeps its native portrait bounds and is centered instead.
-// The notification is cheap and idempotent, so a newly-created editor can be
-// reconciled without touching its loading state.
-NSString *vpSizeText(CGSize size) {
- return [NSString stringWithFormat:@"{%.0f, %.0f}", size.width, size.height];
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplaySurfaceProbe.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplaySurfaceProbe.m
deleted file mode 100644
index 49117c23..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplaySurfaceProbe.m
+++ /dev/null
@@ -1,53 +0,0 @@
-// backboardd: the CAWindowServerDisplay extendedProperties surface-type probe.
-
-#import "FoldDisplayPrivate.h"
-
-IMP vpOriginalExtendedProperties;
-atomic_bool vpInnerSurfaceProbeEnabled;
-atomic_uint vpPrimarySurfaceType = 2;
-static unsigned int vpSurfaceProbeGeneration;
-static atomic_bool vpCoverSurfaceProbeEnabled;
-static atomic_uint vpSurfaceProbeLogCount;
-
-// backboardd's native traits RPC reads DeviceSurfaceType from this dictionary.
-// Keep the probe bounded and scoped to the real primary render display. It
-// 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);
- 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"];
- if ((!primary && !cover) || (properties && ![properties isKindOfClass:NSDictionary.class])) return properties;
- NSMutableDictionary *derived = properties ? [properties mutableCopy] : [NSMutableDictionary dictionary];
- derived[@"DeviceSurfaceType"] = primary ? @(atomic_load_explicit(&vpPrimarySurfaceType, memory_order_acquire)) : @1;
- if (atomic_fetch_add_explicit(&vpSurfaceProbeLogCount, 1, memory_order_relaxed) < 8)
- vpFoldDisplayLog([NSString stringWithFormat:@"surface probe: %@ traits %@ -> %@", name, properties, derived]);
- return [derived copy];
-}
-
-void vpBeginSurfaceProbe(unsigned int surfaceType, BOOL pair) {
- if (!vpOriginalExtendedProperties) return;
- if (surfaceType != 1 && surfaceType != 2) return;
- unsigned int generation = ++vpSurfaceProbeGeneration;
- atomic_store_explicit(&vpPrimarySurfaceType, surfaceType, memory_order_release);
- atomic_store_explicit(&vpCoverSurfaceProbeEnabled, pair, memory_order_release);
- atomic_store_explicit(&vpInnerSurfaceProbeEnabled, true, memory_order_release);
- vpFoldDisplayLog([NSString stringWithFormat:@"surface probe: primary role=%u enabled for 30 seconds; pairedCover=%d", surfaceType, pair]);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- if (generation != vpSurfaceProbeGeneration) return;
- atomic_store_explicit(&vpInnerSurfaceProbeEnabled, false, memory_order_release);
- atomic_store_explicit(&vpCoverSurfaceProbeEnabled, false, memory_order_release);
- vpFoldDisplayLog(@"surface probe: primary native role restored");
- });
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayUIConfiguration.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayUIConfiguration.m
deleted file mode 100644
index 7c4e6719..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayUIConfiguration.m
+++ /dev/null
@@ -1,536 +0,0 @@
-// The UIKit display configuration and screen traits published to SpringBoard's
-// scenes, with their restore paths.
-
-#import "FoldDisplayPrivate.h"
-
-__weak id vpUIConfigWindowScene;
-static __weak id vpUIConfigServerScene, vpUIConfigClientScene;
-static _Atomic(IMP) vpUIIdentityCopyOriginal;
-static _Thread_local void *vpUIIdentityCopySource, *vpUIIdentityCopyReplacement;
-id vpUIConfigPublished;
-static id vpUIConfigOriginalHosted, vpUIConfigOriginalServerDisplay, vpUIConfigOriginalUI;
-static atomic_uint vpUIConfigGeneration;
-static id vpUIOldStatusComponent, vpUINewStatusComponent, vpUIStatusComponentKey;
-static BOOL vpUIStatusDetachedBeforeRollback;
-static __weak id vpUIOldStatusWindow;
-static NSNumber *vpUIOldStatusWindowHidden;
-static __weak id vpUITraitsScreen;
-static NSNumber *vpUITraitsOriginalIdiom;
-static NSInteger vpUITraitsPublishedIdiom;
-static NSString *vpUITraitsIdentifier;
-
-@protocol VPhoneDisplayProjectionBuilding
-- (instancetype)initWithConfiguration:(id)configuration;
-- (void)setUniqueIdentifier:(NSString *)identifier;
-- (void)setDisplayType:(NSInteger)type;
-- (void)setUIKitMainLike;
-- (id)buildConfigurationWithError:(NSError **)error;
-@end
-@protocol VPhoneDisplayIdentityInitializing
-- (instancetype)_initWithType:(NSInteger)type UIKitMainLike:(BOOL)mainLike displayID:(uint32_t)displayID
- connectionType:(NSInteger)connectionType connectionSeed:(uint32_t)connectionSeed pid:(int)pid
- external:(BOOL)external uniqueIdentifier:(id)identifier secure:(BOOL)secure
- alwaysConnected:(BOOL)alwaysConnected root:(id)root;
-@end
-
-// MARK: - configuration builders
-
-static id vpCreateUIConfiguration(id configuration) {
- Class cls = objc_getClass("FBSDisplayConfigurationBuilder");
- Method type = class_getInstanceMethod(cls, sel_registerName("setDisplayType:"));
- Method mainLike = class_getInstanceMethod(cls, sel_registerName("setUIKitMainLike"));
- if (!type || strcmp(method_getTypeEncoding(type), "v24@0:8q16") != 0 ||
- !mainLike || strcmp(method_getTypeEncoding(mainLike), "v16@0:8") != 0) return nil;
- id<VPhoneDisplayProjectionBuilding> builder = [(id<VPhoneDisplayProjectionBuilding>)[cls alloc] initWithConfiguration:configuration];
- [builder setUniqueIdentifier:@"vphone-duo-ui-preview"];
- [builder setDisplayType:7];
- [builder setUIKitMainLike];
- NSError *error = nil;
- id result = [builder buildConfigurationWithError:&error];
- if (!result) vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration build failed: %@", error]);
- return result;
-}
-
-static id vpUIIdentityDuringUnpublishedCopy(id self, SEL selector) {
- if ((__bridge void *)self == vpUIIdentityCopySource) return (__bridge id)vpUIIdentityCopyReplacement;
- return ((id (*)(id, SEL))vpUIIdentityCopyOriginal)(self, selector);
-}
-
-static id vpCreateNonEmbeddedUIConfiguration(id root) {
- // The native builder can set MainLike but has no clear operation. Copy
- // from a distinct, unpublished UI configuration whose identity getter is
- // substituted only on this thread for the duration of the native build.
- // The physical Main and its accessors are never substituted.
- id source = vpCreateUIConfiguration(root);
- id identity = vpReadObject(source, "identity");
- if (!source || source == root || [[identity valueForKey:@"isMainDisplay"] boolValue] ||
- ![vpReadObject(identity, "rootIdentity") isEqual:vpReadObject(root, "identity")]) return nil;
- Class cls = objc_getClass("FBSDisplayIdentity");
- SEL initializer = sel_registerName("_initWithType:UIKitMainLike:displayID:connectionType:connectionSeed:pid:external:uniqueIdentifier:secure:alwaysConnected:root:");
- Method method = class_getInstanceMethod(cls, initializer);
- if (!method || strcmp(method_getTypeEncoding(method), "@76@0:8q16B24I28q32I40i44B48@52B60B64@68") != 0) return nil;
- id replacement = [(id<VPhoneDisplayIdentityInitializing>)[cls alloc]
- _initWithType:[[identity valueForKey:@"type"] integerValue] UIKitMainLike:NO
- displayID:[[identity valueForKey:@"displayID"] unsignedIntValue]
- connectionType:[[identity valueForKey:@"connectionType"] integerValue]
- connectionSeed:[[identity valueForKey:@"connectionSeed"] unsignedIntValue]
- pid:[[identity valueForKey:@"pid"] intValue] external:[[identity valueForKey:@"isExternal"] boolValue]
- uniqueIdentifier:vpReadObject(identity, "uniqueIdentifier")
- secure:[[identity valueForKey:@"expectsSecureRendering"] boolValue]
- alwaysConnected:[[identity valueForKey:@"isAlwaysConnected"] boolValue] root:vpReadObject(identity, "rootIdentity")];
- if (!replacement || [[replacement valueForKey:@"isUIKitMainLike"] boolValue]) return nil;
- id<VPhoneDisplayProjectionBuilding> builder = [(id<VPhoneDisplayProjectionBuilding>)[objc_getClass("FBSDisplayConfigurationBuilder") alloc]
- initWithConfiguration:source];
- [builder setUniqueIdentifier:@"vphone-duo-ui-unembedded-preview"];
- [builder setDisplayType:7];
- SEL getter = sel_registerName("identity");
- Method identityMethod = class_getInstanceMethod(object_getClass(source), getter);
- if (!identityMethod || strcmp(method_getTypeEncoding(identityMethod), "@16@0:8") != 0 || vpUIIdentityCopySource) return nil;
- vpUIIdentityCopyOriginal = method_getImplementation(identityMethod);
- vpUIIdentityCopySource = (__bridge void *)source;
- vpUIIdentityCopyReplacement = (__bridge void *)replacement;
- id result = nil;
- @try {
- method_setImplementation(identityMethod, (IMP)vpUIIdentityDuringUnpublishedCopy);
- NSError *error = nil;
- result = [builder buildConfigurationWithError:&error];
- if (!result) vpFoldDisplayLog([NSString stringWithFormat:@"nonembedded UI copy failed: %@", error]);
- } @finally {
- if (method_getImplementation(identityMethod) == (IMP)vpUIIdentityDuringUnpublishedCopy)
- method_setImplementation(identityMethod, vpUIIdentityCopyOriginal);
- vpUIIdentityCopySource = NULL; vpUIIdentityCopyReplacement = NULL;
- }
- if ([[vpReadObject(result, "identity") valueForKey:@"isUIKitMainLike"] boolValue] ||
- vpReadObject(result, "CADisplay") != vpReadObject(root, "CADisplay")) return nil;
- return result;
-}
-
-void vpPreviewNonEmbeddedUIConfiguration(void) {
- @try {
- id root = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- id result = vpCreateNonEmbeddedUIConfiguration(root);
- id identity = vpReadObject(result, "identity");
- NSDictionary *fields = @{@"built": @(result != nil),
- @"mainLike": [identity valueForKey:@"isUIKitMainLike"] ?: NSNull.null,
- @"main": [identity valueForKey:@"isMainDisplay"] ?: NSNull.null,
- @"rootMatchesMain": @([vpReadObject(identity, "rootIdentity") isEqual:vpReadObject(root, "identity")]),
- @"sameCADisplay": @(result && vpReadObject(result, "CADisplay") == vpReadObject(root, "CADisplay")),
- @"physicalMainLike": [vpReadObject(root, "identity") valueForKey:@"isUIKitMainLike"] ?: NSNull.null,
- @"bounds": vpSnapshotRect(result, "bounds"), @"previewOnly": @YES};
- NSData *data = [NSJSONSerialization dataWithJSONObject:fields options:0 error:NULL];
- if (data) vpFoldDisplayLog([@"nonembedded UI preview " stringByAppendingString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"nonembedded UI preview exception: %@", exception.reason]);
- }
-}
-
-static BOOL vpUIObjectsEqual(id a, id b) { return a == b || [a isEqual:b]; }
-
-// MARK: - screen traits
-
-static void vpPropagateUIScreenTraits(id screen) {
- SEL update = sel_registerName("_updateTraits");
- Method updateMethod = class_getInstanceMethod(object_getClass(screen), update);
- if (updateMethod && strcmp(method_getTypeEncoding(updateMethod), "v16@0:8") == 0)
- ((void (*)(id, SEL))objc_msgSend)(screen, update);
- SEL selector = sel_registerName("_notifyTraitsChangedAndPropagate");
- Method method = class_getInstanceMethod(object_getClass(screen), selector);
- if (method && strcmp(method_getTypeEncoding(method), "v16@0:8") == 0)
- ((void (*)(id, SEL))objc_msgSend)(screen, selector);
-}
-
-static BOOL vpRestoreUIScreenTraits(void) {
- id screen = vpUITraitsScreen;
- if (!vpUITraitsOriginalIdiom) return YES;
- id identity = vpReadObject(screen, "displayIdentity");
- if (screen && ![[identity valueForKey:@"isMainDisplay"] boolValue] &&
- [vpReadObject(identity, "uniqueIdentifier") isEqual:vpUITraitsIdentifier] &&
- [[screen valueForKey:@"_userInterfaceIdiom"] integerValue] == vpUITraitsPublishedIdiom) {
- ((void (*)(id, SEL, NSInteger))objc_msgSend)(screen, sel_registerName("_setUserInterfaceIdiom:"), vpUITraitsOriginalIdiom.integerValue);
- vpPropagateUIScreenTraits(screen);
- vpFoldDisplayLog([NSString stringWithFormat:@"UI screen traits: restored idiom=%@ readback=%@",
- vpUITraitsOriginalIdiom, [screen valueForKey:@"_userInterfaceIdiom"]]);
- if (![[screen valueForKey:@"_userInterfaceIdiom"] isEqual:vpUITraitsOriginalIdiom]) return NO;
- } else vpFoldDisplayLog(@"UI screen traits: detached screen gone or newer identity/value preserved");
- vpUITraitsScreen = nil; vpUITraitsOriginalIdiom = nil; vpUITraitsIdentifier = nil;
- return YES;
-}
-
-void vpSyncUIScreenTraits(void) {
- @try {
- if (vpUITraitsOriginalIdiom || !vpUIConfigPublished) return;
- id scene = vpUIConfigWindowScene;
- id screen = vpReadObject(scene, "screen");
- id identity = vpReadObject(screen, "displayIdentity");
- id root = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- id mainScreen = vpReadObject(vpReadObject(root, "identity"), "UIScreen");
- if (!scene || !screen || screen == mainScreen || !mainScreen ||
- [[identity valueForKey:@"isMainDisplay"] boolValue] ||
- ![identity isEqual:vpReadObject(vpUIConfigPublished, "identity")] ||
- ![vpReadObject(identity, "rootIdentity") isEqual:vpReadObject(root, "identity")]) {
- vpFoldDisplayLog(@"UI screen traits: owned alias/Main screen binding unavailable"); return;
- }
- SEL selector = sel_registerName("_setUserInterfaceIdiom:");
- Method setter = class_getInstanceMethod(object_getClass(screen), selector);
- NSNumber *source = [mainScreen valueForKey:@"_userInterfaceIdiom"];
- NSNumber *original = [screen valueForKey:@"_userInterfaceIdiom"];
- if (!setter || strcmp(method_getTypeEncoding(setter), "v24@0:8q16") != 0 ||
- ![source isKindOfClass:NSNumber.class] || ![original isKindOfClass:NSNumber.class] || source.integerValue != 0) {
- vpFoldDisplayLog([NSString stringWithFormat:@"UI screen traits: native setter/source unavailable source=%@ original=%@", source, original]); return;
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"UI screen traits: source=%@ alias=%@ trait=%@",
- source, original, [vpReadObject(screen, "traitCollection") valueForKey:@"userInterfaceIdiom"]]);
- vpUITraitsScreen = screen; vpUITraitsOriginalIdiom = original;
- vpUITraitsPublishedIdiom = source.integerValue;
- vpUITraitsIdentifier = vpReadObject(identity, "uniqueIdentifier");
- ((void (*)(id, SEL, NSInteger))objc_msgSend)(screen, selector, source.integerValue);
- vpPropagateUIScreenTraits(screen);
- vpFoldDisplayLog([NSString stringWithFormat:@"UI screen traits: native phone inheritance idiom=%@ trait=%@ embedded=%@",
- [screen valueForKey:@"_userInterfaceIdiom"], [vpReadObject(screen, "traitCollection") valueForKey:@"userInterfaceIdiom"],
- vpReadBoolValue(screen, "_isEmbeddedScreen")]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"UI screen traits exception: %@", exception.reason]);
- }
-}
-
-// MARK: - status component
-
-static void vpUIStatusLifecycle(id component, const char *name, id scene) {
- SEL selector = sel_registerName(name);
- Method method = class_getInstanceMethod(object_getClass(component), selector);
- if (method && strcmp(method_getTypeEncoding(method), "v24@0:8@16") == 0)
- ((void (*)(id, SEL, id))objc_msgSend)(component, selector, scene);
-}
-
-static BOOL vpUIStatusRegistryAvailable(id scene) {
- Method reg = class_getInstanceMethod(object_getClass(scene), sel_registerName("_registerSceneComponent:forKey:"));
- Method unreg = class_getInstanceMethod(object_getClass(scene), sel_registerName("_unregisterSceneComponentForKey:"));
- return reg && unreg && strcmp(method_getTypeEncoding(reg), "v32@0:8@16@24") == 0 &&
- strcmp(method_getTypeEncoding(unreg), "v24@0:8@16") == 0;
-}
-
-static void vpDetachUIStatusComponent(void) {
- id scene = vpUIConfigWindowScene;
- if (!scene || !vpUINewStatusComponent || !vpUIStatusComponentKey) return;
- id current = vpReadObject(scene, "statusBarManager");
- if (current != vpUINewStatusComponent) return;
- id replacementWindow = vpReadObject(current, "statusBarWindow");
- if (replacementWindow && replacementWindow != vpUIOldStatusWindow)
- ((void (*)(id, SEL, BOOL))objc_msgSend)(replacementWindow, sel_registerName("setHidden:"), YES);
- vpUIStatusLifecycle(current, "windowSceneDidDisconnect:", scene);
- // Keep a registered component while UIKit processes the identity rollback;
- // replace it only after the original identity has been acknowledged.
- vpUIStatusDetachedBeforeRollback = YES;
- vpFoldDisplayLog(@"UI configuration: replacement native component detached before identity rollback");
-}
-
-static BOOL vpRestoreUIStatusComponent(void) {
- if (!vpUIOldStatusComponent) return YES;
- id scene = vpUIConfigWindowScene;
- if (!scene) {
- vpUIOldStatusComponent = nil; vpUINewStatusComponent = nil; vpUIStatusComponentKey = nil;
- vpUIOldStatusWindow = nil; vpUIOldStatusWindowHidden = nil;
- vpUIStatusDetachedBeforeRollback = NO; return YES;
- }
- id current = vpReadObject(scene, "statusBarManager");
- if (current && current != vpUIOldStatusComponent && current != vpUINewStatusComponent) return NO;
- if (current == vpUINewStatusComponent) {
- if (!vpUIStatusDetachedBeforeRollback) return NO;
- ((void (*)(id, SEL, id))objc_msgSend)(scene, sel_registerName("_unregisterSceneComponentForKey:"), vpUIStatusComponentKey);
- current = nil;
- }
- if (!current)
- ((void (*)(id, SEL, id, id))objc_msgSend)(scene, sel_registerName("_registerSceneComponent:forKey:"), vpUIOldStatusComponent, vpUIStatusComponentKey);
- id window = vpReadObject(vpUIOldStatusComponent, "statusBarWindow");
- if (!vpReadObject(window, "windowScene")) {
- Method setter = class_getInstanceMethod(object_getClass(window), sel_registerName("setWindowScene:"));
- if (setter && strcmp(method_getTypeEncoding(setter), "v24@0:8@16") == 0)
- ((void (*)(id, SEL, id))objc_msgSend)(window, sel_registerName("setWindowScene:"), scene);
- }
- vpUIStatusLifecycle(vpUIOldStatusComponent, "windowSceneDidConnect:", scene);
- BOOL verified = vpReadObject(scene, "statusBarManager") == vpUIOldStatusComponent;
- if (verified && vpUIOldStatusWindowHidden && vpUIOldStatusWindow) {
- if (window != vpUIOldStatusWindow) return NO;
- ((void (*)(id, SEL, BOOL))objc_msgSend)(window, sel_registerName("setHidden:"), vpUIOldStatusWindowHidden.boolValue);
- verified = [vpReadBoolValue(window, "isHidden") isEqual:vpUIOldStatusWindowHidden];
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration: original window visibility restored=%d", verified]);
- }
- if (verified) {
- vpUIOldStatusComponent = nil; vpUINewStatusComponent = nil; vpUIStatusComponentKey = nil;
- vpUIOldStatusWindow = nil; vpUIOldStatusWindowHidden = nil;
- vpUIStatusDetachedBeforeRollback = NO;
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration: original component restore verified=%d", verified]);
- return verified;
-}
-
-void vpRefreshUIStatusComponent(void) {
- @try {
- id scene = vpUIConfigWindowScene;
- id identity = vpReadObject(scene, "_fbsDisplayIdentity");
- if (!scene || !vpUIConfigPublished || vpUIOldStatusComponent ||
- ![vpReadObject(identity, "uniqueIdentifier") isEqual:vpReadObject(vpReadObject(vpUIConfigPublished, "identity"), "uniqueIdentifier")] ||
- !vpUIStatusRegistryAvailable(scene)) return;
- id __unsafe_unretained *keyAddress = (id __unsafe_unretained *)dlsym(RTLD_DEFAULT, "_UIStatusBarManagerWindowSceneComponentKey");
- id key = keyAddress ? *keyAddress : nil;
- id old = vpReadObject(scene, "statusBarManager");
- Method init = class_getInstanceMethod(object_getClass(old), sel_registerName("initWithScene:"));
- if (!key || !old || !init || strcmp(method_getTypeEncoding(init), "@24@0:8@16") != 0) return;
- id registered = ((id (*)(id, SEL, id))objc_msgSend)(scene, sel_registerName("_sceneComponentForKey:"), key);
- if (registered != old) { vpFoldDisplayLog(@"UI configuration: native component key did not match"); return; }
- vpUIOldStatusComponent = old;
- vpUIOldStatusWindow = vpReadObject(old, "statusBarWindow");
- vpUIOldStatusWindowHidden = vpReadBoolValue(vpUIOldStatusWindow, "isHidden");
- vpUIStatusComponentKey = key;
- vpUIStatusDetachedBeforeRollback = NO;
- vpUIStatusLifecycle(old, "windowSceneDidDisconnect:", scene);
- ((void (*)(id, SEL, id))objc_msgSend)(scene, sel_registerName("_unregisterSceneComponentForKey:"), key);
- id replacement = nil;
- void *previousScope = vpStatusProfileConstructionScene;
- @try {
- if (vpStatusProfileLookupEnabled) vpStatusProfileConstructionScene = (__bridge void *)scene;
- replacement = ((id (*)(id, SEL, id))objc_msgSend)([object_getClass(old) alloc], sel_registerName("initWithScene:"), scene);
- } @finally { vpStatusProfileConstructionScene = previousScope; }
- vpUINewStatusComponent = replacement;
- if (!replacement) { vpFoldDisplayLog(@"UI configuration: native replacement unavailable; restore checkpoint retained"); return; }
- ((void (*)(id, SEL, id, id))objc_msgSend)(scene, sel_registerName("_registerSceneComponent:forKey:"), replacement, key);
- vpUIStatusLifecycle(replacement, "windowSceneDidConnect:", scene);
- if (vpStatusProfileLookupEnabled) vpResetManagedStatusProvider();
- id replacementWindow = vpReadObject(replacement, "statusBarWindow");
- if (vpUIOldStatusWindow && replacementWindow && vpUIOldStatusWindow != replacementWindow && vpUIOldStatusWindowHidden) {
- ((void (*)(id, SEL, BOOL))objc_msgSend)(vpUIOldStatusWindow, sel_registerName("setHidden:"), YES);
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration: previous profile window deactivated hidden=%@",
- vpReadBoolValue(vpUIOldStatusWindow, "isHidden")]);
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration: native component recreated=%d embedded=%@",
- vpReadObject(scene, "statusBarManager") == replacement, vpReadBoolValue(replacement, "_isEmbeddedDisplay")]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration component exception: %@", exception.reason]);
- }
-}
-
-// MARK: - scene configuration lease
-
-static BOOL vpUIConfigurationOwnedByLease(id configuration) {
- id identity = vpReadObject(configuration, "identity");
- return [vpReadObject(identity, "uniqueIdentifier") isEqual:vpReadObject(vpReadObject(vpUIConfigPublished, "identity"), "uniqueIdentifier")];
-}
-
-static BOOL vpNotifyUIConfiguration(id scene, id configuration) {
- SEL selector = sel_registerName("_noteDisplayIdentityDidChangeWithConfiguration:");
- Method method = class_getInstanceMethod(object_getClass(scene), selector);
- if (!method || strcmp(method_getTypeEncoding(method), "v24@0:8@16") != 0) return NO;
- ((void (*)(id, SEL, id))objc_msgSend)(scene, selector, configuration);
- return YES;
-}
-
-static void vpSetUISceneConfigurations(id configuration, id displayConfiguration, id expected, id expectedDisplay, unsigned int generation) {
- id server = vpUIConfigServerScene;
- SEL update = sel_registerName("updateUISettingsWithBlock:");
- Method method = class_getInstanceMethod(object_getClass(server), update);
- if (!method || strcmp(method_getTypeEncoding(method), "v24@0:8@?16") != 0) {
- vpFoldDisplayLog(@"UI configuration: server settings-update ABI unavailable"); return;
- }
- ((void (*)(id, SEL, id))objc_msgSend)(server, update, ^(id settings) {
- if (generation != atomic_load_explicit(&vpUIConfigGeneration, memory_order_acquire) || server != vpUIConfigServerScene ||
- !vpUIObjectsEqual(vpReadObject(settings, "sb_hostedDisplayConfiguration"), expected) ||
- !vpUIObjectsEqual(vpReadObject(settings, "displayConfiguration"), expectedDisplay)) return;
- SEL setter = sel_registerName("sb_setHostedDisplayConfiguration:");
- Method method = class_getInstanceMethod(object_getClass(settings), setter);
- if (!method || strcmp(method_getTypeEncoding(method), "v24@0:8@16") != 0) return;
- SEL displaySetter = sel_registerName("setDisplayConfiguration:");
- NSMethodSignature *signature = [settings methodSignatureForSelector:displaySetter];
- // Generated settings accessors include @"FBSDisplayConfiguration"
- // in their encoding. Validate the semantic object ABI, not spelling.
- if (!signature || signature.numberOfArguments != 3 || strcmp(signature.methodReturnType, "v") != 0 ||
- [signature getArgumentTypeAtIndex:2][0] != '@') return;
- @try {
- ((void (*)(id, SEL, id))objc_msgSend)(settings, displaySetter, displayConfiguration);
- ((void (*)(id, SEL, id))objc_msgSend)(settings, setter, configuration);
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration: hosted/display transaction generation=%u actual=%@",
- generation, vpReadObject(vpReadObject(settings, "displayIdentity"), "uniqueIdentifier")]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration transaction exception: %@", exception.reason]);
- }
- });
-}
-
-static void vpFinishUIConfigurationRestore(unsigned int generation, unsigned int attempt) {
- if (generation != atomic_load_explicit(&vpUIConfigGeneration, memory_order_acquire) || !vpUIConfigPublished) return;
- @try {
- id server = vpUIConfigServerScene;
- if (!server) {
- if (!vpRestoreUIScreenTraits()) return;
- vpUIConfigPublished = nil; vpUIConfigOriginalHosted = nil; vpUIConfigOriginalServerDisplay = nil; vpUIConfigOriginalUI = nil;
- vpUIOldStatusComponent = nil; vpUINewStatusComponent = nil; vpUIStatusComponentKey = nil;
- vpUIOldStatusWindow = nil; vpUIOldStatusWindowHidden = nil;
- vpUIStatusDetachedBeforeRollback = NO;
- vpUIConfigWindowScene = nil; vpUIConfigClientScene = nil; return;
- }
- id current = vpReadObject(vpReadObject(server, "uiSettings"), "sb_hostedDisplayConfiguration");
- id currentDisplay = vpReadObject(vpReadObject(server, "uiSettings"), "displayConfiguration");
- if (!vpUIObjectsEqual(current, vpUIConfigOriginalHosted) || !vpUIObjectsEqual(currentDisplay, vpUIConfigOriginalServerDisplay)) {
- if ((!vpUIObjectsEqual(current, vpUIConfigPublished) && !vpUIObjectsEqual(current, vpUIConfigOriginalHosted)) ||
- (!vpUIObjectsEqual(currentDisplay, vpUIConfigPublished) && !vpUIObjectsEqual(currentDisplay, vpUIConfigOriginalServerDisplay))) {
- vpFoldDisplayLog(@"UI configuration: newer hosted value preserved; checkpoint retained"); return;
- }
- vpSetUISceneConfigurations(vpUIConfigOriginalHosted, vpUIConfigOriginalServerDisplay, current, currentDisplay, generation);
- } else {
- id scene = vpUIConfigWindowScene;
- id liveIdentityBeforeRestore = vpReadObject(scene, "_fbsDisplayIdentity");
- BOOL uiOwnedBeforeRestore = vpUIConfigurationOwnedByLease(vpReadObject(scene, "_sbDisplayConfiguration")) ||
- [vpReadObject(liveIdentityBeforeRestore, "uniqueIdentifier") isEqual:vpReadObject(vpReadObject(vpUIConfigPublished, "identity"), "uniqueIdentifier")];
- if (scene && vpReadObject(scene, "_FBSScene") == vpUIConfigClientScene && uiOwnedBeforeRestore)
- vpNotifyUIConfiguration(scene, vpUIConfigOriginalUI);
- id liveIdentity = vpReadObject(scene, "_fbsDisplayIdentity");
- BOOL uiStillOwned = scene && (vpUIConfigurationOwnedByLease(vpReadObject(scene, "_sbDisplayConfiguration")) ||
- [vpReadObject(liveIdentity, "uniqueIdentifier") isEqual:vpReadObject(vpReadObject(vpUIConfigPublished, "identity"), "uniqueIdentifier")]);
- if (!uiStillOwned && vpRestoreUIStatusComponent() && vpRestoreUIScreenTraits()) {
- vpUIConfigPublished = nil; vpUIConfigOriginalHosted = nil; vpUIConfigOriginalServerDisplay = nil; vpUIConfigOriginalUI = nil;
- vpUIConfigWindowScene = nil; vpUIConfigServerScene = nil; vpUIConfigClientScene = nil;
- vpFoldDisplayLog(@"UI configuration: original hosted/UI configuration verified"); return;
- }
- }
- if (attempt < 5) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 5), dispatch_get_main_queue(), ^{
- vpFinishUIConfigurationRestore(generation, attempt + 1);
- });
- else vpFoldDisplayLog(@"UI configuration: restore pending; checkpoint retained");
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration restore exception: %@", exception.reason]);
- }
-}
-
-void vpRestoreUIConfiguration(void) {
- vpRestoreStatusProfileLookup();
- @try { vpDetachUIStatusComponent(); } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration component detach exception: %@", exception.reason]);
- }
- unsigned int generation = atomic_fetch_add_explicit(&vpUIConfigGeneration, 1, memory_order_acq_rel) + 1;
- vpFinishUIConfigurationRestore(generation, 0);
-}
-
-void vpActivateUIConfiguration(void) {
- @try {
- id scene = vpUIConfigWindowScene;
- id current = vpReadObject(vpReadObject(vpUIConfigServerScene, "uiSettings"), "sb_hostedDisplayConfiguration");
- if (!scene || vpReadObject(scene, "_FBSScene") != vpUIConfigClientScene ||
- !vpUIConfigPublished || !vpUIObjectsEqual(current, vpUIConfigPublished)) {
- vpFoldDisplayLog(@"UI configuration: activation refused without current hosted lease"); return;
- }
- BOOL submitted = vpNotifyUIConfiguration(scene, vpUIConfigPublished);
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration: native client activation submitted=%d", submitted]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration activation exception: %@", exception.reason]);
- }
-}
-
-void vpPulseUIConfiguration(BOOL nonEmbedded) {
- @try {
- if (vpUIConfigPublished) { vpFoldDisplayLog(@"UI configuration: prior lease must restore first"); return; }
- id scene = vpMainInnerWindowScene();
- id root = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- id monitor = vpReadObject(objc_getClass("FBDisplayManager"), "sharedInstance");
- if (!scene || ![vpReadObject(vpReadObject(scene, "_FBSScene"), "identifier") isEqual:@"SB-main"] ||
- !vpIsDuoInnerBounds(root) ||
- [vpReadObject(monitor, "alwaysConnectedIdentities") count] != 1) return;
- id candidate = nonEmbedded ? vpCreateNonEmbeddedUIConfiguration(root) : vpCreateUIConfiguration(root);
- id render = vpReadObject(root, "CADisplay");
- id identity = vpReadObject(candidate, "identity");
- if (!candidate || !render || vpReadObject(candidate, "CADisplay") != render ||
- ![vpReadObject(identity, "rootIdentity") isEqual:vpReadObject(root, "identity")] ||
- [[identity valueForKey:@"isUIKitMainLike"] boolValue] == nonEmbedded || [[identity valueForKey:@"isExternal"] boolValue]) return;
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id server = nil;
- for (id candidateServer in vpRootServerScenes(app))
- if ([vpReadObject(candidateServer, "identifier") isEqual:@"SB-main"]) { server = candidateServer; break; }
- Method update = class_getInstanceMethod(object_getClass(server), sel_registerName("updateUISettingsWithBlock:"));
- id client = vpReadObject(scene, "_FBSScene");
- if (!client || !update || strcmp(method_getTypeEncoding(update), "v24@0:8@?16") != 0) {
- vpFoldDisplayLog(@"UI configuration: writable SB-main server unavailable"); return;
- }
- id settingsCopy = [vpReadObject(server, "uiSettings") mutableCopy];
- for (NSString *name in @[@"setDisplayConfiguration:", @"_setDisplayConfiguration:", @"setDisplayIdentity:"]) {
- SEL selector = NSSelectorFromString(name);
- BOOL available = [settingsCopy respondsToSelector:selector];
- Method method = available ? class_getInstanceMethod(object_getClass(settingsCopy), selector) : NULL;
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration: mutable %@ %s ABI=%s",
- NSStringFromClass(object_getClass(settingsCopy)), name.UTF8String, method ? method_getTypeEncoding(method) : "unavailable"]);
- }
- vpUIConfigWindowScene = scene;
- vpUIConfigServerScene = server;
- vpUIConfigClientScene = client;
- vpUIConfigOriginalHosted = vpReadObject(vpReadObject(vpUIConfigServerScene, "uiSettings"), "sb_hostedDisplayConfiguration");
- vpUIConfigOriginalServerDisplay = vpReadObject(vpReadObject(vpUIConfigServerScene, "uiSettings"), "displayConfiguration");
- vpUIConfigOriginalUI = vpReadObject(scene, "_sbDisplayConfiguration") ?: root;
- vpUIConfigPublished = candidate;
- unsigned int generation = atomic_fetch_add_explicit(&vpUIConfigGeneration, 1, memory_order_acq_rel) + 1;
- vpSetUISceneConfigurations(candidate, candidate, vpUIConfigOriginalHosted, vpUIConfigOriginalServerDisplay, generation);
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration: ten-second hosted lease generation=%u", generation]);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- if (generation == atomic_load_explicit(&vpUIConfigGeneration, memory_order_acquire)) vpRestoreUIConfiguration();
- });
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"UI configuration pulse exception: %@", exception.reason]);
- }
-}
-
-void vpPreviewUISceneConfiguration(void) {
- @try {
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- id rootIdentity = vpReadObject(configuration, "identity");
- if (![[rootIdentity valueForKey:@"isMainRootDisplay"] boolValue]) return;
- NSArray *physicalBefore = vpReadObject(objc_getClass("CADisplay"), "displays");
- NSUInteger physicalCountBefore = physicalBefore.count;
- id monitor = vpReadObject(objc_getClass("FBDisplayManager"), "sharedInstance");
- id identitiesBefore = vpReadObject(monitor, "alwaysConnectedIdentities");
- NSUInteger connectedCountBefore = [identitiesBefore count];
- Class builderClass = objc_getClass("FBSDisplayConfigurationBuilder");
- Method setType = class_getInstanceMethod(builderClass, sel_registerName("setDisplayType:"));
- Method mainLike = class_getInstanceMethod(builderClass, sel_registerName("setUIKitMainLike"));
- if (!setType || strcmp(method_getTypeEncoding(setType), "v24@0:8q16") != 0 ||
- !mainLike || strcmp(method_getTypeEncoding(mainLike), "v16@0:8") != 0) return;
- id<VPhoneDisplayProjectionBuilding> builder = [(id<VPhoneDisplayProjectionBuilding>)[builderClass alloc] initWithConfiguration:configuration];
- [builder setUniqueIdentifier:@"vphone-duo-ui-preview"];
- // Unknown (7) is native-valid (type 2 is reserved/invalid). Retain
- // the integrated, nonexternal Main backing and mark the UI view main-like.
- [builder setDisplayType:7];
- [builder setUIKitMainLike];
- NSError *error = nil;
- id preview = [builder buildConfigurationWithError:&error];
- if (!preview) { vpFoldDisplayLog([NSString stringWithFormat:@"UI context preview build failed: %@", error]); return; }
- id identity = vpReadObject(preview, "identity");
- NSMutableDictionary *result = [NSMutableDictionary dictionary];
- for (NSString *key in @[@"isMainDisplay", @"isMainRootDisplay", @"isRootIdentity", @"isUIKitMainLike",
- @"isAlwaysConnected", @"isExternal", @"connectionType", @"type", @"displayID", @"uniqueIdentifier"])
- result[key] = [identity valueForKey:key] ?: NSNull.null;
- result[@"rootIdentity"] = vpReadObject(vpReadObject(identity, "rootIdentity"), "uniqueIdentifier") ?: NSNull.null;
- result[@"rootMatchesOriginal"] = @([vpReadObject(identity, "rootIdentity") isEqual:rootIdentity]);
- result[@"bounds"] = vpSnapshotRect(preview, "bounds");
- id originalRender = vpReadObject(configuration, "CADisplay");
- id previewRender = vpReadObject(preview, "CADisplay");
- result[@"renderAccessorAvailable"] = @(originalRender != nil && previewRender != nil);
- result[@"sameRenderDisplay"] = originalRender && previewRender ? @(originalRender == previewRender) : NSNull.null;
- result[@"caDisplayObjectCountBefore"] = @(physicalCountBefore);
- result[@"caDisplayObjectCountAfter"] = @([vpReadObject(objc_getClass("CADisplay"), "displays") count]);
- result[@"connectedCountBefore"] = @(connectedCountBefore);
- result[@"connectedCountAfter"] = @([vpReadObject(monitor, "alwaysConnectedIdentities") count]);
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- for (id serverScene in vpRootServerScenes(app)) {
- if (![vpReadObject(serverScene, "identifier") isEqual:@"SB-main"]) continue;
- id original = vpReadObject(serverScene, "uiSettings");
- id copy = [original mutableCopy];
- Method setter = class_getInstanceMethod(object_getClass(copy), sel_registerName("sb_setHostedDisplayConfiguration:"));
- if (!copy || copy == original || !setter || strcmp(method_getTypeEncoding(setter), "v24@0:8@16") != 0) continue;
- ((void (*)(id, SEL, id))objc_msgSend)(copy, sel_registerName("sb_setHostedDisplayConfiguration:"), preview);
- result[@"originalHostedIdentity"] = vpReadObject(vpReadObject(vpReadObject(original, "sb_hostedDisplayConfiguration"), "identity"), "uniqueIdentifier") ?: NSNull.null;
- result[@"copiedHostedIdentity"] = vpReadObject(vpReadObject(vpReadObject(copy, "sb_hostedDisplayConfiguration"), "identity"), "uniqueIdentifier") ?: NSNull.null;
- result[@"originalFrame"] = vpSnapshotRect(original, "frame");
- result[@"copiedFrame"] = vpSnapshotRect(copy, "frame");
- }
- result[@"published"] = @NO;
- NSData *data = [NSJSONSerialization dataWithJSONObject:result options:0 error:NULL];
- if (data) vpFoldDisplayLog([@"UI context preview " stringByAppendingString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"UI context preview exception: %@", exception.reason]);
- }
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayViewport.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayViewport.m
deleted file mode 100644
index 3d0cc0e3..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayViewport.m
+++ /dev/null
@@ -1,428 +0,0 @@
-// The single-Main logical viewport: cover and inner viewport requests, scene
-// bounds adoption after a transform publishes, and the persistent viewport.
-
-#import "FoldDisplayPrivate.h"
-
-atomic_bool vpCoverViewportEnabled;
-BOOL vpPersistentViewport;
-IMP vpOriginalLogicalSurfaceType;
-static _Thread_local BOOL vpReadingLogicalSurface;
-atomic_uint vpViewportRequestGeneration;
-atomic_bool vpNativeGeometryRefreshEnabled;
-static atomic_uint vpWindowGeometryRefreshGeneration;
-atomic_bool vpSceneResizePropagationEnabled;
-IMP vpOriginalSBWindowResizePolicy;
-static __weak id vpSceneResizeScope;
-NSMutableDictionary<NSString *, NSNumber *> *vpResizedSceneGenerations;
-
-static void vpApplyRootGeometry(void);
-
-// MARK: - adoption after a transform
-
-// The generation whose post-transform adoption pass already ran.
-static atomic_uint vpAdoptionCompletedGeneration;
-
-// The overridden Main configuration keeps its identity, so FrontBoard
-// pushes no scene-settings update when only the mode size changed. The
-// 3803cc4d root-geometry pass published the active bounds to the SB-main
-// root scene through its settings-mutation API; recovered here.
-void vpScheduleViewportAdoption(void) {
- unsigned int adoptionGeneration = atomic_load_explicit(&vpViewportRequestGeneration, memory_order_relaxed);
- if (adoptionGeneration == atomic_load_explicit(&vpAdoptionCompletedGeneration, memory_order_relaxed)) return;
- atomic_store_explicit(&vpAdoptionCompletedGeneration, adoptionGeneration, memory_order_relaxed);
- vpApplyRootGeometry();
- if (vpPersistentViewport) {
- vpProcessViewportWorkspaceRequest(YES);
- // The cover arbiter derives its direction once, at the mode swap,
- // from the pre-swap pose, and holds it; vphoned's confirm loop
- // corrects it only after the bounds settle, leaving a landscape
- // frame visible for about a second. Complete the actuation with
- // the cover's native portrait in the same adoption turn.
- if (atomic_load_explicit(&vpCoverViewportEnabled, memory_order_acquire))
- vpRefreshNativeOrientationActuation();
- }
-}
-static void vpApplyRootGeometry(void) {
- if (!vpAutomaticMainStatus) return;
- @try {
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- if (!app || !configuration) return;
- NSArray *bounds = vpSnapshotRect(configuration, "bounds");
- if (![bounds isKindOfClass:NSArray.class] || bounds.count != 4) return;
- // The 3803cc4d pass (___vpUpdateRootSceneGeometry_block_invoke) set
- // the frame on every root scene through updateUISettingsWithBlock:,
- // whose block receives the mutable settings. The native geometry
- // callback then propagates: icon family switch and window resizes.
- CGRect frame = CGRectMake(0, 0, [bounds[2] doubleValue], [bounds[3] doubleValue]);
- // The cover mode is smaller than the physical surface and the scene
- // renders it at the surface's top-left; the host window crops that
- // region and presents it full-bleed, so the origin stays at zero —
- // centering here would desynchronize the two sides.
- for (id scene in vpRootServerScenes(app)) {
- id identifier = vpReadObject(scene, "identifier");
- if (![identifier isEqual:@"SB-main"] &&
- ![identifier isEqual:@"SB-systemAperture"] &&
- ![identifier isEqual:@"SB-systemApertureCurtain"]) continue;
- SEL updateSelector = sel_registerName("updateUISettingsWithBlock:");
- Method update = class_getInstanceMethod(object_getClass(scene), updateSelector);
- if (!update || strcmp(method_getTypeEncoding(update), "v24@0:8@?16") != 0) {
- vpFoldDisplayLog(@"root geometry: settings-update ABI unavailable");
- continue;
- }
- __block BOOL frameSet = NO;
- ((void (*)(id, SEL, id))objc_msgSend)(scene, updateSelector, ^(id settings) {
- @try {
- if (!settings) return;
- SEL frameSelector = sel_registerName("setFrame:");
- Method frameSetter = class_getInstanceMethod(object_getClass(settings), frameSelector);
- const char *frameABI = frameSetter ? method_getTypeEncoding(frameSetter) : NULL;
- if (frameABI && strcmp(frameABI, "v48@0:8{CGRect={CGPoint=dd}{CGSize=dd}}16") == 0) {
- ((void (*)(id, SEL, CGRect))objc_msgSend)(settings, frameSelector, frame);
- frameSet = YES;
- } else if (frameABI && strcmp(frameABI, "v48@0:8{CGRect={CGPoint=ff}{CGSize=ff}}16") == 0) {
- // 32-bit CGFloat ABI: pass the same frame in float slots.
- ((void (*)(id, SEL, CGRect))objc_msgSend)(settings, frameSelector, frame);
- frameSet = YES;
- } else {
- vpFoldDisplayLog([NSString stringWithFormat:@"root geometry: frame setter ABI %s on %s",
- frameABI ?: "absent", object_getClassName(settings)]);
- }
- Method hosted = class_getInstanceMethod(object_getClass(settings), sel_registerName("sb_setHostedDisplayConfiguration:"));
- if (hosted && strcmp(method_getTypeEncoding(hosted), "v24@0:8@16") == 0)
- ((void (*)(id, SEL, id))objc_msgSend)(settings, sel_registerName("sb_setHostedDisplayConfiguration:"), configuration);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"root geometry settings exception: %@", exception.reason]);
- }
- });
- vpFoldDisplayLog([NSString stringWithFormat:@"root geometry: %@ settings frame=%@ generation=%u",
- identifier, frameSet ? [NSString stringWithFormat:@"(%.0f, %.0f, %.0f, %.0f)",
- frame.origin.x, frame.origin.y, frame.size.width, frame.size.height] : @"unset",
- atomic_load_explicit(&vpViewportRequestGeneration, memory_order_relaxed)]);
- }
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"root geometry exception: %@", exception.reason]);
- }
-}
-
-// MARK: - logical role and scene bounds
-
-void vpLogicalProjectionControl(NSInteger action) {
- vpFoldDisplayLog([NSString stringWithFormat:@"logical projection control requested action=%ld", (long)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");
- if (!vpLogicalRoleExperiment || proxies.count != 1) return;
- id proxy = proxies.allValues.firstObject;
- if (![vpReadObject(proxy, "identifier") isEqual:@"legacyMain"] ||
- [[proxy valueForKey:@"isExternal"] boolValue]) return;
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- if (![[vpReadObject(configuration, "identity") valueForKey:@"isMainRootDisplay"] boolValue]) return;
- SEL boundsSelector = sel_registerName("bounds");
- NSMethodSignature *signature = [configuration methodSignatureForSelector:boundsSelector];
- if (signature.methodReturnLength != sizeof(CGRect)) return;
- CGRect bounds = ((CGRect (*)(id, SEL))objc_msgSend)(configuration, boundsSelector);
- NSInteger role = CGRectEqualToRect(bounds, CGRectMake(0, 0, 669, 951)) ? 2 :
- (CGRectEqualToRect(bounds, CGRectMake(0, 0, 466, 678)) ? 1 : 0);
- SEL setter = sel_registerName("setSurfaceType:");
- SEL update = sel_registerName("_updateResolvedContentModesForDisplays");
- Method sm = class_getInstanceMethod(object_getClass(proxy), setter);
- Method um = class_getInstanceMethod(object_getClass(resolver), update);
- Ivar ready = class_getInstanceVariable(object_getClass(resolver), "_isReadyToResolve");
- if (!role || !sm || strcmp(method_getTypeEncoding(sm), "v24@0:8q16") != 0 ||
- !um || strcmp(method_getTypeEncoding(um), "v16@0:8") != 0 ||
- !ready || strcmp(ivar_getTypeEncoding(ready), "B") != 0) return;
- ((void (*)(id, SEL, NSInteger))objc_msgSend)(proxy, setter, role);
- [resolver setValue:@YES forKey:@"isReadyToResolve"];
- ((void (*)(id, SEL))objc_msgSend)(resolver, update);
- vpFoldDisplayLog([NSString stringWithFormat:@"logical surface resolver: single Main role=%ld %@", (long)role, resolver]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"logical surface resolver exception: %@", exception.reason]);
- }
-}
-
-BOOL vpAllowScopedMainWindowResize(id self, SEL cmd) {
- BOOL original = ((BOOL (*)(id, SEL))vpOriginalSBWindowResizePolicy)(self, cmd);
- id scope = vpSceneResizeScope;
- return original || (scope && vpReadObject(self, "windowScene") == scope);
-}
-
-// Native SBHIconManager owns the provider family independently of UIScreen.
-// Its native setter rebuilds the provider and updates root-folder and Dock
-// consumers; do not replace individual views or reset the user's icon model.
-static void vpRefreshSceneIconFamily(id windowScene) {
- if (![vpReadObject(vpReadObject(windowScene, "_FBSScene"), "identifier") isEqual:@"SB-main"]) return;
- Method familyMethod = class_getInstanceMethod(object_getClass(windowScene), sel_registerName("sbhScreenType"));
- if (!familyMethod || strcmp(method_getTypeEncoding(familyMethod), "Q16@0:8") != 0) return;
- NSUInteger family = ((NSUInteger (*)(id, SEL))objc_msgSend)(windowScene, sel_registerName("sbhScreenType"));
- if (family != 31 && family != 32) return;
- for (id window in vpReadObject(windowScene, "windows")) {
- id controller = vpReadObject(window, "rootViewController");
- Class homeClass = objc_getClass("SBHomeScreenViewController");
- if (!homeClass || ![controller isKindOfClass:homeClass]) continue;
- id manager = vpReadObjectIvar(controller, "_iconManager");
- SEL update = sel_registerName("setScreenType:listLayoutProviderLayoutOptions:animated:");
- Method method = class_getInstanceMethod(object_getClass(manager), update);
- Method optionsMethod = class_getInstanceMethod(object_getClass(manager), sel_registerName("listLayoutProviderLayoutOptions"));
- Ivar screenType = class_getInstanceVariable(object_getClass(manager), "_screenType");
- if (!method || strcmp(method_getTypeEncoding(method), "v36@0:8Q16Q24B32") != 0 ||
- !optionsMethod || strcmp(method_getTypeEncoding(optionsMethod), "Q16@0:8") != 0 ||
- !screenType || strcmp(ivar_getTypeEncoding(screenType), "Q") != 0) return;
- NSUInteger before = [[manager valueForKey:@"screenType"] unsignedIntegerValue];
- NSUInteger options = ((NSUInteger (*)(id, SEL))objc_msgSend)(manager, sel_registerName("listLayoutProviderLayoutOptions"));
- ((void (*)(id, SEL, NSUInteger, NSUInteger, BOOL))objc_msgSend)(manager, update, family, options, NO);
- vpFoldDisplayLog([NSString stringWithFormat:@"native icon family: %lu -> %@ requested=%lu provider=%@",
- (unsigned long)before, [manager valueForKey:@"screenType"], (unsigned long)family,
- vpReadObject(manager, "listLayoutProvider")]);
- return;
- }
-}
-
-static void vpPropagateSceneBounds(id windowScene, unsigned int generation) {
- if (generation != atomic_load_explicit(&vpViewportRequestGeneration, memory_order_relaxed)) return;
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- NSString *identifier = vpReadObject(vpReadObject(windowScene, "_FBSScene"), "identifier");
- if (!identifier || vpResizedSceneGenerations[identifier].unsignedIntValue == generation) return;
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- id identity = vpReadObject(configuration, "identity");
- BOOL owned = NO;
- for (id scene in vpRootServerScenes(app)) {
- id hosted = vpReadObject(vpReadObject(scene, "uiSettings"), "sb_hostedDisplayConfiguration");
- if ([vpReadObject(scene, "identifier") isEqual:identifier] &&
- [vpReadObject(hosted, "identity") isEqual:identity]) { owned = YES; break; }
- }
- if (!owned) return;
- CGRect target = ((CGRect (*)(id, SEL))objc_msgSend)(configuration, sel_registerName("bounds"));
- CGRect actual = ((CGRect (*)(id, SEL))objc_msgSend)(vpReadObject(windowScene, "coordinateSpace"), sel_registerName("bounds"));
- if (!CGSizeEqualToSize(target.size, actual.size)) return;
- vpResizedSceneGenerations[identifier] = @(generation);
- id previousScope = vpSceneResizeScope;
- NSUInteger notified = 0, changed = 0;
- @try {
- vpSceneResizeScope = windowScene;
- NSArray *windows = [vpReadObject(windowScene, "windows") copy];
- for (id window in windows) {
- if (vpReadObject(window, "windowScene") != windowScene ||
- !vpReadBoolValue(window, "_isSceneSized").boolValue) continue;
- // Preserve SpringBoard's TRA-owned transform/rotation state.
- // The full scene-bounds callback also updates transform layers;
- // only its native sizing substep belongs in this adapter.
- SEL update = sel_registerName("_resizeWindowFrameToSceneBoundsIfNecessary");
- Method method = class_getInstanceMethod(object_getClass(window), update);
- if (!method || strcmp(method_getTypeEncoding(method), "B16@0:8") != 0) continue;
- @try {
- NSValue *before = vpReadRectValue(window, "frame");
- ((BOOL (*)(id, SEL))objc_msgSend)(window, update);
- notified++;
- if (![before isEqual:vpReadRectValue(window, "frame")]) changed++;
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"scene resize propagation window exception: %@", exception.reason]);
- }
- }
- if (vpLogicalRoleExperiment) vpSyncLogicalRoleResolver();
- vpRefreshSceneIconFamily(windowScene);
-if (vpAutomaticMainStatus) vpRefreshMainStatusRenderer();
- if (vpPersistentViewport && [identifier isEqual:@"SB-main"])
- dispatch_async(dispatch_get_main_queue(), ^{
- if (generation == atomic_load_explicit(&vpViewportRequestGeneration, memory_order_acquire))
- vpProcessViewportWorkspaceRequest(YES);
- });
- } @finally { vpSceneResizeScope = previousScope; }
- vpFoldDisplayLog([NSString stringWithFormat:@"scene resize propagation: %@ generation=%u native notifications=%lu frames changed=%lu",
- identifier, generation, (unsigned long)notified, (unsigned long)changed]);
-}
-
-void vpObserveSceneGeometry(id self, SEL cmd, id windowScene, id previousSpace,
- NSInteger previousOrientation, id previousTraits) {
- ((void (*)(id, SEL, id, id, NSInteger, id))vpOriginalSceneGeometryCallback)(
- self, cmd, windowScene, previousSpace, previousOrientation, previousTraits);
- if (!atomic_load_explicit(&vpNativeGeometryRefreshEnabled, memory_order_acquire) &&
- !atomic_load_explicit(&vpSceneResizePropagationEnabled, memory_order_acquire)) return;
- unsigned int generation = atomic_load_explicit(&vpViewportRequestGeneration, memory_order_relaxed);
- dispatch_async(dispatch_get_main_queue(), ^{
- @try {
- if (generation != atomic_load_explicit(&vpViewportRequestGeneration, memory_order_relaxed)) return;
- if (atomic_load_explicit(&vpSceneResizePropagationEnabled, memory_order_acquire))
- vpPropagateSceneBounds(windowScene, generation);
- if (!atomic_load_explicit(&vpNativeGeometryRefreshEnabled, memory_order_acquire) ||
- generation == atomic_load_explicit(&vpWindowGeometryRefreshGeneration, memory_order_relaxed)) return;
- if (![vpReadObject(vpReadObject(windowScene, "_FBSScene"), "identifier") isEqual:@"SB-main"]) return;
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- CGRect target = ((CGRect (*)(id, SEL))objc_msgSend)(configuration, sel_registerName("bounds"));
- id space = vpReadObject(windowScene, "coordinateSpace");
- CGRect actual = ((CGRect (*)(id, SEL))objc_msgSend)(space, sel_registerName("bounds"));
- if (!CGSizeEqualToSize(target.size, actual.size)) return;
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- SEL update = sel_registerName("_notePipelineManagerChangedInterfaceOrientation:onWindowScene:duration:force:logMessage:");
- Method method = class_getInstanceMethod(object_getClass(app), update);
- if (!method || strcmp(method_getTypeEncoding(method), "v52@0:8q16@24d32B40@44") != 0) {
- vpFoldDisplayLog(@"native geometry refresh: pipeline callback ABI unavailable");
- return;
- }
- NSInteger orientation = ((NSInteger (*)(id, SEL))objc_msgSend)(windowScene, sel_registerName("interfaceOrientation"));
- if (orientation < 1 || orientation > 4) return;
- atomic_store_explicit(&vpWindowGeometryRefreshGeneration, generation, memory_order_relaxed);
- ((void (*)(id, SEL, NSInteger, id, CGFloat, BOOL, id))objc_msgSend)(app, update,
- orientation, windowScene, 0, YES, @"vphone logical display geometry refresh");
- vpFoldDisplayLog([NSString stringWithFormat:@"native geometry refresh: orientation=%ld generation=%u",
- (long)orientation, generation]);
- if (!atomic_load_explicit(&vpCoverViewportEnabled, memory_order_acquire) &&
- generation == atomic_load_explicit(&vpViewportRequestGeneration, memory_order_relaxed))
- atomic_store_explicit(&vpNativeGeometryRefreshEnabled, false, memory_order_release);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"native geometry refresh exception: %@", exception.reason]);
- }
- });
-}
-
-// MARK: - viewport requests
-
-void vpProcessViewportWorkspaceRequest(BOOL submit) {
- @try {
- id workspace = vpReadObject(objc_getClass("SBMainWorkspace"), "sharedInstance");
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- SEL create = sel_registerName("createRequestWithOptions:displayConfiguration:");
- Method method = class_getInstanceMethod(object_getClass(workspace), create);
- if (!workspace || !configuration || !method || strcmp(method_getTypeEncoding(method), "@32@0:8Q16@24") != 0) {
- vpFoldDisplayLog(@"viewport workspace preview: factory unavailable"); return;
- }
- // Native factory and local finalization only; never submit or run this preview.
- id request = ((id (*)(id, SEL, NSUInteger, id))objc_msgSend)(workspace, create, 0, configuration);
- id context = vpReadObject(request, "applicationContext");
- vpFoldDisplayLog([NSString stringWithFormat:@"viewport workspace preview: request=%@ context=%@ from=%@ to=%@",
- vpReadMultilineDescription(request) ?: request, vpReadMultilineDescription(context) ?: context,
- vpReadObject(request, "fromApplicationSceneEntities"), vpReadObject(request, "toApplicationSceneEntities")]);
- id app = vpReadObject(objc_getClass("UIApplication"), "sharedApplication");
- id scene = vpReadObject(app, "activeDisplayWindowScene") ?: vpReadObject(app, "embeddedDisplayWindowScene");
- id coordinator = vpReadObject(scene, "layoutStateTransitionCoordinator");
-id provider = vpReadObject(scene, "layoutStateProvider");
- id state = vpReadObject(provider, "layoutState");
- vpFoldDisplayLog([NSString stringWithFormat:@"viewport workspace current layout: scene=%@ coordinator=%@ provider=%@ state=%@",
- vpReadObject(vpReadObject(scene, "_FBSScene"), "identifier"), coordinator, provider,
- vpReadMultilineDescription(state) ?: state]);
- NSArray *elements = [vpReadObject(state, "elements") allObjects];
- SEL previousSetter = sel_registerName("setPreviousEntity:forLayoutRole:");
- SEL targetSetter = sel_registerName("setEntity:forLayoutRole:");
- Method previousMethod = class_getInstanceMethod(object_getClass(context), previousSetter);
- Method targetMethod = class_getInstanceMethod(object_getClass(context), targetSetter);
- Method finalize = class_getInstanceMethod(object_getClass(request), sel_registerName("finalize"));
- vpFoldDisplayLog([NSString stringWithFormat:@"viewport workspace guard: elements=%lu previous=%d target=%d finalize=%d",
- (unsigned long)elements.count, previousMethod != NULL, targetMethod != NULL, finalize != NULL]);
- if (elements.count != 1 || !previousMethod || !targetMethod || !finalize ||
- strcmp(method_getTypeEncoding(previousMethod), "v32@0:8@16q24") != 0 ||
- strcmp(method_getTypeEncoding(targetMethod), "v32@0:8@16q24") != 0 ||
- strcmp(method_getTypeEncoding(finalize), "v16@0:8") != 0) return;
- id element = elements.firstObject;
- id entity = vpReadObject(element, "workspaceEntity");
- Method roleMethod = class_getInstanceMethod(object_getClass(element), sel_registerName("layoutRole"));
- if (!entity || !roleMethod || strcmp(method_getTypeEncoding(roleMethod), "q16@0:8") != 0) return;
- NSInteger role = ((NSInteger (*)(id, SEL))objc_msgSend)(element, sel_registerName("layoutRole"));
- ((void (*)(id, SEL, id, NSInteger))objc_msgSend)(context, previousSetter, entity, role);
- ((void (*)(id, SEL, id, NSInteger))objc_msgSend)(context, targetSetter, entity, role);
-SEL attributesSelector = sel_registerName("layoutAttributesForElement:");
- SEL requestedAttributes = sel_registerName("setRequestedLayoutAttributes:forEntity:");
- Method attributesMethod = class_getInstanceMethod(object_getClass(state), attributesSelector);
- Method requestedMethod = class_getInstanceMethod(object_getClass(context), requestedAttributes);
- if (!attributesMethod || strcmp(method_getTypeEncoding(attributesMethod), "@24@0:8@16") != 0 ||
- !requestedMethod || strcmp(method_getTypeEncoding(requestedMethod), "v32@0:8@16@24") != 0) return;
- id attributes = ((id (*)(id, SEL, id))objc_msgSend)(state, attributesSelector, element);
- if (!attributes) return;
- ((void (*)(id, SEL, id, id))objc_msgSend)(context, requestedAttributes, attributes, entity);
- // Finalize the local request before optional controlled submission. Native context binds
- // its request and resolves entities/layout; no transaction is run.
- ((void (*)(id, SEL))objc_msgSend)(request, sel_registerName("finalize"));
- vpFoldDisplayLog([NSString stringWithFormat:@"viewport workspace finalized preview: role=%ld entity=%@ from=%@ to=%@ context=%@",
- (long)role, entity, vpReadObject(request, "fromApplicationSceneEntities"),
- vpReadObject(request, "toApplicationSceneEntities"), vpReadMultilineDescription(context) ?: context]);
- if (submit) {
- id identifier = vpReadObject(element, "uniqueIdentifier");
- NSSet *from = vpReadObject(request, "fromApplicationSceneEntities");
- NSSet *to = vpReadObject(request, "toApplicationSceneEntities");
- Class applicationEntity = objc_getClass("SBApplicationSceneEntity");
- if (!applicationEntity || ![entity isKindOfClass:applicationEntity] || role != 1 ||
- !identifier || from.count != 1 || to.count != 1 ||
- ![vpReadObject(from.anyObject, "uniqueIdentifier") isEqual:identifier] ||
- ![vpReadObject(to.anyObject, "uniqueIdentifier") isEqual:identifier] ||
- vpReadObject(provider, "layoutState") != state ||
- vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration") != configuration ||
- atomic_load_explicit(&vpViewportRequestGeneration, memory_order_acquire) == 0) {
- vpFoldDisplayLog(@"viewport workspace refresh: preservation guard refused"); return;
- }
- SEL execute = sel_registerName("executeTransitionRequest:");
- Method executeMethod = class_getInstanceMethod(object_getClass(workspace), execute);
- if (!executeMethod || strcmp(method_getTypeEncoding(executeMethod), "B24@0:8@16") != 0) return;
- BOOL accepted = ((BOOL (*)(id, SEL, id))objc_msgSend)(workspace, execute, request);
- vpFoldDisplayLog([NSString stringWithFormat:@"viewport workspace refresh: submitted=%d same entity=%@", accepted, identifier]);
- }
-
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"viewport workspace preview exception: %@", exception.reason]);
- }
-}
-
-void vpSetCoverViewport(BOOL enabled) {
- unsigned int generation = atomic_fetch_add_explicit(&vpViewportRequestGeneration, 1, memory_order_relaxed) + 1;
- atomic_store_explicit(&vpCoverViewportEnabled, enabled, memory_order_release);
- vpFoldDisplayLog([NSString stringWithFormat:@"single viewport: requested %@ generation=%u",
- enabled ? @"cover" : @"native inner", generation]);
- vpRefreshMainTransform();
- // The inner revert runs no transform branch of its own; a short delay
- // lets the native pipeline re-publish first, and the generation dedupe
- // keeps a transform-side schedule from double-running.
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(),
- ^{ vpScheduleViewportAdoption(); });
- // The posture path polls the map for the applied bounds; publish after
- // the viewport settles so its confirmation loop sees the new size.
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(),
- ^{ vpExportNativeOrientationMapping(); });
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(),
- ^{
- vpExportNativeOrientationMapping();
- vpApplyQuickActionGlyphScale();
- });
- if (enabled && !vpPersistentViewport) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 45 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- if (atomic_load_explicit(&vpViewportRequestGeneration, memory_order_relaxed) == generation &&
- atomic_load_explicit(&vpCoverViewportEnabled, memory_order_acquire)) {
- vpFoldDisplayLog(@"single viewport: timed native-configuration restore");
- vpSetCoverViewport(NO);
- }
- });
- }
-}
-
-// A single physical Main remains a single hardware source. Its active
-// logical SB-main surface follows the native canonical viewport dimensions.
-// 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);
- // 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;
- id configuration = vpReadObject(objc_getClass("FBDisplayManager"), "mainConfiguration");
- if (![vpReadObject(self, "displayIdentity") isEqual:vpReadObject(configuration, "identity")]) return native;
- NSArray *bounds = vpSnapshotRect(configuration, "bounds");
- if ([bounds isEqual:@[@0, @0, @669, @951]]) return 2;
- if ([bounds isEqual:@[@0, @0, @466, @678]]) return 1;
- return native;
- } @catch (NSException *exception) { return native; }
- @finally { vpReadingLogicalSurface = NO; }
-}
-
-void vpSetPersistentViewport(BOOL cover) {
- if (!vpAutomaticMainStatus || !vpOriginalSceneGeometryCallback || !vpOriginalSBWindowResizePolicy) return;
- if (vpPersistentViewport && atomic_load_explicit(&vpCoverViewportEnabled, memory_order_acquire) == cover) return;
- vpPersistentViewport = YES;
- atomic_store_explicit(&vpNativeGeometryRefreshEnabled, false, memory_order_release);
- atomic_store_explicit(&vpSceneResizePropagationEnabled, true, memory_order_release);
- atomic_store_explicit(&vpCoordinateRootSceneFrame, true, memory_order_release);
- vpSetCoverViewport(cover);
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayVirtualDisplay.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayVirtualDisplay.m
deleted file mode 100644
index 99836949..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayVirtualDisplay.m
+++ /dev/null
@@ -1,161 +0,0 @@
-// Virtual display experiments and render display inspection.
-
-#import "FoldDisplayPrivate.h"
-
-// Disabling the broad server probe restored startup on the Duo guest. The
-// surviving log identified BKDisplayCloneMirroringManager as an evaluator
-// owner. Inspect only this class after startup; do not realize every class or
-// replace methods until their signatures and purpose have been established.
-void vpInspectServerClass(void) {
- Class cls = objc_getClass("BKDisplayCloneMirroringManager");
- if (!cls) {
- vpFoldDisplayLog(@"targeted server probe: class absent");
- return;
- }
- unsigned int count = 0;
- Method *methods = class_copyMethodList(cls, &count);
- vpFoldDisplayLog([NSString stringWithFormat:@"targeted server probe: %u methods", count]);
- for (unsigned int i = 0; i < count; i++) {
- vpFoldDisplayLog([NSString stringWithFormat:@"server method: %s types: %s",
- sel_getName(method_getName(methods[i])), method_getTypeEncoding(methods[i])]);
- }
- free(methods);
- vpFoldDisplayLog(@"targeted server probe: complete");
-}
-
-@protocol VPhoneVirtualDisplayInitialization
-- (instancetype)initWithOptions:(NSDictionary *)options;
-@end
-
-static id vpVirtualDisplayProbe;
-
-void vpInspectRenderDisplays(void) {
- @try {
- Class cls = objc_getClass("CAWindowServer");
- SEL running = sel_registerName("serverIfRunning");
- if (![cls respondsToSelector:running]) return;
- id server = ((id (*)(id, SEL))objc_msgSend)(cls, running);
- if (![server respondsToSelector:sel_registerName("displays")]) return;
- NSArray *displays = ((id (*)(id, SEL))objc_msgSend)(server, sel_registerName("displays"));
- for (id display in displays) {
- NSMutableDictionary *info = [NSMutableDictionary dictionary];
- for (NSString *key in @[@"name", @"deviceName", @"displayId", @"displayType", @"systemIdentifiers", @"tag", @"enabled", @"extendedProperties"]) {
- if (![display respondsToSelector:NSSelectorFromString(key)]) continue;
- id value = [display valueForKey:key];
- info[key] = value ?: NSNull.null;
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"render display metadata: %@", info]);
- }
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"render display metadata exception: %@", exception.reason]);
- }
-}
-
-void vpEnableVirtualDisplayProbe(void) {
- @try {
- id display = vpVirtualDisplayProbe;
- SEL getter = sel_registerName("enabled"), setter = sel_registerName("setEnabled:");
- Method method = class_getInstanceMethod(object_getClass(display), setter);
- if (!display || ![display respondsToSelector:getter] || !method ||
- strcmp(method_getTypeEncoding(method), "v20@0:8B16") != 0) {
- vpFoldDisplayLog(@"virtual display enable: unavailable");
- return;
- }
- BOOL before = ((BOOL (*)(id, SEL))objc_msgSend)(display, getter);
- ((void (*)(id, SEL, BOOL))objc_msgSend)(display, setter, YES);
- BOOL after = ((BOOL (*)(id, SEL))objc_msgSend)(display, getter);
- vpFoldDisplayLog([NSString stringWithFormat:@"virtual display enable: before=%d after=%d", before, after]);
- vpInspectRenderDisplays();
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"virtual display enable exception: %@", exception.reason]);
- }
-}
-
-// Tags a render display with the BKS bit the guest itself describes as
-// `unknown`. FrontBoard drops an untagged source unless it is always
-// connected; this tag is what makes it publish one.
-BOOL vpTagUnknownDisplay(id display) {
- @try {
- NSString *(*describe)(NSUInteger) = dlsym(RTLD_DEFAULT, "NSStringFromBKSDisplayTags");
- SEL setter = sel_registerName("setTag:");
- Method method = class_getInstanceMethod(object_getClass(display), setter);
- if (!describe || !method || strcmp(method_getTypeEncoding(method), "v24@0:8q16") != 0) {
- vpFoldDisplayLog(@"virtual display tag: unavailable");
- return NO;
- }
- NSUInteger unknown = 0;
- for (unsigned int bit = 0; bit < 24; bit++) {
- NSUInteger candidate = (NSUInteger)1 << bit;
- NSString *label = describe(candidate);
- if (label && [label rangeOfString:@"unknown" options:NSCaseInsensitiveSearch].location != NSNotFound) {
- if (unknown) { vpFoldDisplayLog(@"virtual display tag: ambiguous unknown bit"); return NO; }
- unknown = candidate;
- }
- }
- if (!unknown) { vpFoldDisplayLog(@"virtual display tag: no unknown bit"); return NO; }
- ((void (*)(id, SEL, NSInteger))objc_msgSend)(display, setter, (NSInteger)unknown);
- vpFoldDisplayLog([NSString stringWithFormat:@"virtual display tag: %@ (%lu)", describe(unknown), (unsigned long)unknown]);
- return YES;
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"virtual display tag exception: %@", exception.reason]);
- return NO;
- }
-}
-
-void vpTagVirtualDisplayProbe(void) {
- if (vpTagUnknownDisplay(vpVirtualDisplayProbe)) vpInspectRenderDisplays();
-}
-
-void vpVirtualDisplayExperiment(BOOL create) {
- @try {
- Class serverClass = objc_getClass("CAWindowServer");
- SEL running = sel_registerName("serverIfRunning");
- if (![serverClass respondsToSelector:running]) {
- vpFoldDisplayLog(@"virtual display: server accessor absent");
- return;
- }
- id server = ((id (*)(id, SEL))objc_msgSend)(serverClass, running);
- SEL add = sel_registerName("addDisplay:"), remove = sel_registerName("removeDisplay:");
- if (!server || ![server respondsToSelector:add] || ![server respondsToSelector:remove]) {
- vpFoldDisplayLog(@"virtual display: no running render server");
- return;
- }
- if (!create) {
- if (vpVirtualDisplayProbe) {
- ((void (*)(id, SEL, id))objc_msgSend)(server, remove, vpVirtualDisplayProbe);
- vpVirtualDisplayProbe = nil;
- }
- vpFoldDisplayLog(@"virtual display: probe removed");
- id remaining = ((id (*)(id, SEL))objc_msgSend)(server, sel_registerName("displays"));
- vpFoldDisplayLog([NSString stringWithFormat:@"virtual display: server inventory after remove %@", remaining]);
- return;
- }
- if (vpVirtualDisplayProbe) {
- vpFoldDisplayLog(@"virtual display: probe already exists");
- return;
- }
- Class cls = objc_getClass("CAWindowServerVirtualDisplay");
- Method initializer = class_getInstanceMethod(cls, sel_registerName("initWithOptions:"));
- if (!initializer || strcmp(method_getTypeEncoding(initializer), "@24@0:8@16") != 0) {
- vpFoldDisplayLog(@"virtual display: initializer ABI unavailable");
- return;
- }
- // Keys recovered from this guest's QuartzCore initializer. This is
- // an independent software surface, never a new IOMFB hardware mode.
- id display = [(id<VPhoneVirtualDisplayInitialization>)[cls alloc] initWithOptions:@{
- @"kCAVirtualDisplayWidth": @1398, @"kCAVirtualDisplayHeight": @2034,
- @"kCAVirtualDisplayUpdateRate": @60, @"kCAVirtualDisplayName": @"VPhone Cover Probe",
- }];
- if (!display) {
- vpFoldDisplayLog(@"virtual display: initializer returned nil");
- return;
- }
- vpVirtualDisplayProbe = display;
- ((void (*)(id, SEL, id))objc_msgSend)(server, add, display);
- vpFoldDisplayLog([NSString stringWithFormat:@"virtual display: registered %@", display]);
- id inventory = ((id (*)(id, SEL))objc_msgSend)(server, sel_registerName("displays"));
- vpFoldDisplayLog([NSString stringWithFormat:@"virtual display: server inventory after add %@", inventory]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"virtual display exception: %@", exception.reason]);
- }
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayWallpaper.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayWallpaper.m
deleted file mode 100644
index 6397e442..00000000
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayWallpaper.m
+++ /dev/null
@@ -1,344 +0,0 @@
-// Wallpaper: the native orientation pulse, poster scene-host sync, the
-// device-to-interface bridge, the traits experiment, and the landscape gate.
-
-#import "FoldDisplayPrivate.h"
-
-static BOOL vpWallpaperOrientationLeaseActive;
-static void *vpOriginalWallpaperFeatureLookup;
-static IMP vpOriginalWallpaperSetHidden;
-static BOOL vpWallpaperTraitsExperimentInstalled;
-
-// MARK: - native orientation pulse
-
-void vpPulseNativeWallpaperOrientation(void) {
- if (!vpLogicalRoleExperiment || vpWallpaperOrientationLeaseActive) return;
- id scene = vpMainInnerWindowScene();
- id wallpaper = vpReadObject(scene, "wallpaperController");
- SEL getter = sel_registerName("_WallpaperOrientationNotForYou");
- SEL update = sel_registerName("willAnimateRotationToInterfaceOrientation:duration:force:");
- SEL boundsUpdate = sel_registerName("_updateWallpaperContainerViewBoundsForOrientation:");
- Method gm = class_getInstanceMethod(object_getClass(wallpaper), getter);
- Method um = class_getInstanceMethod(object_getClass(wallpaper), update);
- Method bm = class_getInstanceMethod(object_getClass(wallpaper), boundsUpdate);
- if (!scene || !gm || !um || strcmp(method_getTypeEncoding(gm), "q16@0:8") != 0 ||
- strcmp(method_getTypeEncoding(um), "v36@0:8q16d24B32") != 0 ||
- !bm || strcmp(method_getTypeEncoding(bm), "v24@0:8q16") != 0) return;
- NSInteger original = ((NSInteger (*)(id, SEL))objc_msgSend)(wallpaper, getter);
- static BOOL vpLoggedWallpaperOrientationSelectors = NO;
- if (!vpLoggedWallpaperOrientationSelectors) {
- vpLoggedWallpaperOrientationSelectors = YES;
- unsigned int methodCount = 0;
- Method *methods = class_copyMethodList(object_getClass(wallpaper), &methodCount);
- NSMutableArray *names = [NSMutableArray array];
- for (unsigned int i = 0; i < methodCount; i++) {
- NSString *name = NSStringFromSelector(method_getName(methods[i]));
- if ([name rangeOfString:@"rientation"].location != NSNotFound ||
- [name rangeOfString:@"otate"].location != NSNotFound) [names addObject:name];
- }
- free(methods);
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper orientation selectors: %@", names]);
- }
- NSInteger target = [[vpReadObject(scene, "traitsPipelineManager") valueForKey:@"systemArbitratedInterfaceOrientation"] integerValue];
- // The wallpaper controller takes the device-side orientation, whose
- // landscape names mirror the UI ones (UI landscape-left 4 is device
- // landscape-right 3); passing the raw interface code lands the image
- // a quarter turn off on every landscape. Measured on iPhone19,4:
- // portrait stays 1, interface 4 renders upright as 3.
- if (target == 3) target = 4;
- else if (target == 4) target = 3;
- if (original < 1 || original > 4 || target < 1 || target > 4) return;
- vpWallpaperOrientationLeaseActive = YES;
- @try {
- ((void (*)(id, SEL, NSInteger, double, BOOL))objc_msgSend)(wallpaper, update, target, 0, YES);
- ((void (*)(id, SEL, NSInteger))objc_msgSend)(wallpaper, boundsUpdate, target);
- // Traits-active wallpaper skips the legacy bounds path on this
- // single-Main Duo. Keep the existing native wallpaper objects but
- // synchronize their frames to the scene's current interface bounds.
- CGSize sceneSize = (target == 3 || target == 4)
- ? CGSizeMake(951, 669) : CGSizeMake(669, 951);
- id wallpaperWindow = vpReadObjectIvar(wallpaper, "_wallpaperWindow");
- id container = vpReadObjectIvar(wallpaper, "_wallpaperContainerView");
- id presenter = vpReadObjectIvar(wallpaper, "_wallpaperPresenter");
- id presenterView = vpReadObject(presenter, "viewIfLoaded");
- id root = vpReadObjectIvar(wallpaper, "_rootWallpaperViewController");
- id rootView = vpReadObject(root, "viewIfLoaded");
- for (id view in @[wallpaperWindow ?: NSNull.null, container ?: NSNull.null, presenterView ?: NSNull.null, rootView ?: NSNull.null]) {
- if (view == NSNull.null) continue;
- @try {
- CGRect rect = CGRectMake(0, 0, sceneSize.width, sceneSize.height);
- NSValue *value = [NSValue value:&rect withObjCType:@encode(CGRect)];
- [view setValue:value forKey:@"frame"];
- [view setValue:value forKey:@"bounds"];
- if ([view respondsToSelector:sel_registerName("setNeedsLayout")])
- ((void (*)(id, SEL))objc_msgSend)(view, sel_registerName("setNeedsLayout"));
- if ([view respondsToSelector:sel_registerName("layoutIfNeeded")])
- ((void (*)(id, SEL))objc_msgSend)(view, sel_registerName("layoutIfNeeded"));
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"native wallpaper bounds exception: %@", exception.reason]);
- }
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"native wallpaper transforms: window=%@ container=%@ presenter=%@ root=%@",
- [wallpaperWindow valueForKey:@"transform"], [container valueForKey:@"transform"],
- [presenterView valueForKey:@"transform"], [rootView valueForKey:@"transform"]]);
- vpFoldDisplayLog([NSString stringWithFormat:@"native wallpaper orientation: %ld -> %ld readback=%ld",
- (long)original, (long)target, (long)((NSInteger (*)(id, SEL))objc_msgSend)(wallpaper, getter)]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"native wallpaper orientation exception: %@", exception.reason]);
- }
- // PosterBoard may create its floating editor after the wallpaper
- // presenter was rotated. Reconcile the hosted scene after the native
- // wallpaper pass so a portrait editor remains centered in landscape.
- vpSyncWallpaperSceneHosts();
- // This is now part of the normal Duo orientation pipeline. Do not roll
- // the wallpaper back after a timer: the scene's current arbitration is
- // the source of truth and a delayed restore recreates the landscape black
- // band. The next orientation request can update it again.
- vpWallpaperOrientationLeaseActive = NO;
-}
-
-void vpDumpWallpaperTree(id view, NSUInteger depth) {
- if (!view || depth > 8) return;
- id layer = nil;
- @try { layer = [view valueForKey:@"layer"]; } @catch (NSException *exception) { }
- NSString *layerInfo = @"";
- if (layer) {
- @try {
- layerInfo = [NSString stringWithFormat:@" layer=%@ gravity=%@ scale=%@ masks=%@ cRect=%@ cCenter=%@ contents=%@",
- [layer valueForKey:@"bounds"], [layer valueForKey:@"contentsGravity"],
- [layer valueForKey:@"contentsScale"], [layer valueForKey:@"masksToBounds"],
- [layer valueForKey:@"contentsRect"], [layer valueForKey:@"contentsCenter"],
- vpDescribeLayerContents([layer valueForKey:@"contents"])];
- } @catch (NSException *exception) { }
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper tree depth=%lu class=%@ frame=%@ bounds=%@ transform=%@ hidden=%@ alpha=%@%@",
- (unsigned long)depth, NSStringFromClass([view class]), [view valueForKey:@"frame"], [view valueForKey:@"bounds"],
- [view valueForKey:@"transform"], [view valueForKey:@"hidden"], [view valueForKey:@"alpha"], layerInfo]);
- for (id child in [view valueForKey:@"subviews"] ?: @[])
- vpDumpWallpaperTree(child, depth + 1);
-}
-
-// MARK: - poster scene hosts
-
-void vpSyncWallpaperSceneHosts(void) {
- if (!vpLogicalRoleExperiment) { vpFoldDisplayLog(@"wallpaper scene host sync: experiment inactive"); return; }
- @try {
- id scene = vpMainInnerWindowScene();
- id wallpaper = vpReadObject(scene, "wallpaperController");
- id presenter = vpReadObjectIvar(wallpaper, "_wallpaperPresenter");
- id presenterView = vpReadObject(presenter, "viewIfLoaded");
- if (!presenterView) { vpFoldDisplayLog(@"wallpaper scene host sync: no presenter view"); return; }
- CGRect presenterBounds = ((CGRect (*)(id, SEL))objc_msgSend)(presenterView, sel_registerName("bounds"));
- if (presenterBounds.size.width < 100 || presenterBounds.size.height < 100) {
- vpFoldDisplayLog(@"wallpaper scene host sync: presenter bounds unusable");
- return;
- }
- NSMutableArray *pending = [NSMutableArray arrayWithObject:presenterView];
- NSUInteger synced = 0;
- while (pending.count && synced < 32) {
- id view = pending.lastObject;
- [pending removeLastObject];
- NSString *className = NSStringFromClass([view class]);
- CGRect bounds = ((CGRect (*)(id, SEL))objc_msgSend)(view, sel_registerName("bounds"));
- if ([className isEqualToString:@"_UIScenePresentationView"]) {
- id parent = vpReadObject(view, "superview");
- NSString *parentClass = parent ? NSStringFromClass([parent class]) : @"";
- // The floating poster editor remains portrait-native. Keep
- // its scene bounds intact, but center that scene inside the
- // landscape poster host instead of stretching it (stretching
- // restarts its loading transition and leaves the sheet off
- // the visual center). Wallpaper render hosts still fill the
- // presenter below.
- if ([parentClass containsString:@"PosterFloating"] &&
- bounds.size.width < presenterBounds.size.width &&
- bounds.size.height > presenterBounds.size.height) {
- @try {
- CGRect centered = CGRectMake(
- floor((presenterBounds.size.width - bounds.size.width) / 2.0),
- floor((presenterBounds.size.height - bounds.size.height) / 2.0),
- bounds.size.width, bounds.size.height);
- [view setValue:[NSValue value:&centered withObjCType:@encode(CGRect)] forKey:@"frame"];
- ((void (*)(id, SEL))objc_msgSend)(view, sel_registerName("setNeedsLayout"));
- synced++;
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper scene host center: %@ size=%@ origin={%.0f, %.0f}",
- parentClass, vpSizeText(bounds.size), centered.origin.x, centered.origin.y]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper scene host center exception: %@", exception.reason]);
- }
- }
- } else if ([className isEqualToString:@"_UISceneLayerHostContainerView"] ||
- [className isEqualToString:@"_UITouchPassthroughView"]) {
- if (!CGSizeEqualToSize(bounds.size, presenterBounds.size)) {
- @try {
- CGRect rect = CGRectMake(0, 0, presenterBounds.size.width, presenterBounds.size.height);
- NSValue *value = [NSValue value:&rect withObjCType:@encode(CGRect)];
- [view setValue:value forKey:@"frame"];
- [view setValue:value forKey:@"bounds"];
- ((void (*)(id, SEL))objc_msgSend)(view, sel_registerName("setNeedsLayout"));
- synced++;
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper scene host sync: %@ %@ -> %@",
- className, vpSizeText(bounds.size), vpSizeText(presenterBounds.size)]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper scene host node exception: %@", exception.reason]);
- }
- }
- }
- for (id child in [view valueForKey:@"subviews"] ?: @[]) [pending addObject:child];
- }
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper scene host sync: synced=%lu container=%@",
- (unsigned long)synced, vpSizeText(presenterBounds.size)]);
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper scene host sync exception: %@", exception.reason]);
- }
-}
-
-// MARK: - device-to-interface bridge
-
-// The wallpaper layer converts the device orientation to its rendering
-// interface with the platform-default table; the Duo inner panel mounts
-// rotated, so on every landscape the wallpaper bitmap lands a quarter turn
-// off while the icons (which consult the scene's mounting table) stay
-// upright. Route the wallpaper's conversion through the live scene's own
-// device→system-space converter, the one table that is correct here.
-static NSInteger (*vpOriginalWallpaperInterfaceForDevice)(id, SEL, NSInteger);
-static atomic_uint vpWallpaperBridgeCallCount;
-static NSInteger vpWallpaperInterfaceForDevice(id self, SEL cmd, NSInteger device) {
- id scene = vpMainInnerWindowScene();
- SEL convert = sel_registerName("systemSpaceOrientationForDeviceOrientation:");
- if (scene) {
- Method method = class_getInstanceMethod(object_getClass(scene), convert);
- if (method && strcmp(method_getTypeEncoding(method), "q24@0:8q16") == 0) {
- NSInteger mapped = ((NSInteger (*)(id, SEL, NSInteger))objc_msgSend)(scene, convert, device);
- if (mapped >= 1 && mapped <= 4) {
- if (atomic_load_explicit(&vpWallpaperBridgeCallCount, memory_order_relaxed) < 12) {
- atomic_fetch_add_explicit(&vpWallpaperBridgeCallCount, 1, memory_order_relaxed);
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper orientation bridge: device %ld -> interface %ld", (long)device, (long)mapped]);
- }
- return mapped;
- }
- }
- }
- return ((NSInteger (*)(id, SEL, NSInteger))vpOriginalWallpaperInterfaceForDevice)(self, cmd, device);
-}
-
-BOOL vpInstallWallpaperOrientationBridge(void) {
- id scene = vpOrientationArbitrationScene();
- id wallpaper = vpReadObject(scene, "wallpaperController");
- SEL converter = sel_registerName("_interfaceOrientationForDeviceOrientation:");
- Method method = wallpaper ? class_getInstanceMethod(object_getClass(wallpaper), converter) : NULL;
- if (!wallpaper || !method || strcmp(method_getTypeEncoding(method), "q24@0:8q16") != 0) {
- static unsigned int bridgeFailLogs = 0;
- if (bridgeFailLogs < 6) {
- bridgeFailLogs++;
- vpFoldDisplayLog([NSString stringWithFormat:
- @"wallpaper orientation bridge: unavailable scene=%@ wallpaper=%@ method=%@ types=%s",
- scene ? @"yes" : @"no", wallpaper ? NSStringFromClass(object_getClass(wallpaper)) : @"nil",
- method ? @"yes" : @"no", method ? method_getTypeEncoding(method) : "-"]);
- }
- return NO;
- }
- if (method_getImplementation(method) != (IMP)vpWallpaperInterfaceForDevice) {
- vpOriginalWallpaperInterfaceForDevice = (NSInteger (*)(id, SEL, NSInteger))method_getImplementation(method);
- method_setImplementation(method, (IMP)vpWallpaperInterfaceForDevice);
- vpFoldDisplayLog(@"wallpaper orientation bridge: installed");
- }
- return YES;
-}
-
-// MARK: - traits experiment
-
-// One-process experiment for the native wallpaper traits pipeline. The
-// shipped domain plist lacks this named flag; every other query is native.
-static bool vpWallpaperFeatureLookup(const char *domain, const char *feature) {
- if (domain && feature && strcmp(domain, "SpringBoard") == 0 &&
- strcmp(feature, "TraitsArbiterWallpaperTokyoDrift") == 0) return true;
- return ((bool (*)(const char *, const char *))vpOriginalWallpaperFeatureLookup)(domain, feature);
-}
-// Mirror the native pre-visibility role-hint assignment used by the managed
-// wallpaper branch, scoped to the existing Main-inner wallpaper window.
-static void vpWallpaperSetHidden(id self, SEL selector, BOOL hidden) {
- if (!hidden && vpLogicalRoleExperiment && vpWallpaperTraitsExperimentInstalled) {
- @try {
- id scene = vpReadObject(self, "windowScene");
- if (vpIsSingleMainStatusScene(scene, YES) && !vpReadObject(self, "_roleHint")) {
- id __unsafe_unretained *address = (id __unsafe_unretained *)dlsym(RTLD_DEFAULT, "SBTraitsParticipantRoleWallpaper");
- SEL setter = sel_registerName("_setRoleHint:");
- NSMethodSignature *signature = [self methodSignatureForSelector:setter];
- if (address && *address && signature.numberOfArguments == 3 &&
- strcmp(signature.methodReturnType, "v") == 0 && [signature getArgumentTypeAtIndex:2][0] == '@') {
- ((void (*)(id, SEL, id))objc_msgSend)(self, setter, *address);
- vpFoldDisplayLog(@"wallpaper traits experiment: native wallpaper role assigned before visibility");
- }
- }
- } @catch (NSException *exception) {
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper role assignment exception: %@", exception.reason]);
- }
- }
- ((void (*)(id, SEL, BOOL))vpOriginalWallpaperSetHidden)(self, selector, hidden);
-}
-
-void vpInstallWallpaperTraitsExperiment(void) {
- void *target = dlsym(RTLD_DEFAULT, "_os_feature_enabled_impl");
- MISFixDetourResult (*install)(const char *, void *, void *, void **) = dlsym(RTLD_DEFAULT, "MISFixDetour");
- if (!target || !install) { vpFoldDisplayLog(@"wallpaper traits experiment: native feature lookup unavailable"); return; }
- MISFixDetourResult result = install("Duo wallpaper traits experiment", target, (void *)vpWallpaperFeatureLookup, &vpOriginalWallpaperFeatureLookup);
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper traits experiment: feature lookup result=%d", result]);
- if (result == MISFixDetourOK) {
- vpWallpaperTraitsExperimentInstalled = YES;
- Class window = objc_getClass("_SBWallpaperSecureWindow");
- SEL hidden = sel_registerName("setHidden:");
- Method method = class_getInstanceMethod(window, hidden);
- if (method && strcmp(method_getTypeEncoding(method), "v20@0:8B16") == 0) {
- vpOriginalWallpaperSetHidden = method_getImplementation(method);
- BOOL installed = class_addMethod(window, hidden, (IMP)vpWallpaperSetHidden, method_getTypeEncoding(method));
- vpFoldDisplayLog([NSString stringWithFormat:@"wallpaper traits experiment: scoped visibility hook=%d", installed]);
- }
- }
-}
-
-// MARK: - landscape gate
-
-// The landscape-wallpaper gate soft-links PF_IS_PAD_DEVICE, which answers for
-// the whole process; a global YES would leak the pad answer everywhere. The
-// detour below answers YES only when the caller is inside the implementations
-// of the two supportsLandscapeWallpaperContents selectors, so the wallpaper
-// controller alone sees a pad-class answer where its native branch demands it.
-static bool (*vpOriginalPFIsPadDevice)(void);
-static uintptr_t vpLandscapeSupportImpRange[2][2];
-
-static bool vpPFIsPadDeviceReplacement(void) {
- void *caller = __builtin_return_address(0);
- uintptr_t address = (uintptr_t)caller;
- for (int i = 0; i < 2; i++) {
- if (vpLandscapeSupportImpRange[i][0] && address >= vpLandscapeSupportImpRange[i][0] &&
- address < vpLandscapeSupportImpRange[i][1])
- return true;
- }
- return ((bool (*)(void))vpOriginalPFIsPadDevice)();
-}
-
-void vpInstallLandscapeWallpaperGateDetour(void) {
- void *padSymbol = dlsym(RTLD_DEFAULT, "PF_IS_PAD_DEVICE");
- if (!padSymbol) { vpFoldDisplayLog(@"landscape gate: PF_IS_PAD_DEVICE absent"); return; }
- Class remote = objc_getClass("PBUIPosterWallpaperRemoteViewController");
- if (!remote) { vpFoldDisplayLog(@"landscape gate: remote view controller absent"); return; }
- SEL selectors[2] = {
- sel_registerName("supportsLandscapeWallpaperContents"),
- sel_registerName("supportsLandscapeWallpaperContentsForDisplayConfiguration:"),
- };
- NSUInteger ranges = 0;
- for (int i = 0; i < 2; i++) {
- Method method = class_getClassMethod(remote, selectors[i]);
- if (!method) method = class_getInstanceMethod(remote, selectors[i]);
- if (!method) continue;
- uintptr_t imp = (uintptr_t)method_getImplementation(method);
- vpLandscapeSupportImpRange[ranges][0] = imp;
- // The gate check sits within the first pages of each implementation.
- vpLandscapeSupportImpRange[ranges][1] = imp + 0x1000;
- ranges++;
- }
- if (!ranges) { vpFoldDisplayLog(@"landscape gate: no supportsLandscape selector found"); return; }
- MISFixDetourResult (*install)(const char *, void *, void *, void **) = dlsym(RTLD_DEFAULT, "MISFixDetour");
- if (!install) { vpFoldDisplayLog(@"landscape gate: MISFixDetour absent"); return; }
- MISFixDetourResult result = install("Duo landscape wallpaper gate", padSymbol, (void *)vpPFIsPadDeviceReplacement, (void **)&vpOriginalPFIsPadDevice);
- vpFoldDisplayLog([NSString stringWithFormat:@"landscape gate: ranges=%lu detour=%d", (unsigned long)ranges, result]);
-}
diff --git a/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m b/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
index 9bb17bce..83b7f2fc 100644
--- a/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
+++ b/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
@@ -1,376 +1,24 @@
-// Experimental, manifest-gated Duo display diagnostics.
-// The framebuffer already reports the requested inner dimensions, while the
-// home grid retains the narrow family. Identity-count hooks below have not
-// been called on the tested guest. Keep their outcome distinct from the
-// confirmed mainConfiguration and screen-type observations; see
+// 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
// Research/Guest/iphone_duo_bringup.md.
#import "FoldDisplayPrivate.h"
-atomic_bool vpCoordinateRootSceneFrame;
-IMP vpOriginalSceneGeometryCallback;
-BOOL vpAutomaticMainStatus;
-
-// MARK: - backboardd
-
-// backboardd owns the render displays: the surface-type probe, the virtual
-// display experiments and the orientation-event probes run there.
-static void vpInstallBackboardProbes(void) {
- vpInstallInnerRenderDisplay();
- Method extended = class_getInstanceMethod(objc_getClass("CAWindowServerDisplay"), sel_registerName("extendedProperties"));
- if (extended && strcmp(method_getTypeEncoding(extended), "@16@0:8") == 0) {
- vpOriginalExtendedProperties = method_setImplementation(extended, (IMP)vpSurfaceExtendedProperties);
- vpFoldDisplayLog(@"surface probe: extendedProperties observer installed, inactive");
- }
- static int surfaceToken, surfacePairToken, surfaceCoverToken;
- notify_register_dispatch("com.vphone.display.surface.inner", &surfaceToken, dispatch_get_main_queue(),
- ^(int token) { vpBeginSurfaceProbe(2, NO); });
- notify_register_dispatch("com.vphone.display.surface.pair", &surfacePairToken, dispatch_get_main_queue(),
- ^(int token) { vpBeginSurfaceProbe(2, YES); });
- notify_register_dispatch("com.vphone.display.surface.cover", &surfaceCoverToken, dispatch_get_main_queue(),
- ^(int token) { vpBeginSurfaceProbe(1, NO); });
- static int createToken, removeToken, serverInspectToken, enableToken, tagToken;
- notify_register_dispatch("com.vphone.display.virtual.create", &createToken, dispatch_get_main_queue(),
- ^(int token) { vpVirtualDisplayExperiment(YES); });
- notify_register_dispatch("com.vphone.display.virtual.remove", &removeToken, dispatch_get_main_queue(),
- ^(int token) { vpVirtualDisplayExperiment(NO); });
- notify_register_dispatch("com.vphone.display.server.inspect", &serverInspectToken, dispatch_get_main_queue(),
- ^(int token) { vpInspectServerClass(); vpInspectRenderDisplays(); });
- static int orientationInspectToken, orientationEnableToken, orientationRestoreToken;
- notify_register_dispatch("com.vphone.display.server.orientation.inspect", &orientationInspectToken, dispatch_get_main_queue(),
- ^(int token) { vpSnapshotBackboardOrientation(); });
- notify_register_dispatch("com.vphone.display.server.orientation.enable", &orientationEnableToken, dispatch_get_main_queue(),
- ^(int token) { vpProbeBackboardOrientationEvents(); });
- notify_register_dispatch("com.vphone.display.server.orientation.restore", &orientationRestoreToken, dispatch_get_main_queue(),
- ^(int token) { vpRestoreBackboardOrientationEvents(); });
- notify_register_dispatch("com.vphone.display.virtual.enable", &enableToken, dispatch_get_main_queue(),
- ^(int token) { vpEnableVirtualDisplayProbe(); });
- notify_register_dispatch("com.vphone.display.virtual.tag-unknown", &tagToken, dispatch_get_main_queue(),
- ^(int token) { vpTagVirtualDisplayProbe(); });
- static int innerStateToken;
- notify_register_dispatch("com.vphone.display.inner.server-state", &innerStateToken, dispatch_get_main_queue(),
- ^(int token) { vpLogRenderDisplayState(); });
-}
-
-// MARK: - SpringBoard hooks
-
-static void vpInstallSpringBoardHooks(void) {
- vpInstallInnerDisplayAdapter();
- vpInstallInnerTouch();
- // The round-16 landscape wallpaper gate is now part of the Duo startup
- // path. The one-shot marker remains accepted for older guests, but a
- // fresh boot must not silently fall back to the portrait wallpaper
- // admission path (which recreates the black bands).
- if (vpAutomaticMainStatus || vpConsumeDisplayExperimentFlag("/var/mobile/Library/Caches/vphone-duo-wallpaper-traits.once")) {
- vpInstallWallpaperTraitsExperiment();
- vpInstallLandscapeWallpaperGateDetour();
- }
- BOOL requestedFamily = vpConsumeDisplayExperimentFlag("/var/mobile/Library/Caches/vphone-duo-viewport-family.once");
- if (vpAutomaticMainStatus || requestedFamily)
- vpInstallViewportFamilyLookup();
- // Duo has one physical Main, but SpringBoard's native scene policy still
- // needs the inner role to participate in orientation and status-bar
- // arbitration. The role adapter preserves the physical identity and is
- // now part of the normal Duo path; the old once marker remains accepted
- // for older guests but is no longer required.
- if (vpAutomaticMainStatus || vpConsumeDisplayExperimentFlag("/var/mobile/Library/Caches/vphone-duo-logical-role.once")) {
- Method surface = class_getInstanceMethod(objc_getClass("SBWindowScene"), sel_registerName("surfaceType"));
- if (surface && strcmp(method_getTypeEncoding(surface), "q16@0:8") == 0) {
- vpLogicalRoleExperiment = YES;
- Class clock = objc_getClass("SBFMachNextMinuteDateProvider");
- Method tick = class_getInstanceMethod(clock, sel_registerName("_onMachTimer"));
- Method observe = class_getInstanceMethod(clock, sel_registerName("observeMinuteUpdatesWithHandler:"));
- if (tick && observe && strcmp(method_getTypeEncoding(tick), "v16@0:8") == 0 &&
- strcmp(method_getTypeEncoding(observe), "@24@0:8@?16") == 0) {
- vpOriginalMachClockTick = method_setImplementation(tick, (IMP)vpMachClockTick);
- vpOriginalMachClockObserve = method_setImplementation(observe, (IMP)vpMachClockObserve);
- vpFoldDisplayLog(@"native clock reference: detached-view scheduling adapter installed");
- }
- Method timeUpdate = class_getInstanceMethod(objc_getClass("SBStatusBarStateAggregator"), sel_registerName("_updateTimeItemsWithDate:"));
- if (timeUpdate && strcmp(method_getTypeEncoding(timeUpdate), "v24@0:8@16") == 0)
- vpOriginalTimeItemUpdate = method_setImplementation(timeUpdate, (IMP)vpObserveNativeTimeUpdate);
- vpOriginalLogicalSurfaceType = method_setImplementation(surface, (IMP)vpLogicalSurfaceType);
- vpFoldDisplayLog(@"logical surface: native-size scoped SB-main role adapter installed");
- }
- }
- vpObservedDisplayMonitors = [NSHashTable weakObjectsHashTable];
- vpResizedSceneGenerations = [NSMutableDictionary dictionary];
- Method resizePolicy = class_getInstanceMethod(objc_getClass("SBWindow"), sel_registerName("_shouldResizeWithScene"));
- if (resizePolicy && strcmp(method_getTypeEncoding(resizePolicy), "B16@0:8") == 0)
- vpOriginalSBWindowResizePolicy = method_setImplementation(resizePolicy, (IMP)vpAllowScopedMainWindowResize);
- Method sceneGeometry = class_getInstanceMethod(objc_getClass("SBAbstractWindowSceneDelegate"),
- sel_registerName("windowScene:didUpdateCoordinateSpace:interfaceOrientation:traitCollection:"));
- if (sceneGeometry && strcmp(method_getTypeEncoding(sceneGeometry), "v48@0:8@16@24q32@40") == 0)
- vpOriginalSceneGeometryCallback = method_setImplementation(sceneGeometry, (IMP)vpObserveSceneGeometry);
- // Retired: promoting a software CADisplay to builtin asserted in cloning.
- // Consume stale markers without ever installing that type/scale override.
- if (vpConsumeDisplayExperimentFlag("/var/mobile/Library/Caches/vphone-duo-internal-panel.once"))
- vpFoldDisplayLog(@"panel adapter: retired builtin promotion marker discarded");
- if (vpConsumeDisplayExperimentFlag("/var/mobile/Library/Caches/vphone-duo-shared-family.once"))
- vpInstallSharedInnerFamily();
- // With the inner display published, Main is the cover and the inner panel
- // has scenes of its own: each screen's status bar provider is chosen for
- // its own panel (vpInstallDualStatusLookup). The single-display profile
- // lookup and scene status policy below would pin Main to the inner
- // panel's profile instead.
- BOOL nativeStatus = vpInnerDisplayRequested();
- BOOL requestedMainStatus = vpConsumeDisplayExperimentFlag("/var/mobile/Library/Caches/vphone-duo-main-status.once");
- if (nativeStatus) vpInstallDualStatusLookup();
- else if (vpAutomaticMainStatus || requestedMainStatus) vpInstallMainStatusLookup();
- if (vpAutomaticMainStatus) {
- if (!nativeStatus) {
- static int mainStatusStartupToken;
- notify_register_dispatch("com.apple.springboard.finishedstartup", &mainStatusStartupToken, dispatch_get_main_queue(),
- ^(int token) { vpPulseMainStatusProfile(); });
- // The library may load before scene construction or after the startup
- // notification. Bounded retries establish the existing Main renderer.
- for (unsigned int retry = 1; retry <= 12; ++retry)
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, retry * NSEC_PER_SEC), dispatch_get_main_queue(),
- ^{ vpPulseMainStatusProfile(); });
- }
- // The same ladder establishes the default quick-action glyph scale
- // on every lock-screen construction timing without any opt-in file.
- for (unsigned int retry = 1; retry <= 12; ++retry)
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, retry * NSEC_PER_SEC), dispatch_get_main_queue(),
- ^{ vpApplyQuickActionGlyphScale(); });
- }
- BOOL requestedSceneStatus = vpConsumeDisplayExperimentFlag("/var/mobile/Library/Caches/vphone-duo-scene-status.once");
- if (!nativeStatus && (vpAutomaticMainStatus || requestedSceneStatus))
- vpInstallSceneStatusPolicy();
- if (nativeStatus) vpFoldDisplayLog(@"status bar: native per-screen providers, single-display status shims not installed");
- if (vpConsumeDisplayExperimentFlag("/var/mobile/Library/Caches/vphone-duo-root-scene-policy.once"))
- vpFoldDisplayLog(@"root scene policy: retired global Main conversion marker discarded");
- if (vpConsumeDisplayExperimentFlag("/var/mobile/Library/Caches/vphone-duo-inner-family.once")) {
- Method family = class_getInstanceMethod(objc_getClass("SBWindowScene"), sel_registerName("sbhScreenType"));
- if (family && strcmp(method_getTypeEncoding(family), "Q16@0:8") == 0) {
- vpOriginalSceneScreenType = method_setImplementation(family, (IMP)vpNativeInnerSceneFamily);
- vpFoldDisplayLog(@"shared scene family: one-instance classifier adapter installed");
- }
- }
- BOOL requestedSingleInner = vpConsumeDisplayExperimentFlag("/var/mobile/Library/Caches/vphone-duo-single-inner.once");
- if (vpLogicalRoleExperiment || requestedSingleInner) {
- Method resolve = class_getInstanceMethod(objc_getClass("SBFDisplayContentModeResolver"),
- sel_registerName("_startResolvingContentModeOfDisplay:"));
- if (resolve && strcmp(method_getTypeEncoding(resolve), "v24@0:8@16") == 0) {
- vpOriginalStartResolvingDisplay = method_setImplementation(resolve, (IMP)vpResolveSingleInnerDisplay);
- vpFoldDisplayLog(@"single inner readiness: one-instance adapter installed");
- } else vpFoldDisplayLog(@"single inner readiness: native callback ABI unavailable");
- }
- // SBFBSDisplayTransformer requires one result per source. The startup
- // two-result experiment asserted before monitor initialization; retain
- // native builder preview only, never arm that publication again.
- if (vpConsumeDisplayExperimentFlag("/var/mobile/Library/Caches/vphone-duo-logical-panel.once"))
- vpFoldDisplayLog(@"logical projection: unsupported startup marker discarded");
- // Installed before SpringBoard builds its cover sheet, so the first
- // SBSDeviceDeterminedConfiguration construction is captured.
- vpFoldDisplayLog(@"folddisplay build marker: bridge-diag-3");
- vpInstallConfigInitSwizzle();
- vpInstallLayoutClassSwizzle();
- // Keep a fresh SB-main orientation map from the first minute of boot:
- // vphoned's rotation and posture paths refuse to settle without it.
- for (unsigned int retry = 2; retry <= 12; retry += 2)
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(retry * NSEC_PER_SEC)), dispatch_get_main_queue(),
- ^{ vpExportNativeOrientationMapping(); });
-}
-
-// MARK: - notification registry
-
-// Every com.vphone.display.* request SpringBoard answers. Registration only
-// installs the handlers; none runs before the constructor returns.
-static void vpRegisterSpringBoardNotifications(void) {
- static int innerDisplayInspectToken, innerPatternToken, innerShowToken, innerHideToken;
- notify_register_dispatch("com.vphone.display.inner.inspect", &innerDisplayInspectToken, dispatch_get_main_queue(),
- ^(int token) { vpInspectInnerDisplay(); });
- notify_register_dispatch("com.vphone.display.inner.pattern", &innerPatternToken, dispatch_get_main_queue(),
- ^(int token) { vpToggleInnerPattern(); });
- notify_register_dispatch("com.vphone.display.inner.show", &innerShowToken, dispatch_get_main_queue(),
- ^(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); });
- notify_register_dispatch("com.vphone.display.viewport.apply.inner", &persistentInnerToken, dispatch_get_main_queue(),
- ^(int token) { vpSetPersistentViewport(NO); });
- static int workspaceRefreshToken;
- notify_register_dispatch("com.vphone.display.workspace.refresh", &workspaceRefreshToken, dispatch_get_main_queue(),
- ^(int token) { vpProcessViewportWorkspaceRequest(YES); });
- static int workspacePreviewToken;
- notify_register_dispatch("com.vphone.display.workspace.preview", &workspacePreviewToken, dispatch_get_main_queue(),
- ^(int token) { vpProcessViewportWorkspaceRequest(NO); });
- static int presentationWallpaperToken;
- notify_register_dispatch("com.vphone.display.presentation.wallpaper.pulse", &presentationWallpaperToken, dispatch_get_main_queue(),
- ^(int token) { vpPulseNativeWallpaperOrientation(); });
- static int presentationClockToken;
- notify_register_dispatch("com.vphone.display.presentation.clock.refresh", &presentationClockToken, dispatch_get_main_queue(),
- ^(int token) { vpRefreshNativeClockSource(); });
- static int presentationRegistrationToken;
- notify_register_dispatch("com.vphone.display.presentation.registration.refresh", &presentationRegistrationToken, dispatch_get_main_queue(),
- ^(int token) { vpRefreshNativeStatusRegistration(); });
- static int presentationInspectToken;
- notify_register_dispatch("com.vphone.display.presentation.inspect", &presentationInspectToken, dispatch_get_main_queue(),
- ^(int token) { vpInspectNativePresentation(); });
- static int quickActionInspectToken;
- notify_register_dispatch("com.vphone.display.quickaction.inspect", &quickActionInspectToken, dispatch_get_main_queue(),
- ^(int token) { vpInspectQuickActions(); });
- static int windowsInspectToken;
- notify_register_dispatch("com.vphone.display.windows.inspect", &windowsInspectToken, dispatch_get_main_queue(),
- ^(int token) { vpInspectAllWindows(); });
- static int wallpaperSceneHostSyncToken;
- notify_register_dispatch("com.vphone.display.wallpaper.scenehost.sync", &wallpaperSceneHostSyncToken, dispatch_get_main_queue(),
- ^(int token) { vpSyncWallpaperSceneHosts(); });
- static int screenUndimToken;
- notify_register_dispatch("com.vphone.display.screen.undim", &screenUndimToken, dispatch_get_main_queue(),
- ^(int token) { vpUndimScreenOnly(); });
- static int displayStateToken;
- notify_register_dispatch("com.vphone.display.inspect", &displayStateToken, dispatch_get_main_queue(),
- ^(int token) { vpSnapshotMainScene(); });
- static int displayDetailsToken, homeFamilyToken;
- notify_register_dispatch("com.vphone.display.inspect.detail", &displayDetailsToken, dispatch_get_main_queue(),
- ^(int token) { vpInspectDisplayState(); });
- notify_register_dispatch("com.vphone.display.families.inspect", &homeFamilyToken, dispatch_get_main_queue(),
- ^(int token) { vpInspectHomeScreenType(); });
- static int uiContextPreviewToken;
- notify_register_dispatch("com.vphone.display.ui_context.preview", &uiContextPreviewToken, dispatch_get_main_queue(),
- ^(int token) { vpPreviewUISceneConfiguration(); });
- static int duoSystemUIInspectToken;
- notify_register_dispatch("com.vphone.display.duo_system_ui.inspect", &duoSystemUIInspectToken, dispatch_get_main_queue(),
- ^(int token) { vpInspectDuoSystemUI(); });
- static int statusProviderInspectToken;
- notify_register_dispatch("com.vphone.display.status_provider.inspect", &statusProviderInspectToken, dispatch_get_main_queue(),
- ^(int token) { vpInspectStatusProvider(); });
- static int statusProfilePulseToken, statusProfileRestoreToken;
- notify_register_dispatch("com.vphone.display.status_profile.pulse", &statusProfilePulseToken, dispatch_get_main_queue(),
- ^(int token) { vpPulseStatusProfileLookup(); });
- notify_register_dispatch("com.vphone.display.status_profile.restore", &statusProfileRestoreToken, dispatch_get_main_queue(),
- ^(int token) { vpRestoreStatusProfileLookup(); });
- static int inputTracePulseToken, inputTraceRestoreToken;
- notify_register_dispatch("com.vphone.display.input_trace.pulse", &inputTracePulseToken, dispatch_get_main_queue(),
- ^(int token) { vpPulseInputTrace(); });
- notify_register_dispatch("com.vphone.display.input_trace.restore", &inputTraceRestoreToken, dispatch_get_main_queue(),
- ^(int token) { vpRestoreInputTrace(); });
- static int mainStatusPulseToken, mainStatusRestoreToken;
- notify_register_dispatch("com.vphone.display.main_status.pulse", &mainStatusPulseToken, dispatch_get_main_queue(),
- ^(int token) { vpPulseMainStatusProfile(); });
- notify_register_dispatch("com.vphone.display.main_status.restore", &mainStatusRestoreToken, dispatch_get_main_queue(),
- ^(int token) { vpRestoreMainStatusProfile(); });
- static int orientationMappingToken;
- notify_register_dispatch("com.vphone.display.orientation.mapping.request", &orientationMappingToken, dispatch_get_main_queue(),
- ^(int token) { vpExportNativeOrientationMapping(); });
- static int uiContextPulseToken, uiContextActivateToken, uiContextRestoreToken;
- notify_register_dispatch("com.vphone.display.ui_context.pulse", &uiContextPulseToken, dispatch_get_main_queue(),
- ^(int token) { vpPulseUIConfiguration(NO); });
- static int uiNonEmbeddedPreviewToken, uiNonEmbeddedPulseToken;
- notify_register_dispatch("com.vphone.display.ui_context.unembedded.preview", &uiNonEmbeddedPreviewToken, dispatch_get_main_queue(),
- ^(int token) { vpPreviewNonEmbeddedUIConfiguration(); });
- notify_register_dispatch("com.vphone.display.ui_context.unembedded.pulse", &uiNonEmbeddedPulseToken, dispatch_get_main_queue(),
- ^(int token) { vpPulseUIConfiguration(YES); });
- static int uiScreenTraitsToken;
- notify_register_dispatch("com.vphone.display.ui_context.traits.sync", &uiScreenTraitsToken, dispatch_get_main_queue(),
- ^(int token) { vpSyncUIScreenTraits(); });
- notify_register_dispatch("com.vphone.display.ui_context.activate", &uiContextActivateToken, dispatch_get_main_queue(),
- ^(int token) { vpActivateUIConfiguration(); });
- notify_register_dispatch("com.vphone.display.ui_context.restore", &uiContextRestoreToken, dispatch_get_main_queue(),
- ^(int token) { vpRestoreUIConfiguration(); });
- static int uiContextComponentToken;
- notify_register_dispatch("com.vphone.display.ui_context.components.refresh", &uiContextComponentToken, dispatch_get_main_queue(),
- ^(int token) { vpRefreshUIStatusComponent(); });
- static int invalidationPulseToken;
- notify_register_dispatch("com.vphone.display.invalidation.pulse", &invalidationPulseToken, dispatch_get_main_queue(),
- ^(int token) {
- if (!atomic_load_explicit(&vpCoverViewportEnabled, memory_order_acquire)) vpRefreshMainTransform();
- });
- static int coverViewportToken, innerViewportToken;
- notify_register_dispatch("com.vphone.display.viewport.cover", &coverViewportToken, dispatch_get_main_queue(),
- ^(int token) { vpSetCoverViewport(YES); });
- notify_register_dispatch("com.vphone.display.viewport.inner", &innerViewportToken, dispatch_get_main_queue(),
- ^(int token) { vpSetCoverViewport(NO); });
- static int orientationSyncToken, orientationRestoreToken;
- notify_register_dispatch("com.vphone.display.orientation.sync", &orientationSyncToken, dispatch_get_main_queue(),
- ^(int token) { vpSyncRootSceneOrientation(); });
- notify_register_dispatch("com.vphone.display.orientation.restore", &orientationRestoreToken, dispatch_get_main_queue(),
- ^(int token) { vpRestoreRootSceneOrientations(); });
- static int geometryRequestToken, geometryRestoreToken, poseRefreshToken, inputsRefreshToken;
- notify_register_dispatch("com.vphone.display.orientation.geometry", &geometryRequestToken, dispatch_get_main_queue(),
- ^(int token) { vpProbeSceneGeometryRequest(); });
- notify_register_dispatch("com.vphone.display.orientation.geometry.restore", &geometryRestoreToken, dispatch_get_main_queue(),
- ^(int token) { vpRestoreSceneGeometryRequest(); });
- notify_register_dispatch("com.vphone.display.orientation.pose.refresh", &poseRefreshToken, dispatch_get_main_queue(),
- ^(int token) { vpRefreshNativeOrientationInputs(YES); });
- notify_register_dispatch("com.vphone.display.orientation.inputs.refresh", &inputsRefreshToken, dispatch_get_main_queue(),
- ^(int token) { vpRefreshNativeOrientationInputs(NO); });
- static int arbitrationRefreshToken;
- notify_register_dispatch("com.vphone.display.orientation.arbitration.refresh", &arbitrationRefreshToken, dispatch_get_main_queue(),
- ^(int token) { vpForceNativeOrientationResolution(); });
- static int actuationRefreshToken;
- notify_register_dispatch("com.vphone.display.orientation.actuation.refresh", &actuationRefreshToken, dispatch_get_main_queue(),
- ^(int token) {
- vpRefreshNativeOrientationActuation();
- });
- static int embeddedOrientationToken, embeddedOrientationRestoreToken;
- notify_register_dispatch("com.vphone.display.orientation.embedded.sync", &embeddedOrientationToken, dispatch_get_main_queue(),
- ^(int token) { vpProbeEmbeddedOrientation(); });
- notify_register_dispatch("com.vphone.display.orientation.embedded.restore", &embeddedOrientationRestoreToken, dispatch_get_main_queue(),
- ^(int token) { vpRestoreEmbeddedOrientation(); });
- static int canonicalOrientationToken, canonicalOrientationRestoreToken;
- notify_register_dispatch("com.vphone.display.orientation.canonical", &canonicalOrientationToken, dispatch_get_main_queue(),
- ^(int token) { vpSetCanonicalOrientationProbe(YES); });
- notify_register_dispatch("com.vphone.display.orientation.canonical.restore", &canonicalOrientationRestoreToken, dispatch_get_main_queue(),
- ^(int token) { vpSetCanonicalOrientationProbe(NO); });
- static int sceneViewportToken;
- notify_register_dispatch("com.vphone.display.viewport.scene.cover", &sceneViewportToken, dispatch_get_main_queue(),
- ^(int token) {
- atomic_store_explicit(&vpCoordinateRootSceneFrame, true, memory_order_release);
- vpSetCoverViewport(YES);
- });
- static int pipelineViewportToken;
- notify_register_dispatch("com.vphone.display.viewport.pipeline.cover", &pipelineViewportToken, dispatch_get_main_queue(),
- ^(int token) {
- if (!vpOriginalSceneGeometryCallback) return;
- atomic_store_explicit(&vpNativeGeometryRefreshEnabled, true, memory_order_release);
- atomic_store_explicit(&vpCoordinateRootSceneFrame, true, memory_order_release);
- vpSetCoverViewport(YES);
- });
- static int resizeViewportToken;
- notify_register_dispatch("com.vphone.display.viewport.resize.cover", &resizeViewportToken, dispatch_get_main_queue(),
- ^(int token) {
- if (!vpOriginalSceneGeometryCallback || !vpOriginalSBWindowResizePolicy) return;
- atomic_store_explicit(&vpNativeGeometryRefreshEnabled, false, memory_order_release);
- atomic_store_explicit(&vpSceneResizePropagationEnabled, true, memory_order_release);
- atomic_store_explicit(&vpCoordinateRootSceneFrame, true, memory_order_release);
- vpSetCoverViewport(YES);
- });
- static int allowUnknownToken, restoreUnknownToken;
- notify_register_dispatch("com.vphone.display.unknown.allow", &allowUnknownToken, dispatch_get_main_queue(),
- ^(int token) { vpProbeUnknownDisplayPolicy(NO); });
- notify_register_dispatch("com.vphone.display.unknown.restore", &restoreUnknownToken, dispatch_get_main_queue(),
- ^(int token) { vpProbeUnknownDisplayPolicy(YES); });
- static int projectionPreviewToken, projectionEnableToken, projectionDisableToken;
- notify_register_dispatch("com.vphone.display.logical.preview", &projectionPreviewToken, dispatch_get_main_queue(),
- ^(int token) { vpLogicalProjectionControl(0); });
- notify_register_dispatch("com.vphone.display.logical.enable", &projectionEnableToken, dispatch_get_main_queue(),
- ^(int token) { vpFoldDisplayLog(@"logical projection publication rejected: native transformer requires one result"); });
- notify_register_dispatch("com.vphone.display.logical.disable", &projectionDisableToken, dispatch_get_main_queue(),
- ^(int token) { vpLogicalProjectionControl(2); });
-}
-
-// MARK: - constructor
-
__attribute__((constructor)) static void vpInstallFoldDisplay(void) {
- if (strcmp(getprogname(), "backboardd") == 0) {
- vpInstallBackboardProbes();
- return;
- }
- if (strcmp(getprogname(), "SpringBoard") != 0)
- return;
char product[128] = {0};
size_t productLength = sizeof(product);
- vpAutomaticMainStatus = sysctlbyname("hw.machine", product, &productLength, NULL, 0) == 0 &&
- strcmp(product, "iPhone19,4") == 0;
- vpInstallSpringBoardHooks();
- vpRegisterSpringBoardNotifications();
- vpInstallDisplayPipelineObservation();
+ if (sysctlbyname("hw.machine", product, &productLength, NULL, 0) != 0 || strcmp(product, "iPhone19,4") != 0)
+ return;
+ if (strcmp(getprogname(), "backboardd") == 0) {
+ vpInstallInnerRenderDisplay();
+ } else if (strcmp(getprogname(), "SpringBoard") == 0) {
+ vpInstallSharedPanel();
+ vpInstallInnerDisplayAdapter();
+ vpInstallDualStatusLookup();
+ }
}