Modern Apps git

← Modern-Apps.git

library: todo, communicate and camera wear protocols move into wearlink

Commit
61a68e07dcb0f4a6f41df693b915a2d6a851b8d0
Author
Vayun Mathur <[email protected]>
When
2026-12-01 17:53 UTC (4 days ago)
Parents
f207b5d
LOC Phase 2 finale — the duplicated-pair registry is now
empty (structure_check wear: 0 pairs, OK). Todo (328,
drift fixed in 6d1c80260) and communicate (421) verified
byte-identical modulo package and moved as-is. Camera
(299, WCF1 frames): test divergence reconciled BEFORE
migrating, from the protocol code — wear's laxer preview
header assertions unified to the phone's stricter ones,
malformed-input coverage unified to the phone's suite
(bad op bytes, truncated frame, zero-width frame), three
phone-only tests ported to wear; the three genuinely
wear-only WearCameraStore tests stayed. No correct
assertion was weakened.

All moved to com.vayunmathur.library.wearlink.{todo,
communicate,camera} under the same symbol names, both
copies deleted, consumers rewired (zero old-FQN protocol
hits afterwards). Net: todo -331, communicate -385,
camera -201. Phase 2 wear programme total: 13 pairs
unified. Verified: final combined run — wearlink, all
wear suites, all phone protocol classes, all compiles and
assembles — BUILD SUCCESSFUL.

Diff

camera-wear/AGENTS.md
diff --git a/camera-wear/AGENTS.md b/camera-wear/AGENTS.mdindex c210dcf8c0..9396e6456f 100644--- a/camera-wear/AGENTS.md+++ b/camera-wear/AGENTS.md@@ -19,9 +19,11 @@ ADB sideload of this APK onto the watch. The watch has no camera here — with no phone nearby the app says so; it never fakes a local camera.  ## Protocol-`domain/WearCameraProtocol.kt` is a copy of the phone's file (Gradle-cannot depend on another app module). Change both copies together; each-side's `WearCameraProtocolTest` pins the same golden JSON/frame bytes.+The wire protocol (`WearCameraProtocol`, WCF1 preview frames) lives in+`:library:wearlink` at `com.vayunmathur.library.wearlink.camera` (shared+by `:camera` and `:camera-wear`; neither app module depends on the+other). Each side's `WearCameraProtocolTest` pins the same golden+JSON/frame bytes against that shared code.  - Mirrored state + last-capture thumbnail: WearLink data items   (`/camera/state`, `/camera/thumbnail` JPEG)
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 a8b5afb239..d9b52d5f58 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@@ -1,7 +1,7 @@ package com.vayunmathur.camera.wear.data -import com.vayunmathur.camera.wear.domain.PreviewFrame-import com.vayunmathur.camera.wear.domain.WearCameraState+import com.vayunmathur.library.wearlink.camera.PreviewFrame+import com.vayunmathur.library.wearlink.camera.WearCameraState import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow
camera-wear/src/main/java/com/vayunmathur/camera/wear/domain/WearCameraProtocol.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/domain/WearCameraProtocol.kt b/camera-wear/src/main/java/com/vayunmathur/camera/wear/domain/WearCameraProtocol.ktdeleted file mode 100644index c9eb9c49fb..0000000000--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/domain/WearCameraProtocol.kt+++ /dev/null@@ -1,299 +0,0 @@-package com.vayunmathur.camera.wear.domain--import kotlinx.serialization.Serializable-import kotlinx.serialization.encodeToString-import kotlinx.serialization.json.Json--/**- * Phone <-> watch protocol for the Wear OS Camera companion.- *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module (`:camera-wear`,- * applicationId `com.vayunmathur.camera`) carries a copy of this file under- * `com.vayunmathur.camera.wear.domain`. Change both copies together; each- * side's unit tests pin the same golden JSON/frame bytes so a one-sided- * edit fails loudly.- *- * Transport (WearLink, :library:wearlink — RFCOMM, no Play services):- * - Presence is a completed handshake for [CAPABILITY] (the appId).- * - Data items: [STATE_PATH] phone -> watch (mirrored camera state) and- *   [THUMBNAIL_PATH] phone -> watch (last-capture JPEG bytes; the media- *   itself stays on the phone).- * - Messages: [OP_PATH] watch -> phone (one control op), and- *   [PREVIEW_FRAME_PATH] phone -> watch (one live viewfinder frame).- *   Delivery needs a live session; nothing wakes a dead phone process.- *- * Live viewfinder transport choice — stated, not implied: WearLink's- * STREAM primitive is a file transfer (the header commits total size +- * SHA-256 up front, the receiver verifies the whole stream at close, and- * STREAM_ACK resume replays a durable file offset). A live preview is an- * unbounded sequence of ephemeral frames whose total size is unknowable- * and whose stale frames are worthless, so STREAM cannot carry it without- * breaking WearLink's contract. The extension therefore lives behind this- * camera protocol seam, leaving :library:wearlink untouched: each frame- * is one fire-and-forget MESSAGE (JPEG well under the 256 KiB message- * cap), the phone keeps only the latest frame, and the watch keeps only- * the newest sequence. Frames are never queued, resumed or verified.- */-object WearCameraProtocol {-    /** WearLink appId the phone requires in the peer handshake. */-    const val CAPABILITY = "camera_wear_companion"--    /** Data-item path (phone -> watch): the [WearCameraState] JSON. */-    const val STATE_PATH = "/camera/state"--    /** Data-item path (phone -> watch): last-capture thumbnail JPEG bytes. */-    const val THUMBNAIL_PATH = "/camera/thumbnail"--    /** Message path (watch -> phone): one [WearCameraOp] JSON. */-    const val OP_PATH = "/camera/op"--    /** Message path (phone -> watch): one binary preview frame (see [PreviewFrame]). */-    const val PREVIEW_FRAME_PATH = "/camera/preview-frame"--    /** Widest preview/thumbnail frame the watch is ever sent, in pixels. */-    const val PREVIEW_MAX_WIDTH = 320--    /** Nominal preview rate; the phone adapts inside [MIN_FPS]..[MAX_FPS]. */-    const val PREVIEW_NOMINAL_FPS = 5-    const val PREVIEW_MIN_FPS = 2-    const val PREVIEW_MAX_FPS = 8--    /** JPEG quality bounds for the adaptive preview/thumbnail encoder. */-    const val PREVIEW_JPEG_QUALITY = 60-    const val PREVIEW_MIN_JPEG_QUALITY = 40-    const val PREVIEW_MAX_JPEG_QUALITY = 75--    /** Encoded preview frames larger than this lower the next quality step. */-    const val PREVIEW_LARGE_FRAME_BYTES = 24_000--    /**-     * Modes the watch may switch to remotely. PANORAMA/PHOTOSPHERE are-     * excluded: both need an on-phone guided sweep. SLOW_MO is included —-     * the phone's mode switch itself enforces its back-lens rule.-     */-    val REMOTE_MODES = listOf("PHOTO", "VIDEO", "PORTRAIT", "TIMELAPSE", "CINEMATIC", "SLOW_MO")--    /** Modes whose shutter action records video rather than a still. */-    val VIDEO_MODES = setOf("VIDEO", "TIMELAPSE", "CINEMATIC", "SLOW_MO")--    /** Shutter-timer options (seconds) the watch may set; 0 is off. */-    val TIMER_OPTIONS_SECONDS = listOf(0, 1, 3, 5, 10)--    /** Wire JSON: unknown keys ignored so a newer side never breaks an older one. */-    val json: Json = Json { ignoreUnknownKeys = true }-}--/** Mirrored phone-camera state, published at [WearCameraProtocol.STATE_PATH]. */-@Serializable-data class WearCameraState(-    /** Phone mode name (CameraMode.name), including non-remote modes. */-    val mode: String = "PHOTO",-    /** Modes the watch may switch to (see [WearCameraProtocol.REMOTE_MODES]). */-    val remoteModes: List<String> = WearCameraProtocol.REMOTE_MODES,-    val frontLens: Boolean = false,-    val zoomRatio: Float = 1f,-    /** Selectable zoom preset ratios, ascending (the phone's zoom-bar levels). */-    val zoomPresets: List<Float> = listOf(1f),-    val zoomMin: Float = 1f,-    val zoomMax: Float = 1f,-    /** FlashMode.name: ON, OFF or AUTO. */-    val flash: String = "OFF",-    val hasFlashUnit: Boolean = true,-    val torch: Boolean = false,-    val timerSeconds: Int = 0,-    val timerCountdown: Int = 0,-    val recording: Boolean = false,-    val recordingSeconds: Long = 0L,-    val capturing: Boolean = false,-    /** True while the phone is streaming preview frames to the watch. */-    val previewStreaming: Boolean = false,-    /** Epoch millis of the last landed capture, 0 when none this session. */-    val lastCaptureAtMillis: Long = 0L,-    /** "PHOTO" or "VIDEO" for the last capture, empty when none. */-    val lastCaptureKind: String = "",-)--/** Kind of a watch-originated camera control. */-@Serializable-enum class WearOpKind {-    SHUTTER,-    RECORD_TOGGLE,-    SET_MODE,-    SET_ZOOM,-    ZOOM_PRESET,-    SET_FLASH,-    SET_TORCH,-    FLIP_LENS,-    SET_TIMER,-    PREVIEW_START,-    PREVIEW_STOP,-}--/** One watch-originated control, as [WearCameraProtocol.OP_PATH]. Unused fields keep defaults. */-@Serializable-data class WearCameraOp(-    val kind: WearOpKind,-    val mode: String = "",-    val zoomRatio: Float = 1f,-    val zoomPresetIndex: Int = -1,-    val flash: String = "",-    val torch: Boolean = false,-    val timerSeconds: Int = 0,-)--/** Whether a planned op may run against the mirrored state, and why not when it may not. */-sealed interface WearOpDecision {-    data object Apply : WearOpDecision-    data class Reject(val reason: String) : WearOpDecision-}--/**- * Pure op gate, shared by the phone (authoritative, against live state)- * and testable without a camera: mode/lens/zoom changes rebind the phone- * session, so they are refused while recording (the phone's own mode/lens- * actions gate the same way); unknown modes/flash values and out-of-set- * timers are refused rather than guessed at. The phone re-checks against- * its live ViewModel after planning, so a stale watch state never forces- * 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 ->-        WearOpDecision.Apply-    WearOpKind.SET_TORCH -> WearOpDecision.Apply-    WearOpKind.SET_MODE -> when {-        op.mode !in WearCameraProtocol.REMOTE_MODES -> WearOpDecision.Reject("mode not remote-switchable")-        state.recording && op.mode != state.mode -> WearOpDecision.Reject("recording in progress")-        else -> WearOpDecision.Apply-    }-    WearOpKind.FLIP_LENS -> when {-        state.recording -> WearOpDecision.Reject("recording in progress")-        state.mode == "SLOW_MO" -> WearOpDecision.Reject("slo-mo is back-lens only")-        else -> WearOpDecision.Apply-    }-    WearOpKind.SET_ZOOM, WearOpKind.ZOOM_PRESET ->-        if (state.mode == "PANORAMA" || state.mode == "PHOTOSPHERE") {-            WearOpDecision.Reject("zoom locked in this mode")-        } else {-            WearOpDecision.Apply-        }-    WearOpKind.SET_FLASH ->-        if (op.flash in setOf("ON", "OFF", "AUTO")) WearOpDecision.Apply-        else WearOpDecision.Reject("unknown flash mode")-    WearOpKind.SET_TIMER ->-        if (op.timerSeconds in WearCameraProtocol.TIMER_OPTIONS_SECONDS) WearOpDecision.Apply-        else WearOpDecision.Reject("unsupported timer")-}--/** Clamps a requested zoom ratio into the mirrored range; non-finite requests become the current ratio. */-fun clampWearZoom(requested: Float, state: WearCameraState): Float =-    if (!requested.isFinite()) state.zoomRatio-    else requested.coerceIn(state.zoomMin, state.zoomMax)--/** The preset ratio for [index], or null when the index is stale (presets changed under it). */-fun wearZoomPreset(state: WearCameraState, index: Int): Float? = state.zoomPresets.getOrNull(index)--/**- * One live viewfinder frame on [WearCameraProtocol.PREVIEW_FRAME_PATH]:- * a fixed 20-byte header (`WCF1`, sequence, timestamp, size, rotation)- * followed by the JPEG bytes. The sequence lets the watch drop stale- * frames; nothing is ever retransmitted.- */-object PreviewFrame {-    const val HEADER_BYTES = 20-    private val MAGIC = byteArrayOf('W'.code.toByte(), 'C'.code.toByte(), 'F'.code.toByte(), '1'.code.toByte())--    fun encode(sequence: Long, timestampMillis: Long, width: Int, height: Int, rotationDegrees: Int, jpeg: ByteArray): ByteArray {-        val out = ByteArray(HEADER_BYTES + jpeg.size)-        MAGIC.copyInto(out)-        writeInt(out, 4, (sequence and 0xFFFF_FFFFL).toInt())-        writeInt(out, 8, (timestampMillis and 0xFFFF_FFFFL).toInt())-        writeShort(out, 12, width)-        writeShort(out, 14, height)-        writeShort(out, 16, rotationDegrees)-        writeShort(out, 18, 0)-        jpeg.copyInto(out, HEADER_BYTES)-        return out-    }--    /** Decoded header plus the JPEG slice; null on any malformed input. */-    fun decode(body: ByteArray): Decoded? {-        if (body.size <= HEADER_BYTES) return null-        if (!MAGIC.indices.all { body[it] == MAGIC[it] }) return null-        val width = readShort(body, 12)-        val height = readShort(body, 14)-        if (width <= 0 || height <= 0) return null-        return Decoded(-            sequence = readInt(body, 4).toLong() and 0xFFFF_FFFFL,-            timestampMillis = readInt(body, 8).toLong() and 0xFFFF_FFFFL,-            width = width,-            height = height,-            rotationDegrees = readShort(body, 16),-            jpeg = body.copyOfRange(HEADER_BYTES, body.size),-        )-    }--    data class Decoded(-        val sequence: Long,-        val timestampMillis: Long,-        val width: Int,-        val height: Int,-        val rotationDegrees: Int,-        val jpeg: ByteArray,-    ) {-        override fun equals(other: Any?): Boolean {-            if (this === other) return true-            if (other !is Decoded) return false-            return sequence == other.sequence && timestampMillis == other.timestampMillis &&-                width == other.width && height == other.height &&-                rotationDegrees == other.rotationDegrees && jpeg.contentEquals(other.jpeg)-        }--        override fun hashCode(): Int {-            var r = sequence.hashCode()-            r = 31 * r + timestampMillis.hashCode()-            r = 31 * r + width-            r = 31 * r + height-            r = 31 * r + rotationDegrees-            r = 31 * r + jpeg.contentHashCode()-            return r-        }-    }--    private fun writeInt(out: ByteArray, offset: Int, value: Int) {-        out[offset] = (value ushr 24).toByte()-        out[offset + 1] = (value ushr 16).toByte()-        out[offset + 2] = (value ushr 8).toByte()-        out[offset + 3] = value.toByte()-    }--    private fun readInt(body: ByteArray, offset: Int): Int =-        ((body[offset].toInt() and 0xFF) shl 24) or ((body[offset + 1].toInt() and 0xFF) shl 16) or-            ((body[offset + 2].toInt() and 0xFF) shl 8) or (body[offset + 3].toInt() and 0xFF)--    private fun writeShort(out: ByteArray, offset: Int, value: Int) {-        out[offset] = (value ushr 8).toByte()-        out[offset + 1] = value.toByte()-    }--    private fun readShort(body: ByteArray, offset: Int): Int =-        ((body[offset].toInt() and 0xFF) shl 8) or (body[offset + 1].toInt() and 0xFF)-}--/** Serialises [state] for the state data item (the golden-pinned wire form). */-fun encodeWearCameraState(state: WearCameraState): ByteArray =-    WearCameraProtocol.json.encodeToString(state).encodeToByteArray()--/** Parses a state data item; null when malformed (the watch keeps its last state). */-fun decodeWearCameraState(body: ByteArray): WearCameraState? = runCatching {-    WearCameraProtocol.json.decodeFromString<WearCameraState>(body.decodeToString())-}.getOrNull()--/** Serialises [op] for the op message (the golden-pinned wire form). */-fun encodeWearCameraOp(op: WearCameraOp): ByteArray =-    WearCameraProtocol.json.encodeToString(op).encodeToByteArray()--/** Parses an op message; null when malformed (the phone ignores it). */-fun decodeWearCameraOp(body: ByteArray): WearCameraOp? = runCatching {-    WearCameraProtocol.json.decodeFromString<WearCameraOp>(body.decodeToString())-}.getOrNull()
camera-wear/src/main/java/com/vayunmathur/camera/wear/sync/WearLinkBridge.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/sync/WearLinkBridge.kt b/camera-wear/src/main/java/com/vayunmathur/camera/wear/sync/WearLinkBridge.ktindex 4548a81417..bcaeac7713 100644--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/sync/WearLinkBridge.kt+++ b/camera-wear/src/main/java/com/vayunmathur/camera/wear/sync/WearLinkBridge.kt@@ -2,15 +2,15 @@ package com.vayunmathur.camera.wear.sync  import android.content.Context import com.vayunmathur.camera.wear.data.WearCameraStore-import com.vayunmathur.camera.wear.domain.WearCameraOp-import com.vayunmathur.camera.wear.domain.WearCameraProtocol-import com.vayunmathur.camera.wear.domain.WearOpKind-import com.vayunmathur.camera.wear.domain.decodeWearCameraState-import com.vayunmathur.camera.wear.domain.encodeWearCameraOp 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.camera.WearCameraOp+import com.vayunmathur.library.wearlink.camera.WearCameraProtocol+import com.vayunmathur.library.wearlink.camera.WearOpKind+import com.vayunmathur.library.wearlink.camera.decodeWearCameraState+import com.vayunmathur.library.wearlink.camera.encodeWearCameraOp import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob
camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearControlsScreen.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearControlsScreen.kt b/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearControlsScreen.ktindex 26b25e9170..07ad6ee42d 100644--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearControlsScreen.kt+++ b/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearControlsScreen.kt@@ -19,10 +19,10 @@ import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text import com.vayunmathur.camera.wear.R import com.vayunmathur.camera.wear.data.WearCameraStore-import com.vayunmathur.camera.wear.domain.WearCameraOp-import com.vayunmathur.camera.wear.domain.WearCameraProtocol-import com.vayunmathur.camera.wear.domain.WearOpKind import com.vayunmathur.camera.wear.sync.WearLinkBridge+import com.vayunmathur.library.wearlink.camera.WearCameraOp+import com.vayunmathur.library.wearlink.camera.WearCameraProtocol+import com.vayunmathur.library.wearlink.camera.WearOpKind  /**  * Remote controls executed on the phone: zoom presets, a zoom scrub@@ -42,7 +42,7 @@ fun WearControlsScreen(store: WearCameraStore, onBack: () -> Unit) {  /** Stateless controls behind [WearControlsScreen]: mirrored state/op sink are parameters for previews. */ @Composable-internal fun WearControlsContent(state: com.vayunmathur.camera.wear.domain.WearCameraState, onOp: (WearCameraOp) -> Unit, onBack: () -> Unit) {+internal fun WearControlsContent(state: com.vayunmathur.library.wearlink.camera.WearCameraState, onOp: (WearCameraOp) -> Unit, onBack: () -> Unit) {     val listState = rememberScalingLazyListState()     fun send(op: WearCameraOp) = onOp(op) 
camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearViewfinderScreen.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearViewfinderScreen.kt b/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearViewfinderScreen.ktindex 1827888d77..baea65734c 100644--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearViewfinderScreen.kt+++ b/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearViewfinderScreen.kt@@ -2,6 +2,7 @@ package com.vayunmathur.camera.wear.ui  import android.graphics.BitmapFactory import androidx.compose.foundation.Image+import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize@@ -23,17 +24,16 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp-import androidx.compose.foundation.layout.Arrangement import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text import com.vayunmathur.camera.wear.R import com.vayunmathur.camera.wear.data.WearCameraStore-import com.vayunmathur.camera.wear.domain.WearCameraOp-import com.vayunmathur.camera.wear.domain.WearCameraProtocol-import com.vayunmathur.camera.wear.domain.WearOpKind import com.vayunmathur.camera.wear.sync.WearLinkBridge+import com.vayunmathur.library.wearlink.camera.WearCameraOp+import com.vayunmathur.library.wearlink.camera.WearCameraProtocol+import com.vayunmathur.library.wearlink.camera.WearOpKind  /**  * The live viewfinder: newest preview frame from the phone camera, the@@ -71,7 +71,7 @@ fun WearViewfinderScreen( @Composable internal fun WearViewfinderContent(     connected: Boolean,-    state: com.vayunmathur.camera.wear.domain.WearCameraState,+    state: com.vayunmathur.library.wearlink.camera.WearCameraState,     bitmap: android.graphics.Bitmap?,     rotation: Int,     onOp: (WearCameraOp) -> Unit,
camera-wear/src/screenshotTest/kotlin/com/vayunmathur/camera/wear/ui/MetadataPreviews.kt
diff --git a/camera-wear/src/screenshotTest/kotlin/com/vayunmathur/camera/wear/ui/MetadataPreviews.kt b/camera-wear/src/screenshotTest/kotlin/com/vayunmathur/camera/wear/ui/MetadataPreviews.ktindex 9af4713c68..0c74d4bd76 100644--- a/camera-wear/src/screenshotTest/kotlin/com/vayunmathur/camera/wear/ui/MetadataPreviews.kt+++ b/camera-wear/src/screenshotTest/kotlin/com/vayunmathur/camera/wear/ui/MetadataPreviews.kt@@ -10,7 +10,7 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.tooling.preview.Preview import androidx.wear.compose.material.MaterialTheme import com.android.tools.screenshot.PreviewTest-import com.vayunmathur.camera.wear.domain.WearCameraState+import com.vayunmathur.library.wearlink.camera.WearCameraState  /** Round watch, 454x454px class (227dp at 320dpi). */ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"
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 f03692b9b5..cd3276f1eb 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@@ -1,9 +1,23 @@ package com.vayunmathur.camera.wear.domain + import com.vayunmathur.camera.wear.data.WearCameraStore+import com.vayunmathur.library.wearlink.camera.PreviewFrame+import com.vayunmathur.library.wearlink.camera.WearCameraOp+import com.vayunmathur.library.wearlink.camera.WearCameraState+import com.vayunmathur.library.wearlink.camera.WearOpDecision+import com.vayunmathur.library.wearlink.camera.WearOpKind+import com.vayunmathur.library.wearlink.camera.clampWearZoom+import com.vayunmathur.library.wearlink.camera.decodeWearCameraOp+import com.vayunmathur.library.wearlink.camera.decodeWearCameraState+import com.vayunmathur.library.wearlink.camera.encodeWearCameraOp+import com.vayunmathur.library.wearlink.camera.encodeWearCameraState+import com.vayunmathur.library.wearlink.camera.planWearCameraOp+import com.vayunmathur.library.wearlink.camera.wearZoomPreset import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse+import kotlin.test.assertNotNull import kotlin.test.assertNull import kotlin.test.assertTrue @@ -61,18 +75,84 @@ class WearCameraProtocolTest {             ),             frame.map { it.toInt() and 0xFF },         )-        val decoded = PreviewFrame.decode(frame)!!+        val decoded = PreviewFrame.decode(frame)+        assertNotNull(decoded)         assertEquals(0x01020304L, decoded.sequence)+        assertEquals(320, decoded.width)+        assertEquals(240, decoded.height)+        assertEquals(90, decoded.rotationDegrees)         assertTrue(byteArrayOf(9, 8, 7).contentEquals(decoded.jpeg))     }      @Test-    fun stateAndOpRoundTrip() {+    fun stateAndOpRoundTripAndMalformedIgnored() {         val state = WearCameraState(mode = "PORTRAIT", zoomRatio = 1.5f)         assertEquals(state, decodeWearCameraState(encodeWearCameraState(state)))         val op = WearCameraOp(WearOpKind.SET_TIMER, timerSeconds = 5)         assertEquals(op, decodeWearCameraOp(encodeWearCameraOp(op)))         assertNull(decodeWearCameraState("not json".encodeToByteArray()))+        assertNull(decodeWearCameraOp(byteArrayOf(0)))+        assertNull(PreviewFrame.decode(byteArrayOf(1, 2, 3)))+        assertNull(PreviewFrame.decode(PreviewFrame.encode(1L, 1L, 0, 240, 0, byteArrayOf(1))))+    }++    @Test+    fun planRejectsNonRemoteModesAndRecordingSwitches() {+        val idle = WearCameraState(mode = "PHOTO")+        assertEquals(+            WearOpDecision.Apply,+            planWearCameraOp(WearCameraOp(WearOpKind.SET_MODE, mode = "VIDEO"), idle),+        )+        assertTrue(+            planWearCameraOp(WearCameraOp(WearOpKind.SET_MODE, mode = "PANORAMA"), idle)+                is WearOpDecision.Reject,+        )+        val recording = idle.copy(recording = true)+        assertTrue(+            planWearCameraOp(WearCameraOp(WearOpKind.SET_MODE, mode = "VIDEO"), recording)+                is WearOpDecision.Reject,+        )+        assertTrue(+            planWearCameraOp(WearCameraOp(WearOpKind.FLIP_LENS), recording) is WearOpDecision.Reject,+        )+        // Shutter/record and torch stay live while recording.+        assertEquals(WearOpDecision.Apply, planWearCameraOp(WearCameraOp(WearOpKind.RECORD_TOGGLE), recording))+        assertEquals(+            WearOpDecision.Apply,+            planWearCameraOp(WearCameraOp(WearOpKind.SET_TORCH, torch = true), recording),+        )+    }++    @Test+    fun planValidatesFlashTimerAndZoomLock() {+        val state = WearCameraState(mode = "PHOTO")+        assertEquals(+            WearOpDecision.Apply,+            planWearCameraOp(WearCameraOp(WearOpKind.SET_FLASH, flash = "AUTO"), state),+        )+        assertTrue(+            planWearCameraOp(WearCameraOp(WearOpKind.SET_FLASH, flash = "STROBE"), state)+                is WearOpDecision.Reject,+        )+        assertTrue(+            planWearCameraOp(WearCameraOp(WearOpKind.SET_TIMER, timerSeconds = 7), state)+                is WearOpDecision.Reject,+        )+        val pano = state.copy(mode = "PANORAMA")+        assertTrue(+            planWearCameraOp(WearCameraOp(WearOpKind.SET_ZOOM, zoomRatio = 2f), pano)+                is WearOpDecision.Reject,+        )+    }++    @Test+    fun zoomClampAndPresetLookup() {+        val state = WearCameraState(zoomRatio = 1f, zoomPresets = listOf(0.5f, 1f, 2f), zoomMin = 0.5f, zoomMax = 10f)+        assertEquals(10f, clampWearZoom(99f, state))+        assertEquals(0.5f, clampWearZoom(0.1f, state))+        assertEquals(1f, clampWearZoom(Float.NaN, state))+        assertEquals(2f, wearZoomPreset(state, 2))+        assertNull(wearZoomPreset(state, 5))     }      @Test
camera/AGENTS.md
diff --git a/camera/AGENTS.md b/camera/AGENTS.mdindex 9c0e6c2dac..4c9c432e06 100644--- a/camera/AGENTS.md+++ b/camera/AGENTS.md@@ -6,7 +6,7 @@ _Install: ./install camera (dev by default)._ - Gradle: :camera / dir: camera/ - Package roots present: ui, domain, platform - Entry files: MainActivity.kt, Route.kt (`Route.Camera` / `Route.Settings`)-- Deps: :library:ml+- Deps: :library:ml, :library:wearlink - Metadata: metadata_data/camera.md (present) - Rust: yes / screenshotTest: yes (phone + large-tablet preview-rendered over a screenshot-only fake viewfinder scene) @@ -47,6 +47,7 @@ _Install: ./install camera (dev by default)._ - 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` (shared with `:camera-wear`; each side's `WearCameraProtocolTest` pins the same golden JSON/frame bytes) - com/vayunmathur/camera/platform/LensSelector.kt ### ui/ — single screen + settings + panes - com/vayunmathur/camera/ui/CameraScreen.kt
camera/src/main/java/com/vayunmathur/camera/domain/WearPreviewPipeline.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/domain/WearPreviewPipeline.kt b/camera/src/main/java/com/vayunmathur/camera/domain/WearPreviewPipeline.ktindex bd97e34bd9..35a6378870 100644--- a/camera/src/main/java/com/vayunmathur/camera/domain/WearPreviewPipeline.kt+++ b/camera/src/main/java/com/vayunmathur/camera/domain/WearPreviewPipeline.kt@@ -1,5 +1,8 @@ package com.vayunmathur.camera.domain +import com.vayunmathur.library.wearlink.camera.PreviewFrame+import com.vayunmathur.library.wearlink.camera.WearCameraProtocol+ /**  * Pure live-viewfinder pipeline for the watch preview: downscale maths,  * the latest-frame-only hand-off, the adaptive rate controller and the
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 5337c0e7b1..dbb83651ad 100644--- a/camera/src/main/java/com/vayunmathur/camera/platform/WearCameraSync.kt+++ b/camera/src/main/java/com/vayunmathur/camera/platform/WearCameraSync.kt@@ -8,26 +8,25 @@ import com.vayunmathur.camera.data.setTimerDuration import com.vayunmathur.camera.data.toggleTorch import com.vayunmathur.camera.domain.AdaptivePreviewRate import com.vayunmathur.camera.domain.LatestOnlySlot-import com.vayunmathur.camera.domain.PreviewFrame import com.vayunmathur.camera.domain.PreviewFrameProcessor import com.vayunmathur.camera.domain.PreviewJpegEncoder-import com.vayunmathur.camera.domain.WearCameraOp-import com.vayunmathur.camera.domain.WearCameraProtocol-import com.vayunmathur.camera.domain.WearCameraState-import com.vayunmathur.camera.domain.WearOpDecision-import com.vayunmathur.camera.domain.WearOpKind import com.vayunmathur.camera.domain.Yuv420ToArgb-import com.vayunmathur.camera.domain.clampWearZoom-import com.vayunmathur.camera.domain.decodeWearCameraOp-import com.vayunmathur.camera.domain.encodeWearCameraState-import com.vayunmathur.camera.domain.planWearCameraOp import com.vayunmathur.camera.domain.previewDimensions-import com.vayunmathur.camera.domain.wearZoomPreset 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 java.io.ByteArrayOutputStream+import com.vayunmathur.library.wearlink.camera.PreviewFrame+import com.vayunmathur.library.wearlink.camera.WearCameraOp+import com.vayunmathur.library.wearlink.camera.WearCameraProtocol+import com.vayunmathur.library.wearlink.camera.WearCameraState+import com.vayunmathur.library.wearlink.camera.WearOpDecision+import com.vayunmathur.library.wearlink.camera.WearOpKind+import com.vayunmathur.library.wearlink.camera.clampWearZoom+import com.vayunmathur.library.wearlink.camera.decodeWearCameraOp+import com.vayunmathur.library.wearlink.camera.encodeWearCameraState+import com.vayunmathur.library.wearlink.camera.planWearCameraOp+import com.vayunmathur.library.wearlink.camera.wearZoomPreset import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job@@ -36,6 +35,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import kotlinx.coroutines.withContext+import java.io.ByteArrayOutputStream  /**  * The camera control seam the watch ops execute against: every call is one
camera/src/test/java/com/vayunmathur/camera/domain/WearCameraProtocolTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/domain/WearCameraProtocolTest.kt b/camera/src/test/java/com/vayunmathur/camera/domain/WearCameraProtocolTest.ktindex c0b7f42038..0c514cf09d 100644--- a/camera/src/test/java/com/vayunmathur/camera/domain/WearCameraProtocolTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/domain/WearCameraProtocolTest.kt@@ -1,5 +1,18 @@ package com.vayunmathur.camera.domain ++import com.vayunmathur.library.wearlink.camera.PreviewFrame+import com.vayunmathur.library.wearlink.camera.WearCameraOp+import com.vayunmathur.library.wearlink.camera.WearCameraState+import com.vayunmathur.library.wearlink.camera.WearOpDecision+import com.vayunmathur.library.wearlink.camera.WearOpKind+import com.vayunmathur.library.wearlink.camera.clampWearZoom+import com.vayunmathur.library.wearlink.camera.decodeWearCameraOp+import com.vayunmathur.library.wearlink.camera.decodeWearCameraState+import com.vayunmathur.library.wearlink.camera.encodeWearCameraOp+import com.vayunmathur.library.wearlink.camera.encodeWearCameraState+import com.vayunmathur.library.wearlink.camera.planWearCameraOp+import com.vayunmathur.library.wearlink.camera.wearZoomPreset import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull
camera/src/test/java/com/vayunmathur/camera/domain/WearPreviewPipelineTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/domain/WearPreviewPipelineTest.kt b/camera/src/test/java/com/vayunmathur/camera/domain/WearPreviewPipelineTest.ktindex 29c7026d7e..22f84d423d 100644--- a/camera/src/test/java/com/vayunmathur/camera/domain/WearPreviewPipelineTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/domain/WearPreviewPipelineTest.kt@@ -1,5 +1,7 @@ package com.vayunmathur.camera.domain ++import com.vayunmathur.library.wearlink.camera.WearCameraProtocol import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse
camera/src/test/java/com/vayunmathur/camera/platform/WearCameraOpApplicationTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/platform/WearCameraOpApplicationTest.kt b/camera/src/test/java/com/vayunmathur/camera/platform/WearCameraOpApplicationTest.ktindex f4dc58646b..dde7c69486 100644--- a/camera/src/test/java/com/vayunmathur/camera/platform/WearCameraOpApplicationTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/platform/WearCameraOpApplicationTest.kt@@ -1,9 +1,9 @@ package com.vayunmathur.camera.platform -import com.vayunmathur.camera.domain.WearCameraOp-import com.vayunmathur.camera.domain.WearCameraState-import com.vayunmathur.camera.domain.WearOpDecision-import com.vayunmathur.camera.domain.WearOpKind+import com.vayunmathur.library.wearlink.camera.WearCameraOp+import com.vayunmathur.library.wearlink.camera.WearCameraState+import com.vayunmathur.library.wearlink.camera.WearOpDecision+import com.vayunmathur.library.wearlink.camera.WearOpKind import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue
communicate-wear/AGENTS.md
diff --git a/communicate-wear/AGENTS.md b/communicate-wear/AGENTS.mdindex e61f9f121d..7e7ef1a1eb 100644--- a/communicate-wear/AGENTS.md+++ b/communicate-wear/AGENTS.md@@ -16,9 +16,11 @@ on both sides, so changing either breaks phone<->watch sync. Bootstrap is a one-time ADB sideload of this APK onto the watch.  ## Protocol-`domain/WearCommunicateProtocol.kt` is a copy of the phone's file (Gradle-cannot depend on another app module). Change both copies together; each-side's `WearCommunicateProtocolTest` pins the same golden JSON.+The wire protocol lives in `:library:wearlink` at+`com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol`+(shared by `:communicate` and `:communicate-wear`; neither app module+depends on the other). Each side's `WearCommunicateProtocolTest` pins+the same golden JSON against that shared code.  - Snapshot: WearLink data item (`/communicate/snapshot`, phone -> watch);   watch state back (`/communicate/watch-state`)
communicate-wear/src/main/java/com/vayunmathur/communicate/wear/data/WearCommunicateStore.kt
diff --git a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/data/WearCommunicateStore.kt b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/data/WearCommunicateStore.ktindex fd294e2b24..9794d2da25 100644--- a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/data/WearCommunicateStore.kt+++ b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/data/WearCommunicateStore.kt@@ -1,27 +1,27 @@ package com.vayunmathur.communicate.wear.data  import android.content.Context-import com.vayunmathur.communicate.wear.domain.WearCommOp-import com.vayunmathur.communicate.wear.domain.WearCommunicateSnapshot-import com.vayunmathur.communicate.wear.domain.WearIncomingCall-import com.vayunmathur.communicate.wear.domain.WearMessage-import com.vayunmathur.communicate.wear.domain.WearNewMessageAlert-import com.vayunmathur.communicate.wear.domain.WearCommunicateProtocol-import com.vayunmathur.communicate.wear.domain.WearOpKind-import com.vayunmathur.communicate.wear.domain.WearOpResult-import com.vayunmathur.communicate.wear.domain.WearThread-import com.vayunmathur.communicate.wear.domain.WearThreadPage-import com.vayunmathur.communicate.wear.domain.WearVoicemail-import com.vayunmathur.communicate.wear.domain.mergeWearThreadPage-import com.vayunmathur.communicate.wear.domain.pendingAfterResult import com.vayunmathur.library.log.Log-import java.io.File-import java.util.UUID+import com.vayunmathur.library.wearlink.communicate.WearCommOp+import com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol+import com.vayunmathur.library.wearlink.communicate.WearCommunicateSnapshot+import com.vayunmathur.library.wearlink.communicate.WearIncomingCall+import com.vayunmathur.library.wearlink.communicate.WearMessage+import com.vayunmathur.library.wearlink.communicate.WearNewMessageAlert+import com.vayunmathur.library.wearlink.communicate.WearOpKind+import com.vayunmathur.library.wearlink.communicate.WearOpResult+import com.vayunmathur.library.wearlink.communicate.WearThread+import com.vayunmathur.library.wearlink.communicate.WearThreadPage+import com.vayunmathur.library.wearlink.communicate.WearVoicemail+import com.vayunmathur.library.wearlink.communicate.mergeWearThreadPage+import com.vayunmathur.library.wearlink.communicate.pendingAfterResult import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString+import java.io.File+import java.util.UUID  /** Cached pages for one thread, persisted so threads read fully offline. */ @Serializable
communicate-wear/src/main/java/com/vayunmathur/communicate/wear/domain/WearCommunicateProtocol.kt
diff --git a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/domain/WearCommunicateProtocol.kt b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/domain/WearCommunicateProtocol.ktdeleted file mode 100644index f3c46c057a..0000000000--- a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/domain/WearCommunicateProtocol.kt+++ /dev/null@@ -1,421 +0,0 @@-package com.vayunmathur.communicate.wear.domain--import kotlinx.serialization.Serializable-import kotlinx.serialization.encodeToString-import kotlinx.serialization.json.Json--/**- * Phone <-> watch protocol for the Wear OS Communicate companion.- *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module- * (`:communicate-wear`, applicationId `com.vayunmathur.communicate`) carries- * a copy of this file under `com.vayunmathur.communicate.wear.domain`.- * Change both copies together; each side's unit tests pin the same golden- * JSON so a one-sided edit fails loudly.- *- * The watch mirrors the phone app's navigation, not a glance card:- * conversation list (all lines the phone merges: SIM / Google Voice /- * WhatsApp / Signal / RCS), one thread (paged), call log, and voicemail- * indicators. All repository work and all decryption stay on the phone;- * the watch only receives bounded snapshots/pages, caches them for offline- * reading, and sends ops the phone executes.- *- * Page mapping (phone [com.vayunmathur.communicate.Route] -> watch):- * - `Messages` -> conversation list. Mirrored.- * - `Conversation(threadId, ...)` -> thread view. Mirrored, paged.- * - `CallLogs` -> call log. Mirrored (read-only; no watch calling).- * - Voicemail (inside the phone dialer flow) -> voicemail indicators:- *   caller, time, duration, read state and a capped transcript. Audio- *   playback, content URIs and GV audio auth headers NEVER cross.- * - `Dialer` -> OMITTED: no watch telephony/audio route is guaranteed, so- *   the watch never offers dialling or answer-on-watch.- * - `Accounts`, registration wizards, `RcsStatus`/`RcsVerify`,- *   `RcsGroupMembers`, `Call` -> OMITTED: calling setup, line registration,- *   safety-number verification, group management, media viewing and full- *   settings do not fit a wrist and stay phone-only.- * - Archive/mute -> OMITTED: the phone UI offers neither (only the- *   underlying WhatsApp/Signal DBs know the flags), so the watch offers- *   no op the phone UI does not.- *- * Privacy choices (stated, not implied):- * - Disappearing messages: a thread/message flagged disappearing is- *   EXCLUDED in content — snippet and body cross as empty, media is not- *   even counted, and only a `contentExcluded` marker remains so the- *   watch can say why. Persisting their plaintext in a watch cache would- *   defeat the feature. The phone detects this today for WhatsApp- *   conversations (`ephemeralExpiration > 0`); other lines surface no- *   unified flag, so their flag is false until they do.- * - E2EE lines (WhatsApp/Signal/RCS-MLS): the phone is the endpoint and- *   decrypts; capped plaintext then crosses the cert-bound WearLink- *   session to the owner's same-signed watch, like the phone's own- *   notification text. No keys, no serviceData JSON, no media URLs, no- *   attachment bytes ever cross — media is a label ("Photo") only.- *   Revoked messages cross with an empty body.- * - New-message alerts are small messages: display name + capped snippet- *   only when not disappearing (empty snippet then), never a full page.- *- * Transport (WearLink, :library:wearlink — RFCOMM, no Play services):- * - Data items: [SNAPSHOT_PATH] phone -> watch, [WATCH_STATE_PATH] back.- * - Messages: [OP_PATH] watch -> phone, [OP_RESULT_PATH] phone -> watch,- *   [REQUEST_SYNC_PATH] / [REQUEST_THREAD_PATH] watch -> phone,- *   [THREAD_PAGE_PATH] / [NEW_MESSAGE_PATH] / [INCOMING_CALL_PATH]- *   phone -> watch. Delivery needs a live session; nothing wakes a dead- *   phone process, and the watch resends pending ops on reconnect.- */-object WearCommunicateProtocol {-    /** WearLink appId the phone requires in the peer handshake. */-    const val CAPABILITY = "communicate_wear_companion"--    const val SNAPSHOT_PATH = "/communicate/snapshot"-    const val WATCH_STATE_PATH = "/communicate/watch-state"-    const val OP_PATH = "/communicate/op"-    const val OP_RESULT_PATH = "/communicate/op-result"-    const val REQUEST_SYNC_PATH = "/communicate/request-sync"-    const val REQUEST_THREAD_PATH = "/communicate/request-thread"-    const val THREAD_PAGE_PATH = "/communicate/thread-page"-    const val NEW_MESSAGE_PATH = "/communicate/new-message"-    const val INCOMING_CALL_PATH = "/communicate/incoming-call"--    const val MAX_THREADS = 50-    const val MAX_CALLS = 50-    const val MAX_VOICEMAILS = 30-    const val MAX_JSON_BYTES = 90_000-    const val MAX_TITLE_CHARS = 80-    const val MAX_SNIPPET_CHARS = 120-    const val MAX_BODY_CHARS = 1_000-    const val MAX_TRANSCRIPT_CHARS = 200-    const val MAX_PAGE_MESSAGES = 20-    const val MAX_CACHED_MESSAGES_PER_THREAD = 100-    const val MAX_CACHED_THREADS = 10-    const val MAX_REPLY_CHARS = 1_000-    const val MAX_ALERT_SNIPPET_CHARS = 80--    /** Canned quick replies; free text (dictation/IME) is also accepted. */-    val CANNED_REPLIES = listOf(-        "On my way",-        "Call you later",-        "Can't talk right now",-        "OK",-        "Thanks",-    )--    val json: Json = Json { ignoreUnknownKeys = true }-}--/** Line names mirror the phone's `CommunicateLine` enum names exactly. */-@Serializable-enum class WearCommLine { Sim, GoogleVoice, WhatsApp, Signal, Rcs }--/** One conversation in the merged list, trimmed to watch size. */-@Serializable-data class WearThread(-    /** Stable watch key: `"<line>:<remoteId or threadId>"`. */-    val key: String,-    val threadId: Long = 0L,-    val line: WearCommLine = WearCommLine.Sim,-    val address: String = "",-    val remoteId: String? = null,-    val subscriptionId: Int? = null,-    val displayName: String = "",-    /** Capped snippet; empty when [contentExcluded]. */-    val snippet: String = "",-    val timestampMillis: Long = 0L,-    val unreadCount: Int = 0,-    val isGroup: Boolean = false,-    val groupTitle: String? = null,-    val participants: List<String> = emptyList(),-    /** True when the phone flagged disappearing messages for this thread. */-    val disappearing: Boolean = false,-    /** True when content was withheld (disappearing); snippet/body are empty. */-    val contentExcluded: Boolean = false,-)--/** One message in a thread page. Media is a label only; no URL/bytes cross. */-@Serializable-data class WearMessage(-    val messageKey: String,-    val threadKey: String = "",-    /** Capped body; empty when [contentExcluded] or revoked. */-    val body: String = "",-    val timestampMillis: Long = 0L,-    val outgoing: Boolean = false,-    val read: Boolean = true,-    val senderLabel: String? = null,-    /** Display label for an attachment ("Photo", "Video", "File"), or null. */-    val mediaLabel: String? = null,-    val status: String = "None",-    val disappearing: Boolean = false,-    val contentExcluded: Boolean = false,-    val bodyTruncated: Boolean = false,-)--/** One unified call-log row (read-only on the watch). */-@Serializable-data class WearCallEntry(-    val key: String,-    val displayName: String = "",-    val phoneNumber: String = "",-    /** Phone `CommunicateCallType` name. */-    val type: String = "Unknown",-    val timestampMillis: Long = 0L,-    val durationSeconds: Long = 0L,-    val line: WearCommLine = WearCommLine.Sim,-)--/** One voicemail indicator. No audio URI, no auth headers, no playback. */-@Serializable-data class WearVoicemail(-    val key: String,-    val phoneNumber: String = "",-    val timestampMillis: Long = 0L,-    val durationSeconds: Long = 0L,-    /** Capped transcript when the phone has one; never an audio reference. */-    val transcript: String = "",-    val isRead: Boolean = true,-    val line: WearCommLine = WearCommLine.Sim,-)--/** Bounded phone snapshot for the watch ([WearCommunicateProtocol.SNAPSHOT_PATH]). */-@Serializable-data class WearCommunicateSnapshot(-    val generatedAtMillis: Long = 0L,-    val threads: List<WearThread> = emptyList(),-    val calls: List<WearCallEntry> = emptyList(),-    val voicemails: List<WearVoicemail> = emptyList(),-    val voicemailUnreadCount: Int = 0,-    val truncated: Boolean = false,-)--/** One paged slice of a thread, oldest-to-newest inside the page. */-@Serializable-data class WearThreadPage(-    val threadKey: String = "",-    val messages: List<WearMessage> = emptyList(),-    /** True when older messages remain on the phone. */-    val hasMore: Boolean = false,-    /** Cursor for the next older page: oldest timestamp in this page. */-    val oldestTimestampMillis: Long = 0L,-    val generatedAtMillis: Long = 0L,-)--/** Watch request for one thread page ([WearCommunicateProtocol.REQUEST_THREAD_PATH]). */-@Serializable-data class WearThreadRequest(-    val threadKey: String,-    /** Page older than this timestamp; 0 means the latest page. */-    val beforeTimestampMillis: Long = 0L,-)--/** Small new-message alert ([WearCommunicateProtocol.NEW_MESSAGE_PATH]). */-@Serializable-data class WearNewMessageAlert(-    val threadKey: String = "",-    val displayName: String = "",-    val line: WearCommLine = WearCommLine.Sim,-    /** Capped snippet; always empty for disappearing threads. */-    val snippet: String = "",-    val timestampMillis: Long = 0L,-    val unreadCount: Int = 0,-    val contentExcluded: Boolean = false,-)--/**- * Incoming-call alert ([WearCommunicateProtocol.INCOMING_CALL_PATH]).- * Carries no answer capability on purpose: watch audio routing is not- * guaranteed, so the only watch call action is decline (see [WearOpKind]).- */-@Serializable-data class WearIncomingCall(-    val callKey: String = "",-    val displayName: String = "",-    val line: WearCommLine = WearCommLine.Sim,-    val isVideo: Boolean = false,-    val timestampMillis: Long = 0L,-)--/** Watch-originated actions the phone executes. Archive/mute are absent: the phone UI offers neither. */-@Serializable-enum class WearOpKind { QuickReply, MarkRead, MarkVoicemailRead, DeclineCall }--/** One watch-originated action ([WearCommunicateProtocol.OP_PATH]). */-@Serializable-data class WearCommOp(-    /** Watch-generated id; the phone echoes it in [WearOpResult]. */-    val opId: String,-    val kind: WearOpKind,-    val threadKey: String = "",-    val line: WearCommLine = WearCommLine.Sim,-    val threadId: Long = 0L,-    val remoteId: String? = null,-    val address: String = "",-    val subscriptionId: Int? = null,-    val participants: List<String> = emptyList(),-    /** Reply text for [WearOpKind.QuickReply]; empty otherwise. */-    val body: String = "",-    /** Voicemail/call key for [WearOpKind.MarkVoicemailRead] / [WearOpKind.DeclineCall]. */-    val targetKey: String = "",-)--/** Phone verdict for one op ([WearCommunicateProtocol.OP_RESULT_PATH]). */-@Serializable-data class WearOpResult(-    val opId: String = "",-    val kind: WearOpKind = WearOpKind.MarkRead,-    val success: Boolean = false,-)--/** What the watch last applied ([WearCommunicateProtocol.WATCH_STATE_PATH]). */-@Serializable-data class WearCommWatchState(-    val appliedGeneratedAtMillis: Long = 0L,-    val threadCount: Int = 0,-    val pendingOps: Int = 0,-)--/** Stable thread key: remote id when the line has one, else the phone thread id. */-fun wearThreadKey(line: WearCommLine, remoteId: String?, threadId: Long): String =-    "$line:${remoteId?.takeIf { it.isNotBlank() } ?: threadId}"--/** Content that may cross to the watch: nothing for disappearing/revoked, else capped. */-fun sanitizeWearText(text: String, disappearing: Boolean, cap: Int): String =-    if (disappearing) "" else text.take(cap)--/** Applies the disappearing/revoked exclusion and caps to one message. */-fun sanitizeWearMessage(message: WearMessage): WearMessage {-    if (message.disappearing) {-        return message.copy(body = "", mediaLabel = null, contentExcluded = true, bodyTruncated = false)-    }-    return message.copy(-        body = message.body.take(WearCommunicateProtocol.MAX_BODY_CHARS),-        bodyTruncated = message.bodyTruncated ||-            message.body.length > WearCommunicateProtocol.MAX_BODY_CHARS,-    )-}--/** Applies the exclusion and caps to one thread row (snippet is content). */-fun sanitizeWearThread(thread: WearThread): WearThread = thread.copy(-    displayName = thread.displayName.take(WearCommunicateProtocol.MAX_TITLE_CHARS),-    snippet = sanitizeWearText(-        thread.snippet,-        thread.disappearing,-        WearCommunicateProtocol.MAX_SNIPPET_CHARS,-    ),-    contentExcluded = thread.contentExcluded || thread.disappearing,-    participants = thread.participants.take(10),-)--/**- * Builds the bounded snapshot: newest first per section, field caps and- * exclusion applied, then count caps, then the byte cap enforced by- * dropping the oldest voicemails, then calls, then threads (the- * conversation list — the watch's home — survives longest).- */-fun buildWearCommunicateSnapshot(-    threads: List<WearThread>,-    calls: List<WearCallEntry>,-    voicemails: List<WearVoicemail>,-    generatedAtMillis: Long,-): WearCommunicateSnapshot {-    var keptThreads = threads.map(::sanitizeWearThread)-        .sortedWith(compareByDescending<WearThread> { it.timestampMillis }.thenBy { it.key })-        .take(WearCommunicateProtocol.MAX_THREADS)-    var keptCalls = calls-        .sortedWith(compareByDescending<WearCallEntry> { it.timestampMillis }.thenBy { it.key })-        .take(WearCommunicateProtocol.MAX_CALLS)-    var keptVoicemails = voicemails.map {-        it.copy(transcript = it.transcript.take(WearCommunicateProtocol.MAX_TRANSCRIPT_CHARS))-    }.sortedWith(compareByDescending<WearVoicemail> { it.timestampMillis }.thenBy { it.key })-        .take(WearCommunicateProtocol.MAX_VOICEMAILS)-    var truncated = keptThreads.size < threads.size || keptCalls.size < calls.size ||-        keptVoicemails.size < voicemails.size-    fun snapshot() = WearCommunicateSnapshot(-        generatedAtMillis = generatedAtMillis,-        threads = keptThreads,-        calls = keptCalls,-        voicemails = keptVoicemails,-        voicemailUnreadCount = keptVoicemails.count { !it.isRead },-        truncated = truncated,-    )-    var result = snapshot()-    fun overBytes() =-        WearCommunicateProtocol.json.encodeToString(result).encodeToByteArray().size >-            WearCommunicateProtocol.MAX_JSON_BYTES-    while (overBytes() && keptVoicemails.isNotEmpty()) {-        keptVoicemails = keptVoicemails.dropLast(1); truncated = true; result = snapshot()-    }-    while (overBytes() && keptCalls.isNotEmpty()) {-        keptCalls = keptCalls.dropLast(1); truncated = true; result = snapshot()-    }-    while (overBytes() && keptThreads.isNotEmpty()) {-        keptThreads = keptThreads.dropLast(1); truncated = true; result = snapshot()-    }-    return result-}--/**- * One page of a thread: the [pageSize] newest messages strictly older- * than [beforeTimestampMillis] (0 = latest page), returned- * oldest-to-newest. Exclusion/caps are applied before paging so an- * excluded message still occupies its slot (its position is not a leak).- */-fun buildWearThreadPage(-    threadKey: String,-    messages: List<WearMessage>,-    beforeTimestampMillis: Long = 0L,-    generatedAtMillis: Long = 0L,-    pageSize: Int = WearCommunicateProtocol.MAX_PAGE_MESSAGES,-): WearThreadPage {-    val clean = messages.map(::sanitizeWearMessage)-        .sortedWith(compareBy<WearMessage> { it.timestampMillis }.thenBy { it.messageKey })-    val eligible = if (beforeTimestampMillis <= 0L) clean-        else clean.filter { it.timestampMillis < beforeTimestampMillis }-    val page = eligible.takeLast(pageSize.coerceAtLeast(1))-    return WearThreadPage(-        threadKey = threadKey,-        messages = page,-        hasMore = eligible.size > page.size,-        oldestTimestampMillis = page.firstOrNull()?.timestampMillis ?: 0L,-        generatedAtMillis = generatedAtMillis,-    )-}--/**- * Merges a newly arrived [page] into a cached thread view: dedupes by- * messageKey, keeps chronological order, caps to the most recent- * [WearCommunicateProtocol.MAX_CACHED_MESSAGES_PER_THREAD] plus any older- * paged-in messages up to the same cap (oldest dropped first).- */-fun mergeWearThreadPage(cached: List<WearMessage>, page: WearThreadPage): List<WearMessage> {-    val byKey = (cached + page.messages).associateBy { it.messageKey }-    return byKey.values-        .sortedWith(compareBy<WearMessage> { it.timestampMillis }.thenBy { it.messageKey })-        .takeLast(WearCommunicateProtocol.MAX_CACHED_MESSAGES_PER_THREAD)-}--/** Small alert for [thread] after a change; snippet withheld when excluded. */-fun buildWearNewMessageAlert(thread: WearThread, timestampMillis: Long): WearNewMessageAlert =-    WearNewMessageAlert(-        threadKey = thread.key,-        displayName = thread.displayName.take(WearCommunicateProtocol.MAX_TITLE_CHARS),-        line = thread.line,-        snippet = sanitizeWearText(-            thread.snippet,-            thread.disappearing,-            WearCommunicateProtocol.MAX_ALERT_SNIPPET_CHARS,-        ),-        timestampMillis = timestampMillis,-        unreadCount = thread.unreadCount,-        contentExcluded = thread.disappearing || thread.contentExcluded,-    )--/** A reply the phone may execute: non-blank after trim, capped. Null when invalid. */-fun validWearReply(op: WearCommOp): String? {-    if (op.kind != WearOpKind.QuickReply) return null-    val body = op.body.trim().take(WearCommunicateProtocol.MAX_REPLY_CHARS)-    return body.takeIf { it.isNotEmpty() && op.threadKey.isNotBlank() }-}--/** Pending ops after a phone [result]: a success drops its op; a failure keeps it for resend. */-fun pendingAfterResult(pending: List<WearCommOp>, result: WearOpResult): List<WearCommOp> =-    if (result.success) pending.filter { it.opId != result.opId } else pending
communicate-wear/src/main/java/com/vayunmathur/communicate/wear/sync/WearLinkBridge.kt
diff --git a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/sync/WearLinkBridge.kt b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/sync/WearLinkBridge.ktindex f20aee0bc7..bc07008562 100644--- a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/sync/WearLinkBridge.kt+++ b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/sync/WearLinkBridge.kt@@ -2,18 +2,18 @@ package com.vayunmathur.communicate.wear.sync  import android.content.Context import com.vayunmathur.communicate.wear.data.WearCommunicateStore-import com.vayunmathur.communicate.wear.domain.WearCommWatchState-import com.vayunmathur.communicate.wear.domain.WearCommunicateProtocol-import com.vayunmathur.communicate.wear.domain.WearCommunicateSnapshot-import com.vayunmathur.communicate.wear.domain.WearIncomingCall-import com.vayunmathur.communicate.wear.domain.WearNewMessageAlert-import com.vayunmathur.communicate.wear.domain.WearOpResult-import com.vayunmathur.communicate.wear.domain.WearThreadPage-import com.vayunmathur.communicate.wear.domain.WearThreadRequest 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.communicate.WearCommWatchState+import com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol+import com.vayunmathur.library.wearlink.communicate.WearCommunicateSnapshot+import com.vayunmathur.library.wearlink.communicate.WearIncomingCall+import com.vayunmathur.library.wearlink.communicate.WearNewMessageAlert+import com.vayunmathur.library.wearlink.communicate.WearOpResult+import com.vayunmathur.library.wearlink.communicate.WearThreadPage+import com.vayunmathur.library.wearlink.communicate.WearThreadRequest import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob
communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearCallLogScreen.kt
diff --git a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearCallLogScreen.kt b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearCallLogScreen.ktindex ed2518bf0a..a92fa01495 100644--- a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearCallLogScreen.kt+++ b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearCallLogScreen.kt@@ -31,7 +31,7 @@ fun WearCallLogScreen(  /** Stateless call log behind [WearCallLogScreen]: snapshot is a parameter for previews. */ @Composable-internal fun WearCallLogContent(snapshot: com.vayunmathur.communicate.wear.domain.WearCommunicateSnapshot, onBack: () -> Unit) {+internal fun WearCallLogContent(snapshot: com.vayunmathur.library.wearlink.communicate.WearCommunicateSnapshot, onBack: () -> Unit) {      ScalingLazyColumn(state = rememberScalingLazyListState()) {         item {
communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearConversationListScreen.kt
diff --git a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearConversationListScreen.kt b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearConversationListScreen.ktindex adc3d52834..25599516d3 100644--- a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearConversationListScreen.kt+++ b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearConversationListScreen.kt@@ -45,11 +45,11 @@ fun WearConversationListScreen( /** Stateless conversation list behind [WearConversationListScreen]: snapshot/alert are parameters for previews. */ @Composable internal fun WearConversationListContent(-    snapshot: com.vayunmathur.communicate.wear.domain.WearCommunicateSnapshot,+    snapshot: com.vayunmathur.library.wearlink.communicate.WearCommunicateSnapshot,     pendingCount: Int,-    alert: com.vayunmathur.communicate.wear.domain.WearNewMessageAlert?,+    alert: com.vayunmathur.library.wearlink.communicate.WearNewMessageAlert?,     onOpenThread: (String) -> Unit,-    onOpenAlert: (com.vayunmathur.communicate.wear.domain.WearNewMessageAlert) -> Unit,+    onOpenAlert: (com.vayunmathur.library.wearlink.communicate.WearNewMessageAlert) -> Unit,     onOpenCalls: () -> Unit,     onOpenVoicemail: () -> Unit,     onOpenPhoneOnly: () -> Unit,
communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearIncomingCallScreen.kt
diff --git a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearIncomingCallScreen.kt b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearIncomingCallScreen.ktindex 8cdfa086d1..95b92aea2c 100644--- a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearIncomingCallScreen.kt+++ b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearIncomingCallScreen.kt@@ -15,7 +15,7 @@ import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text import com.vayunmathur.communicate.wear.R import com.vayunmathur.communicate.wear.data.WearCommunicateStore-import com.vayunmathur.communicate.wear.domain.WearIncomingCall+import com.vayunmathur.library.wearlink.communicate.WearIncomingCall  /**  * Incoming-call alert. Decline only: answering on the watch is not offered
communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearReplyScreen.kt
diff --git a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearReplyScreen.kt b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearReplyScreen.ktindex 892594a807..b2677fc1d1 100644--- a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearReplyScreen.kt+++ b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearReplyScreen.kt@@ -23,7 +23,7 @@ import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text import com.vayunmathur.communicate.wear.R import com.vayunmathur.communicate.wear.data.WearCommunicateStore-import com.vayunmathur.communicate.wear.domain.WearCommunicateProtocol+import com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol  /**  * Quick reply: canned replies plus a free-text field (the watch IME's
communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearThreadScreen.kt
diff --git a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearThreadScreen.kt b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearThreadScreen.ktindex 74a9e0eb70..0ebfbd1c6b 100644--- a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearThreadScreen.kt+++ b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearThreadScreen.kt@@ -53,7 +53,7 @@ fun WearThreadScreen( /** Stateless thread behind [WearThreadScreen]: thread/cache are parameters for previews. */ @Composable internal fun WearThreadContent(-    thread: com.vayunmathur.communicate.wear.domain.WearThread?,+    thread: com.vayunmathur.library.wearlink.communicate.WearThread?,     cache: com.vayunmathur.communicate.wear.data.WearThreadCache?,     onLoadOlder: () -> Unit,     onReply: (String) -> Unit,
communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearVoicemailScreen.kt
diff --git a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearVoicemailScreen.kt b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearVoicemailScreen.ktindex 5996b458d4..a8bb654a36 100644--- a/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearVoicemailScreen.kt+++ b/communicate-wear/src/main/java/com/vayunmathur/communicate/wear/ui/WearVoicemailScreen.kt@@ -35,7 +35,7 @@ fun WearVoicemailScreen(  /** Stateless voicemail behind [WearVoicemailScreen]: snapshot is a parameter for previews. */ @Composable-internal fun WearVoicemailContent(snapshot: com.vayunmathur.communicate.wear.domain.WearCommunicateSnapshot, onMarkRead: (com.vayunmathur.communicate.wear.domain.WearVoicemail) -> Unit, onBack: () -> Unit) {+internal fun WearVoicemailContent(snapshot: com.vayunmathur.library.wearlink.communicate.WearCommunicateSnapshot, onMarkRead: (com.vayunmathur.library.wearlink.communicate.WearVoicemail) -> Unit, onBack: () -> Unit) {      ScalingLazyColumn(state = rememberScalingLazyListState()) {         item {
communicate-wear/src/screenshotTest/kotlin/com/vayunmathur/communicate/wear/ui/MetadataPreviews.kt
diff --git a/communicate-wear/src/screenshotTest/kotlin/com/vayunmathur/communicate/wear/ui/MetadataPreviews.kt b/communicate-wear/src/screenshotTest/kotlin/com/vayunmathur/communicate/wear/ui/MetadataPreviews.ktindex 7ec607d2c8..15340f8208 100644--- a/communicate-wear/src/screenshotTest/kotlin/com/vayunmathur/communicate/wear/ui/MetadataPreviews.kt+++ b/communicate-wear/src/screenshotTest/kotlin/com/vayunmathur/communicate/wear/ui/MetadataPreviews.kt@@ -11,12 +11,12 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.wear.compose.material.MaterialTheme import com.android.tools.screenshot.PreviewTest import com.vayunmathur.communicate.wear.data.WearThreadCache-import com.vayunmathur.communicate.wear.domain.WearCallEntry-import com.vayunmathur.communicate.wear.domain.WearCommunicateSnapshot-import com.vayunmathur.communicate.wear.domain.WearIncomingCall-import com.vayunmathur.communicate.wear.domain.WearMessage-import com.vayunmathur.communicate.wear.domain.WearThread-import com.vayunmathur.communicate.wear.domain.WearVoicemail+import com.vayunmathur.library.wearlink.communicate.WearCallEntry+import com.vayunmathur.library.wearlink.communicate.WearCommunicateSnapshot+import com.vayunmathur.library.wearlink.communicate.WearIncomingCall+import com.vayunmathur.library.wearlink.communicate.WearMessage+import com.vayunmathur.library.wearlink.communicate.WearThread+import com.vayunmathur.library.wearlink.communicate.WearVoicemail  /** Round watch, 454x454px class (227dp at 320dpi). */ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"
communicate-wear/src/test/java/com/vayunmathur/communicate/wear/data/WearIncomingCallAfterResultTest.kt
diff --git a/communicate-wear/src/test/java/com/vayunmathur/communicate/wear/data/WearIncomingCallAfterResultTest.kt b/communicate-wear/src/test/java/com/vayunmathur/communicate/wear/data/WearIncomingCallAfterResultTest.ktindex c913be9103..684fe8bad1 100644--- a/communicate-wear/src/test/java/com/vayunmathur/communicate/wear/data/WearIncomingCallAfterResultTest.kt+++ b/communicate-wear/src/test/java/com/vayunmathur/communicate/wear/data/WearIncomingCallAfterResultTest.kt@@ -1,9 +1,9 @@ package com.vayunmathur.communicate.wear.data -import com.vayunmathur.communicate.wear.domain.WearCommOp-import com.vayunmathur.communicate.wear.domain.WearIncomingCall-import com.vayunmathur.communicate.wear.domain.WearOpKind-import com.vayunmathur.communicate.wear.domain.WearOpResult+import com.vayunmathur.library.wearlink.communicate.WearCommOp+import com.vayunmathur.library.wearlink.communicate.WearIncomingCall+import com.vayunmathur.library.wearlink.communicate.WearOpKind+import com.vayunmathur.library.wearlink.communicate.WearOpResult import kotlin.test.Test import kotlin.test.assertEquals 
communicate-wear/src/test/java/com/vayunmathur/communicate/wear/domain/WearCommunicateProtocolTest.kt
diff --git a/communicate-wear/src/test/java/com/vayunmathur/communicate/wear/domain/WearCommunicateProtocolTest.kt b/communicate-wear/src/test/java/com/vayunmathur/communicate/wear/domain/WearCommunicateProtocolTest.ktindex 600ad352e0..a85921c978 100644--- a/communicate-wear/src/test/java/com/vayunmathur/communicate/wear/domain/WearCommunicateProtocolTest.kt+++ b/communicate-wear/src/test/java/com/vayunmathur/communicate/wear/domain/WearCommunicateProtocolTest.kt@@ -1,10 +1,28 @@ package com.vayunmathur.communicate.wear.domain ++import com.vayunmathur.library.wearlink.communicate.WearCallEntry+import com.vayunmathur.library.wearlink.communicate.WearCommLine+import com.vayunmathur.library.wearlink.communicate.WearCommOp+import com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol+import com.vayunmathur.library.wearlink.communicate.WearCommunicateSnapshot+import com.vayunmathur.library.wearlink.communicate.WearMessage+import com.vayunmathur.library.wearlink.communicate.WearOpKind+import com.vayunmathur.library.wearlink.communicate.WearOpResult+import com.vayunmathur.library.wearlink.communicate.WearThread+import com.vayunmathur.library.wearlink.communicate.WearVoicemail+import com.vayunmathur.library.wearlink.communicate.buildWearCommunicateSnapshot+import com.vayunmathur.library.wearlink.communicate.buildWearNewMessageAlert+import com.vayunmathur.library.wearlink.communicate.buildWearThreadPage+import com.vayunmathur.library.wearlink.communicate.mergeWearThreadPage+import com.vayunmathur.library.wearlink.communicate.pendingAfterResult+import com.vayunmathur.library.wearlink.communicate.validWearReply+import com.vayunmathur.library.wearlink.communicate.wearThreadKey+import kotlinx.serialization.encodeToString import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue-import kotlinx.serialization.encodeToString  class WearCommunicateProtocolTest { 
communicate/AGENTS.md
diff --git a/communicate/AGENTS.md b/communicate/AGENTS.mdindex 51285da35e..aaccf5027a 100644--- a/communicate/AGENTS.md+++ b/communicate/AGENTS.md@@ -6,7 +6,7 @@ _Install: ./install communicate (dev by default)._ - Gradle: :communicate / dir: communicate/ - Package roots present: ui, data, domain, intents, service, telephony, notifications - Entry files: MainActivity.kt, Route.kt, Navigation.kt-- Deps: :library:network, :library:image, :library:room, :library:aosp-stubs (compileOnly)+- Deps: :library:network, :library:image, :library:room, :library:aosp-stubs (compileOnly), :library:wearlink - Metadata: metadata_data/communicate.md (present) - Rust: no (both crates live in `:communicate-dev`) / screenshotTest: yes @@ -37,6 +37,7 @@ _Install: ./install communicate (dev by default)._ - com/vayunmathur/communicate/data/CommunicateRepositoryMerged.kt — plus per-line splits (`Sim`, `Send`, `Rcs`, `Signal`, `WhatsApp`) - com/vayunmathur/communicate/data/SimManager.kt - com/vayunmathur/communicate/data/SecretSealer.kt+- com/vayunmathur/communicate/data/WearCommunicateSync.kt — phone side of the wear companion; wire protocol `com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol` in `:library:wearlink` (shared with `:communicate-wear`; each side's `WearCommunicateProtocolTest` pins the same golden JSON) ### data/googlevoice/ — Voice line (RPC + SIP calls) - com/vayunmathur/communicate/data/googlevoice/GoogleVoiceClient.kt - com/vayunmathur/communicate/data/googlevoice/GoogleVoiceSession.kt
communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.ktindex 346a10442e..8fc4706bc0 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt@@ -4,26 +4,26 @@ import android.content.Context import com.vayunmathur.communicate.data.call.InAppCallPhase import com.vayunmathur.communicate.data.call.InAppCallRegistry import com.vayunmathur.communicate.data.googlevoice.GoogleVoiceParser-import com.vayunmathur.communicate.domain.WearCommLine-import com.vayunmathur.communicate.domain.WearCommOp-import com.vayunmathur.communicate.domain.WearCommWatchState-import com.vayunmathur.communicate.domain.WearCommunicateProtocol-import com.vayunmathur.communicate.domain.WearCommunicateSnapshot-import com.vayunmathur.communicate.domain.WearIncomingCall-import com.vayunmathur.communicate.domain.WearMessage-import com.vayunmathur.communicate.domain.WearOpKind-import com.vayunmathur.communicate.domain.WearOpResult-import com.vayunmathur.communicate.domain.WearThread-import com.vayunmathur.communicate.domain.WearThreadRequest-import com.vayunmathur.communicate.domain.buildWearCommunicateSnapshot-import com.vayunmathur.communicate.domain.buildWearNewMessageAlert-import com.vayunmathur.communicate.domain.buildWearThreadPage-import com.vayunmathur.communicate.domain.validWearReply-import com.vayunmathur.communicate.domain.wearThreadKey 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.communicate.WearCommLine+import com.vayunmathur.library.wearlink.communicate.WearCommOp+import com.vayunmathur.library.wearlink.communicate.WearCommWatchState+import com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol+import com.vayunmathur.library.wearlink.communicate.WearCommunicateSnapshot+import com.vayunmathur.library.wearlink.communicate.WearIncomingCall+import com.vayunmathur.library.wearlink.communicate.WearMessage+import com.vayunmathur.library.wearlink.communicate.WearOpKind+import com.vayunmathur.library.wearlink.communicate.WearOpResult+import com.vayunmathur.library.wearlink.communicate.WearThread+import com.vayunmathur.library.wearlink.communicate.WearThreadRequest+import com.vayunmathur.library.wearlink.communicate.buildWearCommunicateSnapshot+import com.vayunmathur.library.wearlink.communicate.buildWearNewMessageAlert+import com.vayunmathur.library.wearlink.communicate.buildWearThreadPage+import com.vayunmathur.library.wearlink.communicate.validWearReply+import com.vayunmathur.library.wearlink.communicate.wearThreadKey import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob@@ -350,8 +350,8 @@ class WearCommunicateSync private constructor(context: Context) {         )     } -    private fun CommunicateCallLogEntry.toWearCall(): com.vayunmathur.communicate.domain.WearCallEntry =-        com.vayunmathur.communicate.domain.WearCallEntry(+    private fun CommunicateCallLogEntry.toWearCall(): com.vayunmathur.library.wearlink.communicate.WearCallEntry =+        com.vayunmathur.library.wearlink.communicate.WearCallEntry(             key = "${line.name}:$id",             displayName = displayName ?: phoneNumber,             phoneNumber = phoneNumber,@@ -361,8 +361,8 @@ class WearCommunicateSync private constructor(context: Context) {             line = line.toWearLine(),         ) -    private fun VoicemailEntry.toWearVoicemail(): com.vayunmathur.communicate.domain.WearVoicemail =-        com.vayunmathur.communicate.domain.WearVoicemail(+    private fun VoicemailEntry.toWearVoicemail(): com.vayunmathur.library.wearlink.communicate.WearVoicemail =+        com.vayunmathur.library.wearlink.communicate.WearVoicemail(             key = wearVoicemailKey(this),             phoneNumber = phoneNumber,             timestampMillis = timestampMillis,
communicate/src/test/java/com/vayunmathur/communicate/data/WearCommunicateOpTest.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/data/WearCommunicateOpTest.kt b/communicate/src/test/java/com/vayunmathur/communicate/data/WearCommunicateOpTest.ktindex 9d149fc991..00b09e47e7 100644--- a/communicate/src/test/java/com/vayunmathur/communicate/data/WearCommunicateOpTest.kt+++ b/communicate/src/test/java/com/vayunmathur/communicate/data/WearCommunicateOpTest.kt@@ -1,13 +1,13 @@ package com.vayunmathur.communicate.data -import com.vayunmathur.communicate.domain.WearCommLine-import com.vayunmathur.communicate.domain.WearCommOp-import com.vayunmathur.communicate.domain.WearOpKind+import com.vayunmathur.library.wearlink.communicate.WearCommLine+import com.vayunmathur.library.wearlink.communicate.WearCommOp+import com.vayunmathur.library.wearlink.communicate.WearOpKind+import kotlinx.coroutines.runBlocking import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue-import kotlinx.coroutines.runBlocking  class WearCommunicateOpTest { 
communicate/src/test/java/com/vayunmathur/communicate/domain/WearCommunicateProtocolTest.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/domain/WearCommunicateProtocolTest.kt b/communicate/src/test/java/com/vayunmathur/communicate/domain/WearCommunicateProtocolTest.ktindex cb4fba2b14..bd3419b86c 100644--- a/communicate/src/test/java/com/vayunmathur/communicate/domain/WearCommunicateProtocolTest.kt+++ b/communicate/src/test/java/com/vayunmathur/communicate/domain/WearCommunicateProtocolTest.kt@@ -1,10 +1,28 @@ package com.vayunmathur.communicate.domain ++import com.vayunmathur.library.wearlink.communicate.WearCallEntry+import com.vayunmathur.library.wearlink.communicate.WearCommLine+import com.vayunmathur.library.wearlink.communicate.WearCommOp+import com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol+import com.vayunmathur.library.wearlink.communicate.WearCommunicateSnapshot+import com.vayunmathur.library.wearlink.communicate.WearMessage+import com.vayunmathur.library.wearlink.communicate.WearOpKind+import com.vayunmathur.library.wearlink.communicate.WearOpResult+import com.vayunmathur.library.wearlink.communicate.WearThread+import com.vayunmathur.library.wearlink.communicate.WearVoicemail+import com.vayunmathur.library.wearlink.communicate.buildWearCommunicateSnapshot+import com.vayunmathur.library.wearlink.communicate.buildWearNewMessageAlert+import com.vayunmathur.library.wearlink.communicate.buildWearThreadPage+import com.vayunmathur.library.wearlink.communicate.mergeWearThreadPage+import com.vayunmathur.library.wearlink.communicate.pendingAfterResult+import com.vayunmathur.library.wearlink.communicate.validWearReply+import com.vayunmathur.library.wearlink.communicate.wearThreadKey+import kotlinx.serialization.encodeToString import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue-import kotlinx.serialization.encodeToString  class WearCommunicateProtocolTest { 
docs/structure/wear-protocol-pairs.tsv
diff --git a/docs/structure/wear-protocol-pairs.tsv b/docs/structure/wear-protocol-pairs.tsvindex 63e69e25cb..9438c47c40 100644--- a/docs/structure/wear-protocol-pairs.tsv+++ b/docs/structure/wear-protocol-pairs.tsv@@ -15,7 +15,7 @@ # (com.vayunmathur.library.wearlink.maps), appstore # (com.vayunmathur.library.wearlink.appstore), contacts # (com.vayunmathur.library.wearlink.contacts), findfamily-# (com.vayunmathur.library.wearlink.findfamily).-camera	camera/src/main/java/com/vayunmathur/camera/domain/WearCameraProtocol.kt	camera-wear/src/main/java/com/vayunmathur/camera/wear/domain/WearCameraProtocol.kt-communicate	communicate/src/main/java/com/vayunmathur/communicate/domain/WearCommunicateProtocol.kt	communicate-wear/src/main/java/com/vayunmathur/communicate/wear/domain/WearCommunicateProtocol.kt-todo	todo/src/main/java/com/vayunmathur/todo/domain/WearTodoProtocol.kt	todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.kt+# (com.vayunmathur.library.wearlink.findfamily), todo+# (com.vayunmathur.library.wearlink.todo), communicate+# (com.vayunmathur.library.wearlink.communicate), camera+# (com.vayunmathur.library.wearlink.camera).
library/wearlink/AGENTS.md
diff --git a/library/wearlink/AGENTS.md b/library/wearlink/AGENTS.mdindex 61d490de65..8f10cd4b8f 100644--- a/library/wearlink/AGENTS.md+++ b/library/wearlink/AGENTS.md@@ -17,7 +17,7 @@ duplicated per app pair: each migrated protocol lives in `com.vayunmathur.library.wearlink.<app>` and is consumed by both the phone and wear app modules (which may not depend on each other). Golden-JSON tests stay in each app module and pin the shared code's wire format.-Migrated: clock, launcher, calendar, weather, music, notes, maps, appstore, contacts, findfamily. Remaining pairs are listed in+Migrated: clock, launcher, calendar, weather, music, notes, maps, appstore, contacts, findfamily, todo, communicate, camera. Remaining pairs are listed in `docs/structure/wear-protocol-pairs.tsv`.  ## Verify
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/camera/WearCameraProtocol.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/domain/WearCameraProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/camera/WearCameraProtocol.ktsimilarity index 96%rename from camera/src/main/java/com/vayunmathur/camera/domain/WearCameraProtocol.ktrename to library/wearlink/src/main/java/com/vayunmathur/library/wearlink/camera/WearCameraProtocol.ktindex 0b37881bb8..981bb6a414 100644--- a/camera/src/main/java/com/vayunmathur/camera/domain/WearCameraProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/camera/WearCameraProtocol.kt@@ -1,4 +1,4 @@-package com.vayunmathur.camera.domain+package com.vayunmathur.library.wearlink.camera  import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString@@ -7,12 +7,9 @@ import kotlinx.serialization.json.Json /**  * Phone <-> watch protocol for the Wear OS Camera companion.  *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module (`:camera-wear`,- * applicationId `com.vayunmathur.camera`) carries a copy of this file under- * `com.vayunmathur.camera.wear.domain`. Change both copies together; each- * side's unit tests pin the same golden JSON/frame bytes so a one-sided- * edit fails loudly.+ * Shared by the phone (`:camera`) and the watch (`:camera-wear`) through+ * `:library:wearlink`; neither app module depends on the other. Each+ * side's tests pin the same golden JSON/frame bytes against this code.  *  * Transport (WearLink, :library:wearlink — RFCOMM, no Play services):  * - Presence is a completed handshake for [CAPABILITY] (the appId).
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/communicate/WearCommunicateProtocol.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/domain/WearCommunicateProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/communicate/WearCommunicateProtocol.ktsimilarity index 97%rename from communicate/src/main/java/com/vayunmathur/communicate/domain/WearCommunicateProtocol.ktrename to library/wearlink/src/main/java/com/vayunmathur/library/wearlink/communicate/WearCommunicateProtocol.ktindex 1ac9aed386..af73bbd6f8 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/domain/WearCommunicateProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/communicate/WearCommunicateProtocol.kt@@ -1,4 +1,4 @@-package com.vayunmathur.communicate.domain+package com.vayunmathur.library.wearlink.communicate  import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString@@ -7,12 +7,9 @@ import kotlinx.serialization.json.Json /**  * Phone <-> watch protocol for the Wear OS Communicate companion.  *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module- * (`:communicate-wear`, applicationId `com.vayunmathur.communicate`) carries- * a copy of this file under `com.vayunmathur.communicate.wear.domain`.- * Change both copies together; each side's unit tests pin the same golden- * JSON so a one-sided edit fails loudly.+ * Shared by the phone (`:communicate`) and the watch (`:communicate-wear`)+ * through `:library:wearlink`; neither app module depends on the other.+ * Each side's tests pin the same golden JSON against this code.  *  * The watch mirrors the phone app's navigation, not a glance card:  * conversation list (all lines the phone merges: SIM / Google Voice /
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/todo/WearTodoProtocol.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/domain/WearTodoProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/todo/WearTodoProtocol.ktsimilarity index 96%rename from todo/src/main/java/com/vayunmathur/todo/domain/WearTodoProtocol.ktrename to library/wearlink/src/main/java/com/vayunmathur/library/wearlink/todo/WearTodoProtocol.ktindex 1df736226f..f62442bbf7 100644--- a/todo/src/main/java/com/vayunmathur/todo/domain/WearTodoProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/todo/WearTodoProtocol.kt@@ -1,4 +1,4 @@-package com.vayunmathur.todo.domain+package com.vayunmathur.library.wearlink.todo  import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString@@ -7,11 +7,9 @@ import kotlinx.serialization.json.Json /**  * Phone <-> watch protocol for the Wear OS Todo companion.  *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module (`:todo-wear`,- * applicationId `com.vayunmathur.todo`) carries a copy of this file under- * `com.vayunmathur.todo.wear.domain`. Change both copies together; each- * side's unit tests pin the same golden JSON so a one-sided edit fails loudly.+ * Shared by the phone (`:todo`) and the watch (`:todo-wear`) through+ * `:library:wearlink`; neither app module depends on the other. Each+ * side's tests pin the same golden JSON against this code.  *  * The watch mirrors the phone app's navigation, not a glance card: the phone  * `Route.TodoList(viewKey)` destinations (smart views, per-list views, tag
todo-wear/AGENTS.md
diff --git a/todo-wear/AGENTS.md b/todo-wear/AGENTS.mdindex 488d7a51ed..195cd25348 100644--- a/todo-wear/AGENTS.md+++ b/todo-wear/AGENTS.md@@ -33,9 +33,11 @@ sideload of this APK onto the watch.   available in the phone detail editor the watch data comes from.  ## Protocol-`domain/WearTodoProtocol.kt` is a copy of the phone's file (Gradle cannot-depend on another app module). Change both copies together; each side's-`WearTodoProtocolTest` pins the same golden JSON.+The wire protocol lives in `:library:wearlink` at+`com.vayunmathur.library.wearlink.todo.WearTodoProtocol` (shared by+`:todo` and `:todo-wear`; neither app module depends on the other). Each+side's `WearTodoProtocolTest` pins the same golden JSON against that+shared code.  - Catalog + page snapshots: WearLink data items (`/todo/catalog`,   `/todo/page`, phone -> watch; paginated, PAGE_SIZE tasks per page)
todo-wear/src/main/java/com/vayunmathur/todo/wear/data/WearTodoStore.kt
diff --git a/todo-wear/src/main/java/com/vayunmathur/todo/wear/data/WearTodoStore.kt b/todo-wear/src/main/java/com/vayunmathur/todo/wear/data/WearTodoStore.ktindex 381a8b8390..273d801e79 100644--- a/todo-wear/src/main/java/com/vayunmathur/todo/wear/data/WearTodoStore.kt+++ b/todo-wear/src/main/java/com/vayunmathur/todo/wear/data/WearTodoStore.kt@@ -2,18 +2,18 @@ package com.vayunmathur.todo.wear.data  import android.content.Context import com.vayunmathur.library.log.Log-import com.vayunmathur.todo.wear.domain.WearTodoCatalog-import com.vayunmathur.todo.wear.domain.WearTodoOp-import com.vayunmathur.todo.wear.domain.WearTodoOpKind-import com.vayunmathur.todo.wear.domain.WearTodoPage-import com.vayunmathur.todo.wear.domain.WearTodoProtocol-import com.vayunmathur.todo.wear.domain.pendingOpsNotReflectedBy-import java.io.File-import java.util.UUID+import com.vayunmathur.library.wearlink.todo.WearTodoCatalog+import com.vayunmathur.library.wearlink.todo.WearTodoOp+import com.vayunmathur.library.wearlink.todo.WearTodoOpKind+import com.vayunmathur.library.wearlink.todo.WearTodoPage+import com.vayunmathur.library.wearlink.todo.WearTodoProtocol+import com.vayunmathur.library.wearlink.todo.pendingOpsNotReflectedBy import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.serialization.encodeToString+import java.io.File+import java.util.UUID  /**  * The watch's local cache: the last phone catalog, every visited page
todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.kt
diff --git a/todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.kt b/todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.ktdeleted file mode 100644index a739a9341c..0000000000--- a/todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.kt+++ /dev/null@@ -1,331 +0,0 @@-package com.vayunmathur.todo.wear.domain--import kotlinx.serialization.Serializable-import kotlinx.serialization.encodeToString-import kotlinx.serialization.json.Json--/**- * Phone <-> watch protocol for the Wear OS Todo companion.- *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module (`:todo-wear`,- * applicationId `com.vayunmathur.todo`) carries a copy of this file under- * `com.vayunmathur.todo.wear.domain`. Change both copies together; each- * side's unit tests pin the same golden JSON so a one-sided edit fails loudly.- *- * The watch mirrors the phone app's navigation, not a glance card: the phone- * `Route.TodoList(viewKey)` destinations (smart views, per-list views, tag- * views) become watch pages with the SAME [WearTodoViewEntry.key] strings- * (`TodoView.key`: "inbox", "today", "upcoming", "priority", "all",- * "completed", "list:<syncId>", "tag:<tag>"), and `Route.TodoDetail(id)`- * becomes a watch task page keyed by the task's stable syncId. The phone's- * `Route.Settings` has no watch counterpart (see todo-wear/AGENTS.md).- *- * Transport (WearLink, :library:wearlink — RFCOMM, no Play services):- * - Data items: [CATALOG_PATH] phone -> watch (view index with counts),- *   [PAGE_PATH] phone -> watch (one bounded paginated page snapshot),- *   [WATCH_STATE_PATH] watch -> phone (what the watch cached + pending ops).- * - Messages: [OP_PATH] watch -> phone (one op), [REQUEST_PAGE_PATH]- *   watch -> phone (ask for one page), [REQUEST_SYNC_PATH] watch -> phone- *   (ask for catalog + the default/last pages). Delivery needs a live- *   session; nothing wakes a dead phone process, so the watch caches every- *   catalog/page it receives and reads fully offline.- *- * Data lives on the phone. The watch never holds the task database: it- * renders cached catalog/page snapshots and queues ops. Ops apply on the- * phone only (source of truth); an op stays pending on the watch until a- * refreshed catalog/page reflects it, and the watch UI says so.- */-object WearTodoProtocol {-    /** WearLink appId the phone requires in the peer handshake. */-    const val CAPABILITY = "todo_wear_companion"--    /** Data-item path (phone -> watch): the [WearTodoCatalog] JSON. */-    const val CATALOG_PATH = "/todo/catalog"--    /** Data-item path (phone -> watch): one [WearTodoPage] JSON. */-    const val PAGE_PATH = "/todo/page"--    /** Data-item path (watch -> phone): the [WearTodoWatchState] JSON. */-    const val WATCH_STATE_PATH = "/todo/watch-state"--    /** Message path (watch -> phone): one [WearTodoOp] JSON. */-    const val OP_PATH = "/todo/op"--    /** Message path (watch -> phone): one [WearTodoPageRequest] JSON. */-    const val REQUEST_PAGE_PATH = "/todo/request-page"--    /** Message path (watch -> phone): ask for catalog + default pages. */-    const val REQUEST_SYNC_PATH = "/todo/request-sync"--    /** Tasks per page snapshot; "load more" fetches the next offset. */-    const val PAGE_SIZE = 20--    /** Largest catalog/page JSON in UTF-8 bytes (near the old 100 KB ceiling). */-    const val MAX_JSON_BYTES = 90_000--    /** Largest view index kept in one catalog; extras are dropped (tags last). */-    const val MAX_VIEWS = 100--    /** Field caps applied when a snapshot is built. */-    const val MAX_TITLE_CHARS = 120-    const val MAX_NOTES_CHARS = 1_000-    const val MAX_SUBTASKS = 20--    /** Cap on watch-entered text (quick-add / edit title) before it is sent. */-    const val MAX_TEXT_CHARS = 500--    /** Wire JSON: unknown keys ignored so a newer side never breaks an older one. */-    val json: Json = Json { ignoreUnknownKeys = true }-}--/** One phone navigation destination in the watch catalog (a `TodoView.key`). */-@Serializable-data class WearTodoViewEntry(-    val key: String,-    val title: String,-    /** SMART, LIST or TAG — mirrors the phone drawer's sections. */-    val kind: String = "SMART",-    val openCount: Int = 0,-    val totalCount: Int = 0,-)--/** The phone's view index for the watch home page ([WearTodoProtocol.CATALOG_PATH]). */-@Serializable-data class WearTodoCatalog(-    val generatedAtMillis: Long = 0L,-    val views: List<WearTodoViewEntry> = emptyList(),-    /** The phone's default view key; the watch opens here first. */-    val defaultViewKey: String = "today",-    /** True when the view-count/byte caps dropped entries. */-    val truncated: Boolean = false,-)--/** One subtask trimmed to watch size, shown on the task page. */-@Serializable-data class WearTodoSubtask(-    val syncId: String,-    val title: String,-    val done: Boolean = false,-)--/** One top-level task trimmed to watch size. [syncId] is the stable sync identity. */-@Serializable-data class WearTodoTask(-    val syncId: String,-    val title: String,-    val notes: String = "",-    val done: Boolean = false,-    val dueAt: Long? = null,-    val dueAllDay: Boolean = true,-    val priority: Int = 0,-    val listSyncId: String? = null,-    val listName: String? = null,-    val section: String? = null,-    val tags: List<String> = emptyList(),-    val recurrence: String? = null,-    val reminderAt: Long? = null,-    val completedAt: Long? = null,-    val updatedAt: Long = 0L,-    val subtasks: List<WearTodoSubtask> = emptyList(),-    val overdue: Boolean = false,-    val blocked: Boolean = false,-    /** Due-bucket / section / "Completed" label the phone list groups this row under. */-    val groupLabel: String = "",-    val notesTruncated: Boolean = false,-)--/**- * One bounded page of one view ([WearTodoProtocol.PAGE_PATH]). Paging is by- * [offset] into the phone-ordered rows of [pageKey]; [totalCount] is the- * full row count on the phone at [generatedAtMillis].- */-@Serializable-data class WearTodoPage(-    val pageKey: String,-    val title: String = "",-    val generatedAtMillis: Long = 0L,-    val offset: Int = 0,-    val totalCount: Int = 0,-    val tasks: List<WearTodoTask> = emptyList(),-    /** True when the byte cap cut this page short (the rest pages normally). */-    val truncated: Boolean = false,-) {-    val hasMore: Boolean get() = offset + tasks.size < totalCount-    val nextOffset: Int get() = offset + tasks.size-}--/** What the watch last cached, published at [WearTodoProtocol.WATCH_STATE_PATH]. */-@Serializable-data class WearTodoWatchState(-    val appliedCatalogAtMillis: Long = 0L,-    val cachedPages: Int = 0,-    /** Watch-originated ops not yet reflected by the phone. */-    val pendingOps: Int = 0,-)--/** Ask the phone for one page (message [WearTodoProtocol.REQUEST_PAGE_PATH]). */-@Serializable-data class WearTodoPageRequest(-    val pageKey: String,-    val offset: Int = 0,-)--/** Kind of a watch-originated change. */-@Serializable-enum class WearTodoOpKind { SET_DONE, SNOOZE_HOUR, SNOOZE_TOMORROW, QUICK_ADD, EDIT, DELETE }--/**- * One watch-originated op, as [WearTodoProtocol.OP_PATH]. [opId] is unique- * per user action so quick-adds never dedupe against each other; the other- * kinds carry the target task's [syncId]. EDIT uses null fields for- * "unchanged" and [clearDue] for removing the due date. QUICK_ADD carries- * raw [text] — the PHONE parses it with its QuickAddParser, so watch- * dictation gets the phone's exact date/list/tag/priority semantics.- */-@Serializable-data class WearTodoOp(-    val kind: WearTodoOpKind,-    val opId: String = "",-    val syncId: String = "",-    val done: Boolean = false,-    val text: String = "",-    val pageKey: String = "",-    val title: String? = null,-    val dueAt: Long? = null,-    val clearDue: Boolean = false,-    val priority: Int? = null,-)--/**- * Pending ops that a republished [page] does NOT yet reflect, in queue order.- *- * A page reflects SET_DONE/EDIT/QUICK_ADD by carrying the target task (for- * QUICK_ADD, the task the phone created carries the op's [WearTodoOp.syncId]);- * carrying the task is positive proof, so it holds even on a truncated page.- * It reflects DELETE only by no longer carrying the task on a non-truncated- * page: a truncated page may have byte-cap-dropped the still-live task, so- * its absence proves nothing and the delete stays queued. SNOOZE ops carry- * no page-visible target value, so a page can never prove them reflected- * and they stay queued.- */-fun pendingOpsNotReflectedBy(-    pendingOps: List<WearTodoOp>,-    page: WearTodoPage,-): List<WearTodoOp> {-    if (pendingOps.isEmpty()) return pendingOps-    val ids = page.tasks.flatMap { listOf(it.syncId) + it.subtasks.map { s -> s.syncId } }.toSet()-    return pendingOps.filter { op ->-        when (op.kind) {-            WearTodoOpKind.SET_DONE, WearTodoOpKind.EDIT,-            WearTodoOpKind.QUICK_ADD -> op.syncId !in ids-            WearTodoOpKind.DELETE -> op.syncId in ids || page.truncated-            WearTodoOpKind.SNOOZE_HOUR, WearTodoOpKind.SNOOZE_TOMORROW -> true-        }-    }-}--/** Builds a bounded catalog: view caps then the byte cap (last entries drop first). */-fun buildWearCatalog(-    views: List<WearTodoViewEntry>,-    generatedAtMillis: Long,-    defaultViewKey: String,-): WearTodoCatalog {-    var kept = views.take(WearTodoProtocol.MAX_VIEWS)-    var truncated = kept.size < views.size-    var catalog = WearTodoCatalog(generatedAtMillis, kept, defaultViewKey, truncated)-    while (kept.isNotEmpty() &&-        WearTodoProtocol.json.encodeToString(catalog).encodeToByteArray().size >-        WearTodoProtocol.MAX_JSON_BYTES-    ) {-        kept = kept.dropLast(1)-        truncated = true-        catalog = catalog.copy(views = kept, truncated = true)-    }-    return catalog-}--/**- * Builds one bounded page: field caps, the [WearTodoProtocol.PAGE_SIZE]- * slice at [offset], then the byte cap enforced by shortening the page- * (paging continues from the shortened end via [WearTodoPage.nextOffset]).- */-fun buildWearPage(-    pageKey: String,-    title: String,-    allTasks: List<WearTodoTask>,-    offset: Int,-    generatedAtMillis: Long,-): WearTodoPage {-    val capped = allTasks.map { task ->-        task.copy(-            title = task.title.take(WearTodoProtocol.MAX_TITLE_CHARS),-            notes = task.notes.take(WearTodoProtocol.MAX_NOTES_CHARS),-            notesTruncated = task.notesTruncated ||-                task.notes.length > WearTodoProtocol.MAX_NOTES_CHARS,-            subtasks = task.subtasks.take(WearTodoProtocol.MAX_SUBTASKS).map {-                it.copy(title = it.title.take(WearTodoProtocol.MAX_TITLE_CHARS))-            },-        )-    }-    val safeOffset = offset.coerceIn(0, capped.size)-    var kept = capped.drop(safeOffset).take(WearTodoProtocol.PAGE_SIZE)-    var page = WearTodoPage(-        pageKey = pageKey,-        title = title,-        generatedAtMillis = generatedAtMillis,-        offset = safeOffset,-        totalCount = capped.size,-        tasks = kept,-    )-    while (kept.isNotEmpty() &&-        WearTodoProtocol.json.encodeToString(page).encodeToByteArray().size >-        WearTodoProtocol.MAX_JSON_BYTES-    ) {-        kept = kept.dropLast(1)-        page = page.copy(tasks = kept, truncated = true)-    }-    return page-}--/**- * The watch's local view of a cached page while ops are pending: SET_DONE,- * EDIT and DELETE apply to the cached rows so the watch does not show- * pre-op state as truth; SNOOZE and QUICK_ADD cannot be rendered locally- * (the phone computes reminder times and parses quick-add text) and only- * count as pending. Phone snapshots remain the source of truth.- */-fun overlayPendingTasks(tasks: List<WearTodoTask>, pendingOps: List<WearTodoOp>): List<WearTodoTask> {-    if (pendingOps.isEmpty()) return tasks-    var result = tasks-    for (op in pendingOps) {-        result = when (op.kind) {-            WearTodoOpKind.DELETE -> result.filter { it.syncId != op.syncId }-            WearTodoOpKind.SET_DONE -> result.map { task ->-                when {-                    task.syncId == op.syncId -> task.copy(done = op.done)-                    task.subtasks.any { it.syncId == op.syncId } -> task.copy(-                        subtasks = task.subtasks.map {-                            if (it.syncId == op.syncId) it.copy(done = op.done) else it-                        },-                    )-                    else -> task-                }-            }-            WearTodoOpKind.EDIT -> result.map { task ->-                if (task.syncId != op.syncId) task else task.copy(-                    title = op.title?.take(WearTodoProtocol.MAX_TITLE_CHARS) ?: task.title,-                    dueAt = when {-                        op.clearDue -> null-                        op.dueAt != null -> op.dueAt-                        else -> task.dueAt-                    },-                    priority = op.priority ?: task.priority,-                )-            }-            WearTodoOpKind.SNOOZE_HOUR, WearTodoOpKind.SNOOZE_TOMORROW,-            WearTodoOpKind.QUICK_ADD -> result-        }-    }-    return result-}
todo-wear/src/main/java/com/vayunmathur/todo/wear/sync/WearLinkBridge.kt
diff --git a/todo-wear/src/main/java/com/vayunmathur/todo/wear/sync/WearLinkBridge.kt b/todo-wear/src/main/java/com/vayunmathur/todo/wear/sync/WearLinkBridge.ktindex ab5c02727e..f234ec8668 100644--- a/todo-wear/src/main/java/com/vayunmathur/todo/wear/sync/WearLinkBridge.kt+++ b/todo-wear/src/main/java/com/vayunmathur/todo/wear/sync/WearLinkBridge.kt@@ -5,12 +5,12 @@ 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.todo.WearTodoCatalog+import com.vayunmathur.library.wearlink.todo.WearTodoPage+import com.vayunmathur.library.wearlink.todo.WearTodoPageRequest+import com.vayunmathur.library.wearlink.todo.WearTodoProtocol+import com.vayunmathur.library.wearlink.todo.WearTodoWatchState import com.vayunmathur.todo.wear.data.WearTodoStore-import com.vayunmathur.todo.wear.domain.WearTodoCatalog-import com.vayunmathur.todo.wear.domain.WearTodoPage-import com.vayunmathur.todo.wear.domain.WearTodoPageRequest-import com.vayunmathur.todo.wear.domain.WearTodoProtocol-import com.vayunmathur.todo.wear.domain.WearTodoWatchState import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob
todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoHomeScreen.kt
diff --git a/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoHomeScreen.kt b/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoHomeScreen.ktindex dd505c7ed2..471e2f6d71 100644--- a/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoHomeScreen.kt+++ b/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoHomeScreen.kt@@ -46,7 +46,7 @@ fun WearTodoHomeScreen( /** Stateless home behind [WearTodoHomeScreen]: catalog/pending count are parameters for previews. */ @Composable internal fun WearTodoHomeContent(-    catalog: com.vayunmathur.todo.wear.domain.WearTodoCatalog,+    catalog: com.vayunmathur.library.wearlink.todo.WearTodoCatalog,     pendingCount: Int,     onOpenPage: (String) -> Unit,     onQuickAdd: () -> Unit,
todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoPageScreen.kt
diff --git a/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoPageScreen.kt b/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoPageScreen.ktindex 8a23c0b4a3..8034799bbc 100644--- a/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoPageScreen.kt+++ b/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoPageScreen.kt@@ -19,9 +19,9 @@ import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text+import com.vayunmathur.library.wearlink.todo.overlayPendingTasks import com.vayunmathur.todo.wear.R import com.vayunmathur.todo.wear.data.WearTodoStore-import com.vayunmathur.todo.wear.domain.overlayPendingTasks import com.vayunmathur.todo.wear.sync.WearLinkBridge import kotlinx.coroutines.launch @@ -71,7 +71,7 @@ fun WearTodoPageScreen( @Composable internal fun WearTodoPageContent(     title: String,-    tasks: List<com.vayunmathur.todo.wear.domain.WearTodoTask>,+    tasks: List<com.vayunmathur.library.wearlink.todo.WearTodoTask>,     slicesEmpty: Boolean,     hasMore: Boolean,     onOpenTask: (String) -> Unit,
todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoTaskScreen.kt
diff --git a/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoTaskScreen.kt b/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoTaskScreen.ktindex c19b3aad21..44129b58d7 100644--- a/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoTaskScreen.kt+++ b/todo-wear/src/main/java/com/vayunmathur/todo/wear/ui/WearTodoTaskScreen.kt@@ -16,9 +16,9 @@ import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text+import com.vayunmathur.library.wearlink.todo.overlayPendingTasks import com.vayunmathur.todo.wear.R import com.vayunmathur.todo.wear.data.WearTodoStore-import com.vayunmathur.todo.wear.domain.overlayPendingTasks import java.time.Instant import java.time.ZoneId import java.time.format.DateTimeFormatter@@ -47,7 +47,7 @@ fun WearTodoTaskScreen(         ?: allTasks.firstOrNull { parent -> parent.subtasks.any { it.syncId == syncId } }             ?.let { parent ->                 val sub = parent.subtasks.first { it.syncId == syncId }-                com.vayunmathur.todo.wear.domain.WearTodoTask(+                com.vayunmathur.library.wearlink.todo.WearTodoTask(                     syncId = sub.syncId,                     title = sub.title,                     done = sub.done,@@ -59,7 +59,7 @@ fun WearTodoTaskScreen( /** Stateless task detail behind [WearTodoTaskScreen]: the task is a parameter for previews. */ @Composable internal fun WearTodoTaskContent(-    task: com.vayunmathur.todo.wear.domain.WearTodoTask?,+    task: com.vayunmathur.library.wearlink.todo.WearTodoTask?,     onToggleSubtask: (String, Boolean) -> Unit,     onSetDone: (String, Boolean) -> Unit,     onSnooze: (String, Boolean) -> Unit,
todo-wear/src/screenshotTest/kotlin/com/vayunmathur/todo/wear/ui/MetadataPreviews.kt
diff --git a/todo-wear/src/screenshotTest/kotlin/com/vayunmathur/todo/wear/ui/MetadataPreviews.kt b/todo-wear/src/screenshotTest/kotlin/com/vayunmathur/todo/wear/ui/MetadataPreviews.ktindex 90ef3d6895..df231de16d 100644--- a/todo-wear/src/screenshotTest/kotlin/com/vayunmathur/todo/wear/ui/MetadataPreviews.kt+++ b/todo-wear/src/screenshotTest/kotlin/com/vayunmathur/todo/wear/ui/MetadataPreviews.kt@@ -10,10 +10,10 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.tooling.preview.Preview import androidx.wear.compose.material.MaterialTheme import com.android.tools.screenshot.PreviewTest-import com.vayunmathur.todo.wear.domain.WearTodoCatalog-import com.vayunmathur.todo.wear.domain.WearTodoSubtask-import com.vayunmathur.todo.wear.domain.WearTodoTask-import com.vayunmathur.todo.wear.domain.WearTodoViewEntry+import com.vayunmathur.library.wearlink.todo.WearTodoCatalog+import com.vayunmathur.library.wearlink.todo.WearTodoSubtask+import com.vayunmathur.library.wearlink.todo.WearTodoTask+import com.vayunmathur.library.wearlink.todo.WearTodoViewEntry  /** Round watch, 454x454px class (227dp at 320dpi). */ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"
todo-wear/src/test/java/com/vayunmathur/todo/wear/domain/WearTodoProtocolTest.kt
diff --git a/todo-wear/src/test/java/com/vayunmathur/todo/wear/domain/WearTodoProtocolTest.kt b/todo-wear/src/test/java/com/vayunmathur/todo/wear/domain/WearTodoProtocolTest.ktindex 04ff706fc7..294ee2842c 100644--- a/todo-wear/src/test/java/com/vayunmathur/todo/wear/domain/WearTodoProtocolTest.kt+++ b/todo-wear/src/test/java/com/vayunmathur/todo/wear/domain/WearTodoProtocolTest.kt@@ -1,15 +1,15 @@ package com.vayunmathur.todo.wear.domain -import com.vayunmathur.todo.wear.domain.WearTodoCatalog-import com.vayunmathur.todo.wear.domain.WearTodoOp-import com.vayunmathur.todo.wear.domain.WearTodoOpKind-import com.vayunmathur.todo.wear.domain.WearTodoPage-import com.vayunmathur.todo.wear.domain.WearTodoProtocol-import com.vayunmathur.todo.wear.domain.WearTodoTask-import com.vayunmathur.todo.wear.domain.WearTodoViewEntry-import com.vayunmathur.todo.wear.domain.buildWearPage-import com.vayunmathur.todo.wear.domain.overlayPendingTasks-import com.vayunmathur.todo.wear.domain.pendingOpsNotReflectedBy+import com.vayunmathur.library.wearlink.todo.WearTodoCatalog+import com.vayunmathur.library.wearlink.todo.WearTodoOp+import com.vayunmathur.library.wearlink.todo.WearTodoOpKind+import com.vayunmathur.library.wearlink.todo.WearTodoPage+import com.vayunmathur.library.wearlink.todo.WearTodoProtocol+import com.vayunmathur.library.wearlink.todo.WearTodoTask+import com.vayunmathur.library.wearlink.todo.WearTodoViewEntry+import com.vayunmathur.library.wearlink.todo.buildWearPage+import com.vayunmathur.library.wearlink.todo.overlayPendingTasks+import com.vayunmathur.library.wearlink.todo.pendingOpsNotReflectedBy import kotlinx.serialization.encodeToString import kotlin.test.Test import kotlin.test.assertEquals@@ -170,7 +170,7 @@ class WearTodoProtocolTest {      @Test     fun goldenWatchStateJson() {-        val state = com.vayunmathur.todo.wear.domain.WearTodoWatchState(+        val state = com.vayunmathur.library.wearlink.todo.WearTodoWatchState(             appliedCatalogAtMillis = 1_000L,             cachedPages = 2,             pendingOps = 3,
todo/AGENTS.md
diff --git a/todo/AGENTS.md b/todo/AGENTS.mdindex 89898dc19b..88825a540a 100644--- a/todo/AGENTS.md+++ b/todo/AGENTS.md@@ -6,7 +6,7 @@ _Install: ./install todo (dev by default)._ - Gradle: :todo / dir: todo/ - Package roots present: ui, data, domain, platform, sync, notifications, widget, service, intents - Entry files: MainActivity.kt, Route.kt, Navigation.kt, TodoApplication.kt-- Deps: :library:room, :library:widgets+- Deps: :library:room, :library:widgets, :library:wearlink - Metadata: metadata_data/todo.md (present) - Rust: no / screenshotTest: yes @@ -33,7 +33,7 @@ _Install: ./install todo (dev by default)._ ### platform/ - TodoViewModel.kt, TodoEditor.kt, TodoListUiContract.kt, TodoEditorUiContract.kt, TodoBackground.kt, IntentRouter.kt, TodoDataTransfer.kt, AppBackupAgent.kt ### sync/-- RelayTodoProvider.kt, RelayEnvelopes.kt, CalendarMirror.kt+- RelayTodoProvider.kt, RelayEnvelopes.kt, CalendarMirror.kt, WearTodoSync.kt (phone side of the wear companion; wire protocol `com.vayunmathur.library.wearlink.todo.WearTodoProtocol` in `:library:wearlink`, shared with `:todo-wear`) ### notifications/ widget/ service/ intents/ - ReminderScheduler, ReminderReceiver, ReminderActionReceiver, BootReceiver, DigestScheduler; TodayWidget, QuickAddWidget; QuickAddTileService; Get/Insert/CompleteTodoIntent (openassistant tools) 
todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt b/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.ktindex fb64fe1232..9a13d29ea5 100644--- a/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt+++ b/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt@@ -5,6 +5,18 @@ 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.todo.WearTodoCatalog+import com.vayunmathur.library.wearlink.todo.WearTodoOp+import com.vayunmathur.library.wearlink.todo.WearTodoOpKind+import com.vayunmathur.library.wearlink.todo.WearTodoPage+import com.vayunmathur.library.wearlink.todo.WearTodoPageRequest+import com.vayunmathur.library.wearlink.todo.WearTodoProtocol+import com.vayunmathur.library.wearlink.todo.WearTodoSubtask+import com.vayunmathur.library.wearlink.todo.WearTodoTask+import com.vayunmathur.library.wearlink.todo.WearTodoViewEntry+import com.vayunmathur.library.wearlink.todo.WearTodoWatchState+import com.vayunmathur.library.wearlink.todo.buildWearCatalog+import com.vayunmathur.library.wearlink.todo.buildWearPage import com.vayunmathur.todo.data.Todo import com.vayunmathur.todo.data.TodoRepository import com.vayunmathur.todo.data.getLists@@ -15,18 +27,6 @@ import com.vayunmathur.todo.domain.QuickAddParser import com.vayunmathur.todo.domain.Reminders import com.vayunmathur.todo.domain.TodoQuery import com.vayunmathur.todo.domain.TodoView-import com.vayunmathur.todo.domain.WearTodoCatalog-import com.vayunmathur.todo.domain.WearTodoOp-import com.vayunmathur.todo.domain.WearTodoOpKind-import com.vayunmathur.todo.domain.WearTodoPage-import com.vayunmathur.todo.domain.WearTodoPageRequest-import com.vayunmathur.todo.domain.WearTodoProtocol-import com.vayunmathur.todo.domain.WearTodoSubtask-import com.vayunmathur.todo.domain.WearTodoTask-import com.vayunmathur.todo.domain.WearTodoViewEntry-import com.vayunmathur.todo.domain.WearTodoWatchState-import com.vayunmathur.todo.domain.buildWearCatalog-import com.vayunmathur.todo.domain.buildWearPage import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job
todo/src/test/java/com/vayunmathur/todo/sync/WearTodoApplyTest.kt
diff --git a/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoApplyTest.kt b/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoApplyTest.ktindex 893a5482f3..c657403a19 100644--- a/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoApplyTest.kt+++ b/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoApplyTest.kt@@ -2,12 +2,12 @@ package com.vayunmathur.todo.sync  import android.content.Context import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.library.wearlink.todo.WearTodoOp+import com.vayunmathur.library.wearlink.todo.WearTodoOpKind import com.vayunmathur.todo.data.TestTodoRepository import com.vayunmathur.todo.data.Todo import com.vayunmathur.todo.data.TodoRepository import com.vayunmathur.todo.domain.DueDates-import com.vayunmathur.todo.domain.WearTodoOp-import com.vayunmathur.todo.domain.WearTodoOpKind import kotlinx.coroutines.test.runTest import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone@@ -177,13 +177,13 @@ class WearTodoApplyTest {     @Test fun pageSnapshotPagesThroughView() = runTest {         repeat(25) { repo.upsert(Todo(syncId = "t$it", title = "Task $it", position = it.toDouble())) }         val first = sync.buildPage(-            com.vayunmathur.todo.domain.WearTodoPageRequest("all", 0), now,+            com.vayunmathur.library.wearlink.todo.WearTodoPageRequest("all", 0), now,         )         assertEquals(25, first.totalCount)         assertEquals(20, first.tasks.size)         assertTrue(first.hasMore)         val second = sync.buildPage(-            com.vayunmathur.todo.domain.WearTodoPageRequest("all", first.nextOffset), now,+            com.vayunmathur.library.wearlink.todo.WearTodoPageRequest("all", first.nextOffset), now,         )         assertEquals(5, second.tasks.size)         assertFalse(second.hasMore)
todo/src/test/java/com/vayunmathur/todo/sync/WearTodoProtocolTest.kt
diff --git a/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoProtocolTest.kt b/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoProtocolTest.ktindex 5b8ba90862..575693bf85 100644--- a/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoProtocolTest.kt+++ b/todo/src/test/java/com/vayunmathur/todo/sync/WearTodoProtocolTest.kt@@ -1,16 +1,16 @@ package com.vayunmathur.todo.sync -import com.vayunmathur.todo.domain.WearTodoCatalog-import com.vayunmathur.todo.domain.WearTodoOp-import com.vayunmathur.todo.domain.WearTodoOpKind-import com.vayunmathur.todo.domain.WearTodoPage-import com.vayunmathur.todo.domain.WearTodoProtocol-import com.vayunmathur.todo.domain.WearTodoTask-import com.vayunmathur.todo.domain.WearTodoViewEntry-import com.vayunmathur.todo.domain.WearTodoWatchState-import com.vayunmathur.todo.domain.buildWearPage-import com.vayunmathur.todo.domain.overlayPendingTasks-import com.vayunmathur.todo.domain.pendingOpsNotReflectedBy+import com.vayunmathur.library.wearlink.todo.WearTodoCatalog+import com.vayunmathur.library.wearlink.todo.WearTodoOp+import com.vayunmathur.library.wearlink.todo.WearTodoOpKind+import com.vayunmathur.library.wearlink.todo.WearTodoPage+import com.vayunmathur.library.wearlink.todo.WearTodoProtocol+import com.vayunmathur.library.wearlink.todo.WearTodoTask+import com.vayunmathur.library.wearlink.todo.WearTodoViewEntry+import com.vayunmathur.library.wearlink.todo.WearTodoWatchState+import com.vayunmathur.library.wearlink.todo.buildWearPage+import com.vayunmathur.library.wearlink.todo.overlayPendingTasks+import com.vayunmathur.library.wearlink.todo.pendingOpsNotReflectedBy import kotlinx.serialization.encodeToString import kotlin.test.Test import kotlin.test.assertEquals