Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Apple TV 4k (4th generation) UI

Guilherme Rambo9aa91711c146
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index 3561e270..9bb5c28d 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -391,12 +391,43 @@
> OTA (`24K120`; asset alias `24K6120` shares the archive). OTA manifest
> validation refuses other OS versions for this board. Patch discovery preserves
> the recorded J265 identity over the HD manifest, and Launchpad selects the 4K
-> preset. No new binary patch or preset is introduced. The real OTA staged its
+> preset. The real OTA staged its
> J265 tree and all 42 chunks; `fw patch` processed all 11 components with 239
> patches, and the selected cache patchers passed dry runs against its userland.
> Launchpad and the bundle move to series 2.13 so earlier Launchpad builds cannot
-> choose the HD preset for the new device. Privileged installation and a live
-> boot remain pending. See [bring-up notes](Firmware/tvos_support.md#apple-tv-4k-4th-generation).
+> choose the HD preset for the new device. Restore and full CFW installation
+> completed on 2026-10-24. The guest daemon reports AppleTV18,1 / 27.2.0;
+> rendering initially stalled in SetupBackground and then reached the animated
+> 4K Hello screen after repairing its service lookup. Select did not advance
+> the new Setup scene; no Hello-handler entry appeared in a live log capture.
+> Live validation exposed a missing sandbox lookup in the new SetupBackground
+> app: a native probe with its original three entitlements took 15.049 seconds
+> to initialize PBSDisplayManager; adding only
+> `com.apple.security.exception.mach-lookup.global-name = [com.apple.PineBoardServices]`
+> reduced that to 0.005 seconds. The 10-second scene watchdog kills the original
+> before initialization returns. New declaration
+> `system-setupbackground-exp-pineboard_lookup` targets that app's entitlements,
+> applies only to 27.2, and remains opt-in; the installer also
+> requires an Apple TV identity. It preserves all existing entitlements and
+> backs up the executable for reversal through `cfw update-environment`.
+> The supported `tvos-4k` preset instead selects `system-tv-exp-legacy_setup`
+> for 27.2: `TVSetupV2.Enabled = false` and `TVSetupV2HW.Enabled = false` in
+> `System/Library/FeatureFlags/Domain/CompanionServices.plist`. PineBoard then
+> selects the native TVSetup retained in this OTA. A cold-boot experiment
+> reached its 4K Language screen; consumer HID and native keyboard Down/Up
+> moved focus to Simplified Chinese and restored English. This does not
+> complete setup or select a language. Both feature dictionaries are required;
+> metadata, unrelated flags and encoding are preserved, and a `.bak` supports
+> reversal through the normal guest patch selection. All 59 focused tests
+> passed. The installed final bundle `2.13.0-local.aaf2152c` cold-boots to
+> Language on two cold boots (vphoned in six and five seconds) with the
+> temporary override removed and no crash reports. Its System `.bak` matches the
+> original plist and SetupBackground is restored byte-identically. Native
+> Return advances to Region; Escape returns to Language, without completing
+> setup. No instruction patch or new preset is introduced. The installer promotes the
+> installed TV OTA's SystemVersion after committing its private disk clone,
+> fixing the host's stale 26.6 restore-base label. See
+> [bring-up notes](Firmware/tvos_support.md#apple-tv-4k-4th-generation).
> **tvOS 27 on the Apple TV 4K (2026-10-16).** No new patch. The 4K's tvOS 27.0
> (24J361) OTA goes over the HD's 26.6 IPSW, and the plan resolves for the OTA's
diff --git a/Research/Firmware/tvos_support.md b/Research/Firmware/tvos_support.md
index 82aaad7f..733e67ba 100644
--- a/Research/Firmware/tvos_support.md
+++ b/Research/Firmware/tvos_support.md
@@ -30,7 +30,8 @@ would choose the HD preset for this new product type. The CLI/catalog schema
is unchanged; the new series keeps that preset decision paired with the new
device catalog. Firmware patch discovery now preserves any recorded OTA board
with a restore base, so the HD manifest cannot replace J265's guest identity.
-No new binary patch or preset is needed.
+The 27.2 setup compatibility patch described below is selected by `tvos-4k`;
+there is no new instruction patch or preset.
Validation completed without admin privileges:
@@ -53,16 +54,111 @@ Validation completed without admin privileges:
and lockdown mode had no target. The cache-loader gate patch also succeeded
on a separate extracted copy.
-**Still pending:** bundle installation through Launchpad, restore, privileged
-`cfw install`, and both guest boots. Host-side patch success does not establish
-a working J265 guest. No installed bundle or existing machine was changed.
-The prepared and patched test machine is at
-`/private/tmp/vphone-appletv18-validation/tv4k4`; logs are
-`/private/tmp/vphone-appletv18-prepare.log` and
-`/private/tmp/vphone-appletv18-patch.log`. Resume the normal restore/install
-pipeline with the matching 2.13 bundle when admin authorization is available,
-then verify vphoned identity, TVSetup, 4K rendering, and input before recording
-a live-boot claim.
+Live validation on 2026-10-24 used the persistent machine
+`~/.vphone/machines/tv4k4`, cloned from the prepared scratch machine. Launchpad
+2.13 and its helper installed and admitted the local bundle. The native restore
+completed for ECID `0xF853D2724C37EC35`; full `cfw install --keep-artifacts`
+then applied 109 patches and installed all 42 OTA chunks. The machine is bound
+to local bundle `2.13.0-local.aaf2152c`. Other machines were left stopped.
+
+The installer now promotes the installed OTA's SystemVersion for TV as well
+as HomePod, after the private disk clone is committed. Without this, the host
+kept showing the HD restore base's 26.6 even though the guest ran 27.2.
+`RestoreInfoTests` passed all 21 cases after the change, including both 4K
+identities, and the finished bundle rebuilt successfully.
+
+Both normal boots reached vphoned in about five seconds. `device.info` reports
+`AppleTV18,1`, `27.2.0`, four CPUs, 4 GB, and a 1920×1080-point screen at 2x.
+Graphical startup initially stalled: the native window retained the boot logo,
+and guest screenshots were black. SetupBackground's scene-create watchdog
+found its main thread in `PBSDisplayManager._init`, waiting on a semaphore for
+`fetchCurrentDisplayStateWithReply:`. Static analysis confirms a 15-second
+client wait against the scene's 10-second watchdog; the server implementation
+dispatches to the main queue and replies with its serialized state without a
+display-mode readiness gate. A missing client proxy can also produce that
+wait, so this stack alone did not establish the failure's cause.
+
+One controlled restart of `com.apple.PineBoard` allowed SetupBackground's
+scene to become ready, and the new Setup app rendered its animated Hello
+screen at 3840×2160. A third cold boot stalled again; restarting Setup alone
+did not recover it, and a second PineBoard restart did not reliably help.
+Keyboard Return through vphoned, the host API and the native window did not
+advance the recovered Hello screen.
+
+A temporary native probe then isolated the sandbox lookup. As `mobile`, the
+display service returned real 3840×2160 display state immediately, and
+`PBSDisplayManager.sharedInstance` initialized on the main thread in 0.006 s.
+Signing the same probe with SetupBackground's original three entitlements
+(application identifier, platform bit and container requirement) changed that
+to 15.049 s. Adding only
+`com.apple.security.exception.mach-lookup.global-name = [com.apple.PineBoardServices]`
+reduced it to 0.005 s. The container requirement remained on. This reproduces
+the scene watchdog without involving video playback or the GPU.
+
+`system-setupbackground-exp-pineboard_lookup` adds that single exception,
+preserving the app's other entitlements. The declaration applies only to
+27.2, is opt-in, and the installer rejects a non-TV identity.
+It saves the original executable as `.bak`, allowing the normal guest patch
+selection and `cfw update-environment` to reverse it. All 55 focused patch
+catalog, guest resolution and entitlement tests passed, as did the 32 patch
+model tests; the finished bundle rebuilt successfully. After administrator
+authorization, Launchpad installed `2.13.0-local.ea3237b6`, and
+`vm set-bundle tv4k4 2.13.0-local.ea3237b6 --update-environment` applied the
+patch. The guest receipt records it live. The installed executable has exactly
+the original three keys plus the single lookup array; its `.bak` is byte
+identical to the original pulled before the update.
+
+The first patched cold boot reached vphoned in five seconds and the animated
+4K Hello screen without a PineBoard restart. PineBoard, backboardd, Setup and
+SetupBackground retain their startup PIDs; no crash report was present after
+the boot. Consumer-page Select (`0x0C/0x41`) still did not advance Hello. A
+12-second Setup log capture around a press contained 144 normal rendering
+entries but no `Remote pressed.` handler entry. Static analysis and Swift
+field metadata show this handler checks `_hasDrawingStarted` and
+`ScenePhase.active`, not a mandatory paired-Bluetooth-remote condition. The
+unresolved cause is event delivery or these local scene gates.
+
+PineBoard retains a native fallback: `CompanionServices/TVSetupV2`, or
+`TVSetupV2HW` plus its product-type gate, selects `com.apple.Setup`; with both
+flags disabled it selects `com.apple.purplebuddy` (TVSetup). This TVSetup is
+from the 27.2 OTA (its SDK and minimum OS version are 27.2), not the HD restore
+base. A temporary Data-volume override of both flags followed by a cold boot
+opened its 4K Language screen. Consumer Down/Up and native-window keyboard
+Down/Up moved English to Simplified Chinese and back without selecting a
+language. REA evidence: `ev_e11258e9f22e339e9c8e1eedd8108024a7a9859b12a8c4cb966954461712f258`
+and `ev_be3a9edd8bf4e9ede9361aaa789b4cc9a4e282387021eb2ed7ca9f9fec6dd74a`.
+
+The supported preset therefore uses `system-tv-exp-legacy_setup`, gated to
+27.2 and selected only by `tvos-4k`. It sets `TVSetupV2.Enabled` and
+`TVSetupV2HW.Enabled` to false in the System CompanionServices feature plist,
+preserving other flags, metadata and encoding. The installer requires a TV
+identity and backs up the original plist for reversal. It does not mark setup
+complete or choose any setup options. The SetupBackground lookup repair now
+remains opt-in for investigation of the new setup flow. The 59 focused
+feature-plist, guest-resolution, catalogue and entitlement tests passed.
+
+Launchpad installed final bundle `2.13.0-local.aaf2152c` and updated the guest
+environment. Its receipt records the legacy setup patch and no display-lookup
+patch. The System feature plist matches the offline patch output; its `.bak`
+is byte-identical to the original. SetupBackground reverted byte-identically
+to the original executable. The temporary Data override was removed before
+boot and its absence confirmed from the guest.
+
+The final bundle's first cold boot reached vphoned in six seconds and the 4K
+Language screen. Consumer Down/Up moved English to Simplified Chinese and
+back. Native keyboard Return opened Region, and Escape returned to Language.
+No region, permissions, agreements, accounts or setup completion were chosen.
+The initial host window, tested after clearing only this machine's saved frame,
+has exactly 3840×2160 content plus the 104-pixel toolbar and correctly labels
+tvOS 27.2.0. Window fitting now follows toolbar installation and showing the
+window so AppKit's initial screen constraint cannot distort the wide panel.
+PineBoard (38), backboardd (74) and TVSetup (214) retained their PIDs over the
+first minute; the crash list remained empty. A second final cold boot reached
+vphoned in five seconds and rendered the 4K Language screen again, with no
+crash reports. The VM is left running there. `ui.tree` cannot verify the frontmost app on TV, so input
+verification uses direct screenshots and the native VM window.
+Logs, the watchdog report, a guest spindump and screenshots are retained under
+`/private/tmp/vphone-appletv18-*` and `.build/appletv18-validation/`.
## Earlier Apple TV validation
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareMachLookupExceptions.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareMachLookupExceptions.swift
index 951c70c8..03103015 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareMachLookupExceptions.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareMachLookupExceptions.swift
@@ -63,7 +63,11 @@ public enum CustomFirmwareMachLookupExceptions {
/// format, which is what `plistlib.dump()` defaults to and what `ldid`
/// expects on the way back in.
@discardableResult
- public static func merge(at url: URL, verbose: Bool = true) throws -> Outcome {
+ public static func merge(
+ at url: URL,
+ services: [String] = CustomFirmwareMachLookupExceptions.services,
+ verbose: Bool = true,
+ ) throws -> Outcome {
let data: Data
do {
data = try Data(contentsOfFileToRewrite: url)
@@ -97,7 +101,7 @@ public enum CustomFirmwareMachLookupExceptions {
try output.write(to: url)
if verbose {
- print(" [+] Campo mach-lookup exception count: \(merged.count) (+\(added.count) added)")
+ print(" [+] mach-lookup exception count: \(merged.count) (+\(added.count) added)")
}
return Outcome(total: merged.count, added: added.count)
}
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareTVSetup.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareTVSetup.swift
new file mode 100644
index 00000000..ac30ce40
--- /dev/null
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareTVSetup.swift
@@ -0,0 +1,44 @@
+import Foundation
+import VPhonePatchKit
+
+/// Select the native TVSetup app retained in tvOS 27.2. The new Setup Hello
+/// scene does not respond to the virtual keyboard/consumer remote. This does
+/// not mark setup complete or change any setup choices.
+public enum CustomFirmwareTVSetup {
+ public static let relativePath = "System/Library/FeatureFlags/Domain/CompanionServices.plist"
+ public static let features = ["TVSetupV2", "TVSetupV2HW"]
+
+ /// Preserve unrelated flags, per-feature metadata and the plist encoding.
+ /// Require both known dictionaries before writing either change.
+ @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 changed = false
+ for name in features {
+ guard var feature = root[name] as? [String: Any] else {
+ throw PatcherError.invalidFormat("Missing \(name) feature dictionary: \(url.path)")
+ }
+ if let enabled = feature["Enabled"] {
+ guard let number = enabled as? NSNumber,
+ CFGetTypeID(number) == CFBooleanGetTypeID()
+ else {
+ throw PatcherError.invalidFormat("\(name).Enabled is not a boolean: \(url.path)")
+ }
+ if !number.boolValue { continue }
+ }
+ feature["Enabled"] = false
+ root[name] = feature
+ changed = true
+ }
+ guard changed else { return false }
+ 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/PatchSets/FirmwareGuestPatchResolution.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestPatchResolution.swift
index 17087700..4da517dd 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestPatchResolution.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestPatchResolution.swift
@@ -40,6 +40,8 @@ public enum FirmwareGuestPatchResolution {
public static let tvArm64eGuestPatches: Set<String> = Set([
"system-extensions-boot-gpu_bundle",
FirmwareGuestSystemPatchSet.tvOTAUserland,
+ FirmwareGuestSystemPatchSet.tvSetupDisplayLookup,
+ FirmwareGuestSystemPatchSet.tvLegacySetup,
]).union(FirmwarePatchSetCatalog.tvOS27UserlandPatches)
public static func unvalidatedTVGuestPatches(enabled: Set<String>, arm64eUserland: Bool = false) -> [String] {
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
index f0c58820..102b862a 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
@@ -40,6 +40,8 @@ public enum FirmwareGuestSystemPatchSet {
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"
+ public static let tvSetupDisplayLookup = "system-setupbackground-exp-pineboard_lookup"
+ public static let tvLegacySetup = "system-tv-exp-legacy_setup"
/// Replaces the restored System volume with an Apple TV 4K userland
/// staged from its OTA. Research only: no IPSW exists for that device.
public static let tvOTAUserland = "system-tv-exp-ota_userland"
@@ -99,6 +101,20 @@ public enum FirmwareGuestSystemPatchSet {
target: .guestExecutable(path: "/usr/lib/dyld"),
applicability: VPhonePatchApplicability(iOSBase: .major(26)),
),
+ VPhonePatchDeclaration(
+ identifier: tvLegacySetup,
+ title: "TV setup virtual remote compatibility",
+ summary: "Selects the native TVSetup app retained in tvOS 27.2 by disabling TVSetupV2 and TVSetupV2HW. Its language screen accepts virtual keyboard and consumer remote input. Setup choices and completion remain under user control.",
+ target: .guestFile(path: "/" + CustomFirmwareTVSetup.relativePath),
+ applicability: VPhonePatchApplicability(iOSBase: .release(major: 27, minor: 2)),
+ ),
+ VPhonePatchDeclaration(
+ identifier: tvSetupDisplayLookup,
+ title: "TV setup display connection",
+ summary: "Lets tvOS 27.2 SetupBackground look up PineBoardServices on the cloudOS kernel. Without this one sandbox exception, its display-state request times out and setup stays black.",
+ target: .guestEntitlements(path: "/Applications/SetupBackground.app/SetupBackground"),
+ applicability: VPhonePatchApplicability(iOSBase: .release(major: 27, minor: 2)),
+ ),
VPhonePatchDeclaration(
identifier: tvOTAUserland,
title: "Apple TV 4K userland from OTA",
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
index 71cbe361..fee6eead 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
@@ -69,7 +69,7 @@ public enum FirmwarePatchSetCatalog {
.union(hypervisorConcealmentPatches)
.union(experimentalIdentityPatches)
.union([FirmwareGuestSystemPatchSet.otaUserland, FirmwareGuestSystemPatchSet.homePodTopCap, FirmwareGuestSystemPatchSet.homePodSetupBypass, FirmwareGuestSystemPatchSet.homePodAudioProduct, FirmwareGuestSystemPatchSet.homePodWelcome, FirmwareGuestSystemPatchSet.homePodSiriSpeech, FirmwareGuestSystemPatchSet.homePodOTAUserland, FirmwareGuestSystemPatchSet.homePodSoundGlow])
- .union([FirmwareKernelCustomFirmwarePatchSet.tvTPROPagers, misTrustAuthPatch, FirmwareGuestSystemPatchSet.settingsRootRows, FirmwareGuestSystemPatchSet.settingsSoftwareUpdate, FirmwareGuestSystemPatchSet.tvTPRO, FirmwareGuestSystemPatchSet.tvOTAUserland])
+ .union([FirmwareKernelCustomFirmwarePatchSet.tvTPROPagers, misTrustAuthPatch, FirmwareGuestSystemPatchSet.settingsRootRows, FirmwareGuestSystemPatchSet.settingsSoftwareUpdate, FirmwareGuestSystemPatchSet.tvTPRO, FirmwareGuestSystemPatchSet.tvOTAUserland, FirmwareGuestSystemPatchSet.tvSetupDisplayLookup, FirmwareGuestSystemPatchSet.tvLegacySetup])
/// ProMotion: the 120 Hz timing for the paravirtual display.
///
@@ -226,7 +226,7 @@ public enum FirmwarePatchSetCatalog {
freshly restored 26.4 guest does not survive. The HomePod-only top cap is off.
""",
patchSets: bundledReferences,
- selection: .block([FirmwareGuestSystemPatchSet.homePodTopCap, FirmwareGuestSystemPatchSet.homePodSetupBypass, FirmwareGuestSystemPatchSet.homePodAudioProduct, FirmwareGuestSystemPatchSet.homePodWelcome, FirmwareGuestSystemPatchSet.homePodSiriSpeech, FirmwareGuestSystemPatchSet.homePodOTAUserland, FirmwareGuestSystemPatchSet.homePodSoundGlow]),
+ selection: .block([FirmwareGuestSystemPatchSet.tvLegacySetup, FirmwareGuestSystemPatchSet.tvSetupDisplayLookup, FirmwareGuestSystemPatchSet.homePodTopCap, FirmwareGuestSystemPatchSet.homePodSetupBypass, FirmwareGuestSystemPatchSet.homePodAudioProduct, FirmwareGuestSystemPatchSet.homePodWelcome, FirmwareGuestSystemPatchSet.homePodSiriSpeech, FirmwareGuestSystemPatchSet.homePodOTAUserland, FirmwareGuestSystemPatchSet.homePodSoundGlow]),
)
/// The iOS payloads, hooks and shared-cache patches an Apple TV guest has no
@@ -318,7 +318,7 @@ public enum FirmwarePatchSetCatalog {
patchSets: bundledReferences,
selection: .block(
manualOnlyPatches
- .subtracting([FirmwareGuestSystemPatchSet.tvOTAUserland])
+ .subtracting([FirmwareGuestSystemPatchSet.tvOTAUserland, FirmwareGuestSystemPatchSet.tvLegacySetup])
.union(tvOSBlockedPatches.subtracting(["system-extensions-boot-gpu_bundle"]).subtracting(tvOS27UserlandPatches)),
),
)
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwarePlistPatchTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwarePlistPatchTests.swift
index 4a05ae89..1d6a3240 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwarePlistPatchTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwarePlistPatchTests.swift
@@ -429,6 +429,27 @@ struct CustomFirmwareMachLookupExceptionTests {
.write(to: url)
}
+ @Test func `TV setup adds only PineBoard lookup and preserves its sandbox`() throws {
+ let directory = try CustomFirmwarePatchFixtures.makeTemporaryDirectory()
+ defer { try? FileManager.default.removeItem(at: directory) }
+ let url = directory.appending(path: "SetupBackground.entitlements")
+ try write([
+ "application-identifier": "com.apple.SetupBackground",
+ "platform-application": true,
+ "com.apple.private.security.container-required": true,
+ CustomFirmwareMachLookupExceptions.exceptionKey: ["com.apple.existing.service"],
+ ], to: url)
+ try CustomFirmwareMachLookupExceptions.merge(at: url, services: ["com.apple.PineBoardServices"], verbose: false)
+ let patched = try #require(PlistComparison.load(url) as? [String: Any])
+ #expect(patched.count == 4)
+ #expect(patched["application-identifier"] as? String == "com.apple.SetupBackground")
+ #expect(patched["platform-application"] as? Bool == true)
+ #expect(patched["com.apple.private.security.container-required"] as? Bool == true)
+ #expect(patched[CustomFirmwareMachLookupExceptions.exceptionKey] as? [String] == ["com.apple.existing.service", "com.apple.PineBoardServices"])
+ let repeated = try CustomFirmwareMachLookupExceptions.merge(at: url, services: ["com.apple.PineBoardServices"], verbose: false)
+ #expect(repeated.added == 0 && repeated.total == 2)
+ }
+
@Test func `adds every service when the key is absent`() throws {
let directory = try CustomFirmwarePatchFixtures.makeTemporaryDirectory()
defer { try? FileManager.default.removeItem(at: directory) }
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareTVSetupTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareTVSetupTests.swift
new file mode 100644
index 00000000..168a0769
--- /dev/null
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareTVSetupTests.swift
@@ -0,0 +1,52 @@
+@testable import FirmwarePatcher
+import Foundation
+import Testing
+
+@Suite("TV setup feature flags")
+struct CustomFirmwareTVSetupTests {
+ @Test(arguments: [PropertyListSerialization.PropertyListFormat.xml, .binary])
+ func preservesMetadataAndEncoding(format: PropertyListSerialization.PropertyListFormat) throws {
+ let url = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
+ defer { try? FileManager.default.removeItem(at: url) }
+ let original: [String: Any] = [
+ "TVSetupV2": ["DevelopmentPhase": "FeatureComplete", "Metadata": "retained"],
+ "TVSetupV2HW": ["Enabled": true, "DevelopmentPhase": "FeatureComplete"],
+ "OtherFeature": ["Enabled": true],
+ ]
+ let input = try PropertyListSerialization.data(fromPropertyList: original, format: format, options: 0)
+ try input.write(to: url)
+ #expect(try CustomFirmwareTVSetup.patch(at: url, dryRun: true))
+ #expect(try Data(contentsOf: url) == input)
+ #expect(try CustomFirmwareTVSetup.patch(at: url))
+ let output = try Data(contentsOf: url)
+ var outputFormat = PropertyListSerialization.PropertyListFormat.xml
+ let root = try #require(PropertyListSerialization.propertyList(from: output, format: &outputFormat) as? [String: Any])
+ #expect(outputFormat == format)
+ #expect((root["OtherFeature"] as? NSDictionary) == (original["OtherFeature"] as? NSDictionary))
+ for name in CustomFirmwareTVSetup.features {
+ let feature = try #require(root[name] as? [String: Any])
+ #expect(feature["Enabled"] as? Bool == false)
+ #expect(feature["DevelopmentPhase"] as? String == "FeatureComplete")
+ }
+ #expect((root["TVSetupV2"] as? [String: Any])?["Metadata"] as? String == "retained")
+ #expect(try !CustomFirmwareTVSetup.patch(at: url))
+ #expect(try Data(contentsOf: url) == output)
+ }
+
+ @Test
+ func refusesUnexpectedSchemaWithoutPartialWrite() throws {
+ let url = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
+ defer { try? FileManager.default.removeItem(at: url) }
+ for invalid: Any in ["invalid", ["Enabled": 0], ["Enabled": "false"]] {
+ let root: [String: Any] = ["TVSetupV2": [:], "TVSetupV2HW": invalid]
+ let input = try PropertyListSerialization.data(fromPropertyList: root, format: .binary, options: 0)
+ try input.write(to: url)
+ #expect(throws: (any Error).self) { try CustomFirmwareTVSetup.patch(at: url) }
+ #expect(try Data(contentsOf: url) == input)
+ }
+ let input = try PropertyListSerialization.data(fromPropertyList: ["TVSetupV2": [:]], format: .binary, options: 0)
+ try input.write(to: url)
+ #expect(throws: (any Error).self) { try CustomFirmwareTVSetup.patch(at: url) }
+ #expect(try Data(contentsOf: url) == input)
+ }
+}
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwareGuestPatchResolutionTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwareGuestPatchResolutionTests.swift
index 9aeee471..9188d179 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwareGuestPatchResolutionTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwareGuestPatchResolutionTests.swift
@@ -12,6 +12,35 @@ import VPhonePatchKit
@Suite("Guest patch resolution")
struct FirmwareGuestPatchResolutionTests {
+ @Test func `TV legacy setup is limited to the 27 point 2 4K preset`() throws {
+ let identifier = FirmwareGuestSystemPatchSet.tvLegacySetup
+ for version in ["26.6", "27.0", "27.1", "27.2", "27.3"] {
+ for preset in FirmwarePatchSetCatalog.builtInPresets {
+ let plan = try VPhonePatchPlan.resolve(
+ preset: preset, patchSets: FirmwarePatchSetCatalog.bundled,
+ iOSBase: VPhoneVersion(version), cloudOS: VPhoneVersion("26.4"),
+ )
+ #expect(plan.isEnabled(identifier) == (version == "27.2" && preset.identifier == VPhonePatchPreset.tvOS4KIdentifier))
+ }
+ }
+ #expect(FirmwareGuestPatchResolution.unvalidatedTVGuestPatches(enabled: [identifier], arm64eUserland: true).isEmpty)
+ #expect(FirmwareGuestPatchResolution.unvalidatedHomePodGuestPatches(enabled: [identifier]) == [identifier])
+ #expect(FirmwareGuestPatchResolution.guestPatchesOff(selectionEnabled: []).contains(identifier))
+ }
+
+ @Test func `new TV setup display repair remains opt in`() throws {
+ let identifier = FirmwareGuestSystemPatchSet.tvSetupDisplayLookup
+ for preset in FirmwarePatchSetCatalog.builtInPresets {
+ let plan = try VPhonePatchPlan.resolve(
+ preset: preset, patchSets: FirmwarePatchSetCatalog.bundled,
+ iOSBase: VPhoneVersion("27.2"), cloudOS: VPhoneVersion("26.4"),
+ )
+ #expect(!plan.isEnabled(identifier))
+ }
+ #expect(FirmwareGuestPatchResolution.unvalidatedTVGuestPatches(enabled: [identifier], arm64eUserland: true).isEmpty)
+ #expect(FirmwareGuestPatchResolution.unvalidatedHomePodGuestPatches(enabled: [identifier]) == [identifier])
+ }
+
@Test(arguments: [FirmwareGuestSystemPatchSet.homePodOTAUserland, FirmwareGuestSystemPatchSet.homePodSoundGlow])
func `HomePod OTA and Sound Glow require 27 point 2 and stay out of other presets`(identifier: String) throws {
for version in ["26.6", "27.0", "27.1", "27.2", "27.3"] {
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
index fe868b6a..514f15f8 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
@@ -217,7 +217,7 @@ struct FirmwarePatchSetCatalogTests {
}
@Test
- func `Extended adds the applicable manual patches except the HomePod-only device`() throws {
+ func `Extended adds the applicable manual patches except device-specific repairs`() throws {
for base in ["18.6.2", "26.4", "27.0", "27.1", "27.2"] {
let version = VPhoneVersion(base)
let cloud = VPhoneVersion("26.4")
@@ -242,6 +242,8 @@ struct FirmwarePatchSetCatalogTests {
&& $0.identifier != FirmwareGuestSystemPatchSet.homePodAudioProduct
&& $0.identifier != FirmwareGuestSystemPatchSet.homePodOTAUserland
&& $0.identifier != FirmwareGuestSystemPatchSet.homePodSoundGlow
+ && $0.identifier != FirmwareGuestSystemPatchSet.tvSetupDisplayLookup
+ && $0.identifier != FirmwareGuestSystemPatchSet.tvLegacySetup
&& $0.applicability.matches(iOSBase: version, cloudOS: cloud)
}.map(\.identifier))
#expect(experimental.enabled.subtracting(standard.enabled) == applicableManual)
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
index ef39cf86..c64a11e0 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
@@ -211,6 +211,12 @@ struct VPhoneCustomFirmwareInstaller {
? try restoreTree(in: bundleDirectory, path: bundlePath, owner: callerUID)
: nil
let device = configuredGuestDevice(in: bundleDirectory) ?? guestDevice(of: restore)
+ if effectiveEnabled.contains(FirmwareGuestSystemPatchSet.tvLegacySetup), device.family != .appleTV {
+ throw ValidationError("The TV setup compatibility patch is supported only for an Apple TV guest.")
+ }
+ if effectiveEnabled.contains(FirmwareGuestSystemPatchSet.tvSetupDisplayLookup), device.family != .appleTV {
+ throw ValidationError("The TV setup display-connection patch is supported only for an Apple TV guest.")
+ }
if effectiveEnabled.contains(FirmwareGuestSystemPatchSet.homePodTopCap), device.family != .homePod {
throw ValidationError("The HomePod top-cap patch is supported only for a HomePod guest.")
}
@@ -1889,6 +1895,38 @@ struct VPhoneCustomFirmwareInstaller {
}
}
+ let tvLegacySetup = FirmwareGuestSystemPatchSet.tvLegacySetup
+ let tvSetupFlags = CustomFirmwareTVSetup.relativePath
+ isolate([tvLegacySetup]) {
+ if (version == "27.2" || version.hasPrefix("27.2.")), on(tvLegacySetup), guestDevice.family == .appleTV {
+ try patchCopy(
+ of: tvSetupFlags, in: system, work: work,
+ verb: "patch-tv-setup", backupSafe: backupSafe(tvLegacySetup),
+ )
+ live.insert(tvLegacySetup)
+ } else if try revertCopy(of: tvSetupFlags, in: system) {
+ print(" [+] \(tvLegacySetup): restored CompanionServices feature flags")
+ } else if priorGuest.contains(tvLegacySetup) {
+ print(" [!] \(tvLegacySetup): no backup to revert (not revertible)")
+ live.insert(tvLegacySetup)
+ }
+ }
+
+ let tvSetupLookup = FirmwareGuestSystemPatchSet.tvSetupDisplayLookup
+ let tvSetupBackground = "Applications/SetupBackground.app/SetupBackground"
+ isolate([tvSetupLookup]) {
+ if on(tvSetupLookup), guestDevice.family == .appleTV {
+ if try patchTVSetupDisplayLookup(system: system, work: work, backupSafe: backupSafe(tvSetupLookup)) {
+ live.insert(tvSetupLookup)
+ }
+ } else if try revertMachO(system: system, work: work, path: tvSetupBackground) {
+ print(" [+] \(tvSetupLookup): restored SetupBackground from backup")
+ } else if priorGuest.contains(tvSetupLookup) {
+ print(" [!] \(tvSetupLookup): off now but no backup to revert (not revertible)")
+ live.insert(tvSetupLookup)
+ }
+ }
+
let personaPatch = FirmwareGuestSystemPatchSet.installCoordinationPersona
let personaMarker = String(FirmwareGuestSystemPatchSet.installCoordinationPersonaMarker.dropFirst())
isolate([personaPatch]) {
@@ -3624,6 +3662,27 @@ struct VPhoneCustomFirmwareInstaller {
return true
}
+ /// The cloudOS application sandbox does not include the TV service name.
+ /// SetupBackground's only other entitlements are its identity, container
+ /// requirement and platform bit; keep them and add just this lookup.
+ private func patchTVSetupDisplayLookup(system: VPhoneConfinedDirectory, work: WorkDirectory, backupSafe: Bool) throws -> Bool {
+ let target = "Applications/SetupBackground.app/SetupBackground"
+ guard let staged = try stageOptional(target, from: system, work: work, label: "SetupBackground") else { return false }
+ guard let source = try VPhoneSigner.entitlements(ofFileAt: staged).first(where: { !$0.isEmpty }) else {
+ throw ValidationError("SetupBackground has no readable entitlements")
+ }
+ let ent = work.file("SetupBackground.entitlements")
+ try source.write(to: ent)
+ try CustomFirmwareMachLookupExceptions.merge(at: ent, services: ["com.apple.PineBoardServices"])
+ try backupEntitlementTarget(target, in: system, backupSafe: backupSafe)
+ try VPhoneSigner.sign(
+ fileAt: staged,
+ options: .init(entitlements: Data(contentsOf: ent), style: .appleAdHoc),
+ )
+ try system.replaceFile(target, fromFileAt: staged, mode: 0o755, owner: Self.guestOwner)
+ return true
+ }
+
// MARK: - xART volume
/// The patched seputil looks for the gigalocker as `AA.gl` rather than
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift
index 263f44ef..ed6878db 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift
@@ -221,6 +221,27 @@ struct VPhoneCustomFirmwarePatchLocationdCohortingCommand: ParsableCommand {
}
}
+// MARK: - patch-tv-setup
+
+struct VPhoneCustomFirmwarePatchTVSetupCommand: ParsableCommand {
+ static let configuration = CommandConfiguration(
+ commandName: "patch-tv-setup",
+ abstract: "Select the native tvOS 27.2 setup flow for virtual remote input",
+ shouldDisplay: false,
+ )
+
+ @Argument(transform: URL.init(fileURLWithPath:))
+ var plist: URL
+
+ @Flag(name: .customLong("dry-run"))
+ var dryRun = false
+
+ func run() throws {
+ let changed = try CustomFirmwareTVSetup.patch(at: plist, dryRun: dryRun)
+ print(" [\(changed ? "+" : ".")] TVSetupV2 / TVSetupV2HW = false\(dryRun ? " (dry-run)" : "")")
+ }
+}
+
// MARK: - patch-jetsam-disable-allowed
struct VPhoneCustomFirmwarePatchJetsamDisableAllowedCommand: ParsableCommand {
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift
index 637b9d55..f5678482 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift
@@ -245,6 +245,7 @@ struct VPhoneCustomFirmwareCommand: ParsableCommand {
VPhoneCustomFirmwareInjectDylibCommand.self,
VPhoneCustomFirmwarePatchBuildVersionCommand.self,
VPhoneCustomFirmwarePatchLocationdCohortingCommand.self,
+ VPhoneCustomFirmwarePatchTVSetupCommand.self,
VPhoneCustomFirmwarePatchVirtualBluetoothCommand.self,
VPhoneCustomFirmwarePatchJetsamDisableAllowedCommand.self,
VPhoneCustomFirmwarePatchVirtualAudioGraphConfigurationsCommand.self,
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/experimental.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/experimental.plist
index 7344f710..1174508e 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/experimental.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/experimental.plist
@@ -94,6 +94,8 @@
<key>Patches</key>
<array>
<string>system-homepod-exp-top_cap</string>
+ <string>system-setupbackground-exp-pineboard_lookup</string>
+ <string>system-tv-exp-legacy_setup</string>
<string>system-homepod-exp-setup_bypass</string>
<string>system-homepod-exp-welcome</string>
<string>system-homepod-exp-siri_speech</string>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist
index f12453c9..d8b0e9d4 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist
@@ -114,6 +114,8 @@
<string>system-diskimagesiod-cfw-is_mount_complete</string>
<string>system-extensions-boot-gpu_bundle</string>
<string>system-tv-exp-ota_userland</string>
+ <string>system-setupbackground-exp-pineboard_lookup</string>
+ <string>system-tv-exp-legacy_setup</string>
<string>system-fsck-boot-arm64e_x1_bootstrap</string>
<string>system-installcoordination_proxy-cfw-persona_lookup</string>
<string>system-jetsamproperties-cfw-disable_allowed</string>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/standard.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/standard.plist
index f140853d..846682ab 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/standard.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/standard.plist
@@ -102,6 +102,8 @@
<string>system-dyld-exp-tv_tpro</string>
<string>kernel-exp-tv_tpro_pagers</string>
<string>system-tv-exp-ota_userland</string>
+ <string>system-setupbackground-exp-pineboard_lookup</string>
+ <string>system-tv-exp-legacy_setup</string>
<string>system-exp-ota_userland</string>
</array>
</dict>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist
index 8ca0f78f..3e81dea4 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist
@@ -73,6 +73,7 @@
<string>Block</string>
<key>Patches</key>
<array>
+ <string>system-setupbackground-exp-pineboard_lookup</string>
<string>system-homepod-exp-top_cap</string>
<string>system-homepod-exp-setup_bypass</string>
<string>system-homepod-exp-welcome</string>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist
index 53706d4f..a28512b6 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist
@@ -144,6 +144,8 @@
<string>system-virtualaudio-cfw-speaker_route_throws</string>
<string>system-virtualaudio-cfw-volume_mode_precondition</string>
<string>system-tv-exp-ota_userland</string>
+ <string>system-setupbackground-exp-pineboard_lookup</string>
+ <string>system-tv-exp-legacy_setup</string>
<string>system-exp-ota_userland</string>
</array>
</dict>
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift
index cbba6626..7d1c4475 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift
@@ -121,9 +121,6 @@ class VPhoneVirtualMachineWindowController: NSObject, NSWindowDelegate {
}
window.setFrameAutosaveName(sceneName)
observeKeyState(of: window)
- // A frame saved while the guest was sideways is turned back: the guest
- // boots in portrait, and the orientation poll turns it again if not.
- if !homePodGuest { applyOrientation(.portrait, to: window, force: true) }
// An empty unified toolbar gives the title bar its full height. The Home
// button is a titlebar accessory rather than a toolbar item so that a
@@ -146,6 +143,11 @@ class VPhoneVirtualMachineWindowController: NSObject, NSWindowDelegate {
let controller = NSWindowController(window: window)
controller.showWindow(nil)
windowController = controller
+ // AppKit constrains the initial frame when showing it. Fit the panel
+ // after the toolbar and actual screen are known, including a wide TV
+ // panel whose saved frame may otherwise be clamped out of proportion.
+ // The guest starts unturned; the orientation poll follows it later.
+ if !homePodGuest { applyOrientation(.portrait, to: window, force: true) }
keySender.window = window
NSApp.activate(ignoringOtherApps: true)
@@ -392,14 +394,15 @@ class VPhoneVirtualMachineWindowController: NSObject, NSWindowDelegate {
])
}
- /// `iOS <version> - <address>` from vphoned's health report, which picks
+ /// OS version and address from vphoned's health report, which picks
/// the IPv4 address first and falls back to IPv6; hidden until it connects.
private func updateSubtitle(control: VPhoneGuestControl) {
guard let window = windowController?.window else { return }
var parts: [String] = []
if control.isConnected {
if let version = control.guestIOSVersion, !version.isEmpty {
- parts.append("\(homePodGuest ? "HomePod" : "iOS") \(version)")
+ let osName = homePodGuest ? "HomePod" : homeButtonHoldsInGuest ? "tvOS" : "iOS"
+ parts.append("\(osName) \(version)")
}
if let address = control.guestIPAddress, !address.isEmpty {
parts.append(address)