Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / library / wearlink / AGENTS.md

AGENTS.md5.6 KiBRenderedCodeRaw

AGENTS.md — library/wearlink/ (':library:wearlink')

Scoped supplement. Global rules in root AGENTS.md apply.

  • Gradle: :library:wearlink / dir: library/wearlink/
  • Package: com.vayunmathur.library.wearlink for the transport, plus one

per-app protocol subpackage (e.g. com.vayunmathur.library.wearlink.clock)

  • Entry: WearLinkNode.kt (Android), WearLinkProtocol.kt (pure wire),

conduit/WearLinkClientNode.kt (Messenger client used by every app except the Watch apps)

  • Wear entry shell: WearShellActivity.kt — every wear companion's main

activity extends WearShellActivity<route, store> (createStore() warm-up, Wear Material theme + Scaffold host filling the theme background, and a WearBackStack route stack held in the shell: system back pops one watch level at a time and only finishes the activity at the root; no permission request — the Watch conduit owns Bluetooth); each wear module keeps its concrete activity name, route type and screen when. Shared watch action buttons live in WearActionButtons.kt (centered filled WearFilledButton, red WearDeleteButton, and the wearOpenOnPhoneItem/wearDeleteItem list helpers; the open-on-phone conduit path suffix is WEAR_OPEN_ON_PHONE_PATH_SUFFIX).

  • Watch detail-screen button order (owner rule): content-specific

actions first, then "Open on phone" as the last button, with only the red Delete button allowed directly after it; nothing follows Delete. Delete appears only where the phone can really delete over the app's conduit protocol (add the op end-to-end when missing); never a dead or fake delete button.

  • Watch button theming (owner rule): action buttons follow the watch

Material theme (primary/onPrimary); Delete alone stays red (error, white content). Buttons are icon+label pairs wherever the generated icon set has a fitting glyph, and the icon is tinted with LocalContentColor.current so it always matches the label text — never a hard-coded or mismatched tint.

Purpose

First-party replacement for the proprietary Play-services Wearable Data Layer. RFCOMM over already-bonded Bluetooth, both sides listen + dial, cert-bound handshake. No Play services, no BLE scan/advertise, no location.

Also hosts the shared phone<->wear wire protocols that were previously duplicated per app pair: each migrated protocol lives in com.vayunmathur.library.wearlink.<app> and is consumed by both the phone and wear app modules (which may not depend on each other). Golden-JSON tests stay in each app module and pin the shared code's wire format. Migrated: clock, launcher, calendar, weather, music, notes, maps, appstore, contacts, findfamily, todo, communicate, camera, email, securemail. Remaining pairs are listed in docs/structure/wear-protocol-pairs.tsv. The contacts protocol (contacts/WearContactsProtocol) carries, additively, each contact's joined messenger platforms per action (call/message/video) and a bounded photo (≤96 px, ≤8,192 decoded bytes per contact, ≤512,000 decoded photo bytes per snapshot, letter-avatar fallback), and its handoff request carries kind (call/message/video/email), platform and contact id; older snapshots and handoffs decode with empty/absent defaults.

The conduit/ package is the Watch conduit contract and core: ConduitProtocol (Messenger codes/keys), ConduitRouter (pure routing: registrations with caller packages, latest-data replay, bounded queue for unregistered apps, status fan-out, counters), WearLinkClientNode (drop-in WearLinkNode replacement over the conduit binding; reports NotInstalled/Unavailable when the Watch app is absent), OpenOnPhoneContract/OpenOnPhoneLauncher (the watch open-on-phone wake: a /<appId>/open-on-phone message, or camera's OPEN_ON_PHONE op, for an app with no live registration is turned by ConduitHost into a package-addressed, signature-permission broadcast that the app's manifest receiver answers by launching its main activity as a new task; a registered app handles the message in its sync listener and is not broadcast to, and unregistered open requests are never queued for stale replay), and ConduitHost/ConduitRuntime used by the two Watch apps' ConduitServices. Merged phone/watch pairs ship as single APKs whose phone and watch experiences pick their side at runtime. This module declares no Bluetooth permissions; only the Watch apps (:watch, :watch:wear) do.

Push sync runs on three triggers, all converging on each app's existing conduit publish path (snapshots are conduit data items; per-app wire formats are unchanged): (1) the phone Watch app's scheduled intent — ConduitSync is the contract (action com.vayunmathur.watch.action.SYNC_TRIGGER, appId extra, no data; receivers are exported only under the CONDUIT signature permission and the sender package-addresses the intent; ConduitSyncDispatcher fans it out to the merge of package-manager-discovered receivers for the action with the registered appId->package registry — deduped by package, the persisted registry a supplement, not the source of truth — tolerating absent apps); (2) a phone app's own data changing (immediate publish by that app); (3) a watch app's own data changing (immediate publish over its conduit client, watch->phone). ConduitDataStore is the persistent latest-wins, size-capped mirror of the router data cache (one store per conduit host, keyed by appId+path, restored at host start), so data pushed while the receiving app is not running is replayed to it on its next registration, in either direction.

Verify

./gradlew :library:wearlink:testDebugUnitTest
./gradlew :library:wearlink:lint