maps: answer the conduit sync trigger with the region publish
- Commit
32bfb1079dc2029e3ce2cf2f17369a3c19319496- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-05 06:45 UTC (1 day ago)
- Parents
4ef9c61
Adds ConduitSyncTriggerReceiver (exported only under the CONDUIT signature permission) following the Contacts reference pattern: the phone Watch app's scheduled sync-trigger intent invokes `WearMapsSync.triggerPush()` (region + route 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. WearMapsSync gains the triggerPush entry point (its start is already gated to phones); before the first location fix the region publish is a no-op and the fix publishes on arrival. Verified: :maps:lint (0 errors) and :maps:lintVitalRelease pass; :maps:testDevUnitTest passes (974 tests).
Diff
maps/AGENTS.md
diff --git a/maps/AGENTS.md b/maps/AGENTS.mdindex b4e258449f..c4a67053d3 100644--- a/maps/AGENTS.md+++ b/maps/AGENTS.md@@ -35,8 +35,9 @@ phones and watches alike. `platform/FormFactor.kt` reads launcher entry) forwards watches to `ui/WearMainActivity` before any phone state loads; phones get the map UI. The phone sync (`platform/WearMapsSync`) gates on the same signal and never starts-on a watch; the watch experience carries no manifest receivers, so no-receiver gating is needed.+on a watch; the one manifest receiver, the conduit sync-trigger+receiver (`sync/ConduitSyncTriggerReceiver`), invokes only that+phone-gated sync, so it is inert on a watch. ## Wear sync (Watch conduit client) **Protocol:** shared wire types live in `:library:wearlink` at@@ -48,6 +49,7 @@ golden-JSON tests in this module pin the shared code's wire format. - Watch state: conduit data item (`/maps/watch-state`, watch -> phone) - Fresh region: conduit message (`/maps/request-region`), watch -> phone - **Transport: Watch conduit client** — phone side `platform/WearMapsSync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `maps`); 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; region and route republish on conduit `Connected`. The phone supplies the region and is the position source (its location manager / navigation session); the watch runs no GPS of its own. The phone republishes the region when the user nears the snapshot edge (hysteresis, 65% of radius); with the link down the watch renders the last region with a stale/offline label — never as live data.+- **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 `WearMapsSync.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`, `exported=false`, no launcher filter) routes `ui/WearRoute` over the rendered map home / route detail / saved-places glance.
maps/src/main/AndroidManifest.xml
diff --git a/maps/src/main/AndroidManifest.xml b/maps/src/main/AndroidManifest.xmlindex 2113d779ec..b0a4b66bcf 100644--- a/maps/src/main/AndroidManifest.xml+++ b/maps/src/main/AndroidManifest.xml@@ -172,6 +172,19 @@ <meta-data android:name="com.google.android.gms.car.application" android:resource="@xml/automotive_app_desc" />+ + <!-- 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>\ No newline at end of file
maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt b/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.ktindex 360fa94d77..cdaae85b03 100644--- a/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt+++ b/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt@@ -126,6 +126,23 @@ object WearMapsSync { } } + /**+ * Push the region and route now, on request from outside this+ * process's own triggers: the Watch app's scheduled sync-trigger+ * intent (see [com.vayunmathur.maps.sync.ConduitSyncTriggerReceiver]).+ * The same publish path as the Connected trigger; before the first+ * location fix the region publish is a no-op and the fix itself+ * publishes on arrival. No-op on a watch ([start] gates there).+ */+ fun triggerPush(context: Context) {+ val appContext = context.applicationContext+ start(appContext)+ scope.launch {+ publishRegion(appContext, force = true)+ publishRoute(appContext, force = true)+ }+ }+ private fun startLocation(appContext: Context) { val manager = FrameworkLocationManager(appContext) // Process-lifetime companion feed: deliberately never stopped while
maps/src/main/java/com/vayunmathur/maps/sync/ConduitSyncTriggerReceiver.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/sync/ConduitSyncTriggerReceiver.kt b/maps/src/main/java/com/vayunmathur/maps/sync/ConduitSyncTriggerReceiver.ktnew file mode 100644index 0000000000..8041e40ef9--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/sync/ConduitSyncTriggerReceiver.kt@@ -0,0 +1,72 @@+package com.vayunmathur.maps.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.maps.WearMapsProtocol+import com.vayunmathur.maps.platform.WearMapsSync+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(WearMapsProtocol.REGION_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 {+ WearMapsSync.triggerPush(appContext)+ } finally {+ pending.finish()+ }+ }+ }+ if (!handled) return+ }+}
maps/src/test/java/com/vayunmathur/maps/sync/ConduitSyncTriggerHandlerTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/sync/ConduitSyncTriggerHandlerTest.kt b/maps/src/test/java/com/vayunmathur/maps/sync/ConduitSyncTriggerHandlerTest.ktnew file mode 100644index 0000000000..14da2356d4--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/sync/ConduitSyncTriggerHandlerTest.kt@@ -0,0 +1,30 @@+package com.vayunmathur.maps.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 maps invokes publish`() {+ var publishes = 0+ val handled =+ ConduitSyncTriggerHandler.handle(ConduitSync.ACTION, ConduitSyncTriggerHandler.APP_ID) {+ publishes+++ }+ assertTrue(handled)+ assertEquals(1, publishes)+ assertEquals("maps", 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", "maps") { publishes++ })+ assertFalse(ConduitSyncTriggerHandler.handle(null, null) { publishes++ })+ assertEquals(0, publishes)+ }+}