Modern Apps git

← Modern-Apps.git

findfamily: sync over the watch conduit client

Commit
77e2e1efb720d43323e7150bb710a537eac409ac
Author
Vayun Mathur <[email protected]>
When
2026-12-04 19:44 UTC (1 day ago)
Parents
4678e6a
The FINDFAMILY phone<->watch sync no longer owns an RFCOMM
WearLinkNode on either side. 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 (WearClockSync /
WearLinkBridge) exactly. The Watch apps are the sole Bluetooth
holders; this app holds no Bluetooth code path for this channel.

What changed:
- sync/WearFindFamilySync.kt (phone): WearLinkNode replaced with
  WearLinkClientNode, same listener, start and state handling.
  Presence still derives from WearLinkState.Connected, snapshots
  still republish on the Connected edge and via the debounced
  live Room collectors that start on first connect, watch-state
  data items still land in WearFindFamilySyncState, request-sync
  still triggers publishSnapshot(), and watch ops still apply
  phone-side (STOP_SHARING_NOW flips the global sharing switch,
  REQUEST_REFRESH reconciles the tracking service).
- sync/WearLinkBridge.kt (watch): same swap; get() now returns
  WearLinkClientNode. Snapshot -> WearFindFamilyStore.setSnapshot,
  the store connected flag still follows the link state,
  watch-state putData and the requestSync / stopSharingNow /
  requestRefresh sendMessage call sites are unchanged.
- Conduit appId is the first path segment of the findfamily paths
  (ConduitProtocol.routeKey of /findfamily/snapshot, i.e.
  "findfamily"), not the old RFCOMM handshake capability
  "findfamily_wear_companion": the conduit router namespaces
  traffic by that segment. With the Watch app absent the client
  reports NotInstalled/Unavailable, sends return false, and both
  experiences keep working from local state.
- MainActivity: Bluetooth prompting removed from the phone entry
  (WearLinkPermissions.requestIfNeeded deleted); only the Watch
  apps prompt now. The app's BLUETOOTH_SCAN gate for the
  powered-off finder is a separate path and stays untouched.

Unchanged by design: the wire protocol
(library.wearlink.findfamily types and paths; the CAPABILITY
constant stays for the shared protocol), the golden-JSON tests,
and every location-sharing / E2EE path — the phone remains the
only E2EE endpoint and only already-decrypted summaries cross
the conduit.

Docs: findfamily/AGENTS.md gains the wear-sync (conduit client)
section and conduit wording for the sync key files.

Verified in this worktree on devvm21958:
- ./gradlew :findfamily:lint :findfamily:lintVitalRelease
  :findfamily:testDevUnitTest --max-workers=128
  -Dorg.gradle.jvmargs=-Xmx64g: BUILD SUCCESSFUL;
  361 unit tests, 0 failures/errors/skipped.

Diff

findfamily/AGENTS.md
diff --git a/findfamily/AGENTS.md b/findfamily/AGENTS.mdindex 18cc6e93bc..3e40a5d9ee 100644--- a/findfamily/AGENTS.md+++ b/findfamily/AGENTS.md@@ -46,6 +46,12 @@ on the same signal — `platform/BootReceiver` and `platform/FixCeilingReceiver` return early on a watch, so phone location sharing never starts there. +## Wear sync (Watch conduit client)+**Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.findfamily.WearFindFamilyProtocol`; the golden-JSON tests in this module pin the shared code's wire format. The phone stays the only E2EE endpoint: peer reports are decrypted into Room by the existing pipeline, and only the already-decrypted all-people summaries cross the conduit.+- Snapshot + watch-state sync: conduit data items (`/findfamily/snapshot` phone -> watch, `/findfamily/watch-state` watch -> phone)+- Ops + sync request: conduit messages (`/findfamily/op` stop-sharing / request-refresh, `/findfamily/request-sync`), watch -> phone only+- **Transport: Watch conduit client** — phone side `sync/WearFindFamilySync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `findfamily`); 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; snapshots republish on conduit `Connected` and on Room changes. `FormFactor` picks the side at runtime, so only one of the two nodes runs on a given device.+ ## Watch experience (in this module) - `ui/WearMainActivity` (a `WearShellActivity`, `exported=false`, no   launcher filter) routes `ui/WearRoute` over people home (every@@ -85,8 +91,8 @@ location sharing never starts there. - com/vayunmathur/findfamily/domain/MovementDetector.kt — sender moving/still state machine (acceleration + fix speed + displacement) - com/vayunmathur/findfamily/domain/ForcedFixPolicy.kt — when a "still" sender forces a one-off fix ### sync/ — wear companion (both sides in this APK)-- com/vayunmathur/findfamily/sync/WearFindFamilySync.kt — phone side of the wear companion; the wire protocol is `com.vayunmathur.library.wearlink.findfamily.WearFindFamilyProtocol` in `:library:wearlink` (the golden-JSON tests in this module pin the shared code's wire format)-- com/vayunmathur/findfamily/sync/WearLinkBridge.kt — watch side of the wear companion; snapshot receive into `data/WearFindFamilyStore`, watch-state publish, stop-sharing/refresh/request-sync messages to the phone+- com/vayunmathur/findfamily/sync/WearFindFamilySync.kt — phone conduit client node; all-people snapshot publish from decrypted Room state, watch-state receive, request-sync + op handling+- com/vayunmathur/findfamily/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive into `data/WearFindFamilyStore`, watch-state publish, stop-sharing/refresh/request-sync messages to the phone ### Watch experience (ui/ + data/ + domain/) - com/vayunmathur/findfamily/ui/WearMainActivity.kt — watch entry (WearShellActivity, exported=false) - com/vayunmathur/findfamily/ui/WearRoute.kt, WearPeopleScreen.kt, WearPersonScreen.kt, WearAllMapScreen.kt, WearRelativeCanvas.kt
findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.ktindex 2c8f1f1fe9..d53a7b38ab 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt@@ -71,9 +71,12 @@ class MainActivity : MaActivity() {      override fun onCreateBeforeContent() {         if (routedToWear) return-        com.vayunmathur.library.wearlink.WearLinkPermissions.requestIfNeeded(this)-        // Wear companion sync lives and dies with this process (WearLink has-        // no system wakeup); it republishes on reconnect and on data changes.+        // No Bluetooth prompt here: the Watch app owns the conduit link+        // and its permission. Wear companion sync runs over+        // WearLinkClientNode and lives and dies with this process (the+        // conduit has no system wakeup); with the Watch app absent it+        // reports NotInstalled/Unavailable, and the sync republishes on+        // reconnect and on data changes.         com.vayunmathur.findfamily.sync.WearFindFamilySync.get(this).start()         deepLinkAddInvite.value = parseAddDeepLink(intent)         noShowTarget.value = parseNoShowTarget(intent)
findfamily/src/main/java/com/vayunmathur/findfamily/data/WearFindFamilyStore.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/data/WearFindFamilyStore.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/data/WearFindFamilyStore.ktindex 9dc637e951..9b043e8a25 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/data/WearFindFamilyStore.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/data/WearFindFamilyStore.kt@@ -36,7 +36,7 @@ class WearFindFamilyStore private constructor(private val context: Context) {     val snapshot: StateFlow<WearFindFamilySnapshot> = _snapshot.asStateFlow()      private val _connected = MutableStateFlow(false)-    /** Last known WearLink session state, for offline honesty in the UI. */+    /** Last known conduit link state, for offline honesty in the UI. */     val connected: StateFlow<Boolean> = _connected.asStateFlow()      fun setConnected(connected: Boolean) {
findfamily/src/main/java/com/vayunmathur/findfamily/sync/WearFindFamilySync.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/sync/WearFindFamilySync.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/sync/WearFindFamilySync.ktindex 7633b1d2f7..e605f2b862 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/sync/WearFindFamilySync.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/sync/WearFindFamilySync.kt@@ -17,8 +17,9 @@ import com.vayunmathur.findfamily.network.Networking import com.vayunmathur.findfamily.platform.LocationServiceController 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 kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job@@ -40,7 +41,15 @@ data class WearFindFamilySyncState( )  /**- * Phone side of the FindFamily wear companion over WearLink.+ * Phone side of the FindFamily 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 all-people snapshot is a data item, and the watch's+ * request-sync / ops are messages handled here while this process+ * lives. There is no Play-services listener service: a request+ * arriving while the phone app is dead waits until it next runs, and+ * the snapshot republishes on reconnect.  *  * The phone is the source of truth and the only E2EE endpoint: peer  * reports are decrypted into Room by the existing pipeline, and this@@ -101,7 +110,13 @@ class WearFindFamilySync private constructor(context: Context) {         }     } -    private val node = WearLinkNode(appContext, WearFindFamilyProtocol.CAPABILITY, listener)+    // Conduit appId = first path segment of the findfamily paths (the+    // ConduitProtocol route key), not the RFCOMM handshake capability.+    private val node = WearLinkClientNode(+        appContext,+        ConduitProtocol.routeKey(WearFindFamilyProtocol.SNAPSHOT_PATH),+        listener,+    )     private var started = false     private var pendingPublish: Job? = null @@ -169,7 +184,7 @@ class WearFindFamilySync private constructor(context: Context) {                 )             }         } else {-            Log.status(TAG, "publish snapshot not delivered (no live WearLink session)")+            Log.status(TAG, "publish snapshot not delivered (conduit link not connected)")         }     } 
findfamily/src/main/java/com/vayunmathur/findfamily/sync/WearLinkBridge.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/sync/WearLinkBridge.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/sync/WearLinkBridge.ktindex 12c17a1142..1198029d84 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/sync/WearLinkBridge.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/sync/WearLinkBridge.kt@@ -9,8 +9,9 @@ import com.vayunmathur.library.wearlink.findfamily.WearOpKind import com.vayunmathur.library.wearlink.findfamily.WearWatchState 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 kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob@@ -18,27 +19,30 @@ import kotlinx.coroutines.launch import kotlinx.serialization.encodeToString  /**- * Watch side of WearLink for FindFamily: snapshot data items land in- * [WearFindFamilyStore], watch state goes back as a data item, and- * stop-sharing / refresh / request-sync are messages to the phone (the- * source of truth — the watch never claims a phone change locally).- * Delivery is bound to this process being alive.+ * Watch side of the Watch conduit client for FindFamily: snapshot data+ * items land in [WearFindFamilyStore], watch state goes back as a data+ * item, and stop-sharing / refresh / request-sync are messages to the+ * phone (the source of truth — the watch never claims a phone change+ * locally). 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; 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 store = WearFindFamilyStore.get(context)         val listener = object : WearLinkListener {             override fun onData(path: String, body: ByteArray) {@@ -53,7 +57,13 @@ object WearLinkBridge {                 store.setSnapshot(snapshot)             }         }-        val created = WearLinkNode(context, WearFindFamilyProtocol.CAPABILITY, listener)+        // Conduit appId = first path segment of the findfamily paths (the+        // ConduitProtocol route key), not the RFCOMM handshake capability.+        val created = WearLinkClientNode(+            context,+            ConduitProtocol.routeKey(WearFindFamilyProtocol.SNAPSHOT_PATH),+            listener,+        )         scope.launch {             created.state.collect { linkState ->                 store.setConnected(linkState is WearLinkState.Connected)