Run a virtual iPhone on an Apple Silicon Mac.
Swift
Use IcliKit 0.6.4 for guest app foreground state
Lakr0e8946f4c9d4
diff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.mdindex da62a57c..fc7f7750 100644--- a/Research/vphoned_http_api.md+++ b/Research/vphoned_http_api.md@@ -35,13 +35,12 @@ directory then renames it after all chunks have been written. JSON bodieshave a 1 MiB limit. Binary transfers stream without loading the entire fileinto memory.-`apps.launch` returns a PID and `frontmost_verified`. On the iOS 26 research VM,-IcliKit can keep reporting SpringBoardEducation after an app reaches the screen.-The guest checks RunningBoard's live focal assertion in that case and accepts-it only when one app owns it. iOS 26.6.2 uses `SuspendableRole-UIFocal`; older-systems may use `Workspace-ForegroundFocal`. The Home screen's widget renderer-can hold `UIFocal`, so it is excluded as an app candidate. `apps.foreground`-also reports `verified` and `source`. If no unique focal app can be confirmed,+`apps.launch` returns a PID and `frontmost_verified`. IcliKit 0.6.4 checks+RunningBoard's live focal assertion and accepts it only when one real app owns+it. iOS 26.6.2 uses `SuspendableRole-UIFocal`; older systems may use+`Workspace-ForegroundFocal`. The Home screen's widget renderer can also hold+`UIFocal`, so the Kit excludes it. `apps.foreground` reports the Kit's+`verified` and `source` values. If no unique focal app can be confirmed,a newly started process is reported with `frontmost_verified=false` and awarning. A failed start or an already running app without foregroundconfirmation remains an error.@@ -63,7 +62,7 @@ correlate them by `id`. The socket also sendsreceive pong frames. JSON WebSocket frames are limited to 1 MiB afterfragment reassembly.-SwiftNIO handles parsing, upgrade, masking, and backpressure. IcliKit 0.6.3+SwiftNIO handles parsing, upgrade, masking, and backpressure. IcliKit 0.6.4owns general device operations. Each HTTP or WebSocket request runs independentlyon a concurrent worker queue, so a stalled system service does not block HID,file browsing, or unrelated requests. The host serializes the input events itdiff --git a/VPhone.xcworkspace/xcshareddata/swiftpm/Package.resolved b/VPhone.xcworkspace/xcshareddata/swiftpm/Package.resolvedindex 2782239b..e8839dbe 100644--- a/VPhone.xcworkspace/xcshareddata/swiftpm/Package.resolved+++ b/VPhone.xcworkspace/xcshareddata/swiftpm/Package.resolved@@ -24,8 +24,8 @@"kind" : "remoteSourceControl","location" : "https://github.com/owngoal-dev/icli.git","state" : {- "revision" : "ee01bde8ceeb4c90779427674185e353bf8e022d",- "version" : "0.6.3"+ "revision" : "12a4fb47bcc68c27bd44a681358289e1a4ffe0c9",+ "version" : "0.6.4"}},{diff --git a/VPhoneDaemon/Daemon/GuestAPI.swift b/VPhoneDaemon/Daemon/GuestAPI.swiftindex 3586729b..f60da861 100644--- a/VPhoneDaemon/Daemon/GuestAPI.swift+++ b/VPhoneDaemon/Daemon/GuestAPI.swift@@ -126,7 +126,9 @@ enum GuestAPI {let after = try runningApps()["apps"] as? [[String: Any]] ?? []guard let pid = after.first(where: { $0["bundle_id"] as? String == id })?["pid"] as? Intelse { throw IcliError.failed(message) }- if GuestForeground.current()["bundle_id"] as? String == id {+ let front = frontmostApp()+ if front["verified"] as? Bool == true,+ front["bundle_id"] as? String == id {return ["pid": pid, "frontmost_verified": true]}guard !wasRunning else { throw IcliError.failed(message) }@@ -138,14 +140,17 @@ enum GuestAPI {}}let running = try? runningApps()["apps"] as? [[String: Any]]+ let front = frontmostApp()return ["pid": running?.first(where: { $0["bundle_id"] as? String == id })?["pid"] ?? 0,- "frontmost_verified": params["url"] == nil,+ "frontmost_verified": params["url"] == nil+ && front["verified"] as? Bool == true+ && front["bundle_id"] as? String == id,]case "apps.terminate":return try killApp(string(params, "bundle_id"), force: true)case "apps.foreground":- let front = GuestForeground.current()+ let front = frontmostApp()let id = front["bundle_id"] as? String ?? ""let apps = try searchApps(id)["apps"] as? [[String: Any]] ?? []let running = try runningApps()["apps"] as? [[String: Any]] ?? []diff --git a/VPhoneDaemon/Daemon/GuestEventPublisher.swift b/VPhoneDaemon/Daemon/GuestEventPublisher.swiftindex 1b0ae4fb..8bd23bb2 100644--- a/VPhoneDaemon/Daemon/GuestEventPublisher.swift+++ b/VPhoneDaemon/Daemon/GuestEventPublisher.swift@@ -24,7 +24,7 @@ final class GuestEventPublisher: @unchecked Sendable {}let state: [String: Any] = ["screen": screenInfo(),- "frontmost_app": GuestForeground.current(),+ "frontmost_app": frontmostApp(),"low_power_mode": (try? lowPowerMode()) ?? [:],]guard let data = try? JSONSerialization.data(withJSONObject: state, options: [.sortedKeys]),diff --git a/VPhoneDaemon/Daemon/GuestForeground.swift b/VPhoneDaemon/Daemon/GuestForeground.swiftdeleted file mode 100644index 653507a0..00000000--- a/VPhoneDaemon/Daemon/GuestForeground.swift+++ /dev/null@@ -1,22 +0,0 @@-import Darwin-import Foundation-import IcliKit-import VphonedNative--enum GuestForeground {- static func current() -> [String: Any] {- let reported = frontmostApp()["bundle_id"] as? String ?? "com.apple.springboard"- let isSpringBoard = reported == "com.apple.springboard" || reported == "com.apple.springboardeducation"- guard isSpringBoard else {- return ["bundle_id": reported, "verified": true, "source": "springboard"]- }-- let screen = screenInfo()- guard screen["locked"] as? Bool != true, screen["screen_off"] as? Bool != true,- let focal = vp_runningboard_focal_bundle_id() else {- return ["bundle_id": reported, "verified": false, "source": "springboard"]- }- defer { free(focal) }- return ["bundle_id": String(cString: focal), "verified": true, "source": "runningboard"]- }-}diff --git a/VPhoneDaemon/Native/Include/VphonedNative.h b/VPhoneDaemon/Native/Include/VphonedNative.hindex 4ace90d1..a16cffef 100644--- a/VPhoneDaemon/Native/Include/VphonedNative.h+++ b/VPhoneDaemon/Native/Include/VphonedNative.h@@ -8,5 +8,3 @@ void vp_native_confirm_cached_binary(void);void vp_vcam_start(void);/// Returns 0 on acceptance, -1 when unavailable, -2 on timeout, or -3 on rejection.int vp_low_power_mode_set_async(bool enabled);-/// A malloc-owned bundle ID only when one live app has RunningBoard's focal assertion.-char *vp_runningboard_focal_bundle_id(void);diff --git a/VPhoneDaemon/Native/vphoned_foreground.m b/VPhoneDaemon/Native/vphoned_foreground.mdeleted file mode 100644index 0a244e64..00000000--- a/VPhoneDaemon/Native/vphoned_foreground.m+++ /dev/null@@ -1,67 +0,0 @@-#import "Include/VphonedNative.h"-#import <dlfcn.h>-#import <objc/message.h>-#import <sys/sysctl.h>--char *vp_runningboard_focal_bundle_id(void) {- @autoreleasepool {- dlopen("/System/Library/PrivateFrameworks/RunningBoardServices.framework/RunningBoardServices", RTLD_NOW);- Class identifierClass = NSClassFromString(@"RBSProcessIdentifier");- Class handleClass = NSClassFromString(@"RBSProcessHandle");- SEL identifierSelector = NSSelectorFromString(@"identifierWithPid:");- SEL handleSelector = NSSelectorFromString(@"handleForIdentifier:error:");- if (![identifierClass respondsToSelector:identifierSelector] || ![handleClass respondsToSelector:handleSelector])- return NULL;- void *libproc = dlopen("/usr/lib/libproc.dylib", RTLD_NOW);- int (*pidPath)(int, void *, uint32_t) = libproc ? dlsym(libproc, "proc_pidpath") : NULL;- if (!pidPath) {- if (libproc) dlclose(libproc);- return NULL;- }-- int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};- size_t length = 0;- if (sysctl(mib, 3, NULL, &length, NULL, 0) != 0) {- dlclose(libproc);- return NULL;- }- length += 64 * sizeof(struct kinfo_proc);- struct kinfo_proc *processes = calloc(1, length);- if (!processes || sysctl(mib, 3, processes, &length, NULL, 0) != 0) {- free(processes);- dlclose(libproc);- return NULL;- }-- NSMutableSet<NSString *> *focalIDs = [NSMutableSet set];- for (size_t i = 0; i < length / sizeof(struct kinfo_proc) && focalIDs.count < 2; i++) {- pid_t pid = processes[i].kp_proc.p_pid;- char path[4096] = {0};- if (pid <= 0 || pidPath(pid, path, sizeof(path)) <= 0 || !strstr(path, ".app/"))- continue;- @try {- id identifier = ((id (*)(id, SEL, int))objc_msgSend)(identifierClass, identifierSelector, pid);- id handle = ((id (*)(id, SEL, id, NSError **))objc_msgSend)(handleClass, handleSelector,- identifier, NULL);- NSString *bundleID = [[handle valueForKey:@"identity"] valueForKey:@"embeddedApplicationIdentifier"];- if (![bundleID isKindOfClass:NSString.class] || !bundleID.length) continue;- // The Home screen's widget renderer can own UIFocal without being the frontmost app.- if ([bundleID hasPrefix:@"com.apple.chrono.WidgetRenderer"]) continue;- for (id assertion in [[handle valueForKey:@"currentState"] valueForKey:@"assertions"]) {- NSString *domain = [assertion valueForKey:@"domain"];- if ([domain isKindOfClass:NSString.class] &&- ([domain containsString:@"Workspace-ForegroundFocal"] ||- [domain containsString:@"com.apple.frontboard:SuspendableRole-UIFocal"])) {- [focalIDs addObject:bundleID];- break;- }- }- } @catch (NSException *exception) {- (void)exception;- }- }- free(processes);- dlclose(libproc);- return focalIDs.count == 1 ? strdup(focalIDs.anyObject.UTF8String) : NULL;- }-}diff --git a/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxproj b/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxprojindex d006f3f2..cee7fd94 100644--- a/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxproj+++ b/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxproj@@ -351,7 +351,7 @@repositoryURL = "https://github.com/owngoal-dev/icli.git";requirement = {kind = exactVersion;- version = 0.6.3;+ version = 0.6.4;};};C10000000000000000000072 /* XCRemoteSwiftPackageReference "swift-nio" */ = {diff --git a/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolvedindex d79a07dd..76c8c25f 100644--- a/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved+++ b/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved@@ -6,8 +6,8 @@"kind" : "remoteSourceControl","location" : "https://github.com/owngoal-dev/icli.git","state" : {- "revision" : "ee01bde8ceeb4c90779427674185e353bf8e022d",- "version" : "0.6.3"+ "revision" : "12a4fb47bcc68c27bd44a681358289e1a4ffe0c9",+ "version" : "0.6.4"}},{