Modern Apps git

← Modern-Apps.git

maps: sync over the watch conduit client

Commit
967c7e59bb47b86e9ae1691ce256006515995b71
Author
Vayun Mathur <[email protected]>
When
2026-12-04 19:49 UTC (1 day ago)
Parents
d5b9b03
The maps phone<->watch pair 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), following the already-migrated clock pair. The
Watch apps are the sole Bluetooth holders; maps holds no Bluetooth
code path for this channel.

What changed:
- platform/WearMapsSync.kt: WearLinkNode replaced with
  WearLinkClientNode, same listener, start and state handling.
  Presence still derives from WearLinkState.Connected, region and
  route still republish on the Connected edge, and the
  request-region message still triggers a forced region publish.
- sync/WearLinkBridge.kt: same swap; get() now returns
  WearLinkClientNode. Region/route/position data items still land
  in WearMapsStore, watch-state putData and requestRegion
  sendMessage call sites are unchanged.
- Conduit appId is the first path segment of the maps paths
  (ConduitProtocol.routeKey of /maps/region, i.e. "maps"), not the
  old RFCOMM handshake capability "maps_wear_companion": the
  router namespaces traffic by that segment and would refuse the
  capability string.
- Bluetooth prompting removed from maps MainActivity
  (WearLinkPermissions.requestIfNeeded deleted). With the Watch
  app absent the client reports NotInstalled/Unavailable, sends
  return false, and both sides keep working from local state;
  only the Watch apps prompt now.
- Wire protocol unchanged: library.wearlink.maps types and the
  golden-JSON tests in this module are untouched.

Docs: maps/AGENTS.md wear-sync section and key-file entries now
describe the conduit-client state in present tense.

Verified in this worktree (no unit tests run, per owner instruction
mid-verification; the combined lint+test invocation was stopped
before tests executed):
- ./gradlew :maps:lint :maps:lintVitalRelease: BUILD SUCCESSFUL.
  Note lintVitalRelease itself is SKIPPED in this build (same as
  the pre-existing build behaviour); lint and lintVitalAnalyzeRelease
  ran green.
- ./gradlew :maps:compileDevKotlin :maps:compileReleaseKotlin
  --rerun-tasks: BUILD SUCCESSFUL (only pre-existing warnings).

Diff

maps/AGENTS.md
diff --git a/maps/AGENTS.md b/maps/AGENTS.mdindex cc62b3c230..b4e258449f 100644--- a/maps/AGENTS.md+++ b/maps/AGENTS.md@@ -38,16 +38,16 @@ phone state loads; phones get the map UI. The phone sync on a watch; the watch experience carries no manifest receivers, so no receiver gating is needed. -## Wear sync (Watch companion, both sides in this module)+## Wear sync (Watch conduit client) **Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.maps.WearMapsProtocol`; the golden-JSON tests in this module pin the shared code's wire format.-- Region snapshot: WearLink data item (`/maps/region`, phone -> watch) — bounded, simplified, quantized vector geometry for the watch Canvas renderer; the watch carries no tile stack and no planet data-- Route overlay: WearLink data item (`/maps/route`, phone -> watch); `active=false` is the explicit clear when navigation ends-- Position: WearLink data item (`/maps/position`, phone -> watch)-- Watch state: WearLink data item (`/maps/watch-state`, watch -> phone)-- Fresh region: WearLink message (`/maps/request-region`), watch -> phone-- **Transport: WearLink (RFCOMM, no Play services)** — phone side `platform/WearMapsSync.kt`, watch side `sync/WearLinkBridge.kt`; app-lifecycle-bound. 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.+- Region snapshot: conduit data item (`/maps/region`, phone -> watch) — bounded, simplified, quantized vector geometry for the watch Canvas renderer; the watch carries no tile stack and no planet data+- Route overlay: conduit data item (`/maps/route`, phone -> watch); `active=false` is the explicit clear when navigation ends+- Position: conduit data item (`/maps/position`, phone -> watch)+- 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.  ## 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.@@ -70,8 +70,8 @@ golden-JSON tests in this module pin the shared code's wire format. - com/vayunmathur/maps/ui/WearMainActivity.kt — watch entry (WearShellActivity) - com/vayunmathur/maps/ui/WearRoute.kt, WearMapScreen.kt, WearMapCanvas.kt, WearRouteDetailScreen.kt, WearSavedScreen.kt - com/vayunmathur/maps/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)-- com/vayunmathur/maps/platform/WearMapsSync.kt — phone sync publisher (gated to phones)-- com/vayunmathur/maps/sync/WearLinkBridge.kt — watch sync receiver + watch-state publisher+- com/vayunmathur/maps/platform/WearMapsSync.kt — phone conduit client node; region/route/position publish, request-region handling (gated to phones)+- com/vayunmathur/maps/sync/WearLinkBridge.kt — watch conduit client node; region/route/position receive into the store, watch-state publish - com/vayunmathur/maps/data/WearMapsStore.kt — persisted watch region/route/position - com/vayunmathur/maps/domain/WearMapProjection.kt — north-up Canvas projection + route/saved helpers ### platform/ — Android Auto surface
maps/src/main/java/com/vayunmathur/maps/MainActivity.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt b/maps/src/main/java/com/vayunmathur/maps/MainActivity.ktindex 1c04a9dc6e..667dc64b51 100644--- a/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt+++ b/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt@@ -109,9 +109,11 @@ class MainActivity : MaActivity() {         if (routedToWear) return         // FIRST_PARTY: data.maproj.org tiles + amenities + api.maproj.org -> ISRG+GTS         NetworkClient.init(this, TrustBundle.FIRST_PARTY)-        // Wear watch companion (region snapshot + route overlay over-        // WearLink; app-lifecycle-bound, see platform/WearMapsSync).-        com.vayunmathur.library.wearlink.WearLinkPermissions.requestIfNeeded(this)+        // Wear watch companion over the Watch conduit client (no Play+        // services, no Bluetooth prompt here — prompting is the Watch+        // app's job; see platform/WearMapsSync). With the Watch app+        // absent the client reports NotInstalled/Unavailable and the+        // sync stays idle; delivery is app-lifecycle-bound.         com.vayunmathur.maps.platform.WearMapsSync.start(this)         intentLauncher = IntentLauncher(this)         // Deferred off the startup path: neither the legacy-file delete nor
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 f1ec4cee5e..360fa94d77 100644--- a/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt+++ b/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt@@ -7,8 +7,9 @@ import com.vayunmathur.library.map.GeoPoint import com.vayunmathur.library.map.MapGeometry import com.vayunmathur.library.util.DataStoreUtils 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 com.vayunmathur.maps.data.MapTileCache import com.vayunmathur.maps.data.PoiIndex import com.vayunmathur.maps.data.SavedPlaceStore@@ -37,8 +38,14 @@ import kotlinx.serialization.encodeToString import kotlin.math.cos  /**- * Phone side of the Maps WearLink companion: the phone supplies the- * region, the watch renders it (see [WearMapsProtocol]).+ * Phone side of the Maps 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): the+ * phone supplies the region, the watch renders it (see+ * [WearMapsProtocol]). Presence is the peer-link Connected state the+ * conduit reports; with the Watch app absent the node reports+ * `NotInstalled`/`Unavailable` and the sync stays idle. Region and+ * route republish on conduit `Connected`.  *  * - Location comes from this phone ([FrameworkLocationManager]); the  *   watch runs no GPS of its own. Every fix publishes a small@@ -67,7 +74,7 @@ object WearMapsSync {     private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)      @Volatile-    private var node: WearLinkNode? = null+    private var node: WearLinkClientNode? = null     @Volatile     private var lastLocation: GeoPoint? = null     @Volatile@@ -94,7 +101,13 @@ object WearMapsSync {                     }                 }             }-            val created = WearLinkNode(appContext, WearMapsProtocol.CAPABILITY, listener)+            // Conduit appId = first path segment of the maps paths (the+            // ConduitProtocol route key), not the RFCOMM handshake capability.+            val created = WearLinkClientNode(+                appContext,+                ConduitProtocol.routeKey(WearMapsProtocol.REGION_PATH),+                listener,+            )             node = created             scope.launch {                 var wasConnected = false@@ -158,7 +171,7 @@ object WearMapsSync {         if (sent) {             lastCenter = user         } else {-            Log.status(TAG, "region not delivered (no live WearLink session)")+            Log.status(TAG, "region not delivered (conduit link not connected)")         }     } 
maps/src/main/java/com/vayunmathur/maps/sync/WearLinkBridge.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/sync/WearLinkBridge.kt b/maps/src/main/java/com/vayunmathur/maps/sync/WearLinkBridge.ktindex e8cd945b66..17a7a70683 100644--- a/maps/src/main/java/com/vayunmathur/maps/sync/WearLinkBridge.kt+++ b/maps/src/main/java/com/vayunmathur/maps/sync/WearLinkBridge.kt@@ -3,8 +3,9 @@ package com.vayunmathur.maps.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.WearLinkState+import com.vayunmathur.library.wearlink.conduit.ConduitProtocol+import com.vayunmathur.library.wearlink.conduit.WearLinkClientNode import com.vayunmathur.maps.data.WearMapsStore import com.vayunmathur.library.wearlink.maps.WearMapSnapshot import com.vayunmathur.library.wearlink.maps.WearMapsProtocol@@ -17,9 +18,11 @@ import kotlinx.coroutines.launch import kotlinx.serialization.encodeToString  /**- * Watch side of WearLink for Maps: region/route/position data items land- * in [WearMapsStore], watch state goes back as a data item, and a fresh- * region is requested by message. Delivery is bound to this process+ * Watch side of the Watch conduit client for Maps: region/route/position+ * data items land in [WearMapsStore], watch state goes back as a data+ * item, and a fresh region is requested by 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; the persisted store covers cold starts and link loss.  */ object WearLinkBridge {@@ -27,16 +30,16 @@ object 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 store = WearMapsStore.get(context)         val listener = object : WearLinkListener {             override fun onData(path: String, body: ByteArray) {@@ -48,7 +51,13 @@ object WearLinkBridge {                 }             }         }-        val created = WearLinkNode(context, WearMapsProtocol.CAPABILITY, listener)+        // Conduit appId = first path segment of the maps paths (the+        // ConduitProtocol route key), not the RFCOMM handshake capability.+        val created = WearLinkClientNode(+            context,+            ConduitProtocol.routeKey(WearMapsProtocol.REGION_PATH),+            listener,+        )         scope.launch {             created.state.collect { linkState ->                 store.setConnected(linkState is WearLinkState.Connected)@@ -75,7 +84,7 @@ object WearLinkBridge {         }     } -    /** Ask the phone for a fresh region; false when no session is live. */+    /** Ask the phone for a fresh region; false when no conduit session is live. */     suspend fun requestRegion(context: Context): Boolean =         get(context).sendMessage(WearMapsProtocol.REQUEST_REGION_PATH, ByteArray(0)) }
maps/src/main/java/com/vayunmathur/maps/ui/WearMainActivity.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/WearMainActivity.kt b/maps/src/main/java/com/vayunmathur/maps/ui/WearMainActivity.ktindex 23a179493a..488b952778 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/WearMainActivity.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/WearMainActivity.kt@@ -12,6 +12,10 @@ import com.vayunmathur.maps.sync.WearLinkBridge  */ class WearMainActivity : WearShellActivity<WearRoute, WearMapsStore>(WearRoute.Map) { +    // No Bluetooth prompt for the conduit channel 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() = WearMapsStore.get(this).also {         WearLinkBridge.get(this)         WearLinkBridge.publishWatchState(this)