todo: answer the conduit sync trigger with the catalog publish
- Commit
4ef9c61b8447568fe1808214247a1cc9c552173e- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-05 06:45 UTC (1 day ago)
- Parents
5719760
Adds ConduitSyncTriggerReceiver (exported only under the CONDUIT signature permission) following the Contacts reference pattern: the phone Watch app's scheduled sync-trigger intent invokes `WearTodoSync.triggerPush()` (catalog + tracked/default page publish), the same publish path as the Connected and data-change triggers, with no UI and no prompt. The pure ConduitSyncTriggerHandler decision (matching action and appId only) is unit-tested. No wire-format change. AGENTS.md describes the push trigger. WearTodoSync gains the triggerPush entry point, publishing the catalog and the tracked (or default) pages. Verified: :todo:lint (0 errors) and :todo:lintVitalRelease pass; :todo:testDevUnitTest passes (432 tests).
Diff
todo/AGENTS.md
diff --git a/todo/AGENTS.md b/todo/AGENTS.mdindex b873a48512..b421f081b4 100644--- a/todo/AGENTS.md+++ b/todo/AGENTS.md@@ -37,7 +37,8 @@ watch, and `notifications/BootReceiver` early-returns there. - 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).+- **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`.+- **Push triggers:** the publish also runs on the phone Watch app's scheduled sync-trigger intent (`sync/ConduitSyncTriggerReceiver`, exported only under the `CONDUIT` signature permission, invoking `WearTodoSync.triggerPush()` — no UI, no prompt). Data arriving while the receiving process is dead lands in the conduit host's persistent store and replays on registration. ## 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.
todo/src/main/AndroidManifest.xml
diff --git a/todo/src/main/AndroidManifest.xml b/todo/src/main/AndroidManifest.xmlindex c1dc459b41..d4552c06df 100644--- a/todo/src/main/AndroidManifest.xml+++ b/todo/src/main/AndroidManifest.xml@@ -181,6 +181,19 @@ <action android:name="android.intent.action.TIMEZONE_CHANGED" /> </intent-filter> </receiver>++ <!-- Watch conduit scheduled push sync: the phone Watch app fires+ ConduitSync.ACTION (signature permission, package-addressed)+ and this receiver pushes the current snapshot over the+ conduit. Exported only to holders of that permission. -->+ <receiver+ android:name=".sync.ConduitSyncTriggerReceiver"+ android:exported="true"+ android:permission="com.vayunmathur.watch.permissions.CONDUIT">+ <intent-filter>+ <action android:name="com.vayunmathur.watch.action.SYNC_TRIGGER" />+ </intent-filter>+ </receiver> </application> </manifest>
todo/src/main/java/com/vayunmathur/todo/sync/ConduitSyncTriggerReceiver.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/sync/ConduitSyncTriggerReceiver.kt b/todo/src/main/java/com/vayunmathur/todo/sync/ConduitSyncTriggerReceiver.ktnew file mode 100644index 0000000000..7b4242b525--- /dev/null+++ b/todo/src/main/java/com/vayunmathur/todo/sync/ConduitSyncTriggerReceiver.kt@@ -0,0 +1,73 @@+package com.vayunmathur.todo.sync++import android.content.BroadcastReceiver+import android.content.Context+import android.content.Intent+import com.vayunmathur.library.wearlink.conduit.ConduitProtocol+import com.vayunmathur.library.wearlink.conduit.ConduitSync+import com.vayunmathur.library.wearlink.todo.WearTodoProtocol+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.SupervisorJob+import kotlinx.coroutines.launch++/**+ * Decides whether an incoming intent is this app's sync trigger and,+ * if so, invokes [publish]. Pure (no Android types) so the decision is+ * unit-tested; the receiver below supplies the platform values.+ */+object ConduitSyncTriggerHandler {+ /** Conduit appId this app pushes under (first segment of its snapshot paths). */+ val APP_ID: String = ConduitProtocol.routeKey(WearTodoProtocol.CATALOG_PATH)++ /**+ * True (and [publish] invoked) only for the [ConduitSync.ACTION]+ * intent addressed to [APP_ID]; anything else is ignored.+ */+ fun handle(+ action: String?,+ appId: String?,+ publish: () -> Unit,+ ): Boolean {+ if (!ConduitSync.isTrigger(action, appId, APP_ID)) return false+ publish()+ return true+ }+}++/**+ * Receiver for the Watch conduit's scheduled push sync: the phone+ * Watch app fires [ConduitSync.ACTION] (signature permission+ * [ConduitSync.PERMISSION], package-addressed to this app) meaning+ * "push your current snapshot to your watch counterpart now". The+ * response is the existing conduit publish — the same path the+ * Connected and data-change triggers use — never a UI or a user+ * prompt. When this process was dead, the sync's Connected trigger+ * republishes as soon as the conduit bind reports the link up.+ */+class ConduitSyncTriggerReceiver : BroadcastReceiver() {+ override fun onReceive(+ context: Context,+ intent: Intent,+ ) {+ val handled =+ ConduitSyncTriggerHandler.handle(+ intent.action,+ intent.getStringExtra(ConduitSync.EXTRA_APP_ID),+ ) {+ val pending = goAsync()+ val appContext = context.applicationContext+ val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)+ scope.launch {+ try {+ val sync = WearTodoSync.get(appContext)+ sync.start()+ sync.triggerPush()+ } finally {+ pending.finish()+ }+ }+ }+ if (!handled) return+ }+}
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 c7f8a6f3ef..4ca700317b 100644--- a/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt+++ b/todo/src/main/java/com/vayunmathur/todo/sync/WearTodoSync.kt@@ -169,6 +169,19 @@ class WearTodoSync private constructor(context: Context) { node.start() } + /**+ * Push the catalog and tracked pages now, on request from outside+ * this process's own triggers: the Watch app's scheduled+ * sync-trigger intent (see [ConduitSyncTriggerReceiver]). The same+ * publish path as the Connected and todo/list-change triggers.+ */+ fun triggerPush() {+ scope.launch {+ publishCatalog()+ publishTrackedOrDefault()+ }+ }+ private fun onTodosChanged() { if (!_state.value.companionPresent) return pendingPublish?.cancel()
todo/src/test/java/com/vayunmathur/todo/sync/ConduitSyncTriggerHandlerTest.kt
diff --git a/todo/src/test/java/com/vayunmathur/todo/sync/ConduitSyncTriggerHandlerTest.kt b/todo/src/test/java/com/vayunmathur/todo/sync/ConduitSyncTriggerHandlerTest.ktnew file mode 100644index 0000000000..cead575b87--- /dev/null+++ b/todo/src/test/java/com/vayunmathur/todo/sync/ConduitSyncTriggerHandlerTest.kt@@ -0,0 +1,30 @@+package com.vayunmathur.todo.sync++import com.vayunmathur.library.wearlink.conduit.ConduitSync+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue++class ConduitSyncTriggerHandlerTest {+ @Test+ fun `the sync trigger for todo invokes publish`() {+ var publishes = 0+ val handled =+ ConduitSyncTriggerHandler.handle(ConduitSync.ACTION, ConduitSyncTriggerHandler.APP_ID) {+ publishes+++ }+ assertTrue(handled)+ assertEquals(1, publishes)+ assertEquals("todo", ConduitSyncTriggerHandler.APP_ID)+ }++ @Test+ fun `other apps and other actions do not invoke publish`() {+ var publishes = 0+ assertFalse(ConduitSyncTriggerHandler.handle(ConduitSync.ACTION, "clock") { publishes++ })+ assertFalse(ConduitSyncTriggerHandler.handle("com.example.OTHER", "todo") { publishes++ })+ assertFalse(ConduitSyncTriggerHandler.handle(null, null) { publishes++ })+ assertEquals(0, publishes)+ }+}