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 }