Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Duo: fold through SpringBoard's display tool service

Jacky30a9809f28f6
diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.md
index 8dfbbb6f..88d02de1 100644
--- a/Research/Guest/iphone_duo_bringup.md
+++ b/Research/Guest/iphone_duo_bringup.md
@@ -4787,6 +4787,54 @@ Measured on the test VM (bundle built from this change):
three cover orientations (cover tested with Safari, which rotates on iPhone).
- Three launch-sequence captures: no black frames, 2-5 transient tiles.
+## 2026-10-29 night: folds go through SpringBoard's display tool service
+
+Xcode 27's iPhone Duo simulator has no hinge: CoreSimulator gives it two real
+displays (screenID 1 cover, 3 inner), and SpringBoard folds itself through
+its display tool service, the one Apple's internal `sbdisplaytool` / `suiatool
+swap` drives. The device SpringBoard has the same service
+(`com.apple.springboard.sbdisplay` in `BSServiceDomains` under
+`com.apple.frontboard`), so `display.posture`'s `position` now uses it instead
+of the test-automation override plus a virtual hinge sweep. Measured on a
+test VM (iPhone19,4 27.1, 24A94425) with the two-display path:
+
+- `-[SBSDisplayToolService swapDisplayWithSettings:completion:]` takes
+ `{q; d duration; q deviceOrientation; q profileOverride; B wait; q
+ targetMode; d targetHingePosition; d}` (`v88@0:8{?=qdqqBqdd}16@?80`).
+ Target mode 1 sweeps to an absolute position (0 closed, 1 open flat);
+ duration < 0 is the per-direction default (0.391 s open, 0.420 s close);
+ profile 1 fade, 2 continuous (`.continuousLive`), 0 SpringBoard's own.
+ The server checks `com.apple.springboard.sbdisplay.service` (read from
+ the simulator SpringBoard's swap handler); without it SpringBoard logs
+ "Insufficient authorization" and never answers. The completion block's
+ arguments are not objects: the client forwards a raw register, and
+ retaining it as an `NSError` PAC-faults.
+- SpringBoard takes a 10 s test lock, sweeps its own pose (`absoluteSweeping
+ 0.0 -> 180.0 over 0.39s`), resolves `FullyClosed→FoldingDual` (or back) as
+ the sweep crosses the boundary, and answers after `completed` / `idle`,
+ about 1.2–1.6 s after the request. Book (100°) from closed swaps to the
+ inner panel; book from open does not.
+- After the lock SpringBoard does not return to the override; it applies the
+ next override against its current pose, so a later `hinge` request equal
+ to the old override still lands. The override does reach SpringBoard under
+ the lock, and it only means 0, 90 or 180°: setting it after a book sweep
+ slid the pose from 100° to 90° and started a transition toward the cover,
+ so vphoned leaves it alone after a SpringBoard sweep.
+- `-[SBSTestAutomationService getDevicePose]` does not follow these sweeps
+ (it kept reading open-flat after a sweep to closed); the replayed posture
+ takes the hinge state from the completed request.
+- Closing with the continuous profile is an interactive transition: it is
+ performed while the inner display still holds the primary content and
+ swaps it as it finishes. FoldDisplay re-read the panel's owner only when a
+ transition was performed, so the panel kept showing the inner display,
+ which SpringBoard keeps lit (and black) for 3 s after a swap. Ownership is
+ now re-read on `-[SpringBoard displayContentModeCoordinator:
+ handleSwapTransitionFromPrimaryWindowScene:toPrimaryWindowScene:
+ withContinuationLockProvider:]` too.
+- Folding from the lock screen or sleep lights the arriving panel's lock
+ screen, which sleeps again after the lock screen's short idle time (about
+ 7 s), as on hardware.
+
## 2026-10-29 night: the inner display at 120 Hz
Open, the VM window counted 60 fps while the cover (the paravirtual panel,
diff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.md
index 00a519f3..172bb597 100644
--- a/Research/vphoned_http_api.md
+++ b/Research/vphoned_http_api.md
@@ -1250,6 +1250,35 @@ upside-down, so with CoreMotion the cover's 180 and the inner panel's 270 are
refused. The accelerometer and the AssistiveTouch rotation other iPhones use
do not turn a foldable's panels.
+A `position` request is a fold, and SpringBoard runs it the way Apple's
+`suiatool swap` does: vphoned calls
+`-[SBSDisplayToolService swapDisplayWithSettings:completion:]` with the
+position as an absolute hinge target (0 closed, 1 open flat), the duration
+(−1 the per-direction default, measured 0.391 s opening and 0.420 s
+closing) and the profile (none, fade 1, continuous 2), and waits for the
+reply that comes once the swap has finished. SpringBoard
+(`SBDisplayToolServiceCoordinator`) takes a 10 s test lock that ignores the
+hinge, sweeps its own hinge pose from the current angle, and swaps displays
+when the sweep crosses the boundary, with the transition style, lock screen
+and backlight handling of a real fold (`book` from closed swaps to the inner
+panel; `book` from open does not). The swap keeps the device orientation
+unless `orientation` is given. vphoned then sets only the virtual hinge to
+the end angle and leaves the override alone: the override reaches
+SpringBoard even under the test lock and stands for 0, 90 or 180 degrees
+only, so setting it after a `book` sweep (100 degrees) slid the pose to 90
+and started a transition toward the cover. SpringBoard does not return to
+the old override when the lock ends, and applies the next override against
+its current pose, so a later `hinge` request lands even when its value
+equals the old one. `display.pose` does not follow SpringBoard's own sweeps
+(it kept reading `open-flat` after a sweep to closed), so the posture
+replayed after a SpringBoard restart takes its hinge state from a completed
+sweep's request. The server checks for
+`com.apple.springboard.sbdisplay.service`, which vphoned carries; a client
+without it is logged as having insufficient authorization and never
+answered. On a guest without the service (or one that does not answer
+within 10 s plus the duration) the virtual hinge sweeps and the override
+jumps, as before. Verified 2026-10-29 on iPhone19,4 27.1 (24A94425).
+
| Param | Values |
| --- | --- |
| `hinge` (required) | `ambiguous` 0, `closed` 1, `partially-open` 2, `open-flat` 3, `open` 4 |
@@ -1258,17 +1287,20 @@ do not turn a foldable's panels.
| `angle` | 0–180 (default: the hinge state's angle; partially open is book, 100°) |
| `position` | `closed` 0°, `book` ~100°, `open` 180°, or a fraction 0–1 — Apple's three screen states; requests a sweep |
| `duration` | sweep seconds; default the per-direction hand-fold time (opening faster), 0 instant |
-| `profile` | `continuous` (default) or `fade`, the two profiles suiatool names |
+| `profile` | `continuous` or `fade`, the two profiles suiatool names; default SpringBoard's own |
The reply echoes the numeric values, the published `angle`, `source`, and
`hinge_hid` (`applied`, `provider_running`, `provider`) describing the
virtual hinge service, so a host can tell a live sensor from an absent one.
-With CoreMotion the hinge is the pose, so a hinge that did not take the
-request fails it; `tabletop` is CoreMotion's to compute and comes back null.
-With the override, a refused override fails the request and a missing hinge
-provider does not. The hinge's stored angle and orientation survive a reboot
-and the provider hands them to the relay when it enumerates; the override is
-state of the running SpringBoard, gone with it at shutdown. The VM sub-type's own
+For a `position` it carries `sweep` (`duration_ms` as requested, −1 the
+default; `profile`; `completed`, true when SpringBoard ran the fold and has
+finished it, so the host settles its chrome at once). With CoreMotion the
+hinge is the pose, so a hinge that did not take the request fails it;
+`tabletop` is CoreMotion's to compute and comes back null. With the override,
+a refused override fails the request and a missing hinge provider does not.
+The hinge's stored angle and orientation survive a reboot and the provider
+hands them to the relay when it enumerates; the override is state of the
+running SpringBoard, gone with it at shutdown. The VM sub-type's own
restore path (`preboot-cfw-devicetree_foldable_vm_subtype`) does not stand
in on a single display: its `SBFDevicePoseLastKnown*` defaults are written
on display-mode transitions, which one display never makes (measured
diff --git a/VPhoneDaemon/Configuration/VPhoneDaemon.entitlements b/VPhoneDaemon/Configuration/VPhoneDaemon.entitlements
index 529432c2..d9801e2e 100644
--- a/VPhoneDaemon/Configuration/VPhoneDaemon.entitlements
+++ b/VPhoneDaemon/Configuration/VPhoneDaemon.entitlements
@@ -550,6 +550,8 @@
<true/>
<key>com.apple.springboard.openurlswhenlocked</key>
<true/>
+ <key>com.apple.springboard.sbdisplay.service</key>
+ <true/>
<key>com.apple.springboard.testautomation</key>
<true/>
<key>com.apple.timed</key>
diff --git a/VPhoneDaemon/Daemon/GuestAPI+Device.swift b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
index 86bad1b8..d6f7b0b3 100644
--- a/VPhoneDaemon/Daemon/GuestAPI+Device.swift
+++ b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
@@ -203,10 +203,11 @@ extension GuestAPI {
/// as on a device; elsewhere SpringBoard's test-automation override sets
/// the pose beside the hinge. The official model is three screen states —
/// `position` `closed`, `book` (~100°) or `open`, or a fraction 0–1 of
- /// the hinge's 180° — changed by a sweep from the current angle
- /// (`duration` seconds; default the per-direction hand-fold time, opening
- /// faster than closing; 0 an instant swap; `profile` `continuous` or
- /// `fade`). The older `hinge` names still work and set the pose at once.
+ /// the hinge's 180° — changed by a sweep from the current angle, which
+ /// SpringBoard's display tool service runs (`duration` seconds; default
+ /// the per-direction hand-fold time, opening faster than closing; 0 an
+ /// instant swap; `profile` `continuous` or `fade`, default SpringBoard's
+ /// own). The older `hinge` names still work and set the pose at once.
private static func setDevicePose(_ params: [String: Any]) throws -> [String: Any] {
func value(_ key: String, names: [String: Int], range: ClosedRange<Int>, default fallback: Int?) throws -> Int {
if let name = params[key] as? String {
@@ -228,7 +229,7 @@ extension GuestAPI {
var angle: Double?
var sweep = false
var durationMs = -1.0
- var profile = 0
+ var profile: String?
if let position = params["position"] {
let target: Double
switch position {
@@ -256,10 +257,8 @@ extension GuestAPI {
durationMs = seconds * 1000
}
if let name = params["profile"] as? String {
- switch name.lowercased() {
- case "continuous": profile = 0
- case "fade": profile = 1
- default:
+ profile = name.lowercased()
+ guard profile == "continuous" || profile == "fade" else {
throw GuestAPIError.invalidRequest("profile must be continuous or fade")
}
}
@@ -282,28 +281,53 @@ extension GuestAPI {
throw GuestAPIError.invalidRequest("the host controls have no upside-down orientation")
}
GuestFoldPose.cancelStartupRestore()
- defer { GuestFoldPose.finishExplicitRequest() }
- if !relayed {
- guard vp_device_pose_set(Int32(orientation), Int32(hinge), Int32(tabletop)) else {
+ var springBoardSwept = false
+ defer { GuestFoldPose.finishExplicitRequest(settledHinge: springBoardSwept ? Int32(hinge) : nil) }
+ let published: Bool
+ if relayed {
+ if let current = vp_hinge_get()["angle"] as? Double, hingeState(for: current) == 1, hingeState(for: angle!) != 1 {
+ // Opening a closed device wakes it; the hinge sensor's own wake
+ // flag does that on hardware, and the host controls cannot set
+ // it. SpringBoard's pose provider publishes a pose in motion only
+ // on display frames, so with the cover asleep the new angle would
+ // sit unpublished until the next wake. The screen is lit before
+ // the sweep starts.
+ GuestScreenUnlock.wakeDisplay()
+ }
+ // With the relay, the hinge is the pose.
+ published = sweep
+ ? vp_hinge_sweep(angle!, durationMs, profile == "fade" ? 1 : 0, Int32(orientation))
+ : vp_hinge_set(angle!, Int32(orientation))
+ guard published else {
+ throw GuestAPIError.operationFailed("The virtual hinge did not take the pose")
+ }
+ } else {
+ // A sweep is SpringBoard's own, as Apple's tooling runs it: the
+ // display tool service moves SpringBoard's hinge pose and swaps
+ // displays on the way, keeping the device orientation unless one
+ // was asked for, and replies once the swap is done. The override is
+ // then left alone: it reaches SpringBoard even under the sweep's
+ // test lock and stands for 0, 90 or 180 degrees only, so book (100)
+ // would slide back to 90 and start a transition toward the cover.
+ // SpringBoard applies the next override against its current pose,
+ // so a later one still lands. The virtual hinge takes the end
+ // angle. Without the service the virtual hinge sweeps and the
+ // override jumps, as before.
+ if sweep {
+ let profileOverride: Int32 = profile == "fade" ? 1 : profile == "continuous" ? 2 : 0
+ let seconds = durationMs < 0 ? -1 : durationMs / 1000
+ springBoardSwept = vp_display_swap(angle! / 180, seconds, params["orientation"] == nil ? 0 : Int32(orientation),
+ profileOverride, 10 + max(seconds, 0)) == 1
+ }
+ guard springBoardSwept || vp_device_pose_set(Int32(orientation), Int32(hinge), Int32(tabletop)) else {
throw GuestAPIError.operationFailed("SpringBoardServices has no device pose override on this guest")
}
- } else if let current = vp_hinge_get()["angle"] as? Double, hingeState(for: current) == 1, hingeState(for: angle!) != 1 {
- // Opening a closed device wakes it; the hinge sensor's own wake
- // flag does that on hardware, and the host controls cannot set
- // it. SpringBoard's pose provider publishes a pose in motion only
- // on display frames, so with the cover asleep the new angle would
- // sit unpublished until the next wake. The screen is lit before
- // the sweep starts.
- GuestScreenUnlock.wakeDisplay()
- }
- // With the override, the pose has landed and the hinge half is
- // published beside it; its absence (no virtual hinge service on this
- // guest) does not undo the pose. With the relay, the hinge is the pose.
- let published = sweep
- ? vp_hinge_sweep(angle!, durationMs, Int32(profile), Int32(orientation))
- : vp_hinge_set(angle!, Int32(orientation))
- if relayed, !published {
- throw GuestAPIError.operationFailed("The virtual hinge did not take the pose")
+ // The pose has landed; the hinge half is published beside it, and
+ // its absence (no virtual hinge service on this guest) does not
+ // undo the pose.
+ published = sweep && !springBoardSwept
+ ? vp_hinge_sweep(angle!, durationMs, profile == "fade" ? 1 : 0, 0)
+ : vp_hinge_set(angle!, 0)
}
var hingeHID = vp_hinge_get()
hingeHID["applied"] = published
@@ -314,7 +338,8 @@ extension GuestAPI {
if sweep {
reply["sweep"] = [
"duration_ms": durationMs,
- "profile": profile == 1 ? "fade" : "continuous",
+ "profile": profile ?? (springBoardSwept ? "springboard" : "continuous"),
+ "completed": springBoardSwept,
]
}
return reply
diff --git a/VPhoneDaemon/Daemon/GuestFoldPose.swift b/VPhoneDaemon/Daemon/GuestFoldPose.swift
index dce2af63..cb22aed4 100644
--- a/VPhoneDaemon/Daemon/GuestFoldPose.swift
+++ b/VPhoneDaemon/Daemon/GuestFoldPose.swift
@@ -41,19 +41,23 @@ enum GuestFoldPose {
/// Capture the actual final state, including a failed request's rollback.
/// Never retain the requested value as proof that SpringBoard applied it.
- static func finishExplicitRequest() {
+ /// The one exception is `settledHinge`, the hinge state of a fold
+ /// SpringBoard itself reported finished: the pose readback does not follow
+ /// SpringBoard's own sweeps (it kept reading open-flat after a sweep to
+ /// closed), so the hinge comes from the request there.
+ static func finishExplicitRequest(settledHinge: Int32? = nil) {
restoration.lock.withLock {
let actual = vp_device_pose_get()
- restoration.latestPose = poseValues(actual)
+ restoration.latestPose = poseValues(actual, hinge: settledHinge)
restoration.explicitRequest = false
restoration.generation &+= 1
}
}
- private static func poseValues(_ actual: [String: Any]) -> [Int32]? {
+ private static func poseValues(_ actual: [String: Any], hinge settled: Int32? = nil) -> [Int32]? {
guard actual["available"] as? Bool == true,
let orientation = actual["device_orientation"] as? Int32,
- let hinge = actual["hinge"] as? Int32,
+ let hinge = settled ?? actual["hinge"] as? Int32,
let tabletop = actual["tabletop"] as? Int32,
(1...4).contains(orientation), (1...4).contains(hinge)
else { return nil }
diff --git a/VPhoneDaemon/Native/Include/VphonedNative.h b/VPhoneDaemon/Native/Include/VphonedNative.h
index dafa5082..4e537401 100644
--- a/VPhoneDaemon/Native/Include/VphonedNative.h
+++ b/VPhoneDaemon/Native/Include/VphonedNative.h
@@ -125,6 +125,16 @@ bool vp_device_pose_set(int deviceOrientation, int hingeState, int tabletopPose)
/// hinge's host controls into CoreMotion and SpringBoard reads its pose from
/// there; otherwise only the test-automation pose override reaches it.
bool vp_core_motion_hinge(void);
+/// Fold a foldable guest through SpringBoard's display tool service: sweep
+/// its hinge pose to `position` (0 closed, 1 open flat) and swap displays on
+/// the way. `durationSeconds` < 0 is the per-direction default, 0 an instant
+/// swap; `deviceOrientation` 0 keeps the current one; `profileOverride` 0
+/// keeps SpringBoard's profile, 1 fade, 2 continuous. Returns 1 once
+/// SpringBoard reports the swap finished, 0 when no reply came within
+/// `timeoutSeconds` (an unentitled client is never answered), -1 when this
+/// guest has no such service.
+int vp_display_swap(double position, double durationSeconds, int deviceOrientation, int profileOverride,
+ double timeoutSeconds);
/// Ask launchd to shut the guest down and halt. Returns 0 once the request is
/// accepted, otherwise an errno value. Needs root.
diff --git a/VPhoneDaemon/Native/vphoned_pose.m b/VPhoneDaemon/Native/vphoned_pose.m
index f50d9801..6d4c2f7b 100644
--- a/VPhoneDaemon/Native/vphoned_pose.m
+++ b/VPhoneDaemon/Native/vphoned_pose.m
@@ -10,7 +10,13 @@
* from the hinge state. The server checks the client for
* com.apple.springboard.testautomation, which vphoned carries.
*
- * The class is resolved at run time, so a base without it reports false.
+ * A fold to a position goes through SpringBoardServices' display tool
+ * client instead, the service behind Apple's suiatool swap: SpringBoard
+ * sweeps its pose itself and swaps displays on the way, as on hardware. The
+ * server checks for com.apple.springboard.sbdisplay.service.
+ *
+ * The classes are resolved at run time, so a base without them reports
+ * false (or -1).
*/
#import "Include/VphonedNative.h"
@@ -50,6 +56,58 @@ bool vp_device_pose_set(int deviceOrientation, int hingeState, int tabletopPose)
return true;
}
+/// The settings `-[SBSDisplayToolService swapDisplayWithSettings:completion:]`
+/// takes (iOS 27.1), the swap Apple's Duo tooling runs. The client sends the
+/// duration (seconds, < 0 the per-direction default, 0 an instant swap),
+/// device orientation (0 the current one), profile override (0 none, 1 fade,
+/// 2 continuous), whether to reply only once the swap has finished, the
+/// target mode (1 an absolute hinge position) and that position (0 closed, 1
+/// open flat); the first and last fields stay on the client.
+typedef struct {
+ int64_t state;
+ double duration;
+ int64_t deviceOrientation;
+ int64_t profileOverride;
+ bool waitForCompletion;
+ int64_t targetMode;
+ double targetHingePosition;
+ double reserved;
+} VPDisplaySwapSettings;
+
+int vp_display_swap(double position, double durationSeconds, int deviceOrientation, int profileOverride,
+ double timeoutSeconds) {
+ static Class service;
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{
+ dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_NOW);
+ service = NSClassFromString(@"SBSDisplayToolService");
+ });
+ SEL selector = NSSelectorFromString(@"swapDisplayWithSettings:completion:");
+ Method method = class_getInstanceMethod(service, selector);
+ if (!method || strcmp(method_getTypeEncoding(method), "v88@0:8{?=qdqqBqdd}16@?80") != 0) return -1;
+ // SpringBoard sweeps its own hinge pose to the position, with the display
+ // swap, transition style and lock screen handling of a real fold, and
+ // ignores the hinge for 10 s so the sweep is not undone. The reply comes
+ // on a BoardServices queue; its block arguments are not objects (reading
+ // them as an NSError faults), so the block takes none.
+ VPDisplaySwapSettings settings = {
+ .duration = durationSeconds,
+ .deviceOrientation = deviceOrientation,
+ .profileOverride = profileOverride,
+ .waitForCompletion = true,
+ .targetMode = 1,
+ .targetHingePosition = position,
+ };
+ dispatch_semaphore_t replied = dispatch_semaphore_create(0);
+ id client = [service new];
+ ((void (*)(id, SEL, VPDisplaySwapSettings, void (^)(void)))objc_msgSend)(client, selector, settings, ^{
+ dispatch_semaphore_signal(replied);
+ });
+ long waited = dispatch_semaphore_wait(replied, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeoutSeconds * NSEC_PER_SEC)));
+ ((void (*)(id, SEL))objc_msgSend)(client, NSSelectorFromString(@"invalidate"));
+ return waited == 0 ? 1 : 0;
+}
+
NSDictionary<NSString *, id> *vp_device_pose_get(void) {
dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_NOW);
Class service = NSClassFromString(@"SBSTestAutomationService");
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlFold.swift b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlFold.swift
index 9e2015e7..9b2ba2b7 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlFold.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlFold.swift
@@ -21,13 +21,17 @@ extension VPhoneGuestControl {
let hinge = result.int("hinge"), 0 ... 4 ~= hinge
else { throw ControlError.protocolError("invalid fold posture reply") }
let hingeHID = result.object("hinge_hid")
- let sweepMilliseconds = result.object("sweep")?.double("duration_ms")
+ let sweep = result.object("sweep")
+ let sweepMilliseconds = sweep?.double("duration_ms")
// Publish for the viewer's fold chrome: the angle the guest settled
// on, and how long its sweep took so a window folds in step. The
// guest's own default sweep answers -1 (its per-direction hand-fold
// time, unknown here) — animate those over a similar beat; an
- // absent sweep dictionary is the legacy instant pose.
- foldSweepSeconds = sweepMilliseconds.map { $0 < 0 ? 1.2 : $0 / 1000 } ?? 0
+ // absent sweep dictionary is the legacy instant pose. A sweep
+ // SpringBoard ran answers only once it has finished, so the window
+ // is already behind it and settles at once.
+ let finished = sweep?.bool("completed") == true
+ foldSweepSeconds = finished ? 0 : sweepMilliseconds.map { $0 < 0 ? 1.2 : $0 / 1000 } ?? 0
foldPosition = position
foldAngle = angle
return VPhoneFoldReply(
diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
index 0a28649f..0153fb35 100644
--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m
@@ -98,12 +98,16 @@ static void vpSharedScanoutTransition(id self, SEL selector, long long state, id
}
// A fold moves the primary content to the other panel, which takes the
-// scanout over even when no power request comes with it.
-static IMP vpOriginalPerformContentModeTransition;
+// scanout over even when no power request comes with it. An instant or fading
+// transition has swapped the primary content by the time it is performed; an
+// interactive one (the continuous fold of a hinge sweep) swaps it as it
+// finishes, so the swap itself is followed too. SpringBoard keeps the panel it
+// left lit for 3 s after a swap, and without this the scanout went on showing
+// it (black) until then.
+static IMP vpOriginalPerformContentModeTransition, vpOriginalHandlePrimarySwap;
static int vpInnerOwnedPanel = -1;
-static void vpFollowContentModeTransition(id self, SEL selector, id transitionCoordinator) {
- ((void (*)(id, SEL, id))vpOriginalPerformContentModeTransition)(self, selector, transitionCoordinator);
+static void vpFollowPanelOwner(void) {
dispatch_async(dispatch_get_main_queue(), ^{
BOOL innerOwns = vpInnerOwnsPanel();
if (innerOwns == vpInnerOwnedPanel) return;
@@ -113,6 +117,16 @@ static void vpFollowContentModeTransition(id self, SEL selector, id transitionCo
});
}
+static void vpFollowContentModeTransition(id self, SEL selector, id transitionCoordinator) {
+ ((void (*)(id, SEL, id))vpOriginalPerformContentModeTransition)(self, selector, transitionCoordinator);
+ vpFollowPanelOwner();
+}
+
+static void vpFollowPrimarySwap(id self, SEL selector, id coordinator, id from, id to, id lockProvider) {
+ ((void (*)(id, SEL, id, id, id, id))vpOriginalHandlePrimarySwap)(self, selector, coordinator, from, to, lockProvider);
+ vpFollowPanelOwner();
+}
+
static void vpInstallContentModeOwnership(void) {
Method perform = class_getInstanceMethod(objc_getClass("SBDisplayContentModeCoordinator"),
sel_registerName("performDisplayContentModeTransitionWithCoordinator:"));
@@ -121,6 +135,14 @@ static void vpInstallContentModeOwnership(void) {
return;
}
vpOriginalPerformContentModeTransition = method_setImplementation(perform, (IMP)vpFollowContentModeTransition);
+ // SpringBoard (the application) observes every primary swap, once each.
+ Method swap = class_getInstanceMethod(objc_getClass("SpringBoard"), sel_registerName(
+ "displayContentModeCoordinator:handleSwapTransitionFromPrimaryWindowScene:toPrimaryWindowScene:withContinuationLockProvider:"));
+ if (!swap || strcmp(method_getTypeEncoding(swap), "v48@0:8@16@24@32@40") != 0) {
+ vpFoldDisplayLog(@"inner display: primary swap ABI unavailable");
+ return;
+ }
+ vpOriginalHandlePrimarySwap = method_setImplementation(swap, (IMP)vpFollowPrimarySwap);
}
void vpInstallSharedPanel(void) {