Run a virtual iPhone on an Apple Silicon Mac.
Swift
Duo: fix stale guest dylib deploys and make the fold libraries installable
Jackyc868da9d1f00
diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.mdindex ba58c405..3cecd311 100644--- a/Research/Guest/iphone_duo_bringup.md+++ b/Research/Guest/iphone_duo_bringup.md@@ -3970,3 +3970,23 @@ created only while a Focus is active) — normalizes without a per-actiontable. Verified on the cover lock screen (both glyphs now matchingextent, flashlight slim); the Control Center focus module icon measuresconsistent with its neighbours and is a different (CCUI) family.++Follow-up (deployment staleness + fresh rebuild): two infrastructure+findings from the wallpaper chase. First, the offline guest-environment+update (set-bundle --update-environment / cfw update-environment) served+the PREVIOUS build's dylib — proven by a build marker absent from the+guest while the bundle contained it; two page-rounded builds sharing a+byte size hid the skip from casual checks. A size-changing padding+buffer now keeps the folddisplay dylib's size per-build distinct, and+the fold-family dylibs (folddisplay, foldguard, hinge, posterprobe) were+added to vphoned's `environmentLibraries` allowlist so the running+machine's hash-based environment sync can update them too. Second, the+first environment rewrite that actually changed sizes was followed by a+boot kernel panic (AppleSEPManager backtrace, pid 0, three consecutive+boots) — unreproduced elsewhere and not yet root-caused; the machine+was deleted and recreated (vm create --device iPhone19,4 --no-template,+standard preset, every step passed). The fresh restore delivers the+current dylib directly (marker verified in-guest), the wallpaper+orientation bridge installs, and 3× fold cycles land closed 466×678/0°+and open 669×951/90°. Wallpaper orientation judgment needs the user's+directional wallpaper set again on the fresh machine.diff --git a/VPhoneDaemon/Daemon/GuestAPI+Device.swift b/VPhoneDaemon/Daemon/GuestAPI+Device.swiftindex 45e6f145..e32b0a1e 100644--- a/VPhoneDaemon/Daemon/GuestAPI+Device.swift+++ b/VPhoneDaemon/Daemon/GuestAPI+Device.swift@@ -132,7 +132,6 @@ extension GuestAPI {_ = try? postDarwinNotification("com.vphone.display.orientation.inputs.refresh", state: nil)_ = try? postDarwinNotification("com.vphone.display.orientation.arbitration.refresh", state: nil)_ = try? postDarwinNotification("com.vphone.display.orientation.actuation.refresh", state: nil)- _ = try? postDarwinNotification("com.vphone.display.presentation.wallpaper.pulse", state: nil)_ = try? postDarwinNotification("com.vphone.display.presentation.clock.refresh", state: nil)}var result: [String: Any]@@ -510,7 +509,6 @@ extension GuestAPI {_ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)_ = try? postDarwinNotification("com.vphone.display.orientation.arbitration.refresh", state: nil)_ = try? postDarwinNotification("com.vphone.display.orientation.actuation.refresh", state: nil)- _ = try? postDarwinNotification("com.vphone.display.presentation.wallpaper.pulse", state: nil)_ = try? postDarwinNotification("com.vphone.display.presentation.clock.refresh", state: nil)if !settled {// Reuse the same public rotation path once the new paneldiff --git a/VPhoneDaemon/Daemon/GuestAPI+Environment.swift b/VPhoneDaemon/Daemon/GuestAPI+Environment.swiftindex 0a2352cc..152daf99 100644--- a/VPhoneDaemon/Daemon/GuestAPI+Environment.swift+++ b/VPhoneDaemon/Daemon/GuestAPI+Environment.swift@@ -21,6 +21,10 @@ extension GuestAPI {"libdevicename.dylib","libprefsfix.dylib","libsigninfix.dylib",+ "libvphonefolddisplay.dylib",+ "libvphonefoldguard.dylib",+ "libvphonehinge.dylib",+ "libvphoneposterprobe.dylib","libvphonegyro.dylib","libvphoneaccelerometer.dylib","libvphoneattitude.dylib",@@ -60,8 +64,11 @@ extension GuestAPI {guard environmentLibraries.contains(name) else {throw GuestAPIError.invalidRequest("\(name) is not part of the vphone environment")}- if ["libvphonegyro.dylib", "libvphoneaccelerometer.dylib", "libvphoneattitude.dylib"].contains(name), !FileManager.default.fileExists(atPath: "/usr/lib/" + name) {- throw GuestAPIError.invalidRequest("Enable the motion sensor patch with cfw install or cfw update-environment first")+ if [+ "libvphonegyro.dylib", "libvphoneaccelerometer.dylib", "libvphoneattitude.dylib",+ "libvphonehinge.dylib", "libvphonefoldguard.dylib", "libvphonefolddisplay.dylib",+ ].contains(name), !FileManager.default.fileExists(atPath: "/usr/lib/" + name) {+ throw GuestAPIError.invalidRequest("Enable the corresponding guest patch with cfw install or cfw update-environment first")}let staged = URL(fileURLWithPath: environmentStaging + "/" + name)guard let data = try? Data(contentsOf: staged, options: .mappedIfSafe) else {diff --git a/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m b/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.mindex abd21297..692ba665 100644--- a/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m+++ b/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m@@ -3062,7 +3062,7 @@ static NSInteger vpWallpaperInterfaceForDevice(id self, SEL cmd, NSInteger devic}static BOOL vpInstallWallpaperOrientationBridge(void) {- id scene = vpMainInnerWindowScene();+ id scene = vpOrientationArbitrationScene();id wallpaper = vpReadObject(scene, "wallpaperController");SEL converter = sel_registerName("_interfaceOrientationForDeviceOrientation:");Method method = wallpaper ? class_getInstanceMethod(object_getClass(wallpaper), converter) : NULL;@@ -3993,7 +3993,7 @@ static int persistentCoverToken, persistentInnerToken;^(int token) { vpInspectQuickActions(); });// Installed before SpringBoard builds its cover sheet, so the first// SBSDeviceDeterminedConfiguration construction is captured.- vpFoldDisplayLog(@"folddisplay build marker: bridge-diag-2");+ vpFoldDisplayLog(@"folddisplay build marker: bridge-diag-3");vpInstallConfigInitSwizzle();vpInstallLayoutClassSwizzle();static int windowsInspectToken;diff --git a/VPhoneKit/VPhoneCoreKit/Support/VPhoneFileDigestCache.swift b/VPhoneKit/VPhoneCoreKit/Support/VPhoneFileDigestCache.swiftindex 78d32e30..4e8e6344 100644--- a/VPhoneKit/VPhoneCoreKit/Support/VPhoneFileDigestCache.swift+++ b/VPhoneKit/VPhoneCoreKit/Support/VPhoneFileDigestCache.swift@@ -1,8 +1,9 @@import CryptoKitimport Foundation-/// The SHA-256 of one file, hashed again only when the file's identity, size-/// or modification time changes.+/// The SHA-256 of one file, hashed again only when the file's identity or+/// metadata changes. The change time is included so an in-place rewrite is+/// noticed even when it keeps the same size and modification timestamp.////// `vphone-vm` compares the bundled vphoned with the guest's on every health/// probe, every three seconds while connected. Reading and hashing the 9 MB@@ -13,9 +14,10 @@ public struct VPhoneFileDigestCache: Sendable {var path: Stringvar device: UInt64var inode: UInt64- var size: Int64var modifiedSeconds: Intvar modifiedNanoseconds: Int+ var changedSeconds: Int+ var changedNanoseconds: Int}private var stamp: Stamp?@@ -55,9 +57,10 @@ public struct VPhoneFileDigestCache: Sendable {path: url.path,device: UInt64(bitPattern: Int64(info.st_dev)),inode: UInt64(info.st_ino),- size: Int64(info.st_size),modifiedSeconds: Int(info.st_mtimespec.tv_sec),modifiedNanoseconds: Int(info.st_mtimespec.tv_nsec),+ changedSeconds: Int(info.st_ctimespec.tv_sec),+ changedNanoseconds: Int(info.st_ctimespec.tv_nsec),)}}diff --git a/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestEnvironment.swift b/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestEnvironment.swiftindex 08c76339..e2c3a104 100644--- a/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestEnvironment.swift+++ b/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestEnvironment.swift@@ -18,6 +18,10 @@ public enum VPhoneGuestEnvironment {"libdevicename.dylib","libprefsfix.dylib","libsigninfix.dylib",+ "libvphonefolddisplay.dylib",+ "libvphonefoldguard.dylib",+ "libvphonehinge.dylib",+ "libvphoneposterprobe.dylib","libvphonegyro.dylib","libvphoneaccelerometer.dylib","libvphoneattitude.dylib",@@ -25,5 +29,12 @@ public enum VPhoneGuestEnvironment {/// Selection installs/removes these. A live hash sync may replace an/// installed copy, but must never reinstall a patch the user turned off.- public static let selectedLibraries: Set<String> = ["libvphonegyro.dylib", "libvphoneaccelerometer.dylib", "libvphoneattitude.dylib"]+ public static let selectedLibraries: Set<String> = [+ "libvphonegyro.dylib",+ "libvphoneaccelerometer.dylib",+ "libvphoneattitude.dylib",+ "libvphonehinge.dylib",+ "libvphonefoldguard.dylib",+ "libvphonefolddisplay.dylib",+ ]}diff --git a/VPhoneKit/VPhoneCoreKitTests/Support/FileDigestCacheTests.swift b/VPhoneKit/VPhoneCoreKitTests/Support/FileDigestCacheTests.swiftindex 428a38ad..0bc9de2a 100644--- a/VPhoneKit/VPhoneCoreKitTests/Support/FileDigestCacheTests.swift+++ b/VPhoneKit/VPhoneCoreKitTests/Support/FileDigestCacheTests.swift@@ -28,6 +28,20 @@ struct FileDigestCacheTests {#expect(cache.hashCount == 2)}+ @Test func `a same-size rewrite with the same modification time is hashed again`() throws {+ let url = try Self.makeFile(Data("old build".utf8))+ defer { try? FileManager.default.removeItem(at: url.deletingLastPathComponent()) }+ let originalDate = try FileManager.default.attributesOfItem(atPath: url.path)[.modificationDate] as? Date+ var cache = VPhoneFileDigestCache()+ _ = cache.sha256(of: url)+ try Data("new build".utf8).write(to: url)+ if let originalDate {+ try FileManager.default.setAttributes([.modificationDate: originalDate], ofItemAtPath: url.path)+ }+ #expect(cache.sha256(of: url) == Self.hex(Data("new build".utf8)))+ #expect(cache.hashCount == 2)+ }+@Test func `a file replaced by a rename is hashed again`() throws {let url = try Self.makeFile(Data("A".utf8))defer { try? FileManager.default.removeItem(at: url.deletingLastPathComponent()) }