Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / wearlink / AGENTS.md
| 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 |
| 37 | First-party replacement for the proprietary Play-services Wearable Data |
| 38 | Layer. RFCOMM over already-bonded Bluetooth, both sides listen + dial, |
| 39 | cert-bound handshake. No Play services, no BLE scan/advertise, no location. |
| 40 | |
| 41 | Also hosts the shared phone<->wear wire protocols that were previously |
| 42 | duplicated per app pair: each migrated protocol lives in |
| 43 | `com.vayunmathur.library.wearlink.<app>` and is consumed by both the phone |
| 44 | and wear app modules (which may not depend on each other). Golden-JSON |
| 45 | tests stay in each app module and pin the shared code's wire format. |
| 46 | Migrated: 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`. |
| 48 | The contacts protocol (`contacts/WearContactsProtocol`) carries, additively, |
| 49 | each contact's joined messenger platforms per action (call/message/video) |
| 50 | and a bounded photo (≤96 px, ≤8,192 decoded bytes per contact, ≤512,000 |
| 51 | decoded photo bytes per snapshot, letter-avatar fallback), and its handoff |
| 52 | request carries kind (call/message/video/email), platform and contact id; |
| 53 | older snapshots and handoffs decode with empty/absent defaults. |
| 54 | |
| 55 | The `conduit/` package is the Watch conduit contract and core: |
| 56 | `ConduitProtocol` (Messenger codes/keys), `ConduitRouter` (pure |
| 57 | routing: registrations with caller packages, latest-data replay, |
| 58 | bounded queue for unregistered apps, status fan-out, counters), |
| 59 | `WearLinkClientNode` (drop-in `WearLinkNode` replacement over the |
| 60 | conduit binding; reports `NotInstalled`/`Unavailable` when the Watch |
| 61 | app is absent), `OpenOnPhoneContract`/`OpenOnPhoneLauncher` (the |
| 62 | watch open-on-phone wake: a `/<appId>/open-on-phone` message, or |
| 63 | camera's `OPEN_ON_PHONE` op, for an app with no live registration is |
| 64 | turned by `ConduitHost` into a package-addressed, signature-permission |
| 65 | broadcast that the app's manifest receiver answers by launching its |
| 66 | main activity as a new task; a registered app handles the message in |
| 67 | its sync listener and is not broadcast to, and unregistered open |
| 68 | requests are never queued for stale replay), and |
| 69 | `ConduitHost`/`ConduitRuntime` used by the two |
| 70 | Watch apps' `ConduitService`s. Merged phone/watch pairs ship as |
| 71 | single APKs whose phone and watch experiences pick their side at |
| 72 | runtime. This module declares no Bluetooth permissions; only the |
| 73 | Watch apps (:watch, :watch:wear) do. |
| 74 | |
| 75 | Push sync runs on three triggers, all converging on each app's |
| 76 | existing conduit publish path (snapshots are conduit data items; |
| 77 | per-app wire formats are unchanged): (1) the phone Watch app's |
| 78 | scheduled intent — `ConduitSync` is the contract (action |
| 79 | `com.vayunmathur.watch.action.SYNC_TRIGGER`, `appId` extra, no data; |
| 80 | receivers are exported only under the `CONDUIT` signature permission |
| 81 | and the sender package-addresses the intent; `ConduitSyncDispatcher` |
| 82 | fans it out to the merge of package-manager-discovered receivers for |
| 83 | the action with the registered appId->package registry — deduped by |
| 84 | package, the persisted registry a supplement, not the source of |
| 85 | truth — tolerating absent apps); (2) a phone app's own data changing (immediate publish |
| 86 | by that app); (3) a watch app's own data changing (immediate publish |
| 87 | over its conduit client, watch->phone). `ConduitDataStore` is the |
| 88 | persistent latest-wins, size-capped mirror of the router data cache |
| 89 | (one store per conduit host, keyed by appId+path, restored at host |
| 90 | start), so data pushed while the receiving app is not running is |
| 91 | replayed to it on its next registration, in either direction. |
| 92 | |
| 93 | ## Verify |
| 94 | ``` |
| 95 | ./gradlew :library:wearlink:testDebugUnitTest |
| 96 | ./gradlew :library:wearlink:lint |
| 97 | ``` |