calendar: sync over the watch conduit client
- Commit
987736eb4dcab1699320120f91f895b60c71b34f- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 01:50 UTC (4 days ago)
- Parents
a0f55cd
Stage B-2 of the Watch conduit migration: the calendar pair (:calendar phone, :calendar:wear watch) no longer owns an RFCOMM WearLinkNode each. Both sides now talk through WearLinkClientNode, the Messenger client of the Watch app's watch_conduit service (:library:wearlink conduit package, Stage A), following the clock pilot (c0d783b88) exactly. The Watch apps are the sole Bluetooth holders; calendar apps hold no Bluetooth code path for this channel. What changed: - calendar sync/WearCalendarSync.kt: WearLinkNode replaced with WearLinkClientNode, same listener, start and state handling. Presence still derives from WearLinkState.Connected via wearCompanionPresent, snapshots still republish on the Connected edge and on debounced calendar changes, watch-state data items still land in WearSyncState, and the request-sync message still triggers publishSnapshot(). - calendar-wear sync/WearLinkBridge.kt: same swap; get() now returns WearLinkClientNode. Snapshot -> WearCalendarStore.setSnapshot, watch-state putData and requestSync sendMessage call sites are unchanged (WearSyncRequest doc updated to conduit wording). - Conduit appId is the first path segment of the calendar paths (ConduitProtocol.routeKey of /calendar/snapshot, i.e. "calendar"), not the old RFCOMM handshake capability "calendar_wear_companion": the router namespaces traffic by that segment and would refuse the capability string. - Bluetooth prompting removed from calendar MainActivity and calendar-wear WearMainActivity (WearLinkPermissions.requestIfNeeded deleted). PermissionMissing handling stays graceful by construction: client nodes report NotInstalled/Unavailable when the Watch app is absent or unbound, sends return false, and both apps keep working from local state with no prompt loops; only the Watch apps prompt now. - Listener callbacks remain non-blocking (StateFlow updates and launches onto the IO scope), so the conduit router sink-under- lock delivery cannot deadlock against these clients, and snapshots republish exactly as before on Connected. Residual Bluetooth source (deliberate, this stage): neither app manifest declares any Bluetooth permission, but the merged manifests still contain BLUETOOTH_CONNECT plus the maxSdk-30 BLUETOOTH/BLUETOOTH_ADMIN pair, merged solely from :library:wearlink's own manifest. That library manifest stays until every app pair has migrated to the client node. Docs: calendar/AGENTS.md gains the wear-sync (conduit client) section and lists the sync package and :library:wearlink dep; calendar-wear/AGENTS.md protocol section and library/wearlink/ AGENTS.md now describe the calendar pair as migrated. Verified on devvm21958 (./gradlew, offline): - :calendar:wear:testDebugUnitTest: 10 tests, 0 failures/errors. - :library:wearlink:testDebugUnitTest: 15 tests, 0 failures. - :calendar:wear:compileDevKotlin, :calendar:wear:assembleDev: successful. - :calendar:wear:lint and :library:wearlink:lint: BUILD SUCCESSFUL, 0 errors. - :calendar:compileDevKotlin, :calendar:testDevUnitTest and :calendar:lint / :calendar:lintVitalRelease: BLOCKED by a pre-existing failure untouched by this change - CustomReminderDialog.kt:19 Unresolved reference CustomReminderDialogContent (no definition in the repo). Reproduced identically on a pristine HEAD (c0d783b88) worktree, so the phone-side compile/test/lint cannot go green until that dialog is fixed separately. The only compiler errors reported in :calendar are that dialog's; no error names a file this change touched. :calendar:ktlintCheck likewise fails on pre-existing module-wide backlog in untouched files.
Diff
calendar-wear/AGENTS.md
diff --git a/calendar-wear/AGENTS.md b/calendar-wear/AGENTS.mdindex eb62473b06..e6797229a4 100644--- a/calendar-wear/AGENTS.md+++ b/calendar-wear/AGENTS.md@@ -4,7 +4,7 @@ > `calendar-wear/` + `calendar/` (the phone side of the same feature). - Gradle: :calendar:wear (dir calendar-wear/) / dir: calendar-wear/ (convention: `common-conventions-wear`)-- Package roots present: ui, data, domain, service+- Package roots present: ui, data, domain, sync - Entry file: ui/WearMainActivity.kt ## Why this module exists (read before changing identity)@@ -22,9 +22,9 @@ The wire protocol lives in `:library:wearlink` at 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-- Transport: :library:wearlink (RFCOMM, no Play services); app-lifecycle-bound+- Snapshot + watch-state sync: conduit data items (`/calendar/snapshot`, `/calendar/watch-state`)+- Sync request: conduit message (`/calendar/request-sync`), watch -> phone only+- Transport: Watch conduit client — `sync/WearLinkBridge.kt` uses `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `calendar`); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so `WearMainActivity` never prompts for Bluetooth. With the Watch app absent the bridge stays `NotInstalled`/`Unavailable` and everything renders from the persisted store. App-lifecycle-bound (no Play services, no listener service) ## What the watch can and cannot do Read-only. It renders today's agenda, upcoming events and event detail from
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 687bf07b66..0587bb2db2 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@@ -7,7 +7,8 @@ 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+import com.vayunmathur.library.wearlink.conduit.ConduitProtocol+import com.vayunmathur.library.wearlink.conduit.WearLinkClientNode import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob@@ -15,26 +16,27 @@ import kotlinx.coroutines.launch import kotlinx.serialization.encodeToString /**- * Watch side of WearLink for Calendar: snapshot data items land in- * [WearCalendarStore], watch state goes back as a data item, and- * request-sync is a message. Replaces the Play-services listener service;- * delivery is bound to this process being alive.+ * Watch side of the Watch conduit client for Calendar: snapshot data items+ * land in [WearCalendarStore], watch state goes back as a data item, and+ * request-sync is a message. Transport is `WearLinkClientNode` (Messenger+ * to the Watch app's conduit service); this app owns no RFCOMM link.+ * Delivery is bound to this process being alive. */ object WearLinkBridge { private const val TAG = "WearLinkBridge" private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO) @Volatile- private var node: WearLinkNode? = null+ private var node: WearLinkClientNode? = null - fun get(context: Context): WearLinkNode {+ fun get(context: Context): WearLinkClientNode { val appContext = context.applicationContext return node ?: synchronized(this) { node ?: create(appContext).also { node = it } } } - private fun create(context: Context): WearLinkNode {+ private fun create(context: Context): WearLinkClientNode { val listener = object : WearLinkListener { override fun onData(path: String, body: ByteArray) { if (path != WearCalendarProtocol.SNAPSHOT_PATH) return@@ -50,7 +52,13 @@ object WearLinkBridge { WearCalendarStore.get(context).setSnapshot(snapshot) } }- return WearLinkNode(context, WearCalendarProtocol.CAPABILITY, listener).also { it.start() }+ // Conduit appId = first path segment of the calendar paths (the+ // ConduitProtocol route key), not the RFCOMM handshake capability.+ return WearLinkClientNode(+ context,+ ConduitProtocol.routeKey(WearCalendarProtocol.SNAPSHOT_PATH),+ listener,+ ).also { it.start() } } fun publishWatchState(context: Context, snapshot: WearCalendarSnapshot) {
calendar-wear/src/main/java/com/vayunmathur/calendar/wear/sync/WearSyncRequest.kt
diff --git a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/sync/WearSyncRequest.kt b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/sync/WearSyncRequest.ktindex ddc22d2425..5e5bded470 100644--- a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/sync/WearSyncRequest.kt+++ b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/sync/WearSyncRequest.kt@@ -3,8 +3,8 @@ package com.vayunmathur.calendar.wear.sync import android.content.Context /**- * Asks the phone for a fresh snapshot over WearLink. Returns false when no- * phone session is live — the watch keeps rendering its last synced copy,+ * Asks the phone for a fresh snapshot over the conduit. Returns false when+ * the conduit link is not connected — the watch keeps rendering its last synced copy, * and the UI says exactly that instead of pretending a sync happened. */ suspend fun requestWearSync(context: Context): Boolean = WearLinkBridge.requestSync(context)
calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearMainActivity.kt
diff --git a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearMainActivity.kt b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearMainActivity.ktindex f8e0f3bfe2..a2fd5099b7 100644--- a/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearMainActivity.kt+++ b/calendar-wear/src/main/java/com/vayunmathur/calendar/wear/ui/WearMainActivity.kt@@ -1,35 +1,47 @@ package com.vayunmathur.calendar.wear.ui -import androidx.compose.runtime.Composable+import android.os.Bundle+import androidx.activity.ComponentActivity+import androidx.activity.compose.setContent+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.wear.compose.material.MaterialTheme import com.vayunmathur.calendar.wear.data.WearCalendarStore-import com.vayunmathur.library.wearlink.WearShellActivity /** * Watch calendar entry: agenda list and event detail, rendered only from the * locally stored snapshot so it works standalone (phone absent, cold start). */-class WearMainActivity : WearShellActivity<WearRoute, WearCalendarStore>(WearRoute.Agenda) {+class WearMainActivity : ComponentActivity() { - override fun createStore() = WearCalendarStore.get(this).also {+ override fun onCreate(savedInstanceState: Bundle?) {+ super.onCreate(savedInstanceState)+ // No Bluetooth prompt here: the Watch app owns the conduit link+ // and its permission. With the Watch app absent the bridge stays+ // NotInstalled/Unavailable and the local store keeps working.+ val store = WearCalendarStore.get(this) com.vayunmathur.calendar.wear.sync.WearLinkBridge.get(this)- it.publishWatchState()- }-- @Composable- override fun Screen(route: WearRoute, navigate: (WearRoute) -> Unit) {- when (val current = route) {- WearRoute.Agenda -> WearAgendaScreen(- store = store,- onOpenEvent = { event ->- navigate(WearRoute.Event(event.eventId, event.startMillis))- },- )- is WearRoute.Event -> WearEventScreen(- store = store,- eventId = current.eventId,- startMillis = current.startMillis,- onBack = { navigate(WearRoute.Agenda) },- )+ store.publishWatchState()+ setContent {+ MaterialTheme {+ var route by remember { mutableStateOf<WearRoute>(WearRoute.Agenda) }+ when (val current = route) {+ WearRoute.Agenda -> WearAgendaScreen(+ store = store,+ onOpenEvent = { event ->+ route = WearRoute.Event(event.eventId, event.startMillis)+ },+ )+ is WearRoute.Event -> WearEventScreen(+ store = store,+ eventId = current.eventId,+ startMillis = current.startMillis,+ onBack = { route = WearRoute.Agenda },+ )+ }+ } } } }
calendar/AGENTS.md
diff --git a/calendar/AGENTS.md b/calendar/AGENTS.mdindex 52e943246b..2dccf0eb36 100644--- a/calendar/AGENTS.md+++ b/calendar/AGENTS.md@@ -4,9 +4,9 @@ _Install: ./install calendar (dev by default)._ - Gradle: :calendar / dir: calendar/-- Package roots present: ui, data, intents-- Entry files: MainActivity.kt, Route.kt, Navigation.kt-- Deps: :library:widgets+- Package roots present: ui, data, intents, sync+- Entry files: MainActivity.kt (no Route.kt — single-screen app with dialogs, not nav destinations)+- Deps: :library:widgets, :library:wearlink - Metadata: metadata_data/calendar.md (present) - Rust: no / screenshotTest: yes @@ -19,6 +19,12 @@ _Install: ./install calendar (dev by default)._ - Self-refreshing Glance widgets (agenda + month); assistant read/add via `intents/` **Architecture / data-flow:** `ui/` screens + `ui/dialogs/` editors → `util/CalendarViewModel` (+ `CalendarUiContract`) → `data/` models (`Calendar`/`Event`/`Instance`/`ReminderMirror`); reminders flow ViewModel → `ReminderScheduler` → `ReminderReceiver` → notification, re-armed on boot. **Entry points + reading order:** `MainActivity.kt` → `ui/CalendarScreen.kt` → `util/CalendarViewModel.kt` → `data/Event.kt` + `data/Instance.kt` → `util/RRule.kt` → `util/ReminderScheduler.kt`.++## Wear sync (Watch conduit client)+**Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.calendar.WearCalendarProtocol` (also consumed by `:calendar:wear`); the golden-JSON tests pin the shared code's wire format.+- Snapshot + watch-state sync: conduit data items (`/calendar/snapshot` phone -> watch, `/calendar/watch-state` watch -> phone)+- Sync request: conduit message (`/calendar/request-sync`), watch -> phone only+- **Transport: Watch conduit client** — `sync/WearCalendarSync.kt` uses `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `calendar`); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so `MainActivity` never prompts for Bluetooth. With the Watch app absent the node reports `NotInstalled`/`Unavailable` and the sync stays idle; snapshots republish on conduit `Connected` and on calendar changes. **Gotchas:** - `util/` is NOT a closed package root — don't add more files there - Holiday data is generated by `scripts/calendar`, not hand-written — regenerate, don't edit@@ -77,8 +83,8 @@ _Install: ./install calendar (dev by default)._ - com/vayunmathur/calendar/ui/dialogs/SettingsDeleteCalendarDialog.kt - com/vayunmathur/calendar/ui/dialogs/SettingsRenameCalendarDialog.kt - com/vayunmathur/calendar/ui/dialogs/TimezonePickerDialog.kt-- com/vayunmathur/calendar/ui/dialogs/CustomReminderDialog.kt-- com/vayunmathur/calendar/ui/dialogs/CustomReminderDialogContent.kt+### sync/ — wear companion sync+- com/vayunmathur/calendar/sync/WearCalendarSync.kt — conduit client node; snapshot publish, watch-state receive, request-sync handling ### glance/ + intents/ — widgets and assistant IPC - com/vayunmathur/calendar/glance/CalendarGlanceWidget.kt - com/vayunmathur/calendar/glance/CalendarGlanceWidgetReceiver.kt
calendar/src/main/java/com/vayunmathur/calendar/MainActivity.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/MainActivity.kt b/calendar/src/main/java/com/vayunmathur/calendar/MainActivity.ktindex 9e67e176ee..dbb311e9ac 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/MainActivity.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/MainActivity.kt@@ -42,7 +42,10 @@ class MainActivity : MaActivity() { private val pendingDate = mutableStateOf<LocalDate?>(null) override fun onCreateBeforeContent() {- com.vayunmathur.library.wearlink.WearLinkPermissions.requestIfNeeded(this)+ // No Bluetooth prompt here: the Watch app owns the conduit link+ // and its permission. Wear sync runs over WearLinkClientNode via+ // CalendarViewModel; with the Watch app absent it reports+ // NotInstalled/Unavailable and the calendar keeps working locally. updateWidgetPreviews(CalendarGlanceWidgetReceiver::class) handleIntent(intent) }
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 498694fccf..273a01f727 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/sync/WearCalendarSync.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/sync/WearCalendarSync.kt@@ -12,8 +12,9 @@ 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 import com.vayunmathur.library.wearlink.WearLinkState+import com.vayunmathur.library.wearlink.conduit.ConduitProtocol+import com.vayunmathur.library.wearlink.conduit.WearLinkClientNode import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job@@ -43,14 +44,18 @@ data class WearSyncState( ) /**- * Phone side of the wear sync over WearLink (RFCOMM, :library:wearlink):- * presence is a completed handshake, the snapshot is a data item, and the- * watch's request-sync is a message handled here while this process lives.+ * Phone side of the wear sync over the Watch conduit client+ * (:library:wearlink `WearLinkClientNode`: a Messenger binding to the+ * Watch app's conduit service, not an RFCOMM link this app owns):+ * presence is the peer-link Connected state the conduit reports, the+ * snapshot is a data item, and the watch's request-sync is a message+ * handled here while this process lives. *- * "No Bluetooth permission / no watch / watch without the companion" is a+ * "Watch app absent / no watch / watch without the companion" is a * normal state ([WearSyncState.companionPresent] = false), never a crash.- * There is no Play-services listener service any more: a sync request- * arriving while the phone app is dead waits until it next runs.+ * There is no Play-services listener service: a sync request arriving+ * while the phone app is dead waits until it next runs, and the snapshot+ * republishes on conduit Connected and on calendar changes. */ class WearCalendarSync private constructor(context: Context) { @@ -92,7 +97,13 @@ class WearCalendarSync private constructor(context: Context) { } } - private val node = WearLinkNode(appContext, WearCalendarProtocol.CAPABILITY, listener)+ // Conduit appId = first path segment of the calendar paths (the+ // ConduitProtocol route key), not the RFCOMM handshake capability.+ private val node = WearLinkClientNode(+ appContext,+ ConduitProtocol.routeKey(WearCalendarProtocol.SNAPSHOT_PATH),+ listener,+ ) private var started = false private var pendingPublish: Job? = null@@ -141,7 +152,7 @@ class WearCalendarSync private constructor(context: Context) { ) } } else {- Log.status(TAG, "publish snapshot not delivered (no live WearLink session)")+ Log.status(TAG, "publish snapshot not delivered (conduit link not connected)") } }
library/wearlink/AGENTS.md
diff --git a/library/wearlink/AGENTS.md b/library/wearlink/AGENTS.mdindex 3317c8fe93..9f614fbb05 100644--- a/library/wearlink/AGENTS.md+++ b/library/wearlink/AGENTS.md@@ -34,10 +34,10 @@ unregistered apps, status fan-out, counters), `WearLinkClientNode` (drop-in `WearLinkNode` replacement over the conduit binding; reports `NotInstalled`/`Unavailable` when the Watch app is absent), and `ConduitHost`/`ConduitRuntime` used by the two Watch apps'-`ConduitService`s. The clock pair (`:clock` / `:clock:wear`) has-migrated to the client; the remaining app pairs still own their-`WearLinkNode`s, and this module's manifest Bluetooth permissions stay-until they migrate.+`ConduitService`s. The clock pair (`:clock` / `:clock:wear`) and the+calendar pair (`:calendar` / `:calendar:wear`) have migrated to the+client; the remaining app pairs still own their `WearLinkNode`s, and+this module's manifest Bluetooth permissions stay until they migrate. ## Verify ```