From 0aab85555c4fcbaad0428b71a1fe347f4f4d09b5 Mon Sep 17 00:00:00 2001 From: gmegidish Date: Tue, 29 Sep 2026 12:44:20 +0200 Subject: [PATCH] fix: report the unfolded screen size in device.info on foldables --- DeviceKitTests/JSONRPC/Handlers/DeviceInfo.swift | 7 ++++--- DeviceKitTests/XCTest/OrientationGeometry.swift | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/DeviceKitTests/JSONRPC/Handlers/DeviceInfo.swift b/DeviceKitTests/JSONRPC/Handlers/DeviceInfo.swift index bcb9771..655306e 100644 --- a/DeviceKitTests/JSONRPC/Handlers/DeviceInfo.swift +++ b/DeviceKitTests/JSONRPC/Handlers/DeviceInfo.swift @@ -13,11 +13,12 @@ struct DeviceInfoMethodHandler: RPCMethodHandler { let start = Date() + // springboard reports the cover display's frame even when unfolded let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") - let frame = springboard.frame + let size = OrientationGeometry.secondaryDisplaySize() ?? springboard.frame.size let scale = Int(UIScreen.main.scale) - let width = Int(frame.width) - let height = Int(frame.height) + let width = Int(size.width) + let height = Int(size.height) let duration = Date().timeIntervalSince(start) logger.info("Device info took \(duration), screen: \(width)x\(height)@\(scale)x") diff --git a/DeviceKitTests/XCTest/OrientationGeometry.swift b/DeviceKitTests/XCTest/OrientationGeometry.swift index 88b15ef..35e1d7c 100644 --- a/DeviceKitTests/XCTest/OrientationGeometry.swift +++ b/DeviceKitTests/XCTest/OrientationGeometry.swift @@ -102,6 +102,20 @@ struct OrientationGeometry { return windows.first { $0.displayID != 0 && $0.displayID != mainDisplayID }?.displayID } + // portrait size of the unfolded inner display, nil when the app is on the + // main display. single-display devices skip the foreground app lookup + static func secondaryDisplaySize() -> CGSize? { + guard isMultiDisplay() else { + return nil + } + + let geometry = current() + guard geometry.displayID != nil else { + return nil + } + return CGSize(width: geometry.portraitWidth, height: geometry.portraitHeight) + } + private static func isMultiDisplay() -> Bool { XCUIScreen.screens.count > 1 }