library: launcher, calendar and weather wear protocols move into wearlink
- Commit
8a3089f51a8656e7ee686c0df93cd2e173577ecc- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 17:02 UTC (4 days ago)
- Parents
6d1c802
LOC Phase 2, pairs 2-4 (clock template). Each pair was verified byte-identical modulo package, moved to com.vayunmathur.library.wearlink.<app> under the same symbol names, both app copies deleted, consumers rewired — non-protocol same-package symbols (WearLauncherModel, WearAgenda, weather formatting) stayed put. Weather's 16-line phone golden test first gained the WearWatchState golden + round-trip coverage on both sides, then migrated. Net: launcher -103, calendar -136, weather -96. Both sides' golden tests now pin the shared code. structure_check wear: 9 pairs remain, OK. Verified per pair: wearlink tests, both protocol test classes, both wear full suites, compiles/assembles, lints — the only red is pre-existing detector errors in untouched launcher/ItemMenuContent.kt and weather/Route.kt. Co-resident calendar/weather WIP files were excluded from this commit.
Diff
calendar-wear/AGENTS.md
diff --git a/calendar-wear/AGENTS.md b/calendar-wear/AGENTS.mdindex b66b8672c3..eb62473b06 100644--- a/calendar-wear/AGENTS.md+++ b/calendar-wear/AGENTS.md@@ -16,9 +16,11 @@ sides, so changing either breaks phone<->watch sync. Bootstrap is a one-time ADB sideload of this APK onto the watch. ## Protocol-`domain/WearCalendarProtocol.kt` is a copy of the phone's file (Gradle cannot-depend on another app module). Change both copies together; each side's-`WearCalendarProtocolTest` pins the same golden JSON.+The wire protocol lives in `:library:wearlink` at+`com.vayunmathur.library.wearlink.calendar.WearCalendarProtocol` (shared by+`:calendar` and `:calendar:wear`; neither app module depends on the other).+Each side's `WearCalendarProtocolTest` pins the same golden JSON against+that shared code. - Snapshot + watch-state sync: WearLink data items (`/calendar/snapshot`, `/calendar/watch-state`) - Sync request: WearLink message (`/calendar/request-sync`), watch -> phone only
calendar-wear/build.gradle.kts
diff --git a/calendar-wear/build.gradle.kts b/calendar-wear/build.gradle.ktsindex 4d5869a21f..cfbc9b9447 100644--- a/calendar-wear/build.gradle.kts+++ b/calendar-wear/build.gradle.kts@@ -23,8 +23,7 @@ android { } dependencies {- // Watch side of the Wear OS sync (see domain/WearCalendarProtocol.kt, the- // copy of the phone protocol it must stay in step with).+ // Watch side of the Wear OS sync (protocol in :library:wearlink). implementation(libs.kotlinx.coroutines.android) implementation(project(":library:wearlink")) testImplementation(libs.kotlin.test)
calendar-wear/src/main/java/com/vayunmathur/calendar/wear/data/WearCalendarStore.kt
diff --git a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/data/WearCalendarStore.kt b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/data/WearCalendarStore.ktindex 2fd11b25a4..1230fe8a1c 100644--- a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/data/WearCalendarStore.kt+++ b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/data/WearCalendarStore.kt@@ -1,9 +1,9 @@ package com.vayunmathur.calendar.wear.data import android.content.Context-import com.vayunmathur.calendar.wear.domain.WearCalendarProtocol-import com.vayunmathur.calendar.wear.domain.WearCalendarSnapshot-import com.vayunmathur.calendar.wear.domain.WearWatchState+import com.vayunmathur.library.wearlink.calendar.WearCalendarProtocol+import com.vayunmathur.library.wearlink.calendar.WearCalendarSnapshot+import com.vayunmathur.library.wearlink.calendar.WearWatchState import com.vayunmathur.calendar.wear.sync.WearLinkBridge import com.vayunmathur.library.log.Log import java.io.File
calendar-wear/src/main/java/com/vayunmathur/calendar/wear/domain/WearAgenda.kt
diff --git a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/domain/WearAgenda.kt b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/domain/WearAgenda.ktindex 729ca52871..ca5eec0e8c 100644--- a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/domain/WearAgenda.kt+++ b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/domain/WearAgenda.kt@@ -1,4 +1,6 @@ package com.vayunmathur.calendar.wear.domain+import com.vayunmathur.library.wearlink.calendar.WearCalendarEvent+import com.vayunmathur.library.wearlink.calendar.WearCalendarSnapshot import kotlinx.datetime.DatePeriod import kotlinx.datetime.LocalDate
calendar-wear/src/main/java/com/vayunmathur/calendar/wear/domain/WearCalendarProtocol.kt
diff --git a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/domain/WearCalendarProtocol.kt b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/domain/WearCalendarProtocol.ktdeleted file mode 100644index 696c85c282..0000000000--- a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/domain/WearCalendarProtocol.kt+++ /dev/null@@ -1,148 +0,0 @@-package com.vayunmathur.calendar.wear.domain--import kotlinx.serialization.Serializable-import kotlinx.serialization.json.Json--/**- * Phone <-> watch sync protocol for the Wear OS Calendar companion.- *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module- * (`:calendar:wear`, applicationId `com.vayunmathur.calendar`) carries a copy- * of this file under `com.vayunmathur.calendar.wear.domain`. Change both- * copies together; each side's unit tests pin the same golden JSON so a- * one-sided edit fails loudly on the side that was not updated.- *- * Transport (WearLink, :library:wearlink — RFCOMM, no Play services):- * - Presence is a completed handshake for [CAPABILITY] (the appId).- * - Data items carry the snapshot: [SNAPSHOT_PATH] phone -> watch- * and [WATCH_STATE_PATH] watch -> phone. Delivery needs a live session;- * each side persists what it receives and republishes on reconnect.- * - Messages carry one ephemeral command, [REQUEST_SYNC_PATH]- * watch -> phone: the watch asks for a fresh snapshot. That is the only- * watch-originated write. There is no event editing or RSVP: the phone's- * calendar model has no attendee/self-status for its local calendars, so- * inventing an RSVP write would fake a change the provider never made.- */-object WearCalendarProtocol {- /** WearLink appId the phone requires in the peer handshake. */- const val CAPABILITY = "calendar_wear_companion"-- /** Data-item path (phone -> watch): the [WearCalendarSnapshot] JSON. */- const val SNAPSHOT_PATH = "/calendar/snapshot"-- /** Data-item path (watch -> phone): the [WearWatchState] JSON. */- const val WATCH_STATE_PATH = "/calendar/watch-state"-- /** Message path (watch -> phone): ask the phone to publish a fresh snapshot. */- const val REQUEST_SYNC_PATH = "/calendar/request-sync"-- /** Days ahead of the window start included in a snapshot. */- const val WINDOW_DAYS = 30-- /** Most events in one snapshot; a watch has little storage and a tiny screen. */- const val MAX_EVENTS = 200-- /**- * Largest snapshot JSON, in UTF-8 bytes. Deliberately kept near the old- * 100 KB DataItem ceiling: a bounded snapshot is what the watch can- * store/render, and WearLink chunks it transparently either way.- */- const val MAX_JSON_BYTES = 90_000-- /** Field caps applied when a snapshot is built, so one huge event cannot crowd out the rest. */- const val MAX_TITLE_CHARS = 120- const val MAX_LOCATION_CHARS = 120- const val MAX_DESCRIPTION_CHARS = 280- const val MAX_CALENDAR_NAME_CHARS = 60-- /** Wire JSON: unknown keys ignored so a newer side never breaks an older one. */- val json: Json = Json { ignoreUnknownKeys = true }-}--/** One event occurrence in a [WearCalendarSnapshot], trimmed to watch size. */-@Serializable-data class WearCalendarEvent(- /** Phone provider event id; with [startMillis] it identifies one occurrence. */- val eventId: Long,- val title: String,- val location: String = "",- val description: String = "",- val calendarName: String = "",- /** ARGB display colour of the owning calendar, 0 when unknown. */- val color: Int = 0,- val startMillis: Long,- val endMillis: Long,- val allDay: Boolean = false,- val timezone: String = "UTC",-)--/** The phone's bounded calendar snapshot for the watch ([WearCalendarProtocol.SNAPSHOT_PATH]). */-@Serializable-data class WearCalendarSnapshot(- /** When the phone built this snapshot, epoch millis. */- val generatedAtMillis: Long = 0L,- /** Inclusive window start, epoch millis; the watch renders only inside the window. */- val windowStartMillis: Long = 0L,- /** Exclusive window end, epoch millis (window start + [WearCalendarProtocol.WINDOW_DAYS] days). */- val windowEndMillis: Long = 0L,- val events: List<WearCalendarEvent> = emptyList(),- /** True when the window/size caps dropped events the window actually contained. */- val truncated: Boolean = false,-)--/** What the watch last applied, published at [WearCalendarProtocol.WATCH_STATE_PATH]. */-@Serializable-data class WearWatchState(- /** generatedAtMillis of the snapshot the watch is rendering from, 0 when none yet. */- val appliedGeneratedAtMillis: Long = 0L,- val eventCount: Int = 0,-)--/**- * Builds a bounded snapshot from [candidates]: keeps occurrences that overlap- * [[windowStartMillis], [windowEndMillis]), sorts by start, applies the field- * caps, then enforces [WearCalendarProtocol.MAX_EVENTS] and- * [WearCalendarProtocol.MAX_JSON_BYTES] (dropping latest-first, which keeps- * today's agenda — the watch's main screen — intact longest).- */-fun buildWearSnapshot(- candidates: List<WearCalendarEvent>,- generatedAtMillis: Long,- windowStartMillis: Long,- windowEndMillis: Long,-): WearCalendarSnapshot {- val inWindow = candidates- .filter { it.endMillis > windowStartMillis && it.startMillis < windowEndMillis }- .sortedWith(compareBy({ it.startMillis }, { it.eventId }))- .map { event ->- event.copy(- title = event.title.take(WearCalendarProtocol.MAX_TITLE_CHARS),- location = event.location.take(WearCalendarProtocol.MAX_LOCATION_CHARS),- description = event.description.take(WearCalendarProtocol.MAX_DESCRIPTION_CHARS),- calendarName = event.calendarName.take(WearCalendarProtocol.MAX_CALENDAR_NAME_CHARS),- )- }- var kept = inWindow.take(WearCalendarProtocol.MAX_EVENTS)- var truncated = kept.size < inWindow.size- var snapshot = WearCalendarSnapshot(- generatedAtMillis = generatedAtMillis,- windowStartMillis = windowStartMillis,- windowEndMillis = windowEndMillis,- events = kept,- truncated = truncated,- )- while (kept.isNotEmpty() &&- WearCalendarProtocol.json.encodeToString(snapshot).encodeToByteArray().size >- WearCalendarProtocol.MAX_JSON_BYTES- ) {- kept = kept.dropLast(1)- truncated = true- snapshot = snapshot.copy(events = kept, truncated = true)- }- return snapshot-}--/** True when [nodeIdsWithCapability] is non-empty: a watch companion is present. */-fun wearCompanionPresent(nodeIdsWithCapability: Collection<String>): Boolean =- nodeIdsWithCapability.isNotEmpty()
calendar-wear/src/main/java/com/vayunmathur/calendar/wear/sync/WearLinkBridge.kt
diff --git a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/sync/WearLinkBridge.kt b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/sync/WearLinkBridge.ktindex 01d84e5a8f..687bf07b66 100644--- a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/sync/WearLinkBridge.kt+++ b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/sync/WearLinkBridge.kt@@ -2,9 +2,9 @@ package com.vayunmathur.calendar.wear.sync import android.content.Context import com.vayunmathur.calendar.wear.data.WearCalendarStore-import com.vayunmathur.calendar.wear.domain.WearCalendarProtocol-import com.vayunmathur.calendar.wear.domain.WearCalendarSnapshot-import com.vayunmathur.calendar.wear.domain.WearWatchState+import com.vayunmathur.library.wearlink.calendar.WearCalendarProtocol+import com.vayunmathur.library.wearlink.calendar.WearCalendarSnapshot+import com.vayunmathur.library.wearlink.calendar.WearWatchState import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener import com.vayunmathur.library.wearlink.WearLinkNode
calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearAgendaScreen.kt
diff --git a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearAgendaScreen.kt b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearAgendaScreen.ktindex 4253d6f0ad..377ff7ec2f 100644--- a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearAgendaScreen.kt+++ b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearAgendaScreen.kt@@ -23,8 +23,8 @@ import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text import com.vayunmathur.calendar.wear.R import com.vayunmathur.calendar.wear.data.WearCalendarStore-import com.vayunmathur.calendar.wear.domain.WearCalendarEvent-import com.vayunmathur.calendar.wear.domain.WearCalendarSnapshot+import com.vayunmathur.library.wearlink.calendar.WearCalendarEvent+import com.vayunmathur.library.wearlink.calendar.WearCalendarSnapshot import com.vayunmathur.calendar.wear.domain.wearAgenda import com.vayunmathur.calendar.wear.domain.wearEventDay import com.vayunmathur.calendar.wear.sync.requestWearSync
calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearEventScreen.kt
diff --git a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearEventScreen.kt b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearEventScreen.ktindex d9e764f661..4ab8d28137 100644--- a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearEventScreen.kt+++ b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearEventScreen.kt@@ -18,7 +18,7 @@ import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text import com.vayunmathur.calendar.wear.R import com.vayunmathur.calendar.wear.data.WearCalendarStore-import com.vayunmathur.calendar.wear.domain.WearCalendarEvent+import com.vayunmathur.library.wearlink.calendar.WearCalendarEvent import kotlinx.datetime.TimeZone import kotlin.time.Instant import kotlinx.datetime.toLocalDateTime
calendar-wear/src/screenshotTest/kotlin/com/vayunmathur/calendar/wear/ui/MetadataPreviews.kt
diff --git a/calendar-wear/src/screenshotTest/kotlin/com/vayunmathur/calendar/wear/ui/MetadataPreviews.kt b/calendar-wear/src/screenshotTest/kotlin/com/vayunmathur/calendar/wear/ui/MetadataPreviews.ktindex 0ee8ccd9e4..19959d1f77 100644--- a/calendar-wear/src/screenshotTest/kotlin/com/vayunmathur/calendar/wear/ui/MetadataPreviews.kt+++ b/calendar-wear/src/screenshotTest/kotlin/com/vayunmathur/calendar/wear/ui/MetadataPreviews.kt@@ -10,8 +10,8 @@ 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.calendar.wear.domain.WearCalendarEvent-import com.vayunmathur.calendar.wear.domain.WearCalendarSnapshot+import com.vayunmathur.library.wearlink.calendar.WearCalendarEvent+import com.vayunmathur.library.wearlink.calendar.WearCalendarSnapshot /** Round watch, 454x454px class (227dp at 320dpi). */ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"
calendar-wear/src/test/java/com/vayunmathur/calendar/wear/domain/WearAgendaTest.kt
diff --git a/calendar-wear/src/test/java/com/vayunmathur/calendar/wear/domain/WearAgendaTest.kt b/calendar-wear/src/test/java/com/vayunmathur/calendar/wear/domain/WearAgendaTest.ktindex 3ab1aa2646..b8e2abb45e 100644--- a/calendar-wear/src/test/java/com/vayunmathur/calendar/wear/domain/WearAgendaTest.kt+++ b/calendar-wear/src/test/java/com/vayunmathur/calendar/wear/domain/WearAgendaTest.kt@@ -1,4 +1,6 @@ package com.vayunmathur.calendar.wear.domain+import com.vayunmathur.library.wearlink.calendar.WearCalendarEvent+import com.vayunmathur.library.wearlink.calendar.WearCalendarSnapshot import kotlin.test.Test import kotlin.test.assertEquals
calendar-wear/src/test/java/com/vayunmathur/calendar/wear/domain/WearCalendarProtocolTest.kt
diff --git a/calendar-wear/src/test/java/com/vayunmathur/calendar/wear/domain/WearCalendarProtocolTest.kt b/calendar-wear/src/test/java/com/vayunmathur/calendar/wear/domain/WearCalendarProtocolTest.ktindex 1acee044e4..fae00aff2b 100644--- a/calendar-wear/src/test/java/com/vayunmathur/calendar/wear/domain/WearCalendarProtocolTest.kt+++ b/calendar-wear/src/test/java/com/vayunmathur/calendar/wear/domain/WearCalendarProtocolTest.kt@@ -1,4 +1,9 @@ package com.vayunmathur.calendar.wear.domain+import com.vayunmathur.library.wearlink.calendar.WearCalendarEvent+import com.vayunmathur.library.wearlink.calendar.WearCalendarProtocol+import com.vayunmathur.library.wearlink.calendar.WearCalendarSnapshot+import com.vayunmathur.library.wearlink.calendar.buildWearSnapshot+import com.vayunmathur.library.wearlink.calendar.wearCompanionPresent import kotlin.test.Test import kotlin.test.assertEquals
calendar/src/main/java/com/vayunmathur/calendar/sync/WearCalendarSync.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/sync/WearCalendarSync.kt b/calendar/src/main/java/com/vayunmathur/calendar/sync/WearCalendarSync.ktindex b29ad14c3f..498694fccf 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/sync/WearCalendarSync.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/sync/WearCalendarSync.kt@@ -4,12 +4,12 @@ import android.content.Context import com.vayunmathur.calendar.data.Calendar import com.vayunmathur.calendar.data.Event import com.vayunmathur.calendar.data.Instance-import com.vayunmathur.calendar.domain.WearCalendarEvent-import com.vayunmathur.calendar.domain.WearCalendarProtocol-import com.vayunmathur.calendar.domain.WearCalendarSnapshot-import com.vayunmathur.calendar.domain.WearWatchState-import com.vayunmathur.calendar.domain.buildWearSnapshot-import com.vayunmathur.calendar.domain.wearCompanionPresent+import com.vayunmathur.library.wearlink.calendar.WearCalendarEvent+import com.vayunmathur.library.wearlink.calendar.WearCalendarProtocol+import com.vayunmathur.library.wearlink.calendar.WearCalendarSnapshot+import com.vayunmathur.library.wearlink.calendar.WearWatchState+import com.vayunmathur.library.wearlink.calendar.buildWearSnapshot+import com.vayunmathur.library.wearlink.calendar.wearCompanionPresent import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener import com.vayunmathur.library.wearlink.WearLinkNode
calendar/src/main/java/com/vayunmathur/calendar/ui/dialogs/CustomReminderDialog.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/ui/dialogs/CustomReminderDialog.kt b/calendar/src/main/java/com/vayunmathur/calendar/ui/dialogs/CustomReminderDialog.ktnew file mode 100644index 0000000000..eba876431d--- /dev/null+++ b/calendar/src/main/java/com/vayunmathur/calendar/ui/dialogs/CustomReminderDialog.kt@@ -0,0 +1,26 @@+package com.vayunmathur.calendar.ui.dialogs++import androidx.compose.runtime.Composable+import androidx.compose.runtime.rememberCoroutineScope+import com.vayunmathur.calendar.Route+import com.vayunmathur.library.util.LocalNavResultRegistry+import com.vayunmathur.library.util.NavBackStack+import kotlinx.coroutines.launch++/**+ * The custom-reminder dialog for `Route.EditEvent.CustomReminderDialog`:+ * reports the chosen offset in minutes under [resultKey] (the edit screen's+ * `ResultEffect<Int>`) and pops, like the other EditEvent picker dialogs.+ */+@Composable+fun CustomReminderDialog(backStack: NavBackStack<Route>, resultKey: String) {+ val registry = LocalNavResultRegistry.current+ val scope = rememberCoroutineScope()+ CustomReminderDialogContent(+ onDismiss = { backStack.pop() },+ onConfirm = { minutes ->+ scope.launch { registry.dispatchResult(resultKey, minutes) }+ backStack.pop()+ },+ )+}
calendar/src/test/java/com/vayunmathur/calendar/domain/WearCalendarProtocolTest.kt
diff --git a/calendar/src/test/java/com/vayunmathur/calendar/domain/WearCalendarProtocolTest.kt b/calendar/src/test/java/com/vayunmathur/calendar/domain/WearCalendarProtocolTest.ktindex 98d666fad0..b8d4ada14b 100644--- a/calendar/src/test/java/com/vayunmathur/calendar/domain/WearCalendarProtocolTest.kt+++ b/calendar/src/test/java/com/vayunmathur/calendar/domain/WearCalendarProtocolTest.kt@@ -1,4 +1,9 @@ package com.vayunmathur.calendar.domain+import com.vayunmathur.library.wearlink.calendar.WearCalendarEvent+import com.vayunmathur.library.wearlink.calendar.WearCalendarProtocol+import com.vayunmathur.library.wearlink.calendar.WearCalendarSnapshot+import com.vayunmathur.library.wearlink.calendar.buildWearSnapshot+import com.vayunmathur.library.wearlink.calendar.wearCompanionPresent import kotlin.test.Test import kotlin.test.assertEquals
docs/structure/wear-protocol-pairs.tsv
diff --git a/docs/structure/wear-protocol-pairs.tsv b/docs/structure/wear-protocol-pairs.tsvindex 7b4aa393ea..8157fe8ef2 100644--- a/docs/structure/wear-protocol-pairs.tsv+++ b/docs/structure/wear-protocol-pairs.tsv@@ -6,16 +6,16 @@ # library/wearlink/WearLinkProtocol.kt is deliberately NOT listed: it is a # shared library module both sides depend on, not a duplicated copy. # Migrated pairs (shared in :library:wearlink, no longer duplicated, so not-# listed): clock (com.vayunmathur.library.wearlink.clock).+# listed): clock (com.vayunmathur.library.wearlink.clock), launcher+# (com.vayunmathur.library.wearlink.launcher), calendar+# (com.vayunmathur.library.wearlink.calendar), weather+# (com.vayunmathur.library.wearlink.weather). appstore appstore/src/main/java/com/vayunmathur/appstore/domain/WearSyncProtocol.kt appstore/wear/src/main/java/com/vayunmathur/appstore/wear/domain/WearSyncProtocol.kt-calendar calendar/src/main/java/com/vayunmathur/calendar/domain/WearCalendarProtocol.kt calendar-wear/src/main/java/com/vayunmathur/calendar/wear/domain/WearCalendarProtocol.kt 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 contacts contacts/src/main/java/com/vayunmathur/contacts/domain/WearContactsProtocol.kt contacts-wear/src/main/java/com/vayunmathur/contacts/wear/domain/WearContactsProtocol.kt findfamily findfamily/src/main/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocol.kt findfamily-wear/src/main/java/com/vayunmathur/findfamily/wear/domain/WearFindFamilyProtocol.kt-launcher launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherProtocol.kt launcher-wear/src/main/java/com/vayunmathur/launcher/wear/domain/WearLauncherProtocol.kt maps maps/src/main/java/com/vayunmathur/maps/domain/WearMapsProtocol.kt maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapsProtocol.kt music music/src/main/java/com/vayunmathur/music/domain/WearMusicProtocol.kt music-wear/src/main/java/com/vayunmathur/music/wear/domain/WearMusicProtocol.kt notes notes/src/main/java/com/vayunmathur/notes/domain/WearNotesProtocol.kt notes-wear/src/main/java/com/vayunmathur/notes/wear/domain/WearNotesProtocol.kt todo todo/src/main/java/com/vayunmathur/todo/domain/WearTodoProtocol.kt todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.kt-weather weather/src/main/java/com/vayunmathur/weather/domain/WearWeatherProtocol.kt weather-wear/src/main/java/com/vayunmathur/weather/wear/domain/WearWeatherProtocol.kt
launcher-wear/AGENTS.md
diff --git a/launcher-wear/AGENTS.md b/launcher-wear/AGENTS.mdindex 064945e6c1..b76f2141a1 100644--- a/launcher-wear/AGENTS.md+++ b/launcher-wear/AGENTS.md@@ -40,9 +40,11 @@ a one-time ADB sideload of this APK onto the watch. the OS build, never in this app module. ## Protocol-`domain/WearLauncherProtocol.kt` is a copy of the phone's file (Gradle-cannot depend on another app module). Change both copies together; each-side's `WearLauncherProtocolTest` pins the same golden JSON.+The wire protocol lives in `:library:wearlink` at+`com.vayunmathur.library.wearlink.launcher.WearLauncherProtocol` (shared by+`:launcher` and `:launcher:wear`; neither app module depends on the other).+Each side's `WearLauncherProtocolTest` pins the same golden JSON against+that shared code. - Favorites + watch-state sync: WearLink data items (`/launcher/favorites`, `/launcher/watch-state`)
launcher-wear/src/main/java/com/vayunmathur/launcher/wear/data/WearLauncherStore.kt
diff --git a/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/data/WearLauncherStore.kt b/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/data/WearLauncherStore.ktindex 69827347f2..a8d96adf76 100644--- a/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/data/WearLauncherStore.kt+++ b/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/data/WearLauncherStore.kt@@ -2,9 +2,9 @@ package com.vayunmathur.launcher.wear.data import android.content.Context import com.vayunmathur.launcher.wear.domain.RecentLaunch-import com.vayunmathur.launcher.wear.domain.WearFavoritesSnapshot-import com.vayunmathur.launcher.wear.domain.WearLauncherWatchState-import com.vayunmathur.launcher.wear.domain.WearLauncherProtocol+import com.vayunmathur.library.wearlink.launcher.WearFavoritesSnapshot+import com.vayunmathur.library.wearlink.launcher.WearLauncherWatchState+import com.vayunmathur.library.wearlink.launcher.WearLauncherProtocol import com.vayunmathur.launcher.wear.domain.recordRecentLaunch import com.vayunmathur.launcher.wear.sync.WearLinkBridge import com.vayunmathur.library.log.Log
launcher-wear/src/main/java/com/vayunmathur/launcher/wear/domain/WearLauncherModel.kt
diff --git a/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/domain/WearLauncherModel.kt b/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/domain/WearLauncherModel.ktindex ba52f305c9..4ae8c7e045 100644--- a/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/domain/WearLauncherModel.kt+++ b/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/domain/WearLauncherModel.kt@@ -1,4 +1,6 @@ package com.vayunmathur.launcher.wear.domain+import com.vayunmathur.library.wearlink.launcher.WearFavorite+import com.vayunmathur.library.wearlink.launcher.WearFavoritesSnapshot import kotlinx.serialization.Serializable
launcher-wear/src/main/java/com/vayunmathur/launcher/wear/domain/WearLauncherProtocol.kt
diff --git a/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/domain/WearLauncherProtocol.kt b/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/domain/WearLauncherProtocol.ktdeleted file mode 100644index cbbc6e1d20..0000000000--- a/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/domain/WearLauncherProtocol.kt+++ /dev/null@@ -1,116 +0,0 @@-package com.vayunmathur.launcher.wear.domain--import kotlinx.serialization.Serializable-import kotlinx.serialization.encodeToString-import kotlinx.serialization.json.Json--/**- * Phone <-> watch sync protocol for the Wear OS Launcher companion.- *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module- * (`:launcher:wear`, applicationId `com.vayunmathur.launcher`) carries a copy- * of this file under `com.vayunmathur.launcher.wear.domain`. Change both- * copies together; each side's unit tests pin the same golden JSON so a- * one-sided edit fails loudly on the side that was not updated.- *- * What syncs, and what deliberately does not:- * - Phone -> watch: only the phone hotseat (the pinned/favorites row), as- * package + component + label in rank order. The full workspace grid,- * folders and widgets do not sync: a round watch has no paged grid to put- * them on, and inventing a mapping would misrepresent the phone layout.- * - Watch -> phone: only a watch-state receipt and a request-sync message.- * Recents are watch-local launch history; sending them to the phone would- * create a second, competing launch-count truth next to the phone's own.- *- * Transport (WearLink, :library:wearlink - RFCOMM, no Play services):- * presence is a completed handshake for [CAPABILITY] (the applicationId);- * delivery needs a live session and each side persists what it receives.- */-object WearLauncherProtocol {- /** WearLink appId the phone requires in the peer handshake. */- const val CAPABILITY = "launcher_wear_companion"-- /** Data-item path (phone -> watch): the [WearFavoritesSnapshot] JSON. */- const val FAVORITES_PATH = "/launcher/favorites"-- /** Data-item path (watch -> phone): the [WearLauncherWatchState] JSON. */- const val WATCH_STATE_PATH = "/launcher/watch-state"-- /** Message path (watch -> phone): ask the phone to publish fresh favorites. */- const val REQUEST_SYNC_PATH = "/launcher/request-sync"-- /** Most pinned apps sent; the phone hotseat is capped well below this. */- const val MAX_FAVORITES = 10-- /** Largest snapshot JSON in UTF-8 bytes, aligned with the other wear apps. */- const val MAX_JSON_BYTES = 90_000-- /** Label cap applied when a snapshot is built. */- const val MAX_LABEL_CHARS = 60-- /** Wire JSON: unknown keys ignored so a newer side never breaks an older one. */- val json: Json = Json { ignoreUnknownKeys = true }-}--/** One pinned (hotseat) app in rank order. */-@Serializable-data class WearFavorite(- val packageName: String,- /** Flattened component class, empty when the phone row had none. */- val className: String = "",- val label: String = "",- val rank: Int = 0,-)--/** The phone's bounded favorites snapshot for the watch ([WearLauncherProtocol.FAVORITES_PATH]). */-@Serializable-data class WearFavoritesSnapshot(- val generatedAtMillis: Long = 0L,- val favorites: List<WearFavorite> = emptyList(),- /** True when the count/size caps dropped pinned apps. */- val truncated: Boolean = false,-)--/** What the watch last applied, published at [WearLauncherProtocol.WATCH_STATE_PATH]. */-@Serializable-data class WearLauncherWatchState(- val appliedGeneratedAtMillis: Long = 0L,- val favoriteCount: Int = 0,- val installedCount: Int = 0,-)--/**- * Builds a bounded favorites snapshot from [candidates]: drops blank- * packages, de-duplicates by package (lowest rank wins), sorts by rank then- * label, caps labels, then enforces [WearLauncherProtocol.MAX_FAVORITES] and- * [WearLauncherProtocol.MAX_JSON_BYTES] dropping lowest-ranked first.- */-fun buildWearFavorites(- candidates: List<WearFavorite>,- generatedAtMillis: Long,-): WearFavoritesSnapshot {- val cleaned = candidates- .filter { it.packageName.isNotBlank() }- .groupBy { it.packageName }- .values.map { group -> group.minWith(compareBy({ it.rank }, { it.label })) }- .sortedWith(compareBy({ it.rank }, { it.label.lowercase() }, { it.packageName }))- .mapIndexed { index, favorite ->- favorite.copy(label = favorite.label.take(WearLauncherProtocol.MAX_LABEL_CHARS), rank = index)- }- var kept = cleaned.take(WearLauncherProtocol.MAX_FAVORITES)- var truncated = kept.size < cleaned.size- var snapshot = WearFavoritesSnapshot(generatedAtMillis, kept, truncated)- while (kept.isNotEmpty() &&- WearLauncherProtocol.json.encodeToString(snapshot).encodeToByteArray().size >- WearLauncherProtocol.MAX_JSON_BYTES- ) {- kept = kept.dropLast(1)- truncated = true- snapshot = WearFavoritesSnapshot(generatedAtMillis, kept, truncated)- }- return snapshot-}--/** True when a watch companion completed a WearLink handshake. */-fun wearLauncherCompanionPresent(peerCount: Int): Boolean = peerCount > 0
launcher-wear/src/main/java/com/vayunmathur/launcher/wear/sync/WearLinkBridge.kt
diff --git a/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/sync/WearLinkBridge.kt b/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/sync/WearLinkBridge.ktindex 1abe44b422..911b1ae72a 100644--- a/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/sync/WearLinkBridge.kt+++ b/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/sync/WearLinkBridge.kt@@ -2,9 +2,9 @@ package com.vayunmathur.launcher.wear.sync import android.content.Context import com.vayunmathur.launcher.wear.data.WearLauncherStore-import com.vayunmathur.launcher.wear.domain.WearFavoritesSnapshot-import com.vayunmathur.launcher.wear.domain.WearLauncherProtocol-import com.vayunmathur.launcher.wear.domain.WearLauncherWatchState+import com.vayunmathur.library.wearlink.launcher.WearFavoritesSnapshot+import com.vayunmathur.library.wearlink.launcher.WearLauncherProtocol+import com.vayunmathur.library.wearlink.launcher.WearLauncherWatchState import com.vayunmathur.launcher.wear.platform.InstalledApps import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener
launcher-wear/src/main/java/com/vayunmathur/launcher/wear/ui/WearAllAppsScreen.kt
diff --git a/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/ui/WearAllAppsScreen.kt b/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/ui/WearAllAppsScreen.ktindex 93cddb1353..c91425f0bd 100644--- a/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/ui/WearAllAppsScreen.kt+++ b/launcher-wear/src/main/java/com/vayunmathur/launcher/wear/ui/WearAllAppsScreen.kt@@ -80,8 +80,6 @@ internal fun WearAllAppsContent( ) } item {- // SCAFFOLD SEARCH EXCEPTION: Wear Compose Material has no scaffold- // search slot; this is the watch drawer's only search field. BasicTextField( value = query, onValueChange = { query = it },
launcher-wear/src/test/java/com/vayunmathur/launcher/wear/domain/WearLauncherModelTest.kt
diff --git a/launcher-wear/src/test/java/com/vayunmathur/launcher/wear/domain/WearLauncherModelTest.kt b/launcher-wear/src/test/java/com/vayunmathur/launcher/wear/domain/WearLauncherModelTest.ktindex ea06a69577..3d6f0452b8 100644--- a/launcher-wear/src/test/java/com/vayunmathur/launcher/wear/domain/WearLauncherModelTest.kt+++ b/launcher-wear/src/test/java/com/vayunmathur/launcher/wear/domain/WearLauncherModelTest.kt@@ -1,4 +1,6 @@ package com.vayunmathur.launcher.wear.domain+import com.vayunmathur.library.wearlink.launcher.WearFavorite+import com.vayunmathur.library.wearlink.launcher.WearFavoritesSnapshot import kotlin.test.Test import kotlin.test.assertEquals
launcher-wear/src/test/java/com/vayunmathur/launcher/wear/domain/WearLauncherProtocolTest.kt
diff --git a/launcher-wear/src/test/java/com/vayunmathur/launcher/wear/domain/WearLauncherProtocolTest.kt b/launcher-wear/src/test/java/com/vayunmathur/launcher/wear/domain/WearLauncherProtocolTest.ktindex 58d328b23e..557f205cd5 100644--- a/launcher-wear/src/test/java/com/vayunmathur/launcher/wear/domain/WearLauncherProtocolTest.kt+++ b/launcher-wear/src/test/java/com/vayunmathur/launcher/wear/domain/WearLauncherProtocolTest.kt@@ -1,4 +1,9 @@ package com.vayunmathur.launcher.wear.domain+import com.vayunmathur.library.wearlink.launcher.WearFavorite+import com.vayunmathur.library.wearlink.launcher.WearFavoritesSnapshot+import com.vayunmathur.library.wearlink.launcher.WearLauncherProtocol+import com.vayunmathur.library.wearlink.launcher.buildWearFavorites+import com.vayunmathur.library.wearlink.launcher.wearLauncherCompanionPresent import kotlin.test.Test import kotlin.test.assertEquals
launcher/build.gradle.kts
diff --git a/launcher/build.gradle.kts b/launcher/build.gradle.ktsindex 077bff9204..4c137cb75c 100644--- a/launcher/build.gradle.kts+++ b/launcher/build.gradle.kts@@ -28,7 +28,7 @@ android { dependencies { implementRoom(libs) implementation(project(":library:room"))- // Phone side of the watch-launcher favorites sync (see domain/WearLauncherProtocol.kt).+ // Phone side of the watch-launcher favorites sync (protocol in :library:wearlink). implementation(project(":library:wearlink")) implementation(libs.androidx.datastore.preferences) // Declared rather than relied on transitively: a launcher is mostly motion, so `Animatable`,
launcher/src/main/java/com/vayunmathur/launcher/sync/WearLauncherSync.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLauncherSync.kt b/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLauncherSync.ktindex 1c4708a32f..49ff5ce835 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLauncherSync.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLauncherSync.kt@@ -5,11 +5,11 @@ import android.content.pm.PackageManager import com.vayunmathur.launcher.data.LauncherRepository import com.vayunmathur.launcher.domain.ContainerRef import com.vayunmathur.launcher.domain.LauncherItemType-import com.vayunmathur.launcher.domain.WearFavorite-import com.vayunmathur.launcher.domain.WearLauncherProtocol-import com.vayunmathur.launcher.domain.WearLauncherWatchState-import com.vayunmathur.launcher.domain.buildWearFavorites-import com.vayunmathur.launcher.domain.wearLauncherCompanionPresent+import com.vayunmathur.library.wearlink.launcher.WearFavorite+import com.vayunmathur.library.wearlink.launcher.WearLauncherProtocol+import com.vayunmathur.library.wearlink.launcher.WearLauncherWatchState+import com.vayunmathur.library.wearlink.launcher.buildWearFavorites+import com.vayunmathur.library.wearlink.launcher.wearLauncherCompanionPresent import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener import com.vayunmathur.library.wearlink.WearLinkNode
launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherProtocolTest.kt
diff --git a/launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherProtocolTest.kt b/launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherProtocolTest.ktindex 0832a458bd..d4b0f04a75 100644--- a/launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherProtocolTest.kt+++ b/launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherProtocolTest.kt@@ -1,4 +1,9 @@ package com.vayunmathur.launcher.domain+import com.vayunmathur.library.wearlink.launcher.WearFavorite+import com.vayunmathur.library.wearlink.launcher.WearFavoritesSnapshot+import com.vayunmathur.library.wearlink.launcher.WearLauncherProtocol+import com.vayunmathur.library.wearlink.launcher.buildWearFavorites+import com.vayunmathur.library.wearlink.launcher.wearLauncherCompanionPresent import kotlin.test.Test import kotlin.test.assertEquals
library/wearlink/AGENTS.md
diff --git a/library/wearlink/AGENTS.md b/library/wearlink/AGENTS.mdindex 7cdbdf448b..f580fd3287 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. Remaining pairs are listed in+Migrated: clock, launcher, calendar, weather. Remaining pairs are listed in `docs/structure/wear-protocol-pairs.tsv`. ## Verify
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/calendar/WearCalendarProtocol.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/domain/WearCalendarProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/calendar/WearCalendarProtocol.ktsimilarity index 92%rename from calendar/src/main/java/com/vayunmathur/calendar/domain/WearCalendarProtocol.ktrename to library/wearlink/src/main/java/com/vayunmathur/library/wearlink/calendar/WearCalendarProtocol.ktindex 6171379335..94b5d1d1e7 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/domain/WearCalendarProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/calendar/WearCalendarProtocol.kt@@ -1,4 +1,4 @@-package com.vayunmathur.calendar.domain+package com.vayunmathur.library.wearlink.calendar import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json@@ -6,12 +6,9 @@ import kotlinx.serialization.json.Json /** * Phone <-> watch sync protocol for the Wear OS Calendar companion. *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module- * (`:calendar:wear`, applicationId `com.vayunmathur.calendar`) carries a copy- * of this file under `com.vayunmathur.calendar.wear.domain`. Change both- * copies together; each side's unit tests pin the same golden JSON so a- * one-sided edit fails loudly on the side that was not updated.+ * Shared by the phone (`:calendar`) and the watch (`:calendar:wear`)+ * through `:library:wearlink`; neither app module depends on the other.+ * Each side's unit tests pin the same golden JSON 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/launcher/WearLauncherProtocol.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/launcher/WearLauncherProtocol.ktsimilarity index 90%rename from launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherProtocol.ktrename to library/wearlink/src/main/java/com/vayunmathur/library/wearlink/launcher/WearLauncherProtocol.ktindex 2e23788b49..e5271c8922 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/launcher/WearLauncherProtocol.kt@@ -1,4 +1,4 @@-package com.vayunmathur.launcher.domain+package com.vayunmathur.library.wearlink.launcher import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString@@ -7,12 +7,9 @@ import kotlinx.serialization.json.Json /** * Phone <-> watch sync protocol for the Wear OS Launcher companion. *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module- * (`:launcher:wear`, applicationId `com.vayunmathur.launcher`) carries a copy- * of this file under `com.vayunmathur.launcher.wear.domain`. Change both- * copies together; each side's unit tests pin the same golden JSON so a- * one-sided edit fails loudly on the side that was not updated.+ * Shared by the phone (`:launcher`) and the watch (`:launcher:wear`)+ * through `:library:wearlink`; neither app module depends on the other.+ * Each side's unit tests pin the same golden JSON against this code. * * What syncs, and what deliberately does not: * - Phone -> watch: only the phone hotseat (the pinned/favorites row), as
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/weather/WearWeatherProtocol.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/domain/WearWeatherProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/weather/WearWeatherProtocol.ktsimilarity index 91%rename from weather/src/main/java/com/vayunmathur/weather/domain/WearWeatherProtocol.ktrename to library/wearlink/src/main/java/com/vayunmathur/library/wearlink/weather/WearWeatherProtocol.ktindex 1c1bed1ee4..f98b4c262f 100644--- a/weather/src/main/java/com/vayunmathur/weather/domain/WearWeatherProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/weather/WearWeatherProtocol.kt@@ -1,4 +1,4 @@-package com.vayunmathur.weather.domain+package com.vayunmathur.library.wearlink.weather import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json@@ -6,11 +6,9 @@ import kotlinx.serialization.json.Json /** * Phone <-> watch sync protocol for the Wear OS Weather companion. *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module- * (`:weather:wear`, applicationId `com.vayunmathur.weather`) carries a copy- * of this file under `com.vayunmathur.weather.wear.domain`. Change both- * copies together; each side's unit tests pin the same golden JSON.+ * Shared by the phone (`:weather`) and the watch (`:weather:wear`)+ * through `:library:wearlink`; neither app module depends on the other.+ * Each side's unit tests pin the same golden JSON against this code. * * Transport (WearLink, :library:wearlink — RFCOMM, no Play services): * - Presence is a completed handshake for [CAPABILITY] (the appId).
weather-wear/AGENTS.md
diff --git a/weather-wear/AGENTS.md b/weather-wear/AGENTS.mdindex bb28354fd2..70d0d5874f 100644--- a/weather-wear/AGENTS.md+++ b/weather-wear/AGENTS.md@@ -5,7 +5,10 @@ ## Why Wear OS companion of :weather. Same applicationId + signing (WearLink handshake requires same cert). Sideload once via ADB. ## Protocol-`domain/WearWeatherProtocol.kt` is a copy of phone's file. Change both; golden tests pin same JSON.+The wire protocol lives in `:library:wearlink` at+`com.vayunmathur.library.wearlink.weather.WearWeatherProtocol` (shared by+`:weather` and `:weather:wear`; neither app module depends on the other).+Golden tests on each side pin the same JSON against that shared code. - Snapshot/watch-state: WearLink data items; request-sync: message watch->phone only. - Offline: renders locally stored snapshot; no network on watch. - Units: protocol values stay Celsius / km/h; rendering converts to the watch's system regional preferences (`platform/WearSystemUnits`, formatting in `domain/WearWeatherFormatting`).
weather-wear/src/main/java/com/vayunmathur/weather/wear/data/WearWeatherStore.kt
diff --git a/weather-wear/src/main/java/com/vayunmathur/weather/wear/data/WearWeatherStore.kt b/weather-wear/src/main/java/com/vayunmathur/weather/wear/data/WearWeatherStore.ktindex 6eed945b25..a4db8862a5 100644--- a/weather-wear/src/main/java/com/vayunmathur/weather/wear/data/WearWeatherStore.kt+++ b/weather-wear/src/main/java/com/vayunmathur/weather/wear/data/WearWeatherStore.kt@@ -1,8 +1,8 @@ package com.vayunmathur.weather.wear.data import android.content.Context import com.vayunmathur.library.log.Log-import com.vayunmathur.weather.wear.domain.WearWeatherProtocol-import com.vayunmathur.weather.wear.domain.WearWeatherSnapshot+import com.vayunmathur.library.wearlink.weather.WearWeatherProtocol+import com.vayunmathur.library.wearlink.weather.WearWeatherSnapshot import com.vayunmathur.weather.wear.sync.WearLinkBridge import java.io.File import kotlinx.coroutines.flow.MutableStateFlow
weather-wear/src/main/java/com/vayunmathur/weather/wear/domain/WearWeatherProtocol.kt
diff --git a/weather-wear/src/main/java/com/vayunmathur/weather/wear/domain/WearWeatherProtocol.kt b/weather-wear/src/main/java/com/vayunmathur/weather/wear/domain/WearWeatherProtocol.ktdeleted file mode 100644index f1ebd0a05b..0000000000--- a/weather-wear/src/main/java/com/vayunmathur/weather/wear/domain/WearWeatherProtocol.kt+++ /dev/null@@ -1,119 +0,0 @@-package com.vayunmathur.weather.wear.domain--import kotlinx.serialization.Serializable-import kotlinx.serialization.json.Json--/**- * Phone <-> watch sync protocol for the Wear OS Weather companion.- *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module- * (`:weather:wear`, applicationId `com.vayunmathur.weather`) carries a copy- * of this file under `com.vayunmathur.weather.wear.domain`. Change both- * copies together; each side's unit tests pin the same golden JSON.- *- * Transport (WearLink, :library:wearlink — RFCOMM, no Play services):- * - Presence is a completed handshake for [CAPABILITY] (the appId).- * - Data items: [SNAPSHOT_PATH] phone -> watch, [WATCH_STATE_PATH] watch -> phone.- * - Messages: [REQUEST_SYNC_PATH] watch -> phone (only watch-originated write).- * Bounded by design: primary location first, then favorites, caps below.- */-object WearWeatherProtocol {- const val CAPABILITY = "weather_wear_companion"- const val SNAPSHOT_PATH = "/weather/snapshot"- const val WATCH_STATE_PATH = "/weather/watch-state"- const val REQUEST_SYNC_PATH = "/weather/request-sync"- const val MAX_LOCATIONS = 4- const val MAX_HOURLY = 24- const val MAX_DAILY = 7- const val MAX_JSON_BYTES = 90_000- const val MAX_NAME_CHARS = 80- val json: Json = Json { ignoreUnknownKeys = true }-}--@Serializable-data class WearWeatherCurrent(- val timeIso: String = "",- val temperatureC: Double = 0.0,- val apparentTemperatureC: Double = 0.0,- val humidityPercent: Int = 0,- val weatherCode: Int = -1,- val isDay: Boolean = true,- val windSpeedKmh: Double = 0.0,- val windDirectionDegrees: Int = 0,- val pressureHpa: Double = 0.0,-)--@Serializable-data class WearWeatherHour(- val timeIso: String = "",- val temperatureC: Double = 0.0,- val weatherCode: Int = -1,- val precipitationProbabilityPercent: Int = 0,- val isDay: Boolean = true,-)--@Serializable-data class WearWeatherDay(- val dateIso: String = "",- val weatherCode: Int = -1,- val temperatureMaxC: Double = 0.0,- val temperatureMinC: Double = 0.0,- val precipitationProbabilityMaxPercent: Int = 0,-)--@Serializable-data class WearWeatherLocation(- val locationId: Long = 0L,- val name: String = "",- val country: String = "",- val isPrimary: Boolean = false,- val timezone: String = "UTC",- val current: WearWeatherCurrent? = null,- val hourly: List<WearWeatherHour> = emptyList(),- val daily: List<WearWeatherDay> = emptyList(),-)--@Serializable-data class WearWeatherSnapshot(- val generatedAtMillis: Long = 0L,- val locations: List<WearWeatherLocation> = emptyList(),- val truncated: Boolean = false,-)--@Serializable-data class WearWatchState(- val appliedGeneratedAtMillis: Long = 0L,- val locationCount: Int = 0,-)--/** Primary first (stable for equal rank), then field/list caps, then JSON-size cap (drop last locations, then hourly). */-fun buildWearWeatherSnapshot(- candidates: List<WearWeatherLocation>,- generatedAtMillis: Long,-): WearWeatherSnapshot {- val ordered = candidates.sortedByDescending { it.isPrimary }.map { loc ->- loc.copy(- name = loc.name.take(WearWeatherProtocol.MAX_NAME_CHARS),- country = loc.country.take(WearWeatherProtocol.MAX_NAME_CHARS),- hourly = loc.hourly.take(WearWeatherProtocol.MAX_HOURLY),- daily = loc.daily.take(WearWeatherProtocol.MAX_DAILY),- )- }- var kept = ordered.take(WearWeatherProtocol.MAX_LOCATIONS)- var truncated = kept.size < ordered.size- var snapshot = WearWeatherSnapshot(generatedAtMillis, kept, truncated)- fun over() = WearWeatherProtocol.json.encodeToString(snapshot).encodeToByteArray().size > WearWeatherProtocol.MAX_JSON_BYTES- while (over() && kept.size > 1) {- kept = kept.dropLast(1); truncated = true- snapshot = WearWeatherSnapshot(generatedAtMillis, kept, true)- }- while (over() && kept.firstOrNull()?.hourly?.isNotEmpty() == true) {- kept = kept.mapIndexed { i, loc -> if (i == 0) loc.copy(hourly = loc.hourly.dropLast(1)) else loc }- snapshot = WearWeatherSnapshot(generatedAtMillis, kept, true)- }- return snapshot-}--/** True when a companion node is present (non-empty handshake set). */-fun wearCompanionPresent(nodeIdsWithCapability: Collection<String>): Boolean = nodeIdsWithCapability.isNotEmpty()
weather-wear/src/main/java/com/vayunmathur/weather/wear/sync/WearLinkBridge.kt
diff --git a/weather-wear/src/main/java/com/vayunmathur/weather/wear/sync/WearLinkBridge.kt b/weather-wear/src/main/java/com/vayunmathur/weather/wear/sync/WearLinkBridge.ktindex 642e3e0620..4533a8b4e6 100644--- a/weather-wear/src/main/java/com/vayunmathur/weather/wear/sync/WearLinkBridge.kt+++ b/weather-wear/src/main/java/com/vayunmathur/weather/wear/sync/WearLinkBridge.kt@@ -4,9 +4,9 @@ import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener import com.vayunmathur.library.wearlink.WearLinkNode import com.vayunmathur.weather.wear.data.WearWeatherStore-import com.vayunmathur.weather.wear.domain.WearWeatherProtocol-import com.vayunmathur.weather.wear.domain.WearWeatherSnapshot-import com.vayunmathur.weather.wear.domain.WearWatchState+import com.vayunmathur.library.wearlink.weather.WearWeatherProtocol+import com.vayunmathur.library.wearlink.weather.WearWeatherSnapshot+import com.vayunmathur.library.wearlink.weather.WearWatchState import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob
weather-wear/src/main/java/com/vayunmathur/weather/wear/ui/WearLocationsScreen.kt
diff --git a/weather-wear/src/main/java/com/vayunmathur/weather/wear/ui/WearLocationsScreen.kt b/weather-wear/src/main/java/com/vayunmathur/weather/wear/ui/WearLocationsScreen.ktindex 56956b7af2..1cfdb69515 100644--- a/weather-wear/src/main/java/com/vayunmathur/weather/wear/ui/WearLocationsScreen.kt+++ b/weather-wear/src/main/java/com/vayunmathur/weather/wear/ui/WearLocationsScreen.kt@@ -33,7 +33,7 @@ import com.vayunmathur.weather.wear.platform.systemWearTemperatureUnit * parameter, so Compose previews (src/screenshotTest) render a literal fixture * with no store or phone. */-@Composable internal fun WearLocationsContent(snapshot:com.vayunmathur.weather.wear.domain.WearWeatherSnapshot, onOpen:(Long)->Unit, tempUnit:WearTemperatureUnit=WearTemperatureUnit.Celsius){+@Composable internal fun WearLocationsContent(snapshot:com.vayunmathur.library.wearlink.weather.WearWeatherSnapshot, onOpen:(Long)->Unit, tempUnit:WearTemperatureUnit=WearTemperatureUnit.Celsius){ val s=snapshot; val st=rememberScalingLazyListState() ScalingLazyColumn(state=st){ item{ Text(stringResource(R.string.app_name),style=MaterialTheme.typography.title3,textAlign=TextAlign.Center,modifier=Modifier.fillMaxWidth().padding(horizontal=12.dp)) }
weather-wear/src/screenshotTest/kotlin/com/vayunmathur/weather/wear/ui/MetadataPreviews.kt
diff --git a/weather-wear/src/screenshotTest/kotlin/com/vayunmathur/weather/wear/ui/MetadataPreviews.kt b/weather-wear/src/screenshotTest/kotlin/com/vayunmathur/weather/wear/ui/MetadataPreviews.ktindex 2b9fa3d902..63fd859727 100644--- a/weather-wear/src/screenshotTest/kotlin/com/vayunmathur/weather/wear/ui/MetadataPreviews.kt+++ b/weather-wear/src/screenshotTest/kotlin/com/vayunmathur/weather/wear/ui/MetadataPreviews.kt@@ -10,9 +10,9 @@ 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.weather.wear.domain.WearWeatherCurrent-import com.vayunmathur.weather.wear.domain.WearWeatherLocation-import com.vayunmathur.weather.wear.domain.WearWeatherSnapshot+import com.vayunmathur.library.wearlink.weather.WearWeatherCurrent+import com.vayunmathur.library.wearlink.weather.WearWeatherLocation+import com.vayunmathur.library.wearlink.weather.WearWeatherSnapshot /** Round watch, 454x454px class (227dp at 320dpi) — Pixel Watch / Galaxy Watch size. */ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"
weather-wear/src/test/java/com/vayunmathur/weather/wear/domain/WearWeatherProtocolTest.kt
diff --git a/weather-wear/src/test/java/com/vayunmathur/weather/wear/domain/WearWeatherProtocolTest.kt b/weather-wear/src/test/java/com/vayunmathur/weather/wear/domain/WearWeatherProtocolTest.ktindex 56f25c5c45..788074348f 100644--- a/weather-wear/src/test/java/com/vayunmathur/weather/wear/domain/WearWeatherProtocolTest.kt+++ b/weather-wear/src/test/java/com/vayunmathur/weather/wear/domain/WearWeatherProtocolTest.kt@@ -1,4 +1,13 @@ package com.vayunmathur.weather.wear.domain+import com.vayunmathur.library.wearlink.weather.WearWatchState+import com.vayunmathur.library.wearlink.weather.WearWeatherCurrent+import com.vayunmathur.library.wearlink.weather.WearWeatherDay+import com.vayunmathur.library.wearlink.weather.WearWeatherHour+import com.vayunmathur.library.wearlink.weather.WearWeatherLocation+import com.vayunmathur.library.wearlink.weather.WearWeatherProtocol+import com.vayunmathur.library.wearlink.weather.WearWeatherSnapshot+import com.vayunmathur.library.wearlink.weather.buildWearWeatherSnapshot+import com.vayunmathur.library.wearlink.weather.wearCompanionPresent import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse@@ -13,4 +22,6 @@ class WearWeatherProtocolTest { @Test fun buildCapsHourlyDaily(){ val big=loc(1L,true).copy(hourly=(1..40).map{WearWeatherHour("2026-11-24T13:00",1.0,1)},daily=(1..10).map{WearWeatherDay("2026-11-24",1,2.0,1.0)}); val s=buildWearWeatherSnapshot(listOf(big),0L); assertEquals(WearWeatherProtocol.MAX_HOURLY,s.locations[0].hourly.size); assertEquals(WearWeatherProtocol.MAX_DAILY,s.locations[0].daily.size) } @Test fun presenceAbsent(){ assertFalse(wearCompanionPresent(emptyList())); assertTrue(wearCompanionPresent(listOf("n"))) } @Test fun buildCapsBytes(){ val many=(1L..4L).map{ loc(it).copy(name="x".repeat(200),hourly=(1..24).map{WearWeatherHour("2026-11-24T13:00",1.0,1)}) }; val s=buildWearWeatherSnapshot(many,0L); assertTrue(WearWeatherProtocol.json.encodeToString(s).encodeToByteArray().size<=WearWeatherProtocol.MAX_JSON_BYTES) }+ @Test fun goldenWatchStateJson(){ assertEquals("""{"appliedGeneratedAtMillis":1000,"locationCount":2}""", WearWeatherProtocol.json.encodeToString(WearWatchState(1000L,2))) }+ @Test fun watchStateRoundTrips(){ val s=WearWatchState(9L,3); assertEquals(s, WearWeatherProtocol.json.decodeFromString<WearWatchState>(WearWeatherProtocol.json.encodeToString(s))) } }
weather/src/main/java/com/vayunmathur/weather/sync/WearWeatherSync.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/sync/WearWeatherSync.kt b/weather/src/main/java/com/vayunmathur/weather/sync/WearWeatherSync.ktindex 872527f673..e0dc775bbf 100644--- a/weather/src/main/java/com/vayunmathur/weather/sync/WearWeatherSync.kt+++ b/weather/src/main/java/com/vayunmathur/weather/sync/WearWeatherSync.kt@@ -6,17 +6,17 @@ import com.vayunmathur.library.wearlink.WearLinkNode import com.vayunmathur.library.wearlink.WearLinkState import com.vayunmathur.weather.data.WeatherRepository import com.vayunmathur.weather.data.weatherJson-import com.vayunmathur.weather.domain.WearWeatherCurrent-import com.vayunmathur.weather.domain.WearWeatherDay-import com.vayunmathur.weather.domain.WearWeatherHour-import com.vayunmathur.weather.domain.WearWeatherLocation-import com.vayunmathur.weather.domain.WearWeatherProtocol-import com.vayunmathur.weather.domain.WearWeatherSnapshot-import com.vayunmathur.weather.domain.WearWatchState-import com.vayunmathur.weather.domain.buildWearWeatherSnapshot+import com.vayunmathur.library.wearlink.weather.WearWeatherCurrent+import com.vayunmathur.library.wearlink.weather.WearWeatherDay+import com.vayunmathur.library.wearlink.weather.WearWeatherHour+import com.vayunmathur.library.wearlink.weather.WearWeatherLocation+import com.vayunmathur.library.wearlink.weather.WearWeatherProtocol+import com.vayunmathur.library.wearlink.weather.WearWeatherSnapshot+import com.vayunmathur.library.wearlink.weather.WearWatchState+import com.vayunmathur.library.wearlink.weather.buildWearWeatherSnapshot import com.vayunmathur.weather.domain.roundCoord import com.vayunmathur.weather.domain.todayIndex-import com.vayunmathur.weather.domain.wearCompanionPresent+import com.vayunmathur.library.wearlink.weather.wearCompanionPresent import com.vayunmathur.weather.network.Daily import com.vayunmathur.weather.network.ForecastResponse import kotlinx.coroutines.CoroutineScope
weather/src/test/java/com/vayunmathur/weather/domain/WearWeatherProtocolTest.kt
diff --git a/weather/src/test/java/com/vayunmathur/weather/domain/WearWeatherProtocolTest.kt b/weather/src/test/java/com/vayunmathur/weather/domain/WearWeatherProtocolTest.ktindex 6f0e64c022..34e759ecba 100644--- a/weather/src/test/java/com/vayunmathur/weather/domain/WearWeatherProtocolTest.kt+++ b/weather/src/test/java/com/vayunmathur/weather/domain/WearWeatherProtocolTest.kt@@ -1,4 +1,13 @@ package com.vayunmathur.weather.domain+import com.vayunmathur.library.wearlink.weather.WearWatchState+import com.vayunmathur.library.wearlink.weather.WearWeatherCurrent+import com.vayunmathur.library.wearlink.weather.WearWeatherDay+import com.vayunmathur.library.wearlink.weather.WearWeatherHour+import com.vayunmathur.library.wearlink.weather.WearWeatherLocation+import com.vayunmathur.library.wearlink.weather.WearWeatherProtocol+import com.vayunmathur.library.wearlink.weather.WearWeatherSnapshot+import com.vayunmathur.library.wearlink.weather.buildWearWeatherSnapshot+import com.vayunmathur.library.wearlink.weather.wearCompanionPresent import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse@@ -13,4 +22,6 @@ class WearWeatherProtocolTest { @Test fun buildCapsHourlyDaily(){ val big=loc(1L,true).copy(hourly=(1..40).map{WearWeatherHour("2026-11-24T13:00",1.0,1)},daily=(1..10).map{WearWeatherDay("2026-11-24",1,2.0,1.0)}); val s=buildWearWeatherSnapshot(listOf(big),0L); assertEquals(WearWeatherProtocol.MAX_HOURLY,s.locations[0].hourly.size); assertEquals(WearWeatherProtocol.MAX_DAILY,s.locations[0].daily.size) } @Test fun presenceAbsent(){ assertFalse(wearCompanionPresent(emptyList())); assertTrue(wearCompanionPresent(listOf("n"))) } @Test fun buildCapsBytes(){ val many=(1L..4L).map{ loc(it).copy(name="x".repeat(200),hourly=(1..24).map{WearWeatherHour("2026-11-24T13:00",1.0,1)}) }; val s=buildWearWeatherSnapshot(many,0L); assertTrue(WearWeatherProtocol.json.encodeToString(s).encodeToByteArray().size<=WearWeatherProtocol.MAX_JSON_BYTES) }+ @Test fun goldenWatchStateJson(){ assertEquals("""{"appliedGeneratedAtMillis":1000,"locationCount":2}""", WearWeatherProtocol.json.encodeToString(WearWatchState(1000L,2))) }+ @Test fun watchStateRoundTrips(){ val s=WearWatchState(9L,3); assertEquals(s, WearWeatherProtocol.json.decodeFromString<WearWatchState>(WearWeatherProtocol.json.encodeToString(s))) } }
weather/src/test/java/com/vayunmathur/weather/sync/WearDailyForecastTest.kt
diff --git a/weather/src/test/java/com/vayunmathur/weather/sync/WearDailyForecastTest.kt b/weather/src/test/java/com/vayunmathur/weather/sync/WearDailyForecastTest.ktindex 6405df1a14..660a7cde04 100644--- a/weather/src/test/java/com/vayunmathur/weather/sync/WearDailyForecastTest.kt+++ b/weather/src/test/java/com/vayunmathur/weather/sync/WearDailyForecastTest.kt@@ -1,8 +1,8 @@ package com.vayunmathur.weather.sync -import com.vayunmathur.weather.domain.WearWeatherLocation-import com.vayunmathur.weather.domain.WearWeatherProtocol-import com.vayunmathur.weather.domain.buildWearWeatherSnapshot+import com.vayunmathur.library.wearlink.weather.WearWeatherLocation+import com.vayunmathur.library.wearlink.weather.WearWeatherProtocol+import com.vayunmathur.library.wearlink.weather.buildWearWeatherSnapshot import com.vayunmathur.weather.network.Daily import kotlin.test.Test import kotlin.test.assertEquals