Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Keep the device tree helper with the display code, and fix two comments

Marvaee2c8e624b8af
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index d3133efd..a5857aa3 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -6030,7 +6030,10 @@ answering all three yes in its `CacheExtra` crashed it the same way. Without
the flipbook, `-[BLSHBacklightOSInterfaceProvider initWithPlatformProvider:]`
gives SpringBoard BacklightServices' own renderer (`BLSHPseudoFlipbook`), which
works on a guest. Answering the first two in the cache leaves the flipbook
-unanswered there and so no.
+unanswered there and so no. Keeping `always-on-time` in the tree and answering
+the flipbook no in the cache would not do: the tree decides whenever the cache
+is missing, at a guest's first boot and after every drop, and one boot with the
+flipbook is enough to lose backboardd.
A guest that went through that crash loop kept losing backboardd after the
answers and the whole cache were removed; the cause was not found. Do not
diff --git a/VPhoneDaemon/Native/Include/VphonedNative.h b/VPhoneDaemon/Native/Include/VphonedNative.h
index 0bee5cee..b4869396 100644
--- a/VPhoneDaemon/Native/Include/VphonedNative.h
+++ b/VPhoneDaemon/Native/Include/VphonedNative.h
@@ -190,10 +190,6 @@ char * _Null_unspecified vp_usb_set_serial(const char * _Null_unspecified serial
/// `unique-chip-id`. malloc-owned, or NULL when the device tree lacks either.
char * _Null_unspecified vp_usb_own_serial(void);
-/// Whether the device tree node at `path` (an `IODeviceTree:` path) has the
-/// property `name`, whatever its value.
-bool vp_device_tree_has_property(const char * _Nonnull path, const char * _Nonnull name);
-
/// The names of the APFS snapshots of the volume mounted at `mount`, in
/// `*names` (free with `vp_apfs_snapshot_names_free`). Returns 0 or an errno value.
int vp_apfs_snapshot_list(const char * _Null_unspecified mount, char * _Null_unspecified * _Null_unspecified * _Null_unspecified names, int * _Null_unspecified count);
@@ -238,6 +234,10 @@ bool vp_devicehub_controls_start(void (^_Nonnull handler)(NSDictionary * _Nonnul
/// hinge stand-ins in dtdeviceinfod read the virtual hinge's newest sample,
/// without moving the hinge.
void vp_hinge_reading_publish(double angleDegrees, int hingeState);
+/// Whether the device tree node at `path` (an `IODeviceTree:` path) has the
+/// property `name`, whatever its value.
+bool vp_device_tree_has_property(const char * _Nonnull path, const char * _Nonnull name);
+
/// Every display-ish IOService object the guest published, with its small
/// properties: what the display stack bound, for the foldable display work.
NSArray * _Nonnull vp_display_probe(void);
diff --git a/VPhoneDaemon/Native/vphoned_display.m b/VPhoneDaemon/Native/vphoned_display.m
index 787522fa..fb4a410f 100644
--- a/VPhoneDaemon/Native/vphoned_display.m
+++ b/VPhoneDaemon/Native/vphoned_display.m
@@ -172,3 +172,14 @@ NSArray *vp_display_probe(void) {
IOObjectRelease(iterator);
return found;
}
+
+bool vp_device_tree_has_property(const char *path, const char *name) {
+ io_registry_entry_t entry = IORegistryEntryFromPath(kIOMainPortDefault, path);
+ if (entry == MACH_PORT_NULL) return false;
+ CFStringRef key = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingUTF8);
+ CFTypeRef value = key ? IORegistryEntryCreateCFProperty(entry, key, kCFAllocatorDefault, 0) : NULL;
+ if (key) CFRelease(key);
+ IOObjectRelease(entry);
+ if (value) CFRelease(value);
+ return value != NULL;
+}
diff --git a/VPhoneDaemon/Native/vphoned_usb.m b/VPhoneDaemon/Native/vphoned_usb.m
index 0c7aafcb..595b6ed0 100644
--- a/VPhoneDaemon/Native/vphoned_usb.m
+++ b/VPhoneDaemon/Native/vphoned_usb.m
@@ -113,14 +113,3 @@ char *vp_usb_own_serial(void) {
asprintf(&serial, "%08X%016llX", chipID, ecid);
return serial;
}
-
-bool vp_device_tree_has_property(const char *path, const char *name) {
- io_registry_entry_t entry = IORegistryEntryFromPath(kIOMainPortDefault, path);
- if (entry == MACH_PORT_NULL) return false;
- CFStringRef key = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingUTF8);
- CFTypeRef value = key ? IORegistryEntryCreateCFProperty(entry, key, kCFAllocatorDefault, 0) : NULL;
- if (key) CFRelease(key);
- IOObjectRelease(entry);
- if (value) CFRelease(value);
- return value != NULL;
-}
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift
index 3af1354d..40c3c4e5 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift
@@ -691,7 +691,7 @@ extension DeviceTreePatcher {
/// renders the always-on Lock Screen itself (BLSHPseudoFlipbook), which
/// works here; so the tree only marks the board, and vphoned answers the
/// first two questions yes in the MobileGestalt cache
- /// (`GuestMobileGestaltCache.presentAlwaysOnDisplay`).
+ /// (`GuestMobileGestaltCache.presentAlwaysOnDisplayOnStartup`).
static let alwaysOnDisplayMarker = "vphone-always-on-display"
/// `/buttons` properties taken from the board when they are placeholders.
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
index ab21038f..ab139267 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
@@ -46,10 +46,10 @@ static NSTimeInterval vpPanelOnAt;
// the panel off and when it dims it to the always-on Lock Screen, which keeps
// the panel on and drawing. The VM window covers the panel while the screen
// is off (display.orientation's screen_off) so that, coming on, it does not
-// show the frame from before it went off; vphoned reads this state so that it
-// does not cover the always-on Lock Screen too. The panel counts as dark from
-// going off until SpringBoard lights the screen again, so a wake from off is
-// covered as before.
+// show the frame from before it went off. vphoned reports this state instead,
+// so the window leaves the always-on Lock Screen uncovered. The panel counts
+// as dark from going off until SpringBoard lights the screen again, so a wake
+// from off is covered as before.
static int vpBlankedToken = -1, vpPanelDarkToken = -1;
static BOOL vpPanelWentDark;