todo: sync over the watch conduit client
- Commit
304025cb1e686250baa170949fc185a5c24eb68a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-04 19:37 UTC (1 day ago)
- Parents
20695a0
Migrate the TODO phone<->watch sync from its direct RFCOMM WearLinkNode to the Watch conduit client, following the already-migrated clock pair exactly. Both sides of the single merged Todo APK now talk through WearLinkClientNode, the Messenger client of the Watch app's watch_conduit service in :library:wearlink's conduit package. The Watch apps are the sole Bluetooth holders; this app owns no RFCOMM link for the channel. What changed: - sync/WearTodoSync.kt (phone): WearLinkNode replaced with WearLinkClientNode under conduit appId "todo" (the ConduitProtocol route key of /todo/catalog), not the old RFCOMM handshake capability. Presence still derives from WearLinkState.Connected, the catalog and tracked/default pages still republish on the Connected edge and on debounced todo/list changes, watch-state data items still land in WearTodoSyncState, and request-sync/request-page/op messages are handled exactly as before, including the phone-side op application (set-done roll-forward, snoozes, QuickAddParser quick-adds, edits, deletes) and the republish that drops ops from the watch's pending queue. - sync/WearLinkBridge.kt (watch): same swap; get() now returns WearLinkClientNode. Catalog/page data items still land in WearTodoStore, watch-state putData, pending-op flush on Connected, and the requestSync/requestPage sendMessage call sites are unchanged. - MainActivity: the Bluetooth permission request (WearLinkPermissions.requestIfNeeded) is deleted, and WearMainActivity documents the same stance as clock's: with the Watch app absent the node reports NotInstalled/ Unavailable, sends return false, and both experiences keep working from local state with no prompt. - todo/AGENTS.md: the wear sections now describe the conduit client in the present tense (conduit data items/messages, appId todo, Connected republishing, NotInstalled/Unavailable degradation). The wire protocol is unchanged: library.wearlink.todo types and the golden-JSON tests are untouched, and no direct WearLinkNode construction remains on this app's path. Verified in the worktree on devvm21958: ./gradlew :todo:lint :todo:lintVitalRelease :todo:testDevUnitTest (with the owner's JDK21/Android SDK env, --max-workers=128 -Dorg.gradle.jvmargs=-Xmx64g): BUILD SUCCESSFUL; 426 unit tests, 0 failures/errors/skipped.
Diff
todo/AGENTS.md
diff --git a/todo/AGENTS.md b/todo/AGENTS.mdindex 5978c65cba..b873a48512 100644--- a/todo/AGENTS.md+++ b/todo/AGENTS.md@@ -34,10 +34,10 @@ watch, and `notifications/BootReceiver` early-returns there. ## Wear sync (Watch conduit client) **Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.todo.WearTodoProtocol`; the golden-JSON tests in this module pin the shared code's wire format.-- Catalog + page snapshots: WearLink data items (`/todo/catalog`, `/todo/page`, phone -> watch; paginated, PAGE_SIZE tasks per page)-- Page/sync requests: WearLink messages (`/todo/request-page`, `/todo/request-sync`, watch -> phone)-- Watch-originated ops: WearLink message (`/todo/op`: SET_DONE incl. repeating-task roll-forward on the phone, SNOOZE_HOUR/SNOOZE_TOMORROW, QUICK_ADD parsed by the phone's QuickAddParser, EDIT title/due/priority, DELETE with watch-side confirmation)-- Transport: :library:wearlink (RFCOMM, no Play services); app-lifecycle-bound. Phone side is `sync/WearTodoSync.kt`; watch side is `sync/WearLinkBridge.kt`.+- Catalog + page snapshots: conduit data items (`/todo/catalog`, `/todo/page`, phone -> watch; paginated, PAGE_SIZE tasks per page)+- Page/sync requests: conduit messages (`/todo/request-page`, `/todo/request-sync`, watch -> phone)+- Watch-originated ops: conduit message (`/todo/op`: SET_DONE incl. repeating-task roll-forward on the phone, SNOOZE_HOUR/SNOOZE_TOMORROW, QUICK_ADD parsed by the phone's QuickAddParser, EDIT title/due/priority, DELETE with watch-side confirmation)+- **Transport: Watch conduit client** — phone side `sync/WearTodoSync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `todo`); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so neither entry activity prompts for Bluetooth. With the Watch app absent the node reports `NotInstalled`/`Unavailable` and the sync stays idle; the catalog and tracked pages republish on conduit `Connected` and on todo/list changes, and pending watch ops flush on `Connected`. App-lifecycle-bound (no Play services, no listener service). ## Watch experience (in this module) - `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over home (the phone drawer's view index) / task pages / task detail / quick-add / edit / delete-confirm, mirroring the phone `Route` (detail routes carry the task syncId, the cross-device identity). Settings, search, sort, manual reorder, bulk selection, list/tag/section editing, recurrence and reminder-offset editing, blocked-by/estimates, and subtask creation stay on the phone; existing subtasks show and can be checked off.@@ -64,7 +64,7 @@ watch, and `notifications/BootReceiver` early-returns there. ### ui/dialogs/ - ListPickerDialog.kt, ListSectionPickerDialog.kt, ListEditDialog.kt, TodoDatePickerDialog.kt, TodoTimePickerDialog.kt, DeleteTodoDialog.kt, DeleteListDialog.kt, ImportConfirmDialog.kt (stateless dialog content for the dialog routes) ### sync/-- RelayTodoProvider.kt, RelayEnvelopes.kt, CalendarMirror.kt, WearTodoSync.kt (phone side of the wear sync; wire protocol `com.vayunmathur.library.wearlink.todo.WearTodoProtocol` in `:library:wearlink`), WearLinkBridge.kt (watch side of the same sync)+- RelayTodoProvider.kt, RelayEnvelopes.kt, CalendarMirror.kt, WearTodoSync.kt (phone conduit client node; catalog/page publish, watch-state receive, page/sync requests and watch-op application; wire protocol `com.vayunmathur.library.wearlink.todo.WearTodoProtocol` in `:library:wearlink`), WearLinkBridge.kt (watch conduit client node; catalog/page receive into the store, watch-state publish, pending-op flush, page/sync requests) ### Watch experience (ui/ + data/) - ui/WearMainActivity.kt — watch entry (WearShellActivity) - ui/WearRoute.kt, WearTodoHomeScreen.kt, WearTodoPageScreen.kt, WearTodoTaskScreen.kt, WearTodoQuickAddScreen.kt, WearTodoEditScreen.kt, WearTodoConfirmDeleteScreen.kt
todo/src/main/java/com/vayunmathur/todo/MainActivity.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/MainActivity.kt b/todo/src/main/java/com/vayunmathur/todo/MainActivity.ktindex e6a095a19e..f9297af2a9 100644--- a/todo/src/main/java/com/vayunmathur/todo/MainActivity.kt+++ b/todo/src/main/java/com/vayunmathur/todo/MainActivity.kt@@ -16,7 +16,7 @@ import com.vayunmathur.todo.ui.WearMainActivity * Sole launcher entry of the single merged Todo APK. On a watch (the * `android.hardware.type.watch` system feature, see [FormFactor]) it hands * off to [WearMainActivity] and finishes before any phone state (Room,- * phone sync, permission request) is touched; on a phone it builds the+ * phone sync) is touched; on a phone it builds the * repository and view model, forwards intents to IntentRouter, and hosts * the navigation graph. */@@ -41,10 +41,12 @@ class MainActivity : MaActivity() { override fun onCreateBeforeContent() { if (routedToWear) return- com.vayunmathur.library.wearlink.WearLinkPermissions.requestIfNeeded(this) todoRepository = TodoRepository.get(applicationContext)- // Wear companion lives and dies with this process (WearLink has no- // system wakeup); it publishes once the link connects.+ // Wear OS companion sync over the Watch conduit client (no Play+ // services, no Bluetooth prompt here — prompting is the Watch+ // app's job). Delivery is app-lifecycle-bound: starting here+ // (re)publishes the catalog/pages whenever the conduit reports+ // the watch link connected. com.vayunmathur.todo.sync.WearTodoSync.get(applicationContext).start() IntentRouter.handle(intent) }
todo/src/main/java/com/vayunmathur/todo/sync/WearLinkBridge.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/sync/WearLinkBridge.kt b/todo/src/main/java/com/vayunmathur/todo/sync/WearLinkBridge.ktindex d8988b8bf0..5b37bf4a2b 100644--- a/todo/src/main/java/com/vayunmathur/todo/sync/WearLinkBridge.kt+++ b/todo/src/main/java/com/vayunmathur/todo/sync/WearLinkBridge.kt@@ -3,7 +3,8 @@ package com.vayunmathur.todo.sync import android.content.Context 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 com.vayunmathur.library.wearlink.WearLinkState import com.vayunmathur.library.wearlink.todo.WearTodoCatalog import com.vayunmathur.library.wearlink.todo.WearTodoPage@@ -18,27 +19,31 @@ import kotlinx.coroutines.launch import kotlinx.serialization.encodeToString /**- * Watch side of WearLink for Todo: catalog/page data items land in- * [WearTodoStore], watch state goes back as a data item, pending ops and- * page/sync requests are messages. Pending ops are (re)sent whenever a- * session connects and whenever a new op is queued — they leave the queue- * only when a phone page reflects them, never on send alone.+ * Watch side of the Watch conduit client for Todo: catalog/page data+ * items land in [WearTodoStore], watch state goes back as a data item,+ * pending ops and page/sync requests are messages. Transport is+ * `WearLinkClientNode` (Messenger to the Watch app's conduit service);+ * this app owns no RFCOMM link. Pending ops are (re)sent whenever the+ * conduit reports the link connected and whenever a new op is queued —+ * they leave the queue only when a phone page reflects them, never on+ * send alone. Delivery is bound to this process being alive; there is+ * no Play-services listener service. */ 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) { val store = WearTodoStore.get(context)@@ -54,7 +59,13 @@ object WearLinkBridge { } } }- val created = WearLinkNode(context, WearTodoProtocol.CAPABILITY, listener)+ // Conduit appId = first path segment of the todo paths (the+ // ConduitProtocol route key), not the RFCOMM handshake capability.+ val created = WearLinkClientNode(+ context,+ ConduitProtocol.routeKey(WearTodoProtocol.CATALOG_PATH),+ listener,+ ) scope.launch { var wasConnected = false created.state.collect { linkState ->
todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt b/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.ktindex 9a13d29ea5..c7f8a6f3ef 100644--- a/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt+++ b/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt@@ -3,7 +3,8 @@ package com.vayunmathur.todo.sync import android.content.Context 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 com.vayunmathur.library.wearlink.WearLinkState import com.vayunmathur.library.wearlink.todo.WearTodoCatalog import com.vayunmathur.library.wearlink.todo.WearTodoOp@@ -51,14 +52,22 @@ data class WearTodoSyncState( ) /**- * Phone side of the Todo wear companion over WearLink. Publishes the view- * catalog and bounded per-view pages on connect/change, and applies- * watch-originated ops here — the phone stays the source of truth, so a- * completion runs the same [TodoRepository.setDone] path as the phone UI- * (repeating tasks roll forward, subtasks reopen) and a quick-add runs the- * phone's [QuickAddParser] against the phone's lists. After any applied- * op the catalog and every page the watch has asked for are republished,- * which is what drops the op from the watch's pending queue.+ * Phone side of the Todo wear companion 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+ * view catalog and bounded per-view pages are data items, and+ * watch-originated ops are messages handled here while this process+ * lives. The phone stays the source of truth, so a completion runs the+ * same [TodoRepository.setDone] path as the phone UI (repeating tasks+ * roll forward, subtasks reopen) and a quick-add runs the phone's+ * [QuickAddParser] against the phone's lists. After any applied op the+ * catalog and every page the watch has asked for are republished, which+ * is what drops the op from the watch's pending queue. There is no+ * Play-services listener service: a request arriving while the phone app+ * is dead waits until it next runs, and the catalog/pages republish on+ * reconnect and on every todo/list change. With the Watch app absent the+ * node reports `NotInstalled`/`Unavailable` and the sync stays idle. */ class WearTodoSync private constructor(context: Context) { @@ -127,7 +136,13 @@ class WearTodoSync private constructor(context: Context) { } } - private val node = WearLinkNode(appContext, WearTodoProtocol.CAPABILITY, listener)+ // Conduit appId = first path segment of the todo paths (the+ // ConduitProtocol route key), not the RFCOMM handshake capability.+ private val node = WearLinkClientNode(+ appContext,+ ConduitProtocol.routeKey(WearTodoProtocol.CATALOG_PATH),+ listener,+ ) private var started = false private var pendingPublish: Job? = null @@ -192,7 +207,7 @@ class WearTodoSync private constructor(context: Context) { if (sent) { _state.update { it.copy(lastPublishedAtMillis = catalog.generatedAtMillis) } } else {- Log.status(TAG, "publish catalog not delivered (no live WearLink session)")+ Log.status(TAG, "publish catalog not delivered (conduit link not connected)") } }
todo/src/main/java/com/vayunmathur/todo/ui/WearMainActivity.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/ui/WearMainActivity.kt b/todo/src/main/java/com/vayunmathur/todo/ui/WearMainActivity.ktindex edf61ddb56..08b5ee2c8b 100644--- a/todo/src/main/java/com/vayunmathur/todo/ui/WearMainActivity.kt+++ b/todo/src/main/java/com/vayunmathur/todo/ui/WearMainActivity.kt@@ -9,10 +9,13 @@ import com.vayunmathur.todo.sync.WearLinkBridge * Watch todo entry: the phone app's navigation (view index -> task pages -> * task detail) rendered from the locally cached catalog/page snapshots, so * it works standalone. Watch-originated changes queue in the store and- * flow back over WearLink; nothing here claims a phone write.+ * flow back over the Watch conduit client; nothing here claims a phone write. */ class WearMainActivity : WearShellActivity<WearRoute, WearTodoStore>(WearRoute.Home) { + // 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. override fun createStore() = WearTodoStore.get(this).also { WearLinkBridge.get(this) WearLinkBridge.publishWatchState(this)