maps: feed the watch map on connect, drop orphaned wear helpers
- Commit
cd273c315d91364d9ce5379c208261b830acff77- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-06 02:52 UTC (59 minutes ago)
- Parents
dda7f8b
Follow-up to the map-only watch screen. On conduit (re)connect the watch bridge now asks the phone for a fresh region over the existing /maps/request-region message (a data-path trigger, not a user action), so the map renders standalone from phone data without any on-watch interaction. Remove the now-dead pieces the screen removal orphaned: the phone-side /open-on-phone message handler in WearMapsSync (its wear_open_id extra was never read), WearMapsStore's connected flow, and the wearIsStale/wearDistanceM domain helpers whose only callers were the deleted labels and saved glance (their tests go with them). The region/route/ position sync, watch-state publish and persisted store are unchanged. The wear listing preview now uses a region-spanning snapshot fixture (roads across the +/-300-unit region, water/building fills, a live route line) instead of a +/-60-unit centre cross, and :maps:metadata was regenerated (group=wear): wear/2.png and wear/3.png are gone with their screens, wear/1.png shows only the map. maps/AGENTS.md updated for the map-only watch surface. Verified: :maps:lint :maps:lintVitalRelease :maps:testDevUnitTest pass; :maps:metadata regenerated.
Diff
maps/AGENTS.md
diff --git a/maps/AGENTS.md b/maps/AGENTS.mdindex 7ac2d44fb5..f88454ed40 100644--- a/maps/AGENTS.md+++ b/maps/AGENTS.md@@ -49,13 +49,13 @@ golden-JSON tests in this module pin the shared code's wire format. - 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.+- **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 as-is (no live-data label is shown on the map-only screen). - **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.-- The watch renders one phone-supplied vector snapshot with a plain Canvas projection (`ui/WearMapCanvas.kt`, `domain/WearMapProjection.kt`): no tile stack, no planet data, north-up; the phone has no Home/Work saved-place concept, so the saved glance shows saved places with distance — no ETA is invented.-- Watch state persists in `data/WearMapsStore` (`wear-maps-*.json`); watch strings are in `res/values/wear_strings.xml`.+- `ui/WearMainActivity` (a `WearShellActivity`, `exported=false`, no launcher filter) routes `ui/WearRoute` to the rendered map only — no route-detail/saved screens, no phone-directed text, buttons or Open-on-phone action on the watch.+- The watch renders one phone-supplied vector snapshot with a plain Canvas projection (`ui/WearMapCanvas.kt`, `domain/WearMapProjection.kt`): no tile stack, no planet data, no native renderer (the arm64-only `libmap_renderer` cannot load on 32-bit watch userspace), north-up. The canvas always draws (land, user puck, scale, north) even before the first snapshot arrives, and all stroke/dot sizes are dp-based. Saved places and the live route draw as map dots/line only. On conduit (re)connect the bridge asks the phone for a fresh region (`WearLinkBridge`) — a data-path trigger, not a user action.+- Watch state persists in `data/WearMapsStore` (`wear-maps-*.json`); the watch experience has no UI strings of its own. - Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:maps:metadata` into `metadata_data/photos/maps/wear/`; phone shots use the `phone` bucket. **Dialogs + screenshots:** every dialog is a `Route.…Dialog` destination (`DialogPage()` entries in `Navigation.kt`, args in the route, stateless content under `ui/dialogs/`; hosts act on the ViewModels, the contact chooser returns its pick via the `RESULT_CONTACT_ADDRESS_*` result keys) — never `show…`/pending-target state in a screen. Each route has a deterministic capture in `src/screenshotTest` (`<n>-<route-key>`, group `phone`); `StreetView` is exempted in `Route.kt` (live Google panorama + GL sphere). Search is a sheet over the live map, so `SearchSheet` carries a `SCAFFOLD SEARCH EXCEPTION`. **Gotchas:**@@ -71,7 +71,7 @@ golden-JSON tests in this module pin the shared code's wire format. - com/vayunmathur/maps/Navigation.kt — `MainNavigation` entries (`DialogPage()` dialog hosts) ### Watch experience (ui/ + platform/ + data/ + domain/ + sync/) - 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/ui/WearRoute.kt, WearMapScreen.kt, WearMapCanvas.kt - com/vayunmathur/maps/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`) - 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
maps/src/main/java/com/vayunmathur/maps/data/WearMapsStore.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/WearMapsStore.kt b/maps/src/main/java/com/vayunmathur/maps/data/WearMapsStore.ktindex dfbbd7edb8..c7aeb9b363 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/WearMapsStore.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/WearMapsStore.kt@@ -16,8 +16,7 @@ import kotlinx.serialization.encodeToString /** * The watch's local truth: the last region snapshot, route overlay and * position, persisted as JSON in app-private storage so the map renders- * fully offline (phone absent, process cold-started) — labelled stale,- * never as live data. An inactive [WearRouteState] clears the overlay+ * fully offline (phone absent, process cold-started). An inactive [WearRouteState] clears the overlay * and is not kept. */ class WearMapsStore private constructor(private val context: Context) {@@ -48,14 +47,6 @@ class WearMapsStore private constructor(private val context: Context) { private val _position = MutableStateFlow(loadPosition()) val position: StateFlow<WearPosition?> = _position.asStateFlow() - private val _connected = MutableStateFlow(false)- /** Last known WearLink session state, for offline honesty in the UI. */- val connected: StateFlow<Boolean> = _connected.asStateFlow()-- fun setConnected(connected: Boolean) {- _connected.value = connected- }- fun setSnapshot(snapshot: WearMapSnapshot) { _snapshot.value = snapshot persist(regionFile, WearMapsProtocol.json.encodeToString(snapshot))
maps/src/main/java/com/vayunmathur/maps/domain/WearMapProjection.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/domain/WearMapProjection.kt b/maps/src/main/java/com/vayunmathur/maps/domain/WearMapProjection.ktindex cdc98e64e8..c91a79d0a9 100644--- a/maps/src/main/java/com/vayunmathur/maps/domain/WearMapProjection.kt+++ b/maps/src/main/java/com/vayunmathur/maps/domain/WearMapProjection.kt@@ -3,13 +3,10 @@ package com.vayunmathur.maps.domain import com.vayunmathur.library.wearlink.maps.WearLineKind import com.vayunmathur.library.wearlink.maps.WearMapLine import com.vayunmathur.library.wearlink.maps.WearMapSnapshot-import com.vayunmathur.library.wearlink.maps.WearMapsProtocol import com.vayunmathur.library.wearlink.maps.WearRouteState-import com.vayunmathur.library.wearlink.maps.WearSavedPlace import com.vayunmathur.library.wearlink.maps.wearDequantize import com.vayunmathur.library.wearlink.maps.wearMetersEast import com.vayunmathur.library.wearlink.maps.wearMetersNorth-import kotlin.math.sqrt /** * Pure north-up projection for the watch Canvas renderer.@@ -79,13 +76,6 @@ fun wearRoutePointInSnapshot( return (originEast + wearDequantize(dxUnits)) to (originNorth + wearDequantize(dyUnits)) } -/** Distance (m) between an E7 position and a saved place, for the glance list. */-fun wearDistanceM(fromLatE7: Int, fromLonE7: Int, to: WearSavedPlace): Double {- val dx = wearMetersEast(fromLatE7 / 1e7, fromLonE7 / 1e7, to.lonE7 / 1e7)- val dy = wearMetersNorth(fromLatE7 / 1e7, to.latE7 / 1e7)- return sqrt(dx * dx + dy * dy)-}- /** Route overlay lifecycle: an inactive state clears the overlay; an active one replaces it. */ fun wearApplyRouteState(current: WearRouteState?, incoming: WearRouteState): WearRouteState? = if (incoming.active) incoming else null@@ -99,7 +89,3 @@ fun wearApplyRouteState(current: WearRouteState?, incoming: WearRouteState): Wea */ fun wearBasemapLines(snapshot: WearMapSnapshot): List<WearMapLine> = snapshot.lines.filter { it.kind != WearLineKind.ROUTE }--/** Stale when the snapshot is older than the protocol window; no snapshot is always stale. */-fun wearIsStale(snapshot: WearMapSnapshot?, nowMillis: Long): Boolean =- snapshot == null || nowMillis - snapshot.generatedAtMillis > WearMapsProtocol.STALE_AFTER_MS
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 aa37c722c6..cdaae85b03 100644--- a/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt+++ b/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt@@ -1,7 +1,6 @@ package com.vayunmathur.maps.platform import android.content.Context-import android.content.Intent import com.vayunmathur.library.log.Log import com.vayunmathur.library.map.GeoBounds import com.vayunmathur.library.map.GeoPoint@@ -97,10 +96,6 @@ object WearMapsSync { if (node != null) return val listener = object : WearLinkListener { override fun onMessage(path: String, body: ByteArray) {- if (path.endsWith("/open-on-phone")) {- runCatching { appContext.startActivity(Intent(appContext, com.vayunmathur.maps.MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra("wear_open_id", body.decodeToString())) }- return- } if (path == WearMapsProtocol.REQUEST_REGION_PATH) { scope.launch { publishRegion(appContext, force = true) } }
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 17a7a70683..9e257dc036 100644--- a/maps/src/main/java/com/vayunmathur/maps/sync/WearLinkBridge.kt+++ b/maps/src/main/java/com/vayunmathur/maps/sync/WearLinkBridge.kt@@ -59,8 +59,15 @@ object WearLinkBridge { listener, ) scope.launch {+ var wasConnected = false created.state.collect { linkState ->- store.setConnected(linkState is WearLinkState.Connected)+ val connected = linkState is WearLinkState.Connected+ if (connected && !wasConnected) {+ // Ask for a fresh region on (re)connect: not a user+ // action, just the data path that feeds the map.+ runCatching { created.sendMessage(WearMapsProtocol.REQUEST_REGION_PATH, ByteArray(0)) }+ }+ wasConnected = connected } } created.start()
maps/src/screenshotTest/kotlin/com/vayunmathur/maps/ui/WearMetadataPreviews.kt
diff --git a/maps/src/screenshotTest/kotlin/com/vayunmathur/maps/ui/WearMetadataPreviews.kt b/maps/src/screenshotTest/kotlin/com/vayunmathur/maps/ui/WearMetadataPreviews.ktindex 8519df4f4e..d2288def83 100644--- a/maps/src/screenshotTest/kotlin/com/vayunmathur/maps/ui/WearMetadataPreviews.kt+++ b/maps/src/screenshotTest/kotlin/com/vayunmathur/maps/ui/WearMetadataPreviews.kt@@ -11,7 +11,6 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.wear.compose.material.MaterialTheme import com.android.tools.screenshot.PreviewTest import com.vayunmathur.library.wearlink.maps.WearLineKind-import com.vayunmathur.library.wearlink.maps.WearManeuver import com.vayunmathur.library.wearlink.maps.WearMapLine import com.vayunmathur.library.wearlink.maps.WearMapPoint import com.vayunmathur.library.wearlink.maps.WearMapSnapshot@@ -25,17 +24,33 @@ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320" /** Fixed preview instant: 2026-11-25 14:41 UTC. */ private const val FIXED_NOW_MILLIS = 1795617660000L -// Berlin centre; geometry is quantized metres relative to it (see WearMapsProtocol).+// Berlin centre; geometry is quantized metres relative to it (see+// WearMapsProtocol: 2 m per unit, region radius 600 m = 300 units, so+// region-crossing roads span most of the +/-300 unit square). private val fixtureSnapshot = WearMapSnapshot( generatedAtMillis = FIXED_NOW_MILLIS, centerLatE7 = 525200000, centerLonE7 = 134050000, lines = listOf(- WearMapLine(kind = WearLineKind.ROAD, pts = listOf(-60, 0, 60, 0)),- WearMapLine(kind = WearLineKind.ROAD, pts = listOf(0, -60, 0, 60)),- WearMapLine(kind = WearLineKind.PATH, pts = listOf(-60, -40, 60, 40)),+ WearMapLine(kind = WearLineKind.ROAD, pts = listOf(-280, 0, -90, 0, 80, 10, 280, 10)),+ WearMapLine(kind = WearLineKind.ROAD, pts = listOf(0, -280, 0, -80, 10, 90, 10, 280)),+ WearMapLine(kind = WearLineKind.ROAD, pts = listOf(-280, -140, -40, -130, 160, -120, 280, -120)),+ WearMapLine(kind = WearLineKind.ROAD, pts = listOf(-140, -280, -130, -40, -120, 160, -120, 280)),+ WearMapLine(kind = WearLineKind.PATH, pts = listOf(-280, 180, -60, 120, 120, 60, 280, 40)),+ WearMapLine(+ kind = WearLineKind.WATER, closed = true,+ pts = listOf(150, 150, 260, 150, 260, 240, 150, 240, 150, 150),+ ),+ WearMapLine(+ kind = WearLineKind.BUILDING, closed = true,+ pts = listOf(-240, 60, -190, 60, -190, 110, -240, 110, -240, 60),+ ),+ WearMapLine(+ kind = WearLineKind.BUILDING, closed = true,+ pts = listOf(60, -240, 120, -240, 120, -190, 60, -190, 60, -240),+ ), ),- points = listOf(WearMapPoint(name = "Cafe", dx = 20, dy = 15)),+ points = listOf(WearMapPoint(name = "Cafe", dx = 40, dy = 30)), saved = listOf( WearSavedPlace(name = "Home", latE7 = 525210000, lonE7 = 134060000), WearSavedPlace(name = "Office", latE7 = 525180000, lonE7 = 134020000),@@ -45,20 +60,20 @@ private val fixtureSnapshot = WearMapSnapshot( private val fixtureRoute = WearRouteState( active = true, destinationName = "Central Station",+ routeOriginLatE7 = 525200000,+ routeOriginLonE7 = 134050000,+ routePts = listOf(0, -200, 0, -60, 5, 40, 10, 160), nextText = "Turn left", distanceToNextM = 120, distanceRemainingM = 1800,- maneuvers = listOf(- WearManeuver(text = "Head north on Main Street", kind = "STRAIGHT", distanceFromStartM = 0),- WearManeuver(text = "Turn left onto High Street", kind = "TURN_LEFT", distanceFromStartM = 120),- WearManeuver(text = "Arrive at Central Station", kind = "ARRIVE", distanceFromStartM = 1800),- ), ) /**- * Store listing images for the watch experience of `:maps` — every top-level screen/route (map, route detail, saved).- * The map capture renders the real Canvas vector renderer over a literal snapshot fixture.- * `./gradlew :maps:metadata` copies renders into `metadata_data/photos/maps/wear/`.+ * Store listing images for the watch experience of `:maps` — the map+ * only. The capture renders the real Canvas vector renderer over a+ * literal snapshot fixture spanning the region, as a phone snapshot+ * does. `./gradlew :maps:metadata` copies renders into+ * `metadata_data/photos/maps/wear/`. */ class WearMetadataPreviews { @@ -67,23 +82,10 @@ class WearMetadataPreviews { @Composable fun Preview1MapRound() { RoundPreview {- WearMapContent(snapshot = fixtureSnapshot, route = fixtureRoute, position = WearPosition(latE7 = 525200000, lonE7 = 134050000, bearingDeg = 90), connected = true, nowMillis = FIXED_NOW_MILLIS, onOpenRoute = {}, onOpenSaved = {})- }- }-- @PreviewTest- @Preview(name = "2-route-round", device = ROUND, group = "wear")- @Composable- fun Preview2RouteRound() {- RoundPreview { WearRouteDetailContent(route = fixtureRoute, onBack = {}) }- }-- @PreviewTest- @Preview(name = "3-saved-round", device = ROUND, group = "wear")- @Composable- fun Preview3SavedRound() {- RoundPreview {- WearSavedContent(snapshot = fixtureSnapshot, position = WearPosition(latE7 = 525200000, lonE7 = 134050000), onBack = {})+ WearMapContent(+ snapshot = fixtureSnapshot, route = fixtureRoute,+ position = WearPosition(latE7 = 525200000, lonE7 = 134050000, bearingDeg = 90),+ ) } } }
maps/src/test/java/com/vayunmathur/maps/domain/WearMapsProtocolTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/domain/WearMapsProtocolTest.kt b/maps/src/test/java/com/vayunmathur/maps/domain/WearMapsProtocolTest.ktindex 1d00128e7f..43a67514a9 100644--- a/maps/src/test/java/com/vayunmathur/maps/domain/WearMapsProtocolTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/domain/WearMapsProtocolTest.kt@@ -106,14 +106,6 @@ class WearMapsProtocolTest { assertEquals(20.0 to -10.0, same) } - @Test- fun staleAfterWindowAndWhenMissing() {- val snapshot = WearMapSnapshot(generatedAtMillis = 1_000L)- assertFalse(wearIsStale(snapshot, 1_000L + WearMapsProtocol.STALE_AFTER_MS))- assertTrue(wearIsStale(snapshot, 1_001L + WearMapsProtocol.STALE_AFTER_MS))- assertTrue(wearIsStale(null, 0L))- }- @Test fun routeOverlayLifecycle() { val active = WearRouteState(active = true, destinationName = "Work", nextText = "Turn left")@@ -144,10 +136,4 @@ class WearMapsProtocolTest { assertEquals(listOf(road, building), wearBasemapLines(snapshot)) } - @Test- fun savedDistanceUsesUserPosition() {- val home = WearSavedPlace("Home", latE7 = 0, lonE7 = (0.01 * 1e7).toInt()) // ~1.1 km east- val distance = wearDistanceM(0, 0, home)- assertTrue(distance in 1_000.0..1_200.0, "distance=$distance")- } }
metadata_data/photos/maps/wear/1.png
diff --git a/metadata_data/photos/maps/wear/1.png b/metadata_data/photos/maps/wear/1.pngindex ec08f55fa7..921878acaa 100644Binary files a/metadata_data/photos/maps/wear/1.png and b/metadata_data/photos/maps/wear/1.png differ
metadata_data/photos/maps/wear/2.png
diff --git a/metadata_data/photos/maps/wear/2.png b/metadata_data/photos/maps/wear/2.pngdeleted file mode 100644index 264a872643..0000000000Binary files a/metadata_data/photos/maps/wear/2.png and /dev/null differ
metadata_data/photos/maps/wear/3.png
diff --git a/metadata_data/photos/maps/wear/3.png b/metadata_data/photos/maps/wear/3.pngdeleted file mode 100644index 1446d795a9..0000000000Binary files a/metadata_data/photos/maps/wear/3.png and /dev/null differ