Modern Apps git

← Modern-Apps.git

library: clock's wear protocol lives in wearlink now, one copy instead of two

Commit
195ff400d98899437958ed157eb9510b765e33a9
Author
Vayun Mathur <[email protected]>
When
2026-12-01 16:30 UTC (4 days ago)
Parents
bfc6072
LOC Phase 2, first pair. WearClockProtocol (214 lines)
existed byte-identically in clock and clock-wear; both
already depend on :library:wearlink, so the protocol moves
to com.vayunmathur.library.wearlink.clock and both copies
are deleted. Wire symbols keep their names; only the
package changes, so the format is byte-identical by
construction — and both sides' golden tests now pin the
SAME shared code. A package-rewrite trap was caught in
implementation: watch-native symbols from WearAlarmState/
WatchTimerState are not protocol and were reverted; only
the 7 protocol symbols repoint. Net -200 source lines for
this pair.

The 'change both copies together' rule dies for clock
(AGENTS + pair registry updated). Remaining pairs sequenced
in the agent report (launcher next; todo blocked on drift
reconciliation). Verified: wearlink 9/9, clock-wear 20/20,
clock protocol 7/7 golden tests pass; both lints BUILD
SUCCESSFUL; structure wear no longer flags clock (todo
drift is pre-existing). The 32 clock UI test failures are
from co-resident in-progress clock UI work, files untouched
here.

Diff

clock-wear/AGENTS.md
diff --git a/clock-wear/AGENTS.md b/clock-wear/AGENTS.mdindex bde32649ee..a93a625af9 100644--- a/clock-wear/AGENTS.md+++ b/clock-wear/AGENTS.md@@ -17,9 +17,11 @@ breaks phone<->watch sync. Bootstrap is a one-time ADB sideload of this APK onto the watch.  ## Protocol-`domain/WearClockProtocol.kt` is a copy of the phone's file (Gradle cannot-depend on another app module). Change both copies together; each side's-`WearClockProtocolTest` pins the same golden JSON.+The wire protocol lives in `:library:wearlink` at+`com.vayunmathur.library.wearlink.clock.WearClockProtocol` (shared by+`:clock` and `:clock:wear`; neither app module depends on the other).+Each side's `WearClockProtocolTest` pins the same golden JSON against+that shared code.  - Snapshot + watch-state sync: WearLink data items (`/clock/snapshot`, `/clock/watch-state`) - Sync request: WearLink message (`/clock/request-sync`), watch -> phone only
clock-wear/build.gradle.kts
diff --git a/clock-wear/build.gradle.kts b/clock-wear/build.gradle.ktsindex d2def3fbb9..58c4dc13fd 100644--- a/clock-wear/build.gradle.kts+++ b/clock-wear/build.gradle.kts@@ -29,8 +29,7 @@ android { }  dependencies {-    // Watch side of the Wear OS sync (see domain/WearClockProtocol.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)
clock-wear/src/main/java/com/vayunmathur/clock/wear/data/WearClockStore.kt
diff --git a/clock-wear/src/main/java/com/vayunmathur/clock/wear/data/WearClockStore.kt b/clock-wear/src/main/java/com/vayunmathur/clock/wear/data/WearClockStore.ktindex 2c566ba6bc..ce71106404 100644--- a/clock-wear/src/main/java/com/vayunmathur/clock/wear/data/WearClockStore.kt+++ b/clock-wear/src/main/java/com/vayunmathur/clock/wear/data/WearClockStore.kt@@ -5,8 +5,8 @@ import com.vayunmathur.clock.wear.domain.ArmFailureRecord import com.vayunmathur.clock.wear.domain.ArmedAlarmRecord import com.vayunmathur.clock.wear.domain.WatchStopwatch import com.vayunmathur.clock.wear.domain.WatchTimer-import com.vayunmathur.clock.wear.domain.WearClockProtocol-import com.vayunmathur.clock.wear.domain.WearClockSnapshot+import com.vayunmathur.library.wearlink.clock.WearClockProtocol+import com.vayunmathur.library.wearlink.clock.WearClockSnapshot import com.vayunmathur.library.log.Log import java.io.File import kotlinx.coroutines.flow.MutableStateFlow
clock-wear/src/main/java/com/vayunmathur/clock/wear/domain/WearAlarmState.kt
diff --git a/clock-wear/src/main/java/com/vayunmathur/clock/wear/domain/WearAlarmState.kt b/clock-wear/src/main/java/com/vayunmathur/clock/wear/domain/WearAlarmState.ktindex 6b163804b6..1fc9dbfa14 100644--- a/clock-wear/src/main/java/com/vayunmathur/clock/wear/domain/WearAlarmState.kt+++ b/clock-wear/src/main/java/com/vayunmathur/clock/wear/domain/WearAlarmState.kt@@ -1,4 +1,5 @@ package com.vayunmathur.clock.wear.domain+import com.vayunmathur.library.wearlink.clock.WearClockAlarm  import kotlinx.serialization.Serializable 
clock-wear/src/main/java/com/vayunmathur/clock/wear/domain/WearClockProtocol.kt
diff --git a/clock-wear/src/main/java/com/vayunmathur/clock/wear/domain/WearClockProtocol.kt b/clock-wear/src/main/java/com/vayunmathur/clock/wear/domain/WearClockProtocol.ktdeleted file mode 100644index 405e75d23f..0000000000--- a/clock-wear/src/main/java/com/vayunmathur/clock/wear/domain/WearClockProtocol.kt+++ /dev/null@@ -1,214 +0,0 @@-package com.vayunmathur.clock.wear.domain--import kotlinx.datetime.DateTimeUnit-import kotlinx.datetime.LocalDateTime-import kotlinx.datetime.TimeZone-import kotlinx.datetime.offsetAt-import kotlinx.datetime.plus-import kotlinx.datetime.toInstant-import kotlinx.datetime.toLocalDateTime-import kotlinx.serialization.Serializable-import kotlinx.serialization.json.Json-import kotlin.time.Duration.Companion.days-import kotlin.time.Instant--/**- * Phone <-> watch sync protocol for the Wear OS Clock companion.- *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module (`:clock:wear`,- * applicationId `com.vayunmathur.clock`) carries the other copy of this file under- * `com.vayunmathur.clock.domain`. Change both copies together; each- * side's unit tests pin the same golden JSON 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 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.- *- * What is synced and what is not: alarms and the world-clock list are the- * phone's, published read-only as a snapshot. Timers and the stopwatch are- * watch-native (they live and run on the watch) and are never in this- * snapshot — a snapshot timer would be a display of a phone timer, which- * could not ring on the watch while the phone is absent.- */-object WearClockProtocol {-    /** WearLink appId the phone requires in the peer handshake. */-    const val CAPABILITY = "clock_wear_companion"--    /** Data-item path (phone -> watch): the [WearClockSnapshot] JSON. */-    const val SNAPSHOT_PATH = "/clock/snapshot"--    /** Data-item path (watch -> phone): the [WearClockWatchState] JSON. */-    const val WATCH_STATE_PATH = "/clock/watch-state"--    /** Message path (watch -> phone): ask the phone to publish a fresh snapshot. */-    const val REQUEST_SYNC_PATH = "/clock/request-sync"--    /** Most alarms in one snapshot; a watch renders a short list. */-    const val MAX_ALARMS = 50--    /** Most world clocks in one snapshot, in the phone's list order. */-    const val MAX_WORLD_CLOCKS = 20--    /** Largest snapshot JSON, in UTF-8 bytes (WearLink chunks it either way). */-    const val MAX_JSON_BYTES = 90_000--    const val MAX_LABEL_CHARS = 60-    const val MAX_CITY_CHARS = 80--    /** Wire JSON: unknown keys ignored so a newer side never breaks an older one. */-    val json: Json = Json { ignoreUnknownKeys = true }-}--/** One phone alarm, trimmed to what the watch needs to arm and render it. */-@Serializable-data class WearClockAlarm(-    /** Phone Room alarm id; stable identity across snapshots. */-    val alarmId: Long,-    val label: String = "",-    val hour: Int,-    val minute: Int,-    /** Weekday bitmask, bit 0 = Sunday (same encoding as the phone Alarm). 0 = one-shot. */-    val daysMask: Int = 0,-    val enabled: Boolean = false,-    /**-     * Phone-computed next fire, epoch millis (0 when disabled/unknown). For-     * display comparison only: the watch computes and arms its own next fire-     * from [hour]/[minute]/[daysMask] in its own timezone.-     */-    val phoneNextTriggerMillis: Long = 0L,-    val vibrate: Boolean = true,-    val snoozeMinutes: Int = 5,-)--/** One world-clock entry: a city and the IANA zone the phone resolved it to. */-@Serializable-data class WearWorldClock(-    val city: String,-    val timezoneId: String,-)--/** The phone's bounded clock snapshot for the watch ([WearClockProtocol.SNAPSHOT_PATH]). */-@Serializable-data class WearClockSnapshot(-    /** When the phone built this snapshot, epoch millis. */-    val generatedAtMillis: Long = 0L,-    val alarms: List<WearClockAlarm> = emptyList(),-    /** In the phone's world-clock list order. */-    val worldClocks: List<WearWorldClock> = emptyList(),-    /** True when the count/byte caps dropped entries. */-    val truncated: Boolean = false,-)--/** What the watch last applied and armed, at [WearClockProtocol.WATCH_STATE_PATH]. */-@Serializable-data class WearClockWatchState(-    /** generatedAtMillis of the snapshot the watch is rendering from, 0 when none yet. */-    val appliedGeneratedAtMillis: Long = 0L,-    val alarmCount: Int = 0,-    /** Alarms actually armed with the watch's AlarmManager (never display-only ones). */-    val armedCount: Int = 0,-    /** Enabled alarms the watch could not arm and only displays. */-    val displayOnlyCount: Int = 0,-)--/**- * Builds a bounded snapshot: alarms sorted by time of day (then id), world- * clocks kept in phone order, field caps applied, then- * [WearClockProtocol.MAX_ALARMS]/[WearClockProtocol.MAX_WORLD_CLOCKS] and- * [WearClockProtocol.MAX_JSON_BYTES] enforced (world clocks drop first —- * alarms that must ring outrank clocks that only display).- */-fun buildWearClockSnapshot(-    alarms: List<WearClockAlarm>,-    worldClocks: List<WearWorldClock>,-    generatedAtMillis: Long,-): WearClockSnapshot {-    val cappedAlarms = alarms-        .sortedWith(compareBy({ it.hour }, { it.minute }, { it.alarmId }))-        .map { it.copy(label = it.label.take(WearClockProtocol.MAX_LABEL_CHARS)) }-    val cappedWorld = worldClocks.map {-        it.copy(city = it.city.take(WearClockProtocol.MAX_CITY_CHARS))-    }-    var keptAlarms = cappedAlarms.take(WearClockProtocol.MAX_ALARMS)-    var keptWorld = cappedWorld.take(WearClockProtocol.MAX_WORLD_CLOCKS)-    var truncated = keptAlarms.size < cappedAlarms.size || keptWorld.size < cappedWorld.size-    var snapshot = WearClockSnapshot(generatedAtMillis, keptAlarms, keptWorld, truncated)-    fun bytes() = WearClockProtocol.json.encodeToString(-        WearClockSnapshot.serializer(), snapshot,-    ).encodeToByteArray().size-    while (bytes() > WearClockProtocol.MAX_JSON_BYTES && keptWorld.isNotEmpty()) {-        keptWorld = keptWorld.dropLast(1)-        truncated = true-        snapshot = WearClockSnapshot(generatedAtMillis, keptAlarms, keptWorld, true)-    }-    while (bytes() > WearClockProtocol.MAX_JSON_BYTES && keptAlarms.isNotEmpty()) {-        keptAlarms = keptAlarms.dropLast(1)-        truncated = true-        snapshot = WearClockSnapshot(generatedAtMillis, keptAlarms, keptWorld, true)-    }-    return snapshot-}--/**- * Next fire instant (epoch millis) for [hour]:[minute] with weekday- * [daysMask] (bit 0 = Sunday, 0 = one-shot) at or after [nowMillis] in- * [timeZone]. Calendar-based day stepping, matching the phone scheduler:- * adding a fixed 24h would land an hour off across DST transitions.- * An alarm whose time is exactly now fires tomorrow / on its next day.- *- * On a fall-back overlap day the wall time occurs twice; when "now" is- * already inside the second pass (the earlier-offset instant is past but- * the later-offset one is still ahead) the alarm fires at that second- * occurrence today, matching the phone scheduler.- */-fun nextWearAlarmTriggerMillis(-    hour: Int,-    minute: Int,-    daysMask: Int,-    nowMillis: Long,-    timeZone: TimeZone,-): Long {-    val now = Instant.fromEpochMilliseconds(nowMillis)-    val today = now.toLocalDateTime(timeZone).date-    val time = kotlinx.datetime.LocalTime(hour, minute)-    // Scan today through a week out (8 dates: a weekday-only alarm whose-    // time already passed today legitimately fires 7 days from today).-    for (dayOffset in 0..7) {-        val candidate = LocalDateTime(today.plus(dayOffset, DateTimeUnit.DAY), time)-        if (daysMask != 0) {-            val bit = when (candidate.dayOfWeek) {-                kotlinx.datetime.DayOfWeek.SUNDAY -> 0-                else -> candidate.dayOfWeek.ordinal + 1 // Mon ordinal 0 -> bit 1-            }-            if (daysMask and (1 shl bit) == 0) continue-        }-        for (occurrence in candidate.wearOccurrences(timeZone)) {-            if (occurrence > now) return occurrence.toEpochMilliseconds()-        }-    }-    return LocalDateTime(today.plus(8, DateTimeUnit.DAY), time)-        .toInstant(timeZone).toEpochMilliseconds()-}--/**- * The instant(s) this wall time occurs on its date in [timeZone]: one,- * except on a fall-back overlap day where it occurs twice — the- * earlier-offset instant plus the same wall time under the later offset.- * The local-time round-trip rejects gap resolutions and offset changes- * that belong to the next day rather than to a second pass today.- */-private fun LocalDateTime.wearOccurrences(timeZone: TimeZone): List<Instant> {-    val first = toInstant(timeZone)-    val laterOffset = timeZone.offsetAt(first.plus(1.days))-    if (laterOffset == timeZone.offsetAt(first)) return listOf(first)-    val second = toInstant(laterOffset)-    return if (second > first && second.toLocalDateTime(timeZone) == this) {-        listOf(first, second)-    } else {-        listOf(first)-    }-}
clock-wear/src/main/java/com/vayunmathur/clock/wear/platform/WatchAlarmScheduler.kt
diff --git a/clock-wear/src/main/java/com/vayunmathur/clock/wear/platform/WatchAlarmScheduler.kt b/clock-wear/src/main/java/com/vayunmathur/clock/wear/platform/WatchAlarmScheduler.ktindex 097adddc02..20969fd6b7 100644--- a/clock-wear/src/main/java/com/vayunmathur/clock/wear/platform/WatchAlarmScheduler.kt+++ b/clock-wear/src/main/java/com/vayunmathur/clock/wear/platform/WatchAlarmScheduler.kt@@ -9,9 +9,9 @@ import com.vayunmathur.clock.wear.domain.ArmAttempt import com.vayunmathur.clock.wear.domain.ArmFailureRecord import com.vayunmathur.clock.wear.domain.ArmedAlarmRecord import com.vayunmathur.clock.wear.domain.DisplayOnlyReason-import com.vayunmathur.clock.wear.domain.WearClockAlarm-import com.vayunmathur.clock.wear.domain.WearClockSnapshot-import com.vayunmathur.clock.wear.domain.nextWearAlarmTriggerMillis+import com.vayunmathur.library.wearlink.clock.WearClockAlarm+import com.vayunmathur.library.wearlink.clock.WearClockSnapshot+import com.vayunmathur.library.wearlink.clock.nextWearAlarmTriggerMillis import com.vayunmathur.clock.wear.ui.WearMainActivity import com.vayunmathur.library.log.Log import kotlinx.datetime.TimeZone
clock-wear/src/main/java/com/vayunmathur/clock/wear/sync/WearLinkBridge.kt
diff --git a/clock-wear/src/main/java/com/vayunmathur/clock/wear/sync/WearLinkBridge.kt b/clock-wear/src/main/java/com/vayunmathur/clock/wear/sync/WearLinkBridge.ktindex 7e673d9983..8f6345915d 100644--- a/clock-wear/src/main/java/com/vayunmathur/clock/wear/sync/WearLinkBridge.kt+++ b/clock-wear/src/main/java/com/vayunmathur/clock/wear/sync/WearLinkBridge.kt@@ -2,9 +2,9 @@ package com.vayunmathur.clock.wear.sync  import android.content.Context import com.vayunmathur.clock.wear.data.WearClockStore-import com.vayunmathur.clock.wear.domain.WearClockProtocol-import com.vayunmathur.clock.wear.domain.WearClockSnapshot-import com.vayunmathur.clock.wear.domain.WearClockWatchState+import com.vayunmathur.library.wearlink.clock.WearClockProtocol+import com.vayunmathur.library.wearlink.clock.WearClockSnapshot+import com.vayunmathur.library.wearlink.clock.WearClockWatchState import com.vayunmathur.clock.wear.domain.armedAndDisplayOnlyCounts import com.vayunmathur.clock.wear.platform.WatchAlarmScheduler import com.vayunmathur.library.log.Log
clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearAlarmsScreen.kt
diff --git a/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearAlarmsScreen.kt b/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearAlarmsScreen.ktindex 6aee39f229..4e461b3433 100644--- a/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearAlarmsScreen.kt+++ b/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearAlarmsScreen.kt@@ -21,7 +21,7 @@ import androidx.wear.compose.material.Text import com.vayunmathur.clock.wear.R import com.vayunmathur.clock.wear.data.WearClockStore import com.vayunmathur.clock.wear.domain.WearAlarmDisplayState-import com.vayunmathur.clock.wear.domain.WearClockAlarm+import com.vayunmathur.library.wearlink.clock.WearClockAlarm import com.vayunmathur.clock.wear.domain.formatWearAlarmDays import com.vayunmathur.clock.wear.domain.formatWearAlarmTime import com.vayunmathur.clock.wear.domain.resolveWearAlarmDisplay
clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearWorldClockScreen.kt
diff --git a/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearWorldClockScreen.kt b/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearWorldClockScreen.ktindex e78544005c..ef9700616d 100644--- a/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearWorldClockScreen.kt+++ b/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearWorldClockScreen.kt@@ -21,7 +21,7 @@ import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text import com.vayunmathur.clock.wear.R import com.vayunmathur.clock.wear.data.WearClockStore-import com.vayunmathur.clock.wear.domain.WearWorldClock+import com.vayunmathur.library.wearlink.clock.WearWorldClock import com.vayunmathur.clock.wear.domain.formatWearAlarmTime import kotlinx.coroutines.delay import kotlinx.datetime.TimeZone
clock-wear/src/screenshotTest/kotlin/com/vayunmathur/clock/wear/ui/MetadataPreviews.kt
diff --git a/clock-wear/src/screenshotTest/kotlin/com/vayunmathur/clock/wear/ui/MetadataPreviews.kt b/clock-wear/src/screenshotTest/kotlin/com/vayunmathur/clock/wear/ui/MetadataPreviews.ktindex f91ddc04f0..28428d9cc5 100644--- a/clock-wear/src/screenshotTest/kotlin/com/vayunmathur/clock/wear/ui/MetadataPreviews.kt+++ b/clock-wear/src/screenshotTest/kotlin/com/vayunmathur/clock/wear/ui/MetadataPreviews.kt@@ -12,8 +12,8 @@ import androidx.wear.compose.material.MaterialTheme import com.android.tools.screenshot.PreviewTest import com.vayunmathur.clock.wear.data.WearClockPersisted import com.vayunmathur.clock.wear.domain.ArmedAlarmRecord-import com.vayunmathur.clock.wear.domain.WearClockAlarm-import com.vayunmathur.clock.wear.domain.WearClockSnapshot+import com.vayunmathur.library.wearlink.clock.WearClockAlarm+import com.vayunmathur.library.wearlink.clock.WearClockSnapshot  /** Round watch, 454x454px class (227dp at 320dpi) — Pixel Watch / Galaxy Watch size. */ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"
clock-wear/src/test/java/com/vayunmathur/clock/wear/domain/WearAlarmStateTest.kt
diff --git a/clock-wear/src/test/java/com/vayunmathur/clock/wear/domain/WearAlarmStateTest.kt b/clock-wear/src/test/java/com/vayunmathur/clock/wear/domain/WearAlarmStateTest.ktindex 2912281543..e0466b601c 100644--- a/clock-wear/src/test/java/com/vayunmathur/clock/wear/domain/WearAlarmStateTest.kt+++ b/clock-wear/src/test/java/com/vayunmathur/clock/wear/domain/WearAlarmStateTest.kt@@ -1,4 +1,5 @@ package com.vayunmathur.clock.wear.domain+import com.vayunmathur.library.wearlink.clock.WearClockAlarm  import kotlin.test.Test import kotlin.test.assertEquals
clock-wear/src/test/java/com/vayunmathur/clock/wear/domain/WearClockProtocolTest.kt
diff --git a/clock-wear/src/test/java/com/vayunmathur/clock/wear/domain/WearClockProtocolTest.kt b/clock-wear/src/test/java/com/vayunmathur/clock/wear/domain/WearClockProtocolTest.ktindex d216eb25b1..cc1c5280b1 100644--- a/clock-wear/src/test/java/com/vayunmathur/clock/wear/domain/WearClockProtocolTest.kt+++ b/clock-wear/src/test/java/com/vayunmathur/clock/wear/domain/WearClockProtocolTest.kt@@ -1,4 +1,11 @@ package com.vayunmathur.clock.wear.domain+import com.vayunmathur.library.wearlink.clock.WearClockAlarm+import com.vayunmathur.library.wearlink.clock.WearClockProtocol+import com.vayunmathur.library.wearlink.clock.WearClockSnapshot+import com.vayunmathur.library.wearlink.clock.WearClockWatchState+import com.vayunmathur.library.wearlink.clock.WearWorldClock+import com.vayunmathur.library.wearlink.clock.buildWearClockSnapshot+import com.vayunmathur.library.wearlink.clock.nextWearAlarmTriggerMillis  import kotlin.test.Test import kotlin.test.assertEquals
clock-wear/src/test/java/com/vayunmathur/clock/wear/platform/BootReceiverTimezoneTest.kt
diff --git a/clock-wear/src/test/java/com/vayunmathur/clock/wear/platform/BootReceiverTimezoneTest.kt b/clock-wear/src/test/java/com/vayunmathur/clock/wear/platform/BootReceiverTimezoneTest.ktindex 66f451d81f..f7e436e63f 100644--- a/clock-wear/src/test/java/com/vayunmathur/clock/wear/platform/BootReceiverTimezoneTest.kt+++ b/clock-wear/src/test/java/com/vayunmathur/clock/wear/platform/BootReceiverTimezoneTest.kt@@ -5,9 +5,9 @@ import android.content.Context import android.content.Intent import androidx.test.core.app.ApplicationProvider import com.vayunmathur.clock.wear.data.WearClockStore-import com.vayunmathur.clock.wear.domain.WearClockAlarm-import com.vayunmathur.clock.wear.domain.WearClockSnapshot-import com.vayunmathur.clock.wear.domain.nextWearAlarmTriggerMillis+import com.vayunmathur.library.wearlink.clock.WearClockAlarm+import com.vayunmathur.library.wearlink.clock.WearClockSnapshot+import com.vayunmathur.library.wearlink.clock.nextWearAlarmTriggerMillis import kotlinx.datetime.TimeZone import kotlinx.datetime.toLocalDateTime import org.junit.After
clock/src/main/java/com/vayunmathur/clock/sync/WearClockSync.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/sync/WearClockSync.kt b/clock/src/main/java/com/vayunmathur/clock/sync/WearClockSync.ktindex 5c4b3594c8..19b63e513a 100644--- a/clock/src/main/java/com/vayunmathur/clock/sync/WearClockSync.kt+++ b/clock/src/main/java/com/vayunmathur/clock/sync/WearClockSync.kt@@ -2,12 +2,12 @@ package com.vayunmathur.clock.sync  import android.content.Context import com.vayunmathur.clock.data.ClockRepository-import com.vayunmathur.clock.domain.WearClockAlarm-import com.vayunmathur.clock.domain.WearClockProtocol-import com.vayunmathur.clock.domain.WearClockSnapshot-import com.vayunmathur.clock.domain.WearClockWatchState-import com.vayunmathur.clock.domain.WearWorldClock-import com.vayunmathur.clock.domain.buildWearClockSnapshot+import com.vayunmathur.library.wearlink.clock.WearClockAlarm+import com.vayunmathur.library.wearlink.clock.WearClockProtocol+import com.vayunmathur.library.wearlink.clock.WearClockSnapshot+import com.vayunmathur.library.wearlink.clock.WearClockWatchState+import com.vayunmathur.library.wearlink.clock.WearWorldClock+import com.vayunmathur.library.wearlink.clock.buildWearClockSnapshot import com.vayunmathur.clock.platform.AlarmScheduler import com.vayunmathur.clock.platform.WorldClockCities import com.vayunmathur.library.log.Log
clock/src/test/java/com/vayunmathur/clock/domain/WearClockProtocolTest.kt
diff --git a/clock/src/test/java/com/vayunmathur/clock/domain/WearClockProtocolTest.kt b/clock/src/test/java/com/vayunmathur/clock/domain/WearClockProtocolTest.ktindex d569b7096a..905290e20e 100644--- a/clock/src/test/java/com/vayunmathur/clock/domain/WearClockProtocolTest.kt+++ b/clock/src/test/java/com/vayunmathur/clock/domain/WearClockProtocolTest.kt@@ -1,4 +1,11 @@ package com.vayunmathur.clock.domain+import com.vayunmathur.library.wearlink.clock.WearClockAlarm+import com.vayunmathur.library.wearlink.clock.WearClockProtocol+import com.vayunmathur.library.wearlink.clock.WearClockSnapshot+import com.vayunmathur.library.wearlink.clock.WearClockWatchState+import com.vayunmathur.library.wearlink.clock.WearWorldClock+import com.vayunmathur.library.wearlink.clock.buildWearClockSnapshot+import com.vayunmathur.library.wearlink.clock.nextWearAlarmTriggerMillis  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 a33479eba4..7b4aa393ea 100644--- a/docs/structure/wear-protocol-pairs.tsv+++ b/docs/structure/wear-protocol-pairs.tsv@@ -5,10 +5,11 @@ # lines and all comments, then requires token-stream identity per pair. # 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). 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-clock	clock/src/main/java/com/vayunmathur/clock/domain/WearClockProtocol.kt	clock-wear/src/main/java/com/vayunmathur/clock/wear/domain/WearClockProtocol.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
library/wearlink/AGENTS.md
diff --git a/library/wearlink/AGENTS.md b/library/wearlink/AGENTS.mdindex 8bdbab2f88..7cdbdf448b 100644--- a/library/wearlink/AGENTS.md+++ b/library/wearlink/AGENTS.md@@ -3,7 +3,8 @@ > Scoped supplement. Global rules in root `AGENTS.md` apply.  - Gradle: :library:wearlink / dir: library/wearlink/-- Package: `com.vayunmathur.library.wearlink` (single package, like :library:log)+- Package: `com.vayunmathur.library.wearlink` for the transport, plus one+  per-app protocol subpackage (e.g. `com.vayunmathur.library.wearlink.clock`) - Entry: `WearLinkNode.kt` (Android), `WearLinkProtocol.kt` (pure wire)  ## Purpose@@ -11,6 +12,14 @@ First-party replacement for the proprietary Play-services Wearable Data Layer. RFCOMM over already-bonded Bluetooth, both sides listen + dial, cert-bound handshake. No Play services, no BLE scan/advertise, no location. +Also hosts the shared phone<->wear wire protocols that were previously+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+`docs/structure/wear-protocol-pairs.tsv`.+ ## Verify ``` ./gradlew :library:wearlink:testDebugUnitTest
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/clock/WearClockProtocol.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/domain/WearClockProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/clock/WearClockProtocol.ktsimilarity index 95%rename from clock/src/main/java/com/vayunmathur/clock/domain/WearClockProtocol.ktrename to library/wearlink/src/main/java/com/vayunmathur/library/wearlink/clock/WearClockProtocol.ktindex 598358144d..64f8da5e47 100644--- a/clock/src/main/java/com/vayunmathur/clock/domain/WearClockProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/clock/WearClockProtocol.kt@@ -1,4 +1,4 @@-package com.vayunmathur.clock.domain+package com.vayunmathur.library.wearlink.clock  import kotlinx.datetime.DateTimeUnit import kotlinx.datetime.LocalDateTime@@ -15,11 +15,9 @@ import kotlin.time.Instant /**  * Phone <-> watch sync protocol for the Wear OS Clock companion.  *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module (`:clock:wear`,- * applicationId `com.vayunmathur.clock`) carries a copy of this file under- * `com.vayunmathur.clock.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 (`:clock`) and the watch (`:clock: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).