wearlink: add phoneOpen state and OPEN_ON_PHONE op to camera protocol
- Commit
21c486094405018d1ab5e401f762d563bf3e3023- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-05 14:21 UTC (23 hours ago)
- Parents
190cdc3
The watch camera experience now gates on whether the phone Camera app is open. WearCameraState gains phoneOpen (appended, defaults false so state from an older phone decodes as closed), and WearOpKind gains OPEN_ON_PHONE for the watch-to-phone handoff. planWearCameraOp applies it unconditionally; the phone decides whether it actually launches from its live phoneOpen flag. Verified: :library:wearlink:testDebugUnitTest and the camera golden-JSON tests pinning the new wire form.
Diff
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/camera/WearCameraProtocol.kt
diff --git a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/camera/WearCameraProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/camera/WearCameraProtocol.ktindex 981bb6a414..c3720be8e3 100644--- a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/camera/WearCameraProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/camera/WearCameraProtocol.kt@@ -109,6 +109,15 @@ data class WearCameraState( val lastCaptureAtMillis: Long = 0L, /** "PHOTO" or "VIDEO" for the last capture, empty when none. */ val lastCaptureKind: String = "",+ /**+ * True while the phone Camera app is open (its MainActivity exists).+ * The watch shows its single "Open in phone" button whenever this is+ * false, and the viewfinder + capture button only while it is true.+ * Defaults false so state published by an older phone (or the+ * conduit's replay of a dead phone's last item) never fakes an open+ * camera the watch could stream from.+ */+ val phoneOpen: Boolean = false, ) /** Kind of a watch-originated camera control. */@@ -125,6 +134,9 @@ enum class WearOpKind { SET_TIMER, PREVIEW_START, PREVIEW_STOP,++ /** Ask the phone to open its Camera app (conduit handoff from the watch's "Open in phone" button). */+ OPEN_ON_PHONE, } /** One watch-originated control, as [WearCameraProtocol.OP_PATH]. Unused fields keep defaults. */@@ -155,7 +167,9 @@ sealed interface WearOpDecision { * an unsafe op — the mirrored state corrects the watch on the next publish. */ fun planWearCameraOp(op: WearCameraOp, state: WearCameraState): WearOpDecision = when (op.kind) {- WearOpKind.SHUTTER, WearOpKind.RECORD_TOGGLE, WearOpKind.PREVIEW_START, WearOpKind.PREVIEW_STOP ->+ WearOpKind.SHUTTER, WearOpKind.RECORD_TOGGLE, WearOpKind.PREVIEW_START, WearOpKind.PREVIEW_STOP,+ WearOpKind.OPEN_ON_PHONE,+ -> WearOpDecision.Apply WearOpKind.SET_TORCH -> WearOpDecision.Apply WearOpKind.SET_MODE -> when {