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

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

AGENTS.md5.6 KiBRenderedCodeRaw
1# AGENTS.md — library/wearlink/ (':library:wearlink')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply.
4
5- Gradle: :library:wearlink / dir: library/wearlink/
6- Package: `com.vayunmathur.library.wearlink` for the transport, plus one
7 per-app protocol subpackage (e.g. `com.vayunmathur.library.wearlink.clock`)
8- Entry: `WearLinkNode.kt` (Android), `WearLinkProtocol.kt` (pure wire),
9 `conduit/WearLinkClientNode.kt` (Messenger client used by every app
10 except the Watch apps)
11- Wear entry shell: `WearShellActivity.kt` — every wear companion's main
12 activity extends `WearShellActivity<route, store>` (`createStore()`
13 warm-up, Wear Material theme + `Scaffold` host filling the theme
14 background, and a `WearBackStack` route stack held in the shell:
15 system back pops one watch level at a time and only finishes the
16 activity at the root; no permission request — the Watch conduit owns
17 Bluetooth); each wear module keeps its concrete activity name, route
18 type and screen `when`. Shared watch action buttons live in
19 `WearActionButtons.kt` (centered filled `WearFilledButton`, red
20 `WearDeleteButton`, and the `wearOpenOnPhoneItem`/`wearDeleteItem`
21 list helpers; the open-on-phone conduit path suffix is
22 `WEAR_OPEN_ON_PHONE_PATH_SUFFIX`).
23- Watch detail-screen button order (owner rule): content-specific
24 actions first, then "Open on phone" as the last button, with only
25 the red Delete button allowed directly after it; nothing follows
26 Delete. Delete appears only where the phone can really delete over
27 the app's conduit protocol (add the op end-to-end when missing);
28 never a dead or fake delete button.
29- Watch button theming (owner rule): action buttons follow the watch
30 Material theme (`primary`/`onPrimary`); Delete alone stays red
31 (`error`, white content). Buttons are icon+label pairs wherever the
32 generated icon set has a fitting glyph, and the icon is tinted with
33 `LocalContentColor.current` so it always matches the label text —
34 never a hard-coded or mismatched tint.
35
36## Purpose
37First-party replacement for the proprietary Play-services Wearable Data
38Layer. RFCOMM over already-bonded Bluetooth, both sides listen + dial,
39cert-bound handshake. No Play services, no BLE scan/advertise, no location.
40
41Also hosts the shared phone<->wear wire protocols that were previously
42duplicated per app pair: each migrated protocol lives in
43`com.vayunmathur.library.wearlink.<app>` and is consumed by both the phone
44and wear app modules (which may not depend on each other). Golden-JSON
45tests stay in each app module and pin the shared code's wire format.
46Migrated: clock, launcher, calendar, weather, music, notes, maps, appstore, contacts, findfamily, todo, communicate, camera, email, securemail. Remaining pairs are listed in
47`docs/structure/wear-protocol-pairs.tsv`.
48The contacts protocol (`contacts/WearContactsProtocol`) carries, additively,
49each contact's joined messenger platforms per action (call/message/video)
50and a bounded photo (≤96 px, ≤8,192 decoded bytes per contact, ≤512,000
51decoded photo bytes per snapshot, letter-avatar fallback), and its handoff
52request carries kind (call/message/video/email), platform and contact id;
53older snapshots and handoffs decode with empty/absent defaults.
54
55The `conduit/` package is the Watch conduit contract and core:
56`ConduitProtocol` (Messenger codes/keys), `ConduitRouter` (pure
57routing: registrations with caller packages, latest-data replay,
58bounded queue for unregistered apps, status fan-out, counters),
59`WearLinkClientNode` (drop-in `WearLinkNode` replacement over the
60conduit binding; reports `NotInstalled`/`Unavailable` when the Watch
61app is absent), `OpenOnPhoneContract`/`OpenOnPhoneLauncher` (the
62watch open-on-phone wake: a `/<appId>/open-on-phone` message, or
63camera's `OPEN_ON_PHONE` op, for an app with no live registration is
64turned by `ConduitHost` into a package-addressed, signature-permission
65broadcast that the app's manifest receiver answers by launching its
66main activity as a new task; a registered app handles the message in
67its sync listener and is not broadcast to, and unregistered open
68requests are never queued for stale replay), and
69`ConduitHost`/`ConduitRuntime` used by the two
70Watch apps' `ConduitService`s. Merged phone/watch pairs ship as
71single APKs whose phone and watch experiences pick their side at
72runtime. This module declares no Bluetooth permissions; only the
73Watch apps (:watch, :watch:wear) do.
74
75Push sync runs on three triggers, all converging on each app's
76existing conduit publish path (snapshots are conduit data items;
77per-app wire formats are unchanged): (1) the phone Watch app's
78scheduled intent — `ConduitSync` is the contract (action
79`com.vayunmathur.watch.action.SYNC_TRIGGER`, `appId` extra, no data;
80receivers are exported only under the `CONDUIT` signature permission
81and the sender package-addresses the intent; `ConduitSyncDispatcher`
82fans it out to the merge of package-manager-discovered receivers for
83the action with the registered appId->package registry — deduped by
84package, the persisted registry a supplement, not the source of
85truth — tolerating absent apps); (2) a phone app's own data changing (immediate publish
86by that app); (3) a watch app's own data changing (immediate publish
87over its conduit client, watch->phone). `ConduitDataStore` is the
88persistent latest-wins, size-capped mirror of the router data cache
89(one store per conduit host, keyed by appId+path, restored at host
90start), so data pushed while the receiving app is not running is
91replayed to it on its next registration, in either direction.
92
93## Verify
94```
95./gradlew :library:wearlink:testDebugUnitTest
96./gradlew :library:wearlink:lint
97```