launcher: sync over the watch conduit client
- Commit
3c06bf988f8f98bb92a742be6ef7c5b52fd1e794- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-04 19:43 UTC (1 day ago)
- Parents
46d1e0a
The launcher 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 in
:library:wearlink's conduit package, following the already-migrated
clock pair exactly. The Watch apps are the sole Bluetooth holders;
the launcher holds no Bluetooth code path for this channel.
What changed:
- sync/WearLauncherSync.kt (phone): WearLinkNode replaced with
WearLinkClientNode, same listener, start and state handling.
Presence still derives from WearLinkState.Connected via
wearLauncherCompanionPresent, favorites still republish on the
Connected edge, watch-state data items still land in
WearLauncherSyncState, and the request-sync message still triggers
publishFavorites().
- sync/WearLinkBridge.kt (watch): same swap; get() now returns
WearLinkClientNode. Favorites -> WearLauncherStore.setSnapshot,
watch-state putData and requestSync sendMessage call sites are
unchanged (WearSyncRequest doc updated to conduit wording).
- Conduit appId is the first path segment of the launcher paths
(ConduitProtocol.routeKey of /launcher/favorites, i.e. "launcher"),
not the old RFCOMM handshake capability
"launcher_wear_companion": the router namespaces traffic by that
segment and would refuse the capability string.
- Bluetooth prompting removed from the watch entry:
ui/WearMainActivity no longer extends WearShellActivity (whose
onCreate requests BLUETOOTH_CONNECT via WearLinkPermissions); it is
a plain ComponentActivity replicating the shell's store warm-up,
Wear Material theme and route state, mirroring the migrated
calendar watch entry. The phone MainActivity never requested
Bluetooth for this channel and still does not. With the Watch app
absent the client nodes report NotInstalled/Unavailable, sends
return false, and both sides keep working from local state with
no prompt loops; only the Watch apps prompt now.
- The wire protocol is unchanged: library.wearlink.launcher types
and the golden-JSON tests are untouched, and neither app manifest
declares any Bluetooth permission (the merged manifest still
carries :library:wearlink's own Bluetooth permissions until every
app pair has migrated, as in the clock/calendar stages).
- launcher/AGENTS.md wear sections now describe the conduit-client
state in present tense.
Verified in this worktree on devvm21958:
JAVA_HOME=/home/vayun/maos/prebuilts/jdk/jdk21/linux-x86
ANDROID_HOME=~/Android/Sdk
GRADLE_USER_HOME=~/.local/share/containers/storage/volumes/g2-gradle-cache/_data
./gradlew :launcher:lint :launcher:lintVitalRelease
:launcher:testDevUnitTest --max-workers=128
-Dorg.gradle.jvmargs=-Xmx64g
BUILD SUCCESSFUL; 419 unit tests, 0 failures/errors/skipped.Diff
launcher/AGENTS.md
diff --git a/launcher/AGENTS.md b/launcher/AGENTS.mdindex d9c8b6c892..cdc905545b 100644--- a/launcher/AGENTS.md+++ b/launcher/AGENTS.md@@ -38,7 +38,7 @@ bridge (`sync/WearLinkBridge`) only from `ui/WearMainActivity`, so neither runs on the wrong form factor. ## Watch experience (in this module)-- `ui/WearMainActivity` (a `WearShellActivity`, `exported=false`, no+- `ui/WearMainActivity` (`exported=false`, no launcher/HOME filter of its own) routes `ui/WearRoute` over home (synced favorites, watch-local recents, companion shortcuts) / all-apps drawer with local filter / settings rows that open only@@ -56,12 +56,12 @@ neither runs on the wrong form factor. `:launcher:metadata` into `metadata_data/photos/launcher/wear/`; phone shots use the `phone` bucket. -## Wear sync (phone <-> watch, one APK)+## Wear sync (Watch conduit client) **Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.launcher.WearLauncherProtocol`; the golden-JSON tests in this module pin the shared code's wire format.-- Favorites + watch-state sync: WearLink data items (`/launcher/favorites`, `/launcher/watch-state`)-- Sync request: WearLink message (`/launcher/request-sync`), watch -> phone only+- Favorites + watch-state sync: conduit data items (`/launcher/favorites`, `/launcher/watch-state`)+- Sync request: conduit message (`/launcher/request-sync`), watch -> phone only - Only the phone hotseat (pinned row) syncs — not the workspace grid, folders or widgets. Recents are watch-local and never sync.-- Transport: :library:wearlink (RFCOMM, no Play services); phone side `sync/WearLauncherSync`, watch side `sync/WearLinkBridge`+- **Transport: Watch conduit client** — phone side `sync/WearLauncherSync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `launcher`); 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; favorites republish on conduit `Connected`. **Gotchas:** - Exempt from the raw-animation rule: built on `animateBounds`/`Animatable` — do NOT "migrate" its motion to library helpers. TV code under `tv/` keeps using `library.ui` helpers anyway — no regression just because the package is exempt.@@ -111,11 +111,13 @@ neither runs on the wrong form factor. - com/vayunmathur/launcher/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`) - com/vayunmathur/launcher/platform/InstalledApps.kt — watch installed-app enumeration + settings targets ### Watch experience (ui/ + data/ + domain/ + platform/ + sync/)-- com/vayunmathur/launcher/ui/WearMainActivity.kt — watch entry (WearShellActivity, exported=false)+- com/vayunmathur/launcher/ui/WearMainActivity.kt — watch entry (exported=false) - com/vayunmathur/launcher/ui/WearRoute.kt, WearLauncherScreen.kt, WearAllAppsScreen.kt, WearSettingsScreen.kt - com/vayunmathur/launcher/data/WearLauncherStore.kt - com/vayunmathur/launcher/domain/WearLauncherModel.kt-- com/vayunmathur/launcher/sync/WearLinkBridge.kt, WearSyncRequest.kt — watch side; sync/WearLauncherSync.kt is the phone side+- com/vayunmathur/launcher/sync/WearLauncherSync.kt — phone conduit client node; favorites publish, watch-state receive, request-sync handling+- com/vayunmathur/launcher/sync/WearLinkBridge.kt — watch conduit client node; favorites receive into the store, watch-state publish+- com/vayunmathur/launcher/sync/WearSyncRequest.kt — `requestWearSync` helper (watch asks phone for fresh favorites) ### tv/ — TV mode (UiMode-routed, DataStore order, no Room/widgets) - com/vayunmathur/launcher/tv/TvRoute.kt
launcher/src/main/java/com/vayunmathur/launcher/MainActivity.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/MainActivity.kt b/launcher/src/main/java/com/vayunmathur/launcher/MainActivity.ktindex df7befa310..1e152c0f8e 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/MainActivity.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/MainActivity.kt@@ -105,8 +105,10 @@ class MainActivity : MaActivity(), ActivityBridge { if (routedToWear) return tvMode = isTvMode() viewModel.bridge = this- // Wear favorites sync (phone hotseat -> watch launcher). No-op state- // when there is no watch: absence is normal, never an error.+ // Wear favorites sync over the Watch conduit client (phone hotseat+ // -> watch launcher; no Bluetooth prompt here — prompting is the+ // Watch app's job). No-op state when there is no watch: absence is+ // normal, never an error. if (!tvMode) com.vayunmathur.launcher.sync.WearLauncherSync.get(this).start() }
launcher/src/main/java/com/vayunmathur/launcher/sync/WearLauncherSync.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLauncherSync.kt b/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLauncherSync.ktindex 49ff5ce835..b0072e3918 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLauncherSync.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLauncherSync.kt@@ -12,8 +12,9 @@ import com.vayunmathur.library.wearlink.launcher.buildWearFavorites import com.vayunmathur.library.wearlink.launcher.wearLauncherCompanionPresent 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@@ -34,12 +35,15 @@ data class WearLauncherSyncState( ) /**- * Phone side of the launcher wear sync over WearLink (RFCOMM,- * :library:wearlink): presence is a completed handshake, the favorites- * snapshot is a data item, and the watch's request-sync is a message- * handled here while this process lives. There is no Play-services- * listener service: a request arriving while the launcher is dead waits- * until it next runs (it republish on connect in any case).+ * Phone side of the launcher 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):+ * presence is the peer-link Connected state the conduit reports, the+ * favorites snapshot is a data item, and the watch's request-sync is a+ * message handled here while this process lives. There is no+ * Play-services listener service: a request arriving while the launcher+ * is dead waits until it next runs, and the snapshot republishes on+ * conduit Connected. * * Only the hotseat - the pinned/favorites row - is exported. The paged * workspace, folders and widgets stay phone-only by design (see the@@ -82,7 +86,13 @@ class WearLauncherSync private constructor(context: Context) { } } - private val node = WearLinkNode(appContext, WearLauncherProtocol.CAPABILITY, listener)+ // Conduit appId = first path segment of the launcher paths (the+ // ConduitProtocol route key), not the RFCOMM handshake capability.+ private val node = WearLinkClientNode(+ appContext,+ ConduitProtocol.routeKey(WearLauncherProtocol.FAVORITES_PATH),+ listener,+ ) private var started = false fun start() {@@ -120,7 +130,7 @@ class WearLauncherSync private constructor(context: Context) { ) } } else {- Log.status(TAG, "publish favorites not delivered (no live WearLink session)")+ Log.status(TAG, "publish favorites not delivered (conduit link not connected)") } }
launcher/src/main/java/com/vayunmathur/launcher/sync/WearLinkBridge.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLinkBridge.kt b/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLinkBridge.ktindex 1dd253515f..9961e79ed6 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLinkBridge.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/sync/WearLinkBridge.kt@@ -8,7 +8,8 @@ import com.vayunmathur.library.wearlink.launcher.WearLauncherWatchState import com.vayunmathur.launcher.platform.InstalledApps import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener-import com.vayunmathur.library.wearlink.WearLinkNode+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@@ -16,25 +17,27 @@ import kotlinx.coroutines.launch import kotlinx.serialization.encodeToString /**- * Watch side of WearLink for Launcher: favorites data items land in- * [WearLauncherStore], watch state goes back as a data item, and- * request-sync is a message. Delivery is bound to this process being alive;- * there is no system listener waking a dead watch app.+ * Watch side of the Watch conduit client for Launcher: favorites data items+ * land in [WearLauncherStore], watch state goes back as a data item, and+ * request-sync is a 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; 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+ @Volatile 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 listener = object : WearLinkListener { override fun onData(path: String, body: ByteArray) { if (path != WearLauncherProtocol.FAVORITES_PATH) return@@ -48,7 +51,13 @@ object WearLinkBridge { WearLauncherStore.get(context).setSnapshot(snapshot, InstalledApps.load(context).size) } }- return WearLinkNode(context, WearLauncherProtocol.CAPABILITY, listener).also { it.start() }+ // Conduit appId = first path segment of the launcher paths (the+ // ConduitProtocol route key), not the RFCOMM handshake capability.+ return WearLinkClientNode(+ context,+ ConduitProtocol.routeKey(WearLauncherProtocol.FAVORITES_PATH),+ listener,+ ).also { it.start() } } fun publishWatchState(context: Context, snapshot: WearFavoritesSnapshot, installedCount: Int) {
launcher/src/main/java/com/vayunmathur/launcher/sync/WearSyncRequest.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/sync/WearSyncRequest.kt b/launcher/src/main/java/com/vayunmathur/launcher/sync/WearSyncRequest.ktindex 94dec15e05..456cda9191 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/sync/WearSyncRequest.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/sync/WearSyncRequest.kt@@ -2,5 +2,5 @@ package com.vayunmathur.launcher.sync import android.content.Context -/** Asks the phone for fresh favorites; false when no session is live. */+/** Asks the phone for fresh favorites over the conduit; false when the conduit link is not connected. */ suspend fun requestWearSync(context: Context): Boolean = WearLinkBridge.requestSync(context)
launcher/src/main/java/com/vayunmathur/launcher/ui/WearMainActivity.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearMainActivity.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearMainActivity.ktindex bda63eb901..63adb98762 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearMainActivity.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearMainActivity.kt@@ -1,36 +1,48 @@ package com.vayunmathur.launcher.ui -import androidx.compose.runtime.Composable+import android.os.Bundle+import androidx.activity.ComponentActivity+import androidx.activity.compose.setContent+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.wear.compose.material.MaterialTheme import com.vayunmathur.launcher.data.WearLauncherStore-import com.vayunmathur.library.wearlink.WearShellActivity /** * Watch launcher entry. This is a launcher-style app drawer, not the system * home: stock Wear OS reserves home for the system launcher (see manifest). * It renders from installed apps + the last synced favorites, fully offline. */-class WearMainActivity : WearShellActivity<WearRoute, WearLauncherStore>(WearRoute.Home) {+class WearMainActivity : ComponentActivity() { - override fun createStore() = WearLauncherStore.get(this).also {+ override fun onCreate(savedInstanceState: Bundle?) {+ super.onCreate(savedInstanceState)+ // No Bluetooth prompt 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.+ val store = WearLauncherStore.get(this) com.vayunmathur.launcher.sync.WearLinkBridge.get(this)- it.publishWatchState()- }-- @Composable- override fun Screen(route: WearRoute, navigate: (WearRoute) -> Unit) {- when (route) {- WearRoute.Home -> WearLauncherScreen(- store = store,- onOpenAllApps = { navigate(WearRoute.AllApps) },- onOpenSettings = { navigate(WearRoute.Settings) },- )- WearRoute.AllApps -> WearAllAppsScreen(- store = store,- onBack = { navigate(WearRoute.Home) },- )- WearRoute.Settings -> WearSettingsScreen(- onBack = { navigate(WearRoute.Home) },- )+ store.publishWatchState()+ setContent {+ MaterialTheme {+ var route by remember { mutableStateOf<WearRoute>(WearRoute.Home) }+ when (route) {+ WearRoute.Home -> WearLauncherScreen(+ store = store,+ onOpenAllApps = { route = WearRoute.AllApps },+ onOpenSettings = { route = WearRoute.Settings },+ )+ WearRoute.AllApps -> WearAllAppsScreen(+ store = store,+ onBack = { route = WearRoute.Home },+ )+ WearRoute.Settings -> WearSettingsScreen(+ onBack = { route = WearRoute.Home },+ )+ }+ } } } }