camera-wear: a stopped stream clears the frozen frame instead of presenting it as live
- Commit
5fd4bb3925fe7ace7ea592a47fd94a2164c30756- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 10:36 UTC (5 days ago)
- Parents
5e4a993
The watch cleared its viewfinder frame only when the WearLink link dropped, never when the phone reported it had stopped streaming. Apply a frame (seq 7, 320x240, rot 90), then the phone exits the viewfinder and republishes state with previewStreaming=false every 250 ms — old applyState never read that signal (nor capturing) — and returning to the viewfinder drew the frozen JPEG as the live viewfinder, indefinitely when the phone-side stream could not restart. applyState now clears the live frame and rotation whenever the mirrored state says previewStreaming == false, sharing the link-down clearing path. The stale-sequence guard is deliberately not reset, so a replayed frame from the stopped stream cannot resurrect it, while the phone's monotonic sequence resumes cleanly (test: seq 7 replay dropped, seq 8 accepted with its own rotation). AGENTS.md documents the clearing. Protocol copies, rotation semantics, connection honesty and trigger/settings sync were audited and cleared. Verified: :camera-wear:testDebugUnitTest and lint BUILD SUCCESSFUL.
Diff
camera-wear/AGENTS.md
diff --git a/camera-wear/AGENTS.md b/camera-wear/AGENTS.mdindex ca2f9d0260..c210dcf8c0 100644--- a/camera-wear/AGENTS.md+++ b/camera-wear/AGENTS.md@@ -31,7 +31,10 @@ side's `WearCameraProtocolTest` pins the same golden JSON/frame bytes. SHA-256 committed up front, verified at close, resumable by file offset), which a live ephemeral frame sequence cannot satisfy. The extension lives behind the camera protocol seam; :library:wearlink is- unchanged. Phone drops frames latest-only; watch drops stale sequences.+ unchanged. Phone drops frames latest-only; watch drops stale sequences+ and clears the live frame (and its rotation) when the link drops or the+ mirrored state reports preview streaming stopped — a frozen frame is+ never shown as live. - Transport: :library:wearlink (RFCOMM, no Play services); app-lifecycle-bound ## Viewfinder design point
camera-wear/src/main/java/com/vayunmathur/camera/wear/data/WearCameraStore.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/data/WearCameraStore.kt b/camera-wear/src/main/java/com/vayunmathur/camera/wear/data/WearCameraStore.ktindex 6c001f7df9..a8b5afb239 100644--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/data/WearCameraStore.kt+++ b/camera-wear/src/main/java/com/vayunmathur/camera/wear/data/WearCameraStore.kt@@ -42,7 +42,7 @@ class WearCameraStore { if (!connected) { // Link down: no fake viewfinder. The last mirrored state stays // for context, but the live frame is gone.- _previewJpeg.value = null+ clearLivePreview() lastPreviewSequence = -1L } }@@ -50,6 +50,19 @@ class WearCameraStore { /** Applies a mirrored phone state (state mirroring is replace, never merge). */ fun applyState(state: WearCameraState) { _state.value = state+ if (!state.previewStreaming) {+ // The phone says it is not streaming: the last frame is stale,+ // not live, so it must not sit in the viewfinder. The sequence+ // guard is kept — a late frame from the stopped stream (or a+ // replay of the frame just cleared) must not resurrect it;+ // the phone's sequence only moves forward within a session.+ clearLivePreview()+ }+ }++ private fun clearLivePreview() {+ _previewJpeg.value = null+ _previewRotation.value = 0 } /** Applies one preview frame body; returns false when malformed or stale. */
camera-wear/src/test/java/com/vayunmathur/camera/wear/domain/WearCameraProtocolTest.kt
diff --git a/camera-wear/src/test/java/com/vayunmathur/camera/wear/domain/WearCameraProtocolTest.kt b/camera-wear/src/test/java/com/vayunmathur/camera/wear/domain/WearCameraProtocolTest.ktindex 0d854bdef1..f03692b9b5 100644--- a/camera-wear/src/test/java/com/vayunmathur/camera/wear/domain/WearCameraProtocolTest.kt+++ b/camera-wear/src/test/java/com/vayunmathur/camera/wear/domain/WearCameraProtocolTest.kt@@ -104,6 +104,38 @@ class WearCameraProtocolTest { assertTrue(byteArrayOf(5, 6).contentEquals(store.thumbnailJpeg.value!!)) } + @Test+ fun streamingStopClearsLiveFrameButKeepsMirroredStateAndSequenceGuard() {+ val store = WearCameraStore()+ store.setLinkConnected(true)+ store.applyState(WearCameraState(mode = "PHOTO", previewStreaming = true))+ val frame7 = PreviewFrame.encode(7L, 7L, 320, 240, 90, byteArrayOf(7))+ assertTrue(store.applyPreviewFrame(frame7))+ assertTrue(byteArrayOf(7).contentEquals(store.previewJpeg.value!!))+ assertEquals(90, store.previewRotation.value)++ // The phone reports it stopped streaming (e.g. the watch left the+ // viewfinder and PREVIEW_STOP landed): the frozen frame is stale,+ // not live, and must leave the viewfinder. Mirrored state stays.+ store.applyState(WearCameraState(mode = "PHOTO", previewStreaming = false))+ assertNull(store.previewJpeg.value)+ assertEquals(0, store.previewRotation.value)+ assertEquals("PHOTO", store.state.value.mode)++ // A late/replayed frame from the stopped stream must not resurrect+ // the cleared frame; only a newer sequence may.+ assertFalse(store.applyPreviewFrame(frame7))+ assertNull(store.previewJpeg.value)+ assertEquals(1L, store.droppedStaleFrames)++ // Streaming resumes: the next sequence is shown with its own rotation.+ store.applyState(WearCameraState(mode = "PHOTO", previewStreaming = true))+ val frame8 = PreviewFrame.encode(8L, 8L, 320, 240, 0, byteArrayOf(8))+ assertTrue(store.applyPreviewFrame(frame8))+ assertTrue(byteArrayOf(8).contentEquals(store.previewJpeg.value!!))+ assertEquals(0, store.previewRotation.value)+ }+ @Test fun linkDownClearsLiveFrameButKeepsMirroredState() { val store = WearCameraStore()