Modern Apps git

← Modern-Apps.git

communicate: migrate wear sync to Watch conduit client

Commit
836f31d9580efab145fda98f09788ef7b9e1a2e9
Author
Vayun Mathur <[email protected]>
When
2026-12-04 19:44 UTC (1 day ago)
Parents
3c06bf9
Convert both sides of the COMMUNICATE phone<->watch sync from a
direct RFCOMM WearLinkNode to the Watch conduit client
(WearLinkClientNode), following the already-migrated clock pair.

Phone side (data/WearCommunicateSync) and watch side
(sync/WearLinkBridge) now register with the conduit under appId
'communicate' (ConduitProtocol.routeKey of the snapshot path)
instead of the RFCOMM handshake capability, and hold no Bluetooth
permission for this channel. MainActivity no longer describes a
BLUETOOTH_CONNECT grant path. With the Watch app absent the node
reports NotInstalled/Unavailable and the sync stays idle; the
snapshot republishes on conduit Connected.

The wire protocol (library.wearlink.communicate types and the
golden-JSON tests), all messaging/E2EE paths, and :communicate-dev
are unchanged. communicate/AGENTS.md wear sections updated to the
conduit-client state.

Verified: ./gradlew :communicate:lint
:communicate:lintVitalRelease :communicate:testDevUnitTest green
in the worktree.

Diff

communicate/AGENTS.md
diff --git a/communicate/AGENTS.md b/communicate/AGENTS.mdindex 3c51d4096e..bb36472743 100644--- a/communicate/AGENTS.md+++ b/communicate/AGENTS.md@@ -34,12 +34,13 @@ launcher entry) forwards watches to `ui/WearMainActivity` before any phone state loads; phones get the tab UI. The phone telephony receivers (`telephony/SmsDeliverReceiver`, `telephony/MmsDeliverReceiver`) early-return on a watch — a watch has no default-SMS role and receives-its messages over WearLink.+its messages over the Watch conduit. -## Wear sync (Watch conduit over WearLink)+## Wear sync (Watch conduit client) **Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol`; this module's golden-JSON test pins the shared code's wire format.-- Snapshot + watch-state, thread pages, new-message/incoming-call alerts, and watch ops with phone verdicts (see the protocol file for paths and caps)-- **Transport:** phone side `data/WearCommunicateSync.kt` and watch side `sync/WearLinkBridge.kt` both live in this APK; `FormFactor` picks the side at runtime. Delivery is app-lifecycle-bound; the watch keeps ops pending and resends on reconnect.+- Snapshot + watch-state sync: conduit data items (`/communicate/snapshot` phone -> watch, `/communicate/watch-state` watch -> phone)+- Thread pages, new-message/incoming-call alerts, and watch ops with phone verdicts: conduit messages (see the protocol file for paths and caps)+- **Transport: Watch conduit client** — phone side `data/WearCommunicateSync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `communicate`); 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`. `FormFactor` picks the side at runtime, so only one of the two nodes runs on a given device. Delivery is app-lifecycle-bound; the watch keeps ops pending and resends on reconnect.  ## Watch experience (in this module) - `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over the conversation list / thread (paged, cached offline) / quick reply / call log (read-only) / voicemail indicators / phone-only explanation; an incoming-call overlay offers Decline only (no answer-on-watch: watch audio routing is not guaranteed).@@ -64,9 +65,9 @@ its messages over WearLink. - com/vayunmathur/communicate/data/CommunicateRepositoryMerged.kt — plus per-line splits (`Sim`, `Send`, `Rcs`, `Signal`, `WhatsApp`) - com/vayunmathur/communicate/data/SimManager.kt - com/vayunmathur/communicate/data/SecretSealer.kt-- com/vayunmathur/communicate/data/WearCommunicateSync.kt — phone side of the wear sync in this same APK; wire protocol `com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol` in `:library:wearlink` (this module's `WearCommunicateProtocolTest` pins the golden JSON)+- com/vayunmathur/communicate/data/WearCommunicateSync.kt — phone conduit client node; snapshot publish, watch-state receive, thread-page/op handling; wire protocol `com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol` in `:library:wearlink` (this module's `WearCommunicateProtocolTest` pins the golden JSON) - com/vayunmathur/communicate/data/WearCommunicateStore.kt — watch-side snapshot/thread-page/pending-op store-- com/vayunmathur/communicate/sync/WearLinkBridge.kt — watch side of the wear sync (snapshot/pages in, ops/requests out)+- com/vayunmathur/communicate/sync/WearLinkBridge.kt — watch conduit client node; snapshot/pages/alerts in, ops/requests out ### data/googlevoice/ — Voice line (RPC + SIP calls) - com/vayunmathur/communicate/data/googlevoice/GoogleVoiceClient.kt - com/vayunmathur/communicate/data/googlevoice/GoogleVoiceSession.kt
communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt b/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.ktindex 1e4c8c9732..5c609bba28 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt@@ -43,11 +43,10 @@ class MainActivity : MaActivity() {     override fun onCreateBeforeContent() {         if (routedToWear) return         pendingDeepLink = DeepLinks.parse(intent)-        // Wear companion sync lives and dies with this process (WearLink has-        // no system wakeup); the watch reads its cached snapshot offline.-        // No permission request here: launch must not ask for any permission-        // at startup, so WearLink simply reports PermissionMissing until-        // BLUETOOTH_CONNECT is granted through system settings.+        // Wear companion sync over the Watch conduit client lives and dies+        // with this process (no system wakeup); the watch reads its cached+        // snapshot offline. No Bluetooth prompt here: the Watch app owns+        // the conduit link and its permission.         com.vayunmathur.communicate.data.WearCommunicateSync.get(this).start()     } 
communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.ktindex 8fc4706bc0..a0ad956e49 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/WearCommunicateSync.kt@@ -6,8 +6,9 @@ import com.vayunmathur.communicate.data.call.InAppCallRegistry import com.vayunmathur.communicate.data.googlevoice.GoogleVoiceParser 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.library.wearlink.communicate.WearCommLine import com.vayunmathur.library.wearlink.communicate.WearCommOp import com.vayunmathur.library.wearlink.communicate.WearCommWatchState@@ -65,13 +66,17 @@ internal suspend fun applyWearCommOp(op: WearCommOp, handler: WearOpHandler): Bo     }  /**- * Phone side of the Communicate wear companion over WearLink (RFCOMM,- * :library:wearlink): bounded snapshot data item, thread pages and small- * alerts as messages, watch ops executed here against- * [CommunicateRepository]. Repository access and decryption stay on the- * phone; see [WearCommunicateProtocol] for caps and privacy choices.- * Delivery is app-lifecycle-bound (no Play-services wakeup): the watch- * keeps ops pending and resends on the next live session.+ * Phone side of the Communicate 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):+ * bounded snapshot data item, thread pages and small alerts as messages,+ * watch ops executed here against [CommunicateRepository]. Repository+ * access and decryption stay on the phone; see [WearCommunicateProtocol]+ * for caps and privacy choices. Delivery is app-lifecycle-bound (no+ * Play-services wakeup): the watch keeps ops pending and resends on the+ * next live session, and the snapshot republishes on conduit Connected.+ * With the Watch app absent the node reports `NotInstalled`/`Unavailable`+ * and the sync stays idle.  */ class WearCommunicateSync private constructor(context: Context) { @@ -190,8 +195,13 @@ class WearCommunicateSync private constructor(context: Context) {         }     } -    private val node: WearLinkNode =-        WearLinkNode(appContext, WearCommunicateProtocol.CAPABILITY, listener)+    // Conduit appId = first path segment of the communicate paths (the+    // ConduitProtocol route key), not the RFCOMM handshake capability.+    private val node: WearLinkClientNode = WearLinkClientNode(+        appContext,+        ConduitProtocol.routeKey(WearCommunicateProtocol.SNAPSHOT_PATH),+        listener,+    )     private var started = false      fun start() {@@ -279,7 +289,7 @@ class WearCommunicateSync 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)")         }     } 
communicate/src/main/java/com/vayunmathur/communicate/sync/WearLinkBridge.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/sync/WearLinkBridge.kt b/communicate/src/main/java/com/vayunmathur/communicate/sync/WearLinkBridge.ktindex 94766f6082..d0c82c95b4 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/sync/WearLinkBridge.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/sync/WearLinkBridge.kt@@ -4,8 +4,9 @@ import android.content.Context import com.vayunmathur.communicate.data.WearCommunicateStore 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.library.wearlink.communicate.WearCommWatchState import com.vayunmathur.library.wearlink.communicate.WearCommunicateProtocol import com.vayunmathur.library.wearlink.communicate.WearCommunicateSnapshot@@ -21,27 +22,29 @@ import kotlinx.coroutines.launch import kotlinx.serialization.encodeToString  /**- * Watch side of WearLink for Communicate: snapshot data items and thread- * pages land in [WearCommunicateStore], alerts surface as store state,- * pending ops and page/sync requests are messages. Delivery is bound to- * this process being alive; pending ops resend on reconnect and leave- * only on a phone success verdict.+ * Watch side of the Watch conduit client for Communicate: snapshot data+ * items and thread pages land in [WearCommunicateStore], alerts surface+ * as store state, pending ops and page/sync requests are messages.+ * 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; pending ops resend on reconnect and leave only on+ * a phone success verdict.  */ 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 = WearCommunicateStore.get(context)         val listener = object : WearLinkListener {             override fun onData(path: String, body: ByteArray) {@@ -76,7 +79,13 @@ object WearLinkBridge {                 }             }         }-        val created = WearLinkNode(context, WearCommunicateProtocol.CAPABILITY, listener)+        // Conduit appId = first path segment of the communicate paths (the+        // ConduitProtocol route key), not the RFCOMM handshake capability.+        val created = WearLinkClientNode(+            context,+            ConduitProtocol.routeKey(WearCommunicateProtocol.SNAPSHOT_PATH),+            listener,+        )         scope.launch {             var wasConnected = false             created.state.collect { linkState ->