camera: Watch conduit client for phone-watch sync
- Commit
d41295a31bb4876c0b6668f098bc82f7343ab03e- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-04 19:45 UTC (1 day ago)
- Parents
77e2e1e
Convert both sides of the camera phone<->watch sync from the direct RFCOMM WearLinkNode to the Watch conduit client (WearLinkClientNode), following the migrated clock pair: phone platform/WearCameraSync and watch sync/WearLinkBridge register with conduit appId camera (the ConduitProtocol route key of the camera paths), state and thumbnail republish on conduit Connected, and NotInstalled/Unavailable leaves the sync idle with the watch at its honest no-phone state. Drop the Bluetooth permission request from MainActivity; the Watch app owns the conduit link. The wire protocol in library.wearlink.camera (golden-JSON pinned) is unchanged, and the watch camera remote never opens a local camera. Update camera/AGENTS.md wear sections to the conduit-client state. Verified green in the worktree: ./gradlew :camera:lint :camera:lintVitalRelease :camera:testDevUnitTest (BUILD SUCCESSFUL).
Diff
camera/AGENTS.md
diff --git a/camera/AGENTS.md b/camera/AGENTS.mdindex ff3196d296..f5559432bb 100644--- a/camera/AGENTS.md+++ b/camera/AGENTS.md@@ -24,8 +24,7 @@ _Install: ./install camera (dev by default)._ ## One APK, two form factors (phone + watch) This module is the single Camera APK for phones and watches: same-`applicationId = "com.vayunmathur.camera"` and signing on both, as the-WearLink handshake requires. The manifest deliberately declares no+`applicationId = "com.vayunmathur.camera"` and signing on both. The manifest deliberately declares no `android.hardware.type.watch` feature (required=true would block phones; required=false is disallowed for this feature), declares the camera feature not-required (a watch has no camera; the watch@@ -42,8 +41,14 @@ the phone-side `platform/WearCameraSync` starts only on the phone path, and the watch-side `sync/WearLinkBridge` is created only by `ui/WearMainActivity` (`exported=false`, no launcher filter). +## Wear sync (Watch conduit client)+**Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.camera.WearCameraProtocol`; the golden-JSON tests in this module pin the shared code's wire format.+- Mirrored state + thumbnail: conduit data items (`/camera/state`, `/camera/thumbnail`, phone -> watch)+- Control ops + live viewfinder: conduit messages (`/camera/op` watch -> phone, `/camera/preview-frame` phone -> watch)+- **Transport: Watch conduit client** — phone side `platform/WearCameraSync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `camera`); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so neither entry activity prompts for Bluetooth. With the Watch app absent the node reports `NotInstalled`/`Unavailable` and the sync stays idle; state + thumbnail republish on conduit `Connected`.+ ## Watch experience (in this module)-- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over viewfinder / controls / last capture; the watch has no camera of its own — with no phone nearby it says so, honestly. Mirrored truth is in-memory only in `data/WearCameraStore` (no offline copy: nothing is usable without the phone).+- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over viewfinder / controls / last capture; the watch camera remote never opens a local camera — with no phone nearby it says so, honestly. Mirrored truth is in-memory only in `data/WearCameraStore` (no offline copy: nothing is usable without the phone). - Wire protocol (`WearCameraProtocol`, WCF1 preview frames) lives in `:library:wearlink` at `com.vayunmathur.library.wearlink.camera`; this module's `WearCameraProtocolTest` pins the golden JSON/frame bytes (including the watch store's stale-frame rules). Live viewfinder frames travel as `/camera/preview-frame` messages (never the bounded STREAM primitive); phone drops frames latest-only, watch drops stale sequences and clears the live frame when the link drops or streaming stops — a frozen frame is never shown as live. - Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:camera:metadata` into `metadata_data/photos/camera/wear/`; phone/tablet shots keep their buckets. **Gotchas:**@@ -72,7 +77,7 @@ path, and the watch-side `sync/WearLinkBridge` is created only by - com/vayunmathur/camera/domain/MotionPhotoWriter.kt ### platform/ — capability queries - com/vayunmathur/camera/platform/CameraCapabilities.kt-- com/vayunmathur/camera/platform/WearCameraSync.kt — phone side of the wear companion; wire protocol `com.vayunmathur.library.wearlink.camera.WearCameraProtocol` (WCF1 frames) in `:library:wearlink`; this module's `WearCameraProtocolTest` pins the golden JSON/frame bytes+- com/vayunmathur/camera/platform/WearCameraSync.kt — phone conduit client node; mirrored state/thumbnail publish, op handling, preview streaming; wire protocol `com.vayunmathur.library.wearlink.camera.WearCameraProtocol` (WCF1 frames) in `:library:wearlink`; this module's `WearCameraProtocolTest` pins the golden JSON/frame bytes - com/vayunmathur/camera/platform/LensSelector.kt ### ui/ — single screen + settings + panes - com/vayunmathur/camera/ui/CameraScreen.kt
camera/build.gradle.kts
diff --git a/camera/build.gradle.kts b/camera/build.gradle.ktsindex 5ee83cdedf..df4d626ed7 100644--- a/camera/build.gradle.kts+++ b/camera/build.gradle.kts@@ -157,10 +157,10 @@ dependencies { implementation(project(":library:ml")) // Wear OS experience (live viewfinder + remote controls) lives in this // one APK: phone side platform/WearCameraSync, watch side- // sync/WearLinkBridge + ui/Wear*, same applicationId and signing as the- // WearLink handshake requires; FEATURE_WATCH (platform/FormFactor)- // picks the side at runtime. WearLink transport, RFCOMM with no Play- // services.+ // sync/WearLinkBridge + ui/Wear*, same applicationId and signing on+ // both form factors; FEATURE_WATCH (platform/FormFactor)+ // picks the side at runtime. Watch conduit client transport+ // (WearLinkClientNode) with no Play services. implementation(project(":library:wearlink")) // Watch experience (ui/Wear*): Wear Compose + the repo log facade the // watch sync code writes through.
camera/src/main/java/com/vayunmathur/camera/MainActivity.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/MainActivity.kt b/camera/src/main/java/com/vayunmathur/camera/MainActivity.ktindex c8144cecb8..33967247ce 100644--- a/camera/src/main/java/com/vayunmathur/camera/MainActivity.kt+++ b/camera/src/main/java/com/vayunmathur/camera/MainActivity.kt@@ -78,10 +78,10 @@ class MainActivity : MaActivity() { ) viewModel.enableCaptureForResult(outputUri) }- // Wear OS companion (live viewfinder + remote controls over- // WearLink): lifecycle-bound to this process, like the other wear- // pairs — nothing wakes a dead phone app for the watch.- com.vayunmathur.library.wearlink.WearLinkPermissions.requestIfNeeded(this)+ // Wear OS companion (live viewfinder + remote controls over the+ // Watch conduit client): lifecycle-bound to this process — nothing+ // wakes a dead phone app for the watch. No Bluetooth prompt here:+ // the Watch app owns the conduit link and its permission. val wearSync = com.vayunmathur.camera.platform.WearCameraSync.get(this) wearSync.viewModel = viewModel wearSync.start()
camera/src/main/java/com/vayunmathur/camera/platform/WearCameraSync.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/platform/WearCameraSync.kt b/camera/src/main/java/com/vayunmathur/camera/platform/WearCameraSync.ktindex dbb83651ad..be5379c3fe 100644--- a/camera/src/main/java/com/vayunmathur/camera/platform/WearCameraSync.kt+++ b/camera/src/main/java/com/vayunmathur/camera/platform/WearCameraSync.kt@@ -14,8 +14,9 @@ import com.vayunmathur.camera.domain.Yuv420ToArgb import com.vayunmathur.camera.domain.previewDimensions import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener-import com.vayunmathur.library.wearlink.WearLinkNode import com.vayunmathur.library.wearlink.WearLinkState+import com.vayunmathur.library.wearlink.conduit.ConduitProtocol+import com.vayunmathur.library.wearlink.conduit.WearLinkClientNode import com.vayunmathur.library.wearlink.camera.PreviewFrame import com.vayunmathur.library.wearlink.camera.WearCameraOp import com.vayunmathur.library.wearlink.camera.WearCameraProtocol@@ -154,10 +155,15 @@ private object BitmapPreviewEncoder : PreviewJpegEncoder { private class RawPreviewFrame(val argb: IntArray, val width: Int, val height: Int, val rotationDegrees: Int) /**- * Phone side of the Camera watch companion over WearLink (RFCOMM,- * :library:wearlink): mirrored state + last-capture thumbnail are data- * items, watch ops are messages executed through [ViewModelWearControls],- * and the live viewfinder streams analysis frames as preview messages.+ * Phone side of the Camera watch companion over the Watch conduit client+ * (:library:wearlink `WearLinkClientNode`: a Messenger binding to the+ * Watch app's conduit service, not an RFCOMM link this app owns):+ * mirrored state + last-capture thumbnail are data items, watch ops are+ * messages executed through [ViewModelWearControls], and the live+ * viewfinder streams analysis frames as preview messages. Presence is+ * the peer-link Connected state the conduit reports; with the Watch app+ * absent the node reports `NotInstalled`/`Unavailable` and the sync+ * stays idle, and the state + thumbnail republish on Connected. * * Viewfinder design point: frames come from the phone's existing Camera2 * analysis stream (small frames already), are converted and downscaled to@@ -239,7 +245,13 @@ class WearCameraSync private constructor(context: Context) { } } - private val node = WearLinkNode(appContext, WearCameraProtocol.CAPABILITY, listener)+ // Conduit appId = first path segment of the camera paths (the+ // ConduitProtocol route key), not the RFCOMM handshake capability.+ private val node = WearLinkClientNode(+ appContext,+ ConduitProtocol.routeKey(WearCameraProtocol.STATE_PATH),+ listener,+ ) private var started = false fun start() {
camera/src/main/java/com/vayunmathur/camera/sync/WearLinkBridge.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/sync/WearLinkBridge.kt b/camera/src/main/java/com/vayunmathur/camera/sync/WearLinkBridge.ktindex dbbb6de2d2..f71875e110 100644--- a/camera/src/main/java/com/vayunmathur/camera/sync/WearLinkBridge.kt+++ b/camera/src/main/java/com/vayunmathur/camera/sync/WearLinkBridge.kt@@ -4,8 +4,9 @@ import android.content.Context import com.vayunmathur.camera.data.WearCameraStore import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener-import com.vayunmathur.library.wearlink.WearLinkNode import com.vayunmathur.library.wearlink.WearLinkState+import com.vayunmathur.library.wearlink.conduit.ConduitProtocol+import com.vayunmathur.library.wearlink.conduit.WearLinkClientNode import com.vayunmathur.library.wearlink.camera.WearCameraOp import com.vayunmathur.library.wearlink.camera.WearCameraProtocol import com.vayunmathur.library.wearlink.camera.WearOpKind@@ -17,26 +18,31 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch /**- * Watch side of WearLink for Camera: mirrored state + thumbnail data items- * and preview-frame messages land in [WearCameraStore]; every watch control- * is one op message executed on the phone. App-lifecycle-bound like every- * WearLink pair — no Play-services listener, no background wakeups.+ * Watch side of the Watch conduit client for Camera: mirrored state ++ * thumbnail data items and preview-frame messages land in+ * [WearCameraStore]; every watch control is one op message executed on+ * the phone. Transport is `WearLinkClientNode` (Messenger to the Watch+ * app's conduit service); this app owns no RFCOMM link and the watch+ * camera remote never opens a local camera. With the Watch app absent+ * the node reports `NotInstalled`/`Unavailable` and the store stays at+ * its honest no-phone state. Delivery is bound to this process being+ * alive; there is no Play-services listener service. */ object WearLinkBridge { private const val TAG = "WearLinkBridge" private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO) @Volatile- private var node: WearLinkNode? = null+ private var node: WearLinkClientNode? = null - fun get(context: Context): WearLinkNode {+ fun get(context: Context): WearLinkClientNode { val appContext = context.applicationContext return node ?: synchronized(this) { node ?: create(appContext).also { node = it } } } - private fun create(context: Context): WearLinkNode {+ private fun create(context: Context): WearLinkClientNode { val store = WearCameraStore.get() val listener = object : WearLinkListener { override fun onData(path: String, body: ByteArray) {@@ -57,7 +63,13 @@ object WearLinkBridge { if (path == WearCameraProtocol.PREVIEW_FRAME_PATH) store.applyPreviewFrame(body) } }- val created = WearLinkNode(context, WearCameraProtocol.CAPABILITY, listener)+ // Conduit appId = first path segment of the camera paths (the+ // ConduitProtocol route key), not the RFCOMM handshake capability.+ val created = WearLinkClientNode(+ context,+ ConduitProtocol.routeKey(WearCameraProtocol.STATE_PATH),+ listener,+ ) scope.launch { created.state.collect { linkState -> store.setLinkConnected(linkState is WearLinkState.Connected)
camera/src/main/java/com/vayunmathur/camera/ui/WearMainActivity.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/WearMainActivity.kt b/camera/src/main/java/com/vayunmathur/camera/ui/WearMainActivity.ktindex 0e6f3af0a4..ab6843ee92 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/WearMainActivity.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/WearMainActivity.kt@@ -12,6 +12,10 @@ import com.vayunmathur.library.wearlink.WearShellActivity */ class WearMainActivity : WearShellActivity<WearRoute, WearCameraStore>(WearRoute.Viewfinder) { + // No Bluetooth prompt here: the Watch app owns the conduit link+ // and its permission. With the Watch app absent the bridge stays+ // NotInstalled/Unavailable and the remote shows its no-phone state;+ // the watch camera remote never opens a local camera. override fun createStore() = WearCameraStore.get().also { WearLinkBridge.get(this) } @Composable