Modern Apps git

← Modern-Apps.git

wearlink: bind conduit implicitly by action

Commit
e45bcbe7d36435d54af1a86dad25ae00f39a9663
Author
Vayun Mathur <[email protected]>
When
2026-12-04 20:27 UTC (1 day ago)
Parents
8b553f3
Watch-side WearLinkClientNode binds failed with "Unable to start
service Intent { act=com.vayunmathur.watch.action.CONDUIT
cmp=com.vayunmathur.watch/.service.ConduitService }: not found" on
the Pixel Watch 5. The client bound with an explicit ComponentName
built from ConduitProtocol.SERVICE_CLASS, which names the phone
app class com.vayunmathur.watch.service.ConduitService. The wear
Watch app (namespace com.vayunmathur.watch.wear) implements the
service as com.vayunmathur.watch.wear.service.ConduitService, so
the explicit class cannot resolve on a watch even though both
manifests resolve the CONDUIT action to their own class.

Bind instead with Intent(ConduitProtocol.ACTION) scoped via
setPackage(ConduitProtocol.WATCH_PACKAGE). The action resolves to
whichever ConduitService the installed Watch app declares, so the
same client code works on phones and watches. The phone service
also answers the CONDUIT action, so the phone path still binds.
The <queries><package> declaration already in the library manifest
makes the Watch package visible for this implicit resolution, and
the signature permission on the service still gates the bind; no
permission gating is weakened.

Remove ConduitProtocol.SERVICE_CLASS: a repo-wide search shows its
only use was this bind, and keeping a phone-only class name in the
shared contract would invite the same bug again. Document on
ACTION that clients bind implicitly by action plus package, and
update the library manifest comment to describe the package-scoped
implicit bind instead of an explicit-component bind.

Verified: ./gradlew :library:wearlink:lint
:library:wearlink:testDebugUnitTest :watch:compileReleaseKotlin
:watch:wear:assembleDev --max-workers=128 is green.

Diff

library/wearlink/src/main/AndroidManifest.xml
diff --git a/library/wearlink/src/main/AndroidManifest.xml b/library/wearlink/src/main/AndroidManifest.xmlindex 01ae8f4a2a..31e128421a 100644--- a/library/wearlink/src/main/AndroidManifest.xml+++ b/library/wearlink/src/main/AndroidManifest.xml@@ -8,13 +8,14 @@      <!-- Package visibility for the conduit client: WearLinkClientNode          probes com.vayunmathur.watch with getPackageInfo and binds its-         ConduitService by explicit component. Under Android 11+ package-         visibility both fail unless the calling app can see the Watch-         package, so every consuming app must declare it visible. This-         <queries> entry lives in the library manifest so manifest merger-         injects it into every consumer; a <package> entry (rather than-         an <intent> one) covers both the probe and the explicit bind,-         and it declares no permission. -->+         ConduitService implicitly by the CONDUIT action scoped to that+         package. Under Android 11+ package visibility both fail unless+         the calling app can see the Watch package, so every consuming+         app must declare it visible. This <queries> entry lives in the+         library manifest so manifest merger injects it into every+         consumer; a <package> entry (rather than an <intent> one) covers+         both the probe and the package-scoped bind, and it declares no+         permission. -->     <queries>         <package android:name="com.vayunmathur.watch" />     </queries>
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/conduit/ConduitProtocol.kt
diff --git a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/conduit/ConduitProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/conduit/ConduitProtocol.ktindex 946428020b..72823b424c 100644--- a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/conduit/ConduitProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/conduit/ConduitProtocol.kt@@ -25,10 +25,12 @@ object ConduitProtocol {     /** Package / applicationId of both Watch apps. */     const val WATCH_PACKAGE = "com.vayunmathur.watch" -    /** Explicit component of the conduit service in the Watch app. */-    const val SERVICE_CLASS = "com.vayunmathur.watch.service.ConduitService"--    /** Bind action (the component is set explicitly as well). */+    /**+     * Bind action. Clients bind implicitly (this action + [WATCH_PACKAGE]),+     * never by explicit component: the phone and wear Watch apps implement+     * the service in different classes, and only the action resolves in+     * both manifests.+     */     const val ACTION = "com.vayunmathur.watch.action.CONDUIT"      /** Signature permission guarding the bound service, declared in both Watch manifests. */
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/conduit/WearLinkClientNode.kt
diff --git a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/conduit/WearLinkClientNode.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/conduit/WearLinkClientNode.ktindex 7153c668ec..e3f1636812 100644--- a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/conduit/WearLinkClientNode.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/conduit/WearLinkClientNode.kt@@ -95,9 +95,17 @@ class WearLinkClientNode(         val worker = HandlerThread("WearLinkClient-$appId").also { it.start() }         thread = worker         incoming = Messenger(Handler(worker.looper) { msg -> handleConduitMessage(msg) })+        // Implicit bind by action + package, not an explicit component:+        // the phone and wear Watch apps declare different ConduitService+        // classes (com.vayunmathur.watch.service vs+        // com.vayunmathur.watch.wear.service) for the same CONDUIT action,+        // so an explicit phone class cannot resolve on a watch. The+        // <queries><package> entry in this library's manifest makes the+        // Watch package visible for the resolution, and the service's+        // signature permission still gates the bind.         val intent =             Intent(ConduitProtocol.ACTION).apply {-                component = ComponentName(ConduitProtocol.WATCH_PACKAGE, ConduitProtocol.SERVICE_CLASS)+                setPackage(ConduitProtocol.WATCH_PACKAGE)             }         bound =             runCatching { appContext.bindService(intent, connection, Context.BIND_AUTO_CREATE) }