Modern Apps git

← Modern-Apps.git

launcher: answer the conduit sync trigger with the favorites publish

Commit
5719760d11931d17964bcdb240caeda68d4c23ba
Author
Vayun Mathur <[email protected]>
When
2026-12-05 06:45 UTC (1 day ago)
Parents
260375c
Adds ConduitSyncTriggerReceiver (exported only under the CONDUIT
signature permission) following the Contacts reference pattern: the
phone Watch app's scheduled sync-trigger intent invokes `WearLauncherSync.syncNow()` (hotseat favorites publish), the
same publish path as the Connected and data-change triggers, with no
UI and no prompt. The pure ConduitSyncTriggerHandler decision
(matching action and appId only) is unit-tested. No wire-format
change. AGENTS.md describes the push trigger.

Verified: :launcher:lint (0 errors) and :launcher:lintVitalRelease pass;
:launcher:testDevUnitTest passes (426 tests).

Diff

launcher/AGENTS.md
diff --git a/launcher/AGENTS.md b/launcher/AGENTS.mdindex 708db5560f..b1986e30b8 100644--- a/launcher/AGENTS.md+++ b/launcher/AGENTS.md@@ -32,9 +32,10 @@ phones, TVs and watches alike. `platform/FormFactor.kt` reads `PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the sole launcher entry) forwards watches to `ui/WearMainActivity` before any phone/TV state loads; phones/TVs get the UiMode-routed UI. There-are no broadcast receivers in this module; the phone sync-(`sync/WearLauncherSync`) starts only from the phone path and the watch-bridge (`sync/WearLinkBridge`) only from `ui/WearMainActivity`, so+one broadcast receiver, the conduit sync-trigger receiver+(`sync/ConduitSyncTriggerReceiver`), starts the phone sync+(`sync/WearLauncherSync`) outside the phone path; the watch+bridge (`sync/WearLinkBridge`) starts only from `ui/WearMainActivity`, so neither runs on the wrong form factor.  ## Watch experience (in this module)@@ -62,6 +63,7 @@ neither runs on the wrong form factor. - 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: 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`.+- **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 `WearLauncherSync.syncNow()` — no UI, no prompt). Data arriving while the receiving process is dead lands in the conduit host's persistent store and replays on registration.  **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.
launcher/src/main/AndroidManifest.xml
diff --git a/launcher/src/main/AndroidManifest.xml b/launcher/src/main/AndroidManifest.xmlindex 5c127774b0..a2d18ecd21 100644--- a/launcher/src/main/AndroidManifest.xml+++ b/launcher/src/main/AndroidManifest.xml@@ -128,5 +128,18 @@             android:exported="false"             android:taskAffinity=""             android:theme="@android:style/Theme.Material.NoActionBar" />+    +        <!-- Watch conduit scheduled push sync: the phone Watch app fires+             ConduitSync.ACTION (signature permission, package-addressed)+             and this receiver pushes the current snapshot over the+             conduit. Exported only to holders of that permission. -->+        <receiver+            android:name=".sync.ConduitSyncTriggerReceiver"+            android:exported="true"+            android:permission="com.vayunmathur.watch.permissions.CONDUIT">+            <intent-filter>+                <action android:name="com.vayunmathur.watch.action.SYNC_TRIGGER" />+            </intent-filter>+        </receiver>     </application> </manifest>
launcher/src/main/java/com/vayunmathur/launcher/sync/ConduitSyncTriggerReceiver.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/sync/ConduitSyncTriggerReceiver.kt b/launcher/src/main/java/com/vayunmathur/launcher/sync/ConduitSyncTriggerReceiver.ktnew file mode 100644index 0000000000..ca79c72495--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/sync/ConduitSyncTriggerReceiver.kt@@ -0,0 +1,73 @@+package com.vayunmathur.launcher.sync++import android.content.BroadcastReceiver+import android.content.Context+import android.content.Intent+import com.vayunmathur.library.wearlink.conduit.ConduitProtocol+import com.vayunmathur.library.wearlink.conduit.ConduitSync+import com.vayunmathur.library.wearlink.launcher.WearLauncherProtocol+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.SupervisorJob+import kotlinx.coroutines.launch++/**+ * Decides whether an incoming intent is this app's sync trigger and,+ * if so, invokes [publish]. Pure (no Android types) so the decision is+ * unit-tested; the receiver below supplies the platform values.+ */+object ConduitSyncTriggerHandler {+    /** Conduit appId this app pushes under (first segment of its snapshot paths). */+    val APP_ID: String = ConduitProtocol.routeKey(WearLauncherProtocol.FAVORITES_PATH)++    /**+     * True (and [publish] invoked) only for the [ConduitSync.ACTION]+     * intent addressed to [APP_ID]; anything else is ignored.+     */+    fun handle(+        action: String?,+        appId: String?,+        publish: () -> Unit,+    ): Boolean {+        if (!ConduitSync.isTrigger(action, appId, APP_ID)) return false+        publish()+        return true+    }+}++/**+ * Receiver for the Watch conduit's scheduled push sync: the phone+ * Watch app fires [ConduitSync.ACTION] (signature permission+ * [ConduitSync.PERMISSION], package-addressed to this app) meaning+ * "push your current snapshot to your watch counterpart now". The+ * response is the existing conduit publish — the same path the+ * Connected and data-change triggers use — never a UI or a user+ * prompt. When this process was dead, the sync's Connected trigger+ * republishes as soon as the conduit bind reports the link up.+ */+class ConduitSyncTriggerReceiver : BroadcastReceiver() {+    override fun onReceive(+        context: Context,+        intent: Intent,+    ) {+        val handled =+            ConduitSyncTriggerHandler.handle(+                intent.action,+                intent.getStringExtra(ConduitSync.EXTRA_APP_ID),+            ) {+                val pending = goAsync()+                val appContext = context.applicationContext+                val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)+                scope.launch {+                    try {+                        val sync = WearLauncherSync.get(appContext)+                        sync.start()+                        sync.syncNow()+                    } finally {+                        pending.finish()+                    }+                }+            }+        if (!handled) return+    }+}
launcher/src/test/java/com/vayunmathur/launcher/sync/ConduitSyncTriggerHandlerTest.kt
diff --git a/launcher/src/test/java/com/vayunmathur/launcher/sync/ConduitSyncTriggerHandlerTest.kt b/launcher/src/test/java/com/vayunmathur/launcher/sync/ConduitSyncTriggerHandlerTest.ktnew file mode 100644index 0000000000..8f4a35501a--- /dev/null+++ b/launcher/src/test/java/com/vayunmathur/launcher/sync/ConduitSyncTriggerHandlerTest.kt@@ -0,0 +1,30 @@+package com.vayunmathur.launcher.sync++import com.vayunmathur.library.wearlink.conduit.ConduitSync+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue++class ConduitSyncTriggerHandlerTest {+    @Test+    fun `the sync trigger for launcher invokes publish`() {+        var publishes = 0+        val handled =+            ConduitSyncTriggerHandler.handle(ConduitSync.ACTION, ConduitSyncTriggerHandler.APP_ID) {+                publishes+++            }+        assertTrue(handled)+        assertEquals(1, publishes)+        assertEquals("launcher", ConduitSyncTriggerHandler.APP_ID)+    }++    @Test+    fun `other apps and other actions do not invoke publish`() {+        var publishes = 0+        assertFalse(ConduitSyncTriggerHandler.handle(ConduitSync.ACTION, "clock") { publishes++ })+        assertFalse(ConduitSyncTriggerHandler.handle("com.example.OTHER", "launcher") { publishes++ })+        assertFalse(ConduitSyncTriggerHandler.handle(null, null) { publishes++ })+        assertEquals(0, publishes)+    }+}