From 23981496f968237cc9d8129aeab5b98aed1f5184 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 16 Jan 2026 06:15:37 +0000 Subject: [PATCH] fix: resolve bridge warnings --- .../clawdbot/android/bridge/BridgeSession.kt | 40 +++++++++---------- apps/ios/Sources/Bridge/BridgeTLS.swift | 11 +++-- .../ios/Sources/Camera/CameraController.swift | 29 +++++++++----- .../Sources/Screen/ScreenRecordService.swift | 2 + 4 files changed, 47 insertions(+), 35 deletions(-) diff --git a/apps/android/app/src/main/java/com/clawdbot/android/bridge/BridgeSession.kt b/apps/android/app/src/main/java/com/clawdbot/android/bridge/BridgeSession.kt index 0a12c1eb3..768ec9128 100644 --- a/apps/android/app/src/main/java/com/clawdbot/android/bridge/BridgeSession.kt +++ b/apps/android/app/src/main/java/com/clawdbot/android/bridge/BridgeSession.kt @@ -212,7 +212,7 @@ class BridgeSession( connectWithSocket(endpoint, hello, null) } - private fun connectWithSocket(endpoint: BridgeEndpoint, hello: Hello, tls: BridgeTlsParams?) { + private suspend fun connectWithSocket(endpoint: BridgeEndpoint, hello: Hello, tls: BridgeTlsParams?) { val socket = createBridgeSocket(tls) { fingerprint -> onTlsFingerprint?.invoke(tls?.stableId ?: endpoint.stableId, fingerprint) @@ -260,15 +260,15 @@ class BridgeSession( else -> throw IllegalStateException("unexpected bridge response") } - while (scope.isActive) { - val line = reader.readLine() ?: break - val frame = json.parseToJsonElement(line).asObjectOrNull() ?: continue - when (frame["type"].asStringOrNull()) { - "event" -> { - val event = frame["event"].asStringOrNull() ?: return@withContext - val payload = frame["payloadJSON"].asStringOrNull() - onEvent(event, payload) - } + while (scope.isActive) { + val line = reader.readLine() ?: break + val frame = json.parseToJsonElement(line).asObjectOrNull() ?: continue + when (frame["type"].asStringOrNull()) { + "event" -> { + val event = frame["event"].asStringOrNull() ?: continue + val payload = frame["payloadJSON"].asStringOrNull() + onEvent(event, payload) + } "ping" -> { val id = frame["id"].asStringOrNull() ?: "" conn.sendJson(buildJsonObject { put("type", JsonPrimitive("pong")); put("id", JsonPrimitive(id)) }) @@ -314,20 +314,20 @@ class BridgeSession( }, ) } - "invoke-res" -> { - // gateway->node only (ignore) - } + "invoke-res" -> { + // gateway->node only (ignore) } } - } finally { - currentConnection = null - for ((_, waiter) in pending) { - waiter.cancel() - } - pending.clear() - conn.closeQuietly() } + } finally { + currentConnection = null + for ((_, waiter) in pending) { + waiter.cancel() + } + pending.clear() + conn.closeQuietly() } + } private fun buildHelloJson(hello: Hello): JsonObject = buildJsonObject { diff --git a/apps/ios/Sources/Bridge/BridgeTLS.swift b/apps/ios/Sources/Bridge/BridgeTLS.swift index a7f2223e9..5ede00d3f 100644 --- a/apps/ios/Sources/Bridge/BridgeTLS.swift +++ b/apps/ios/Sources/Bridge/BridgeTLS.swift @@ -32,11 +32,10 @@ func makeBridgeTLSOptions(_ params: BridgeTLSParams?) -> NWProtocolTLS.Options? sec_protocol_options_set_verify_block( options.securityProtocolOptions, { _, trust, complete in - guard let trust else { - complete(false) - return - } - if let cert = SecTrustGetCertificateAtIndex(trust, 0) { + let trustRef = sec_trust_copy_ref(trust).takeRetainedValue() + if let chain = SecTrustCopyCertificateChain(trustRef) as? [SecCertificate], + let cert = chain.first + { let data = SecCertificateCopyData(cert) as Data let fingerprint = sha256Hex(data) if let expected { @@ -49,7 +48,7 @@ func makeBridgeTLSOptions(_ params: BridgeTLSParams?) -> NWProtocolTLS.Options? return } } - let ok = SecTrustEvaluateWithError(trust, nil) + let ok = SecTrustEvaluateWithError(trustRef, nil) complete(ok) }, DispatchQueue(label: "com.clawdbot.bridge.tls.verify")) diff --git a/apps/ios/Sources/Camera/CameraController.swift b/apps/ios/Sources/Camera/CameraController.swift index ee0f44529..e2ea47e05 100644 --- a/apps/ios/Sources/Camera/CameraController.swift +++ b/apps/ios/Sources/Camera/CameraController.swift @@ -190,14 +190,7 @@ actor CameraController { } func listDevices() -> [CameraDeviceInfo] { - let types: [AVCaptureDevice.DeviceType] = [ - .builtInWideAngleCamera, - ] - let session = AVCaptureDevice.DiscoverySession( - deviceTypes: types, - mediaType: .video, - position: .unspecified) - return session.devices.map { device in + return Self.discoverVideoDevices().map { device in CameraDeviceInfo( id: device.uniqueID, name: device.localizedName, @@ -232,7 +225,7 @@ actor CameraController { deviceId: String?) -> AVCaptureDevice? { if let deviceId, !deviceId.isEmpty { - if let match = AVCaptureDevice.devices(for: .video).first(where: { $0.uniqueID == deviceId }) { + if let match = Self.discoverVideoDevices().first(where: { $0.uniqueID == deviceId }) { return match } } @@ -252,6 +245,24 @@ actor CameraController { } } + private nonisolated static func discoverVideoDevices() -> [AVCaptureDevice] { + let types: [AVCaptureDevice.DeviceType] = [ + .builtInWideAngleCamera, + .builtInUltraWideCamera, + .builtInTelephotoCamera, + .builtInDualCamera, + .builtInDualWideCamera, + .builtInTripleCamera, + .builtInTrueDepthCamera, + .builtInLiDARDepthCamera, + ] + let session = AVCaptureDevice.DiscoverySession( + deviceTypes: types, + mediaType: .video, + position: .unspecified) + return session.devices + } + nonisolated static func clampQuality(_ quality: Double?) -> Double { let q = quality ?? 0.9 return min(1.0, max(0.05, q)) diff --git a/apps/ios/Sources/Screen/ScreenRecordService.swift b/apps/ios/Sources/Screen/ScreenRecordService.swift index 33880ec0a..e31762e51 100644 --- a/apps/ios/Sources/Screen/ScreenRecordService.swift +++ b/apps/ios/Sources/Screen/ScreenRecordService.swift @@ -137,9 +137,11 @@ final class ScreenRecordService: @unchecked Sendable { recordQueue: DispatchQueue) -> @Sendable (CMSampleBuffer, RPSampleBufferType, Error?) -> Void { { sample, type, error in + let sampleBox = UncheckedSendableBox(value: sample) // ReplayKit can call the capture handler on a background queue. // Serialize writes to avoid queue asserts. recordQueue.async { + let sample = sampleBox.value if let error { state.withLock { state in if state.handlerError == nil { state.handlerError = error }