Run a virtual iPhone on an Apple Silicon Mac.
Swift
Pair a virtual Apple Watch with a virtual iPhone
Maximilian Paßa44273ee1939
diff --git a/Documents/Guides/create-and-run.md b/Documents/Guides/create-and-run.mdindex dc7f4ca6..0b313f3b 100644--- a/Documents/Guides/create-and-run.md+++ b/Documents/Guides/create-and-run.md@@ -96,7 +96,7 @@ Every step has a deadline. A failed step stops the VM, records nothing and leave| `--slim on\|off` | on | `off` trims nothing and keeps every app and service. The setup boot still runs: Setup is skipped and the snapshot deleted. || `--trim none\|conservative\|standard` | standard | The offline trim above. || `--keep-languages <list>` | `en,zh-Hans,zh` | The languages `--trim standard` keeps. |-| `--service-profile trimmed\|none` | trimmed | vphoned's trimmed profile: about 140 launchd jobs off, the App Store daemons and sign-in follow-up among them. |+| `--service-profile trimmed\|none` | trimmed | vphoned's trimmed profile: about 140 launchd jobs off, the App Store daemons and sign-in follow-up among them. A phone with this profile cannot pair an Apple Watch (see `Research/Guest/watch_pairing.md`). || `--remove-apps on\|off` | on | Removes App Store, Home, TV, News, FaceTime, iTunes Store, Messages, Games, Find My and Wallet. Camera and Phone stay. || `--keep-apps <ids>` | none | Bundle IDs from that list to keep, comma-separated (`com.apple.findmy,com.apple.Passbook`). || `--accounts-off` | off | Also turns off `akd`, `amsaccountsd` and `appleaccountd`. The guest then cannot sign in to an Apple Account. |diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex ffe8e08d..1f73e751 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -3543,3 +3543,15 @@ imports from them, is in the watchOS 26.4 arm64e cache; `ui.ocr` andChecked on 2026-10-20: `vm create --device Watch7,18` with the Watch7,18 26.4(23T240) IPSW and cloudOS 26.4 (23E244) links the mix, restores, boots, andvphoned answers the first-boot ping.++### Pairing with a phone++See `Research/Guest/watch_pairing.md`. The watch preset now patches activation+(`filesystem-boot-mobileactivationd_should_hactivate`, on the arm64e slice of+the universal binary), and three patches are new:++| Patch | Target | Change |+| --- | --- | --- |+| `devicetree-cfw-watch_companion` | an iPhone guest's tree | `/product/watch-companion = 1`, added where the board copy removed a placeholder. vphone600's `syscfg/waco` has no syscfg value on a VM, so iBoot drops it and the phone pairs with no watch. |+| `system-bluetoothd-cfw-btvc_le_connection` | `/System/Library/FeatureFlags/Domain/BluetoothFeatures.plist`, `cfw install`, iOS 26+ | `EnableBTVCLeConnection.Enabled = true`: bluetoothd's virtual LE controller may connect. Reverted from the `.bak` when turned off; blocked for tvOS. |+| `filesystem-exp-btvc_le_connection` | the same file in the restore image (`minimal`, `watchos`) | The same flag, written before the seal. |diff --git a/Research/Guest/watch_pairing.md b/Research/Guest/watch_pairing.mdnew file mode 100644index 00000000..d2b66f25--- /dev/null+++ b/Research/Guest/watch_pairing.md@@ -0,0 +1,70 @@+# Pairing a virtual Apple Watch with a virtual iPhone++A watchOS 26.4 (Watch7,18) guest pairs with an iOS 26 guest through the+phone's Watch app, and the initial sync completes. No Bluetooth hardware is+involved: Apple's VM builds carry the plumbing.++Checked on 2026-10-20: a `watchos` watch and a `minimal` iPhone17,3 of iOS 26.4+(23E246), both on cloudOS 26.4 (23E244) and on the NAT network with peers+reachable, paired from the phone's Watch app. A `minimal` phone comes up in+Setup Assistant (it has no template); skip it (`setup.skip`) or go through it+before opening the Watch app.++## How pairing works between VMs++- **Discovery and link: NetworkRelay over IP.** On a VM, nanoregistryd pairs+ through NetworkRelay (`networkrelay_pairing || IsVirtualDevice`), and+ terminusd runs only `NRLinkManagerWired`. The watch advertises Bonjour+ `_nrd._tcp`, the phone browses for it, and the PIN pairing runs over IKEv2.+- **Virtual Bluetooth.** On a VM, bluetoothd drives a built-in virtual LE+ controller (BTVC) whose radio is Bonjour `_btvc._tcp`. It needs the device+ tree node `arm-io/bluetooth` with `transport-encoding = 10`, which vphone600's+ tree has (and the research board conversion adds), and `kern.hv_vmm_present`.+ The feature flag `BluetoothFeatures/EnableBTVCLeConnection` gates its LE+ connections and is off as shipped.+- **Version gate.** `NRPairingCompatibilityVersionInfo`: watchOS 26.4 is+ version 26; iOS 26.4 accepts 25 to 26, iOS 18.1 at most 23. The phone has to+ run iOS 26.++## What the VMs need++| Requirement | Patch | Why |+| --- | --- | --- |+| The machines reach each other | `vm config --nat-peers` (on by default) | vmnet isolates guests on the shared NAT network from each other; `_nrd._tcp` and `_btvc._tcp` are guest-to-guest |+| `/product/watch-companion = 1` on the phone | `devicetree-cfw-watch_companion` | vphone600's is `syscfg/waco`, which the VM's syscfg lacks, so iBoot drops it. MobileGestalt then says the phone pairs with no watch: `+[NRRegistry _supportsWatch]` is NO, the Watch app has no icon, and NanoRegistry's clients load the registry once and never see the watch nanoregistryd discovers ("Searching for Apple Watch" times out) |+| `EnableBTVCLeConnection` on both | `system-bluetoothd-cfw-btvc_le_connection` (`cfw install`), `filesystem-exp-btvc_le_connection` (restore image) | LE connections over the virtual controller |+| Activation on the watch | `filesystem-boot-mobileactivationd_should_hactivate` in `watchos` | After the PIN, the Watch app asks the watch for an activation request; an unactivated VM watch cannot make one ("Activation Failed! (Decoded request from Gizmo is nil)") |++The flag needs a reboot to change at runtime: feature flags are cached in+shared memory (`com.apple.featureflags.shm`), so restarting bluetoothd is not+enough. A runtime override goes in+`/var/preferences/FeatureFlags/Domain/BluetoothFeatures.plist`.++## Pairing++1. Create the watch (`vm create --device Watch7,18`, preset `watchos`) and an+ iOS 26 phone, and start both.+2. On the phone, open the Watch app (`com.apple.Bridge`): Start Pairing → Set+ Up for Myself. The phone lists the watch as "Apple Watch NNNNN"; choose it.+3. The watch shows a six-digit code. Type it in the phone's window: the VM has a+ hardware keyboard, so there is no on-screen keypad.+4. Continue on the phone. "Apple Watch is Syncing" takes about 8 minutes:+ three pairedsyncd activities (`appconduitd` 300 s, `appconduitd.appstate`+ 60 s, `tccd` 60 s) get no answer from the watch and end by timeout. The sync+ then reaches 100 %.++## Pitfalls++- A phone built from a template with the `trimmed` service profile (the+ `standard` default) has the pairing daemons off: `terminusd` (NetworkRelay),+ `identityservicesd`, `nanobackupd`, `nanoprefsyncd`, `nanotimekitcompaniond`,+ `security.otpaird`, `watchpresenced`, `magicswitchd.companion`. Build the phone+ with `minimal`, or keep those labels (`allow`) when applying the profile.+- If the phone remembers an unfinished pairing, choose Start Over.+- Killing only the watch's Setup leaves stale pairing managers in terminusd,+ and the phone can connect to one whose code no screen shows. Restart+ terminusd, nanoregistryd and Setup together.+- A tap on a dimmed watch display only wakes it; press the crown (Home) first.+- The watch's Setup crashed in a UIKit layout trap ("Screen class invalid") on+ the language list before the watch display patches; pairing from the phone+ avoids that screen.diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swiftindex 6a5c109c..06dff920 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift@@ -90,6 +90,7 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {(FirmwareRestoreImagePatchSet.mobileActivation, "Patch mobileactivationd"),(FirmwareRestoreImagePatchSet.vphoned, "Install vphoned and its launch daemon"),(FirmwareRestoreImagePatchSet.launchdCacheLoader, "Patch launchd_cache_loader"),+ (FirmwareRestoreImagePatchSet.virtualBluetooth, "Enable LE connections over the virtual Bluetooth controller"),]@discardableResult@@ -187,6 +188,12 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {if gate.isEnabled(FirmwareRestoreImagePatchSet.launchdCacheLoader) {try patchLaunchdCacheLoader(targetMount: targetMount)}+ if gate.isEnabled(FirmwareRestoreImagePatchSet.virtualBluetooth) {+ try CustomFirmwareBluetoothVirtualController.patch(+ at: URL(filePath: targetMount).appending(path: CustomFirmwareBluetoothVirtualController.relativePath),+ )+ print(" [+] \(CustomFirmwareBluetoothVirtualController.feature) on")+ }try removeHostEventLog(mount: targetMount)}diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swiftindex 4b7b11d1..6026747b 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift@@ -171,6 +171,7 @@ extension CryptexFilesystemPatcher {func patchMobileActivation(targetMount: String) throws {let target = URL(filePath: targetMount)let mobileActivationdPath = target.appending(path: "/usr/libexec/mobileactivationd")+ try thinToArm64e(mobileActivationdPath)// `resign: false` because the sign below replaces the signature, and// re-attesting would refuse an unsigned input the Python accepted.try CustomFirmwareMobileActivation.patch(fileAt: mobileActivationdPath, resign: false)diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareBluetoothVirtualController.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareBluetoothVirtualController.swiftnew file mode 100644index 00000000..046baa41--- /dev/null+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareBluetoothVirtualController.swift@@ -0,0 +1,38 @@+import Foundation+import VPhonePatchKit++/// Let bluetoothd connect over its virtual controller. On a VM (DT+/// `arm-io/bluetooth` `transport-encoding` 10, `kern.hv_vmm_present`)+/// bluetoothd drives a built-in virtual LE controller, BTVC, whose radio is+/// Bonjour `_btvc._tcp` on the VMs' shared network. The shipped feature flag+/// `EnableBTVCLeConnection` is off, which keeps it from connecting: a watch and+/// its phone pair over NetworkRelay, then talk over this link.+/// See Research/Guest/watch_pairing.md.+public enum CustomFirmwareBluetoothVirtualController {+ public static let relativePath = "System/Library/FeatureFlags/Domain/BluetoothFeatures.plist"+ public static let feature = "EnableBTVCLeConnection"++ /// Turn the feature on, keeping every other feature and the plist's+ /// encoding. Returns false when it already is on.+ @discardableResult+ public static func patch(at url: URL, dryRun: Bool = false) throws -> Bool {+ let input = try Data(contentsOf: url)+ var format = PropertyListSerialization.PropertyListFormat.xml+ guard var root = try PropertyListSerialization.propertyList(+ from: input, options: [], format: &format,+ ) as? [String: Any] else {+ throw PatcherError.invalidFormat("Not a feature flag dictionary: \(url.path)")+ }+ var feature = root[Self.feature] as? [String: Any] ?? [:]+ if let enabled = feature["Enabled"] as? NSNumber, CFGetTypeID(enabled) == CFBooleanGetTypeID(), enabled.boolValue {+ return false+ }+ feature["Enabled"] = true+ root[Self.feature] = feature+ let output = try PropertyListSerialization.data(fromPropertyList: root, format: format, options: 0)+ if !dryRun {+ try output.write(to: url, options: .atomic)+ }+ return true+ }+}diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swiftindex a7439d9e..d28dbf88 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreeGuestDevicePatches.swift@@ -64,6 +64,7 @@ extension DeviceTreePatcher {static let tvAppArchitecturePatch = "devicetree-cfw-tv_app_architecture"static let watchPresentationPatch = "devicetree-cfw-watch_presentation"static let watchDriverKitPatch = "devicetree-cfw-watch_driverkit"+ static let watchCompanionPatch = "devicetree-cfw-watch_companion"static let hapticsPatch = "devicetree-cfw-product_haptics_node"static let microphoneArrayPatch = "devicetree-cfw-product_audio_microphone_array"@@ -599,6 +600,49 @@ extension DeviceTreePatcher {}}+ // MARK: - Watch Companion++ /// Give an iPhone guest's `/product/watch-companion` the value 1, adding it+ /// where the board copy removed it. Returns its value before (nil when it+ /// was absent), or nil changes when it already is a plain 1.+ ///+ /// vphone600's is `syscfg/waco`, which the VM's syscfg does not have, so+ /// iBoot drops the property and MobileGestalt answers that the phone pairs+ /// with no watch: the Watch app has no icon, and NanoRegistry's clients+ /// never see the watch nanoregistryd discovers.+ static func presentWatchCompanion(in root: DTNode) -> (before: Data?, after: Data)? {+ guard let product = optionalChild(of: root, named: "product") else { return nil }+ let value = Data([1, 0, 0, 0])+ if let existing = product.properties.first(where: { $0.name == "watch-companion" }) {+ guard existing.flags & placeholderFlag != 0 || existing.value != value else { return nil }+ let before = existing.value+ existing.flags = 0+ existing.value = value+ return (before, value)+ }+ product.properties.append(DTProperty(name: "watch-companion", flags: 0, value: value, valueOffset: 0))+ return (nil, value)+ }++ /// Applies `presentWatchCompanion(in:)` to an iPhone guest's tree.+ func applyWatchCompanion(root: DTNode) {+ guard device.family == .iPhone, gateAllows(Self.watchCompanionPatch),+ let change = Self.presentWatchCompanion(in: root)+ else { return }+ patches.append(PatchRecord(+ patchID: Self.watchCompanionPatch,+ component: component,+ fileOffset: 0,+ virtualAddress: nil,+ originalBytes: change.before ?? Data(),+ patchedBytes: change.after,+ description: "Set /device-tree/product/watch-companion = 1",+ ))+ if verbose {+ print(" =prop : /product/watch-companion = 1, the VM syscfg has no waco [\(Self.watchCompanionPatch)]")+ }+ }+/// Applies `removeMicrophoneArrayClaims(from:)` to the parsed tree,/// whichever guest and role it is for, and records each removal.func applyMicrophoneArrayRemoval(root: DTNode) {diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swiftindex 3c16d649..bbb37639 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swift@@ -396,6 +396,8 @@ public final class DeviceTreePatcher: BufferedPatcher {if presentsGuest {try applyGuestEdits(root: root)}+ // After the board edits, which remove a placeholder the board has too.+ applyWatchCompanion(root: root)// Every guest, every tree: no VM has the haptics the node promises.applyHapticsRemoval(root: root)diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swiftindex d10896cf..998df389 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swift@@ -222,6 +222,11 @@ public enum FirmwareDeviceTreePatchSet {"TV app architecture","Copies app-macho-architecture from a TV board's own device tree into the installed tree, so its userland sees the donor's architecture. Restore, iPhone and iPad trees are unchanged.",),+ property(+ "devicetree-cfw-watch_companion",+ "Watch companion",+ "Sets /product/watch-companion to 1 on an iPhone guest. vphone600 takes it from syscfg, which has no waco on a VM, so the phone would pair with no watch and the Watch app would stay hidden.",+ ),property("devicetree-cfw-watch_presentation","Watch display and gestalt variant",diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swiftindex 42c9aaee..8eb5bc38 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift@@ -35,6 +35,7 @@ public enum FirmwareGuestSystemPatchSet {"System/Library/Extensions/AppleParavirtGPUMetalIOGPUFamily.bundle/AppleParavirtGPUMetalIOGPUFamily"public static let locationdCohorting = "system-locationd-cfw-disable_auto_cohort"+ public static let virtualBluetooth = "system-bluetoothd-cfw-btvc_le_connection"public static let jetsamDisableAllowed = "system-jetsamproperties-cfw-disable_allowed"public static let tvTPRO = "system-dyld-exp-tv_tpro"/// Replaces the restored System volume with an Apple TV 4K userland@@ -78,6 +79,13 @@ public enum FirmwareGuestSystemPatchSet {target: .guestFile(path: "/"),applicability: VPhonePatchApplicability(iOSBase: .atLeast(major: 26, minor: 0)),),+ VPhonePatchDeclaration(+ identifier: virtualBluetooth,+ title: "Virtual Bluetooth",+ summary: "Turns on the feature flag that lets bluetoothd connect over its virtual controller, which a paired watch and phone talk over.",+ target: .guestFile(path: "/" + CustomFirmwareBluetoothVirtualController.relativePath),+ applicability: VPhonePatchApplicability(iOSBase: .atLeast(major: 26, minor: 0)),+ ),VPhonePatchDeclaration(identifier: locationdCohorting,title: "locationd startup stability",diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swiftindex 15f35b28..8275d6c8 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift@@ -225,6 +225,7 @@ public enum FirmwarePatchSetCatalog {/// the iPhone 19 ARM64E_X1 boot path.public static let tvOSBlockedPatches: Set<String> = [FirmwareGuestSystemPatchSet.arm64eX1CacheBootstrap,+ FirmwareGuestSystemPatchSet.virtualBluetooth,"dyld-boot-iomfb_force_kern","dyld-boot-iomfb_swapend","dyld-boot-lockdown_mode",@@ -320,6 +321,7 @@ public enum FirmwarePatchSetCatalog {"devicetree-cfw-island_notch_location","devicetree-cfw-product_haptics_node","devicetree-cfw-product_audio_microphone_array",+ "devicetree-cfw-watch_companion",]/// The boot chain patches ``minimalPreset`` keeps: iBEC's and LLB's, which the@@ -379,19 +381,17 @@ public enum FirmwarePatchSetCatalog {]/// ``minimalPreset`` for an Apple Watch: its device tree presents the watch- /// board, and activation stays stock. The shipped `watchos.plist` must- /// match this.+ /// board. The shipped `watchos.plist` must match this.public static let watchOSPreset = VPhonePatchPreset(identifier: VPhonePatchPreset.watchOSIdentifier,title: "Apple Watch",- summary: "Minimal for an Apple Watch guest: the watch board's device tree, and a resealed system with vphoned and the GPU driver restored onto a stock kernel and TXM.",+ summary: "Minimal for an Apple Watch guest: the watch board's device tree, and a resealed system with vphoned, the GPU driver and activation restored onto a stock kernel and TXM.",patchSets: minimalPreset.patchSets,selection: .allow(minimalBootChainPatches.union(watchOSDeviceTreePatches).union(FirmwareResearchBoardPatchSet.manifest.patches.map(\.identifier))- .union(FirmwareRestoreImagePatchSet.manifest.patches.map(\.identifier))- .subtracting([FirmwareRestoreImagePatchSet.mobileActivation]),+ .union(FirmwareRestoreImagePatchSet.manifest.patches.map(\.identifier)),),)diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swiftindex b53a049c..aec9532d 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swift@@ -26,6 +26,7 @@ public enum FirmwareRestoreImagePatchSet {public static let mobileActivation = "filesystem-boot-mobileactivationd_should_hactivate"public static let vphoned = "filesystem-boot-vphoned"public static let launchdCacheLoader = "filesystem-boot-launchd_cache_loader_unsecure_cache_gate"+ public static let virtualBluetooth = "filesystem-exp-btvc_le_connection"public static let digestRehash = "manifest-boot-digest_rehash"private static func filesystem(_ identifier: String, _ title: String, _ summary: String) -> VPhonePatchDeclaration {@@ -68,6 +69,12 @@ public enum FirmwareRestoreImagePatchSet {"Launch daemon cache","Lets launchd load the launch daemons from the system volume instead of the signed cache, so vphoned starts.",),+ VPhonePatchDeclaration(+ identifier: virtualBluetooth,+ title: "Virtual Bluetooth",+ summary: "Turns on the feature flag that lets bluetoothd connect over its virtual controller, which a watch and its phone talk over once paired.",+ target: .firmware(.filesystem),+ ),VPhonePatchDeclaration(identifier: digestRehash,title: "Manifest digests",diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/DeviceTreeGuestDeviceTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/DeviceTreeGuestDeviceTests.swiftindex df03d09c..fb49fca0 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/DeviceTreeGuestDeviceTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/DeviceTreeGuestDeviceTests.swift@@ -425,6 +425,21 @@ struct DeviceTreeGuestDeviceTests {#expect(twice.patchedData == once.patchedData)}+ // MARK: - Watch Companion++ @Test(arguments: Guest.allCases)+ func `only an iPhone guest says it pairs with a watch`(guest: Guest) throws {+ let (patched, records) = try Self.patched(Self.tree.serialized(), as: guest)+ let property = Self.read(patched)["device-tree/product"]?["watch-companion"]+ if guest == .iPhone {+ #expect(property?.0 == 0)+ #expect(property?.1 == Data([1, 0, 0, 0]))+ #expect(records.contains { $0.patchID == "devicetree-cfw-watch_companion" })+ } else {+ #expect(!records.contains { $0.patchID == "devicetree-cfw-watch_companion" })+ }+ }+// MARK: - Haptics@Test(arguments: Guest.allCases)diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareBluetoothVirtualControllerTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareBluetoothVirtualControllerTests.swiftnew file mode 100644index 00000000..2d482293--- /dev/null+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareBluetoothVirtualControllerTests.swift@@ -0,0 +1,45 @@+@testable import FirmwarePatcher+import Foundation+import Testing+import VPhonePatchKit++@Suite("Virtual Bluetooth feature flag")+struct CustomFirmwareBluetoothVirtualControllerTests {+ @Test(arguments: [PropertyListSerialization.PropertyListFormat.xml, .binary])+ func `turns the feature on and keeps the rest`(format: PropertyListSerialization.PropertyListFormat) throws {+ let url = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)+ defer { try? FileManager.default.removeItem(at: url) }+ let original: [String: Any] = [+ "EnableBTVCLeConnection": ["DevelopmentPhase": "FeatureComplete"],+ "OtherFeature": ["Enabled": false],+ ]+ let input = try PropertyListSerialization.data(fromPropertyList: original, format: format, options: 0)+ try input.write(to: url)+ #expect(try CustomFirmwareBluetoothVirtualController.patch(at: url, dryRun: true))+ #expect(try Data(contentsOf: url) == input)+ #expect(try CustomFirmwareBluetoothVirtualController.patch(at: url))+ var outputFormat = PropertyListSerialization.PropertyListFormat.xml+ let root = try #require(PropertyListSerialization.propertyList(+ from: Data(contentsOf: url), format: &outputFormat,+ ) as? [String: Any])+ #expect(outputFormat == format)+ #expect((root["OtherFeature"] as? NSDictionary) == (original["OtherFeature"] as? NSDictionary))+ let feature = try #require(root["EnableBTVCLeConnection"] as? [String: Any])+ #expect(feature["Enabled"] as? Bool == true)+ #expect(feature["DevelopmentPhase"] as? String == "FeatureComplete")+ // On already: nothing to write.+ #expect(try !CustomFirmwareBluetoothVirtualController.patch(at: url))+ }++ @Test+ func `selected from iOS 26`() throws {+ for base in ["18.6", "26.4", "27.0"] {+ let plan = try VPhonePatchPlan.resolve(+ preset: FirmwarePatchSetCatalog.standardPreset,+ patchSets: FirmwarePatchSetCatalog.bundled,+ iOSBase: VPhoneVersion(base), cloudOS: VPhoneVersion("26.4"),+ )+ #expect(plan.isEnabled(FirmwareGuestSystemPatchSet.virtualBluetooth) == !base.hasPrefix("18."))+ }+ }+}diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swiftindex 6581f49a..36d9cade 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift@@ -137,8 +137,7 @@ struct FirmwarePatchSetCatalogTests {// presets drop exactly the iOS ones an Apple TV has no port of.let tvPresets = [VPhonePatchPreset.tvOSIdentifier, VPhonePatchPreset.tvOS4KIdentifier]// `minimal` drops every boot chain patch but iBEC's and LLB's:- // its system is customised before the restore instead. The- // watch preset drops activation besides, which pairing needs.+ // its system is customised before the restore instead.let restoreImagePresets = [VPhonePatchPreset.minimalIdentifier, VPhonePatchPreset.watchOSIdentifier]let expected = if tvPresets.contains(preset.identifier) {Set(plan.droppedBootEssentials).isSubset(of: FirmwarePatchSetCatalog.tvOSBlockedPatches)@@ -146,8 +145,6 @@ struct FirmwarePatchSetCatalogTests {Set(plan.droppedBootEssentials).isDisjoint(with: FirmwarePatchSetCatalog.minimalBootChainPatches)&& plan.droppedBootEssentials.allSatisfy {FirmwareBootChainPatchSet.manifest.patches.map(\.identifier).contains($0)- || (preset.identifier == VPhonePatchPreset.watchOSIdentifier- && $0 == FirmwareRestoreImagePatchSet.mobileActivation)}} else {plan.droppedBootEssentials.isEmpty@@ -200,7 +197,7 @@ struct FirmwarePatchSetCatalogTests {iOSBase: VPhoneVersion("26.4"),cloudOS: VPhoneVersion("26.4"),)- #expect(watch.enabled == restoreImage.subtracting([FirmwareRestoreImagePatchSet.mobileActivation])+ #expect(watch.enabled == restoreImage.union(FirmwarePatchSetCatalog.watchOSDeviceTreePatches).union(bootChain).union(researchBoard))}diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swiftindex 89d089c6..c4a1e38a 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift@@ -1332,6 +1332,25 @@ struct VPhoneCustomFirmwareInstaller {live: &live, failures: &failures,)+ // The feature plist exists from iOS 26. Turning the patch off restores+ // the original.+ let bluetoothID = FirmwareGuestSystemPatchSet.virtualBluetooth+ let bluetoothPath = CustomFirmwareBluetoothVirtualController.relativePath+ isolate([bluetoothID]) {+ if !version.hasPrefix("1"), on(bluetoothID) {+ try patchCopy(+ of: bluetoothPath, in: system, work: work,+ verb: "patch-virtual-bluetooth", backupSafe: backupSafe(bluetoothID),+ )+ live.insert(bluetoothID)+ } else if try revertCopy(of: bluetoothPath, in: system) {+ print(" [+] \(bluetoothID): restored the Bluetooth feature flags")+ } else if priorGuest.contains(bluetoothID) {+ print(" [!] \(bluetoothID): no backup to revert (not revertible)")+ live.insert(bluetoothID)+ }+ }+// A missing legacy plan must not apply this iOS-27-only change to// other bases. Turning it off restores the original feature plist.let locationdID = FirmwareGuestSystemPatchSet.locationdCohortingdiff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swiftindex 68e48053..4cf92d7e 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift@@ -179,6 +179,27 @@ struct VPhoneCustomFirmwareInjectDylibCommand: ParsableCommand {}}+// MARK: - patch-virtual-bluetooth++struct VPhoneCustomFirmwarePatchVirtualBluetoothCommand: ParsableCommand {+ static let configuration = CommandConfiguration(+ commandName: "patch-virtual-bluetooth",+ abstract: "Enable LE connections over the virtual Bluetooth controller in a staged feature plist",+ shouldDisplay: false,+ )++ @Argument(transform: URL.init(fileURLWithPath:))+ var plist: URL++ @Flag(name: .customLong("dry-run"))+ var dryRun = false++ func run() throws {+ let changed = try CustomFirmwareBluetoothVirtualController.patch(at: plist, dryRun: dryRun)+ print(" [\(changed ? "+" : ".")] \(CustomFirmwareBluetoothVirtualController.feature).Enabled = true\(dryRun ? " (dry-run)" : "")")+ }+}+// MARK: - patch-locationd-cohortingstruct VPhoneCustomFirmwarePatchLocationdCohortingCommand: ParsableCommand {diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swiftindex 5bd5761e..901a616e 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift@@ -244,6 +244,7 @@ struct VPhoneCustomFirmwareCommand: ParsableCommand {VPhoneCustomFirmwareInjectDylibCommand.self,VPhoneCustomFirmwarePatchBuildVersionCommand.self,VPhoneCustomFirmwarePatchLocationdCohortingCommand.self,+ VPhoneCustomFirmwarePatchVirtualBluetoothCommand.self,VPhoneCustomFirmwarePatchJetsamDisableAllowedCommand.self,VPhoneCustomFirmwarePatchVirtualAudioGraphConfigurationsCommand.self,VPhoneCustomFirmwarePatchVirtualAudioSpeakerRawCommand.self,diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/minimal.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/minimal.plistindex 3e45412f..3963fba2 100644--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/minimal.plist+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/minimal.plist@@ -44,11 +44,13 @@<string>devicetree-cfw-product_audio_microphone_array</string><string>devicetree-cfw-product_haptics_node</string><string>devicetree-cfw-serial_number</string>+ <string>devicetree-cfw-watch_companion</string><string>filesystem-boot-cryptex_merge</string><string>filesystem-boot-gpu_driver</string><string>filesystem-boot-launchd_cache_loader_unsecure_cache_gate</string><string>filesystem-boot-mobileactivationd_should_hactivate</string><string>filesystem-boot-vphoned</string>+ <string>filesystem-exp-btvc_le_connection</string><string>ibec-boot-boot_args</string><string>ibec-boot-bootx_precondition</string><string>ibec-boot-image4_callback</string>diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plistindex 2c8f85e2..b1479f3b 100644--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist@@ -100,6 +100,7 @@<string>preboot-cfw-devicetree_microphone_array</string><string>restoreramdisk-boot-apfs_sha3_hash</string><string>system-apps-cfw-attitude</string>+ <string>system-bluetoothd-cfw-btvc_le_connection</string><string>system-backboardd-cfw-gyroscope</string><string>system-backboardd-cfw-accelerometer</string><string>system-campo-cfw-entitlements</string>diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plistindex 4d8d5bc9..57a0fbc7 100644--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist@@ -105,6 +105,7 @@<string>preboot-cfw-devicetree_microphone_array</string><string>restoreramdisk-boot-apfs_sha3_hash</string><string>system-apps-cfw-attitude</string>+ <string>system-bluetoothd-cfw-btvc_le_connection</string><string>system-backboardd-cfw-gyroscope</string><string>system-backboardd-cfw-accelerometer</string><string>system-campo-cfw-entitlements</string>diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plistindex 31392ace..2d3196c2 100644--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plist+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plist@@ -51,7 +51,9 @@<string>filesystem-boot-cryptex_merge</string><string>filesystem-boot-gpu_driver</string><string>filesystem-boot-launchd_cache_loader_unsecure_cache_gate</string>+ <string>filesystem-boot-mobileactivationd_should_hactivate</string><string>filesystem-boot-vphoned</string>+ <string>filesystem-exp-btvc_le_connection</string><string>ibec-boot-boot_args</string><string>ibec-boot-bootx_precondition</string><string>ibec-boot-image4_callback</string>@@ -68,7 +70,7 @@</array></dict><key>Summary</key>- <string>Minimal for an Apple Watch guest: the watch board's device tree, and a resealed system with vphoned and the GPU driver restored onto a stock kernel and TXM.</string>+ <string>Minimal for an Apple Watch guest: the watch board's device tree, and a resealed system with vphoned, the GPU driver and activation restored onto a stock kernel and TXM.</string><key>Title</key><string>Apple Watch</string></dict>diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadSlimmingView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadSlimmingView.swiftindex 04cd6b3e..5f4bd66d 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadSlimmingView.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadSlimmingView.swift@@ -138,6 +138,10 @@ struct VPhoneLaunchpadSlimmingSections: View {} footer: {VStack(alignment: .leading, spacing: 4) {Text("About 140 launch daemons a research machine rarely needs, Apple Account's among them.")+ if slimming.trimsServices {+ // terminusd and the nano daemons are among them.+ Text("A phone with these services off cannot pair an Apple Watch.")+ }if slimming.removesApps {Text("^[\(slimming.removedApps.count) system app](inflect: true) removed; Camera and Phone are never removed.")} else {