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

Modern-Apps.git / findfamily / AGENTS.md

AGENTS.md17.7 KiBRenderedCodeRaw
1# AGENTS.md — findfamily/ (':findfamily')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `findfamily/` + allowed shared modules. Do not root-scan.
4
5_Install: ./install findfamily (dev by default)._
6- Gradle: :findfamily / dir: findfamily/
7- Package roots present: ui, data, domain, platform, intents, service, sync
8- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity) + Route.kt + Navigation.kt + ui/WearMainActivity.kt
9- Deps: :library:network, :library:e2ee-p2p, :library:room, :library:work, :library:image, :library:map, :library:aosp-stubs, :library:wearlink, Wear Compose (material + foundation)
10- Metadata: metadata_data/findfamily.md (present)
11- Rust: no / screenshotTest: yes
12
13### Relay server (backend, outside this repo)
14WebSocket relay host: `wss://api.maproj.org/api/ws` (Cloudflare FIRST_PARTY pins). Server checkout: `../location_share_server` (sibling of this repo root, `C:\Users\Vayun\Documents\code\location_share_server`). Live SSH: `ssh [email protected]`. Full details: root `AGENTS.md` → "Backend server (outside this repo)".
15
16## Overview
17**Purpose:** End-to-end encrypted location sharing for family and friends — no emails, phone numbers, or personal info required. Requires internet.
18**Key features:**
19- `findfamily://add/<base26>` invites (pairing performs no security-code or invite-fingerprint verification; a legacy `k=` query is ignored), and temporary links; the people page offers no per-person hide/sharing toggle, no delete-person action, and no overflow menu icon (pause sharing via the Quick Settings tile)
20- Saved places (waypoints) with enter/leave notifications plus no-show alerts driven by `domain/NoShowPolicy`
21- Live battery, speed, and dwell-time per person; UWB precision ranging where hardware supports it
22- Powered-off finding (BLE beacons) and a Quick Settings tile to stop sharing instantly
23**Architecture / data-flow:** Single `MainPage` UI + `platform/FindFamilyViewModel` over `data/FindFamilyRepository` (Room: users, waypoints, links, no-show alerts); live location flows through `util/LocationTracking*` foreground service + `tracker/` BLE protocol and `uwb/` ranging, relayed E2EE via `:library:e2ee-p2p` (`util/Networking*`). `onCreateBeforeContent`: parse the add-invite deep link, then `NetworkClient.init(FIRST_PARTY)`.
24**Entry points + reading order:** `Route` (`MainPage` / `PersonSheet` / `WaypointSheet` / `PersonHistory` / `FirstRunSheet` / `AddPersonDialog` / `AddLinkDialog` / `AddTrackerDialog` / `MissingFeaturesDialog` / `NoShowAlertDialog` / `PermissionUpgradeDialog` / `UwbRangingPage`) → `Navigation.kt` → `ui/MainPage.kt` → `platform/FindFamilyViewModel.kt` → `data/FindFamilyRepository.kt`. Dialogs are routes: screens push `Route.…Dialog` and the entry renders the stateless `…Content` under `ui/dialogs/` unconditionally (all `DialogPage()`); `PersonDetailSheet` only requests the no-show dialog via its `onShowNoShowAlert` callback. Person/waypoint selection is also route-driven but is not a dialog: `PersonSheet` / `WaypointSheet` entries render `MainPage`, whose bottom panel (phone sheet in the repo's `FreeHeightBottomSheetScaffold`, expanded side panel) swaps from the family list to that route's person/waypoint content, so the map stays reachable to move a saved place by dragging it; back returns the panel to the family list. History is not a panel mode: `Route.PersonHistory` is a separate full screen with its own map and the history scrubber, pushed by the map's history FAB and popped by back to the live map page. Every route has a deterministic capture in `src/screenshotTest` (`MetadataPreviews`, `<n>-<route-kebab>`).
25**Gotchas:**
26- Location permission spec must request fine AND coarse together (Android 12+ Precise/Approximate choice; fine alone is ignored), plus background location and `BLUETOOTH_SCAN` — the powered-off-finder scanner starts then dies without it
27- `singleTop` warm-start invites/UWB taps arrive via `onNewIntent`, not a fresh `onCreate`
28- `AddTrackerDialog` is dev-only (`DEV_BUILD` custom UWB tracker binding); don't expose it in release flows
29- Extra non-conforming dirs (`ipc/`, `tracker/`, `uwb/`, `util/`) hold real code — like camera's `util/`, a closed-roots migration is pending
30- Upgrades from app versions before v2.6.0 start fresh: the `FFDatabase` floor is DB v5, pre-floor DB v1–v4 opens destructively (no data carried over), and DB v5 onward migrates normally
31
32## One APK, two form factors (phone + watch)
33This module is the single FindFamily APK for phones and watches: same
34`applicationId = "com.vayunmathur.findfamily"` and signing on both, as
35the WearLink handshake requires. The manifest deliberately declares no
36`android.hardware.type.watch` feature (required=true would block
37phones; required=false is disallowed for this feature), plus
38touchscreen not-required and
39`com.google.android.wearable.standalone=false`; distribution is
40sideload/F-Droid, not Play's watch channel, so the APK installs on
41phones and watches alike. `platform/FormFactor.kt` reads
42`PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the sole
43launcher entry) forwards watches to `ui/WearMainActivity` before any
44phone state loads; phones get the map UI. Phone-only receivers gate
45on the same signal — `platform/BootReceiver` and
46`platform/FixCeilingReceiver` return early on a watch, so phone
47location sharing never starts there.
48
49## Wear sync (Watch conduit client)
50**Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.findfamily.WearFindFamilyProtocol`; the golden-JSON tests in this module pin the shared code's wire format. The phone stays the only E2EE endpoint: peer reports are decrypted into Room by the existing pipeline, and only the already-decrypted all-people summaries cross the conduit.
51- Snapshot + watch-state sync: conduit data items (`/findfamily/snapshot` phone -> watch, `/findfamily/watch-state` watch -> phone)
52- Ops + sync request: conduit messages (`/findfamily/op` stop-sharing / request-refresh, `/findfamily/request-sync`), watch -> phone only
53- **Transport: Watch conduit client** — phone side `sync/WearFindFamilySync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `findfamily`); 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; snapshots republish on conduit `Connected` and on Room changes. `FormFactor` picks the side at runtime, so only one of the two nodes runs on a given device.
54- **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 `WearFindFamilySync.triggerPush()` — no UI, no prompt). Data arriving while the receiving process is dead lands in the conduit host's persistent store and replays on registration.
55- **Open on phone:** the watch request (`/<appId>/open-on-phone` conduit message; camera: `OPEN_ON_PHONE` op) is handled live by the sync message listener when this app is registered, and otherwise the phone conduit host broadcasts `OpenOnPhoneContract.ACTION` (package-addressed, `CONDUIT` signature permission) to `sync/OpenOnPhoneReceiver`, which launches the main activity as a new task — no phone process needs to be running first.
56
57## Watch experience (in this module)
58- `ui/WearMainActivity` (a `WearShellActivity`, `exported=false`, no
59 launcher filter) routes `ui/WearRoute` over people home (every
60 person, most-recent first) / per-person detail (precise fix
61 age/accuracy/place + relative view) / the all-people relative map
62 centred on the phone-supplied region. There is no vector basemap:
63 markers plot relative to the centre, stale fixes are labelled by
64 age, and precision is never faked.
65- Watch state persists in `data/WearFindFamilyStore`
66 (`wear-findfamily-snapshot.json`); presentation helpers live in
67 `domain/WearRelative.kt`; the watch sync side is
68 `sync/WearLinkBridge.kt`.
69- Watch listing screenshots are the `group = "wear"` previews in
70 `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by
71 `:findfamily:metadata` into `metadata_data/photos/findfamily/wear/`;
72 phone shots use the `phone` bucket.
73
74## Key files
75### Root — entry + navigation
76- com/vayunmathur/findfamily/MainActivity.kt — deep-link parsing, permission spec, permission-upgrade trigger
77- com/vayunmathur/findfamily/Route.kt — sealed `Route` destinations (bottom-panel person/waypoint routes + full-screen history and UWB screens + dialog routes)
78- com/vayunmathur/findfamily/Navigation.kt — `MainNavigation` entries for every route; `PersonSheet`/`WaypointSheet` render `MainPage` (bottom-panel host), `PersonHistory` renders `PersonHistoryPage`, the `…Dialog` routes use `DialogPage()`
79### data/ — Room entities + repository
80- com/vayunmathur/findfamily/data/FindFamilyRepository.kt
81- com/vayunmathur/findfamily/data/FFDatabase.kt
82- com/vayunmathur/findfamily/data/User.kt
83- com/vayunmathur/findfamily/data/Waypoint.kt
84- com/vayunmathur/findfamily/data/TemporaryLink.kt
85- com/vayunmathur/findfamily/data/NoShowAlert.kt
86- com/vayunmathur/findfamily/data/NoShowAlertDao.kt
87- com/vayunmathur/findfamily/data/Coord.kt
88- com/vayunmathur/findfamily/data/LocationValue.kt
89- com/vayunmathur/findfamily/data/DirectBootStore.kt
90- com/vayunmathur/findfamily/data/FindFamilyDbBackupCodec.kt — platform-backup codec: `SqlCipherDbCodec` export/import plus plaintext-export sanitization (see `domain/PlatformBackup.kt`)
91### domain/ — pairing auth, no-show policy, sender movement policy (pure logic)
92- com/vayunmathur/findfamily/domain/PlatformBackup.kt — stock-OS backup contract (`FindFamilyPlatformBackup`): sanitized DB-only agent payload, identity/pairing/link secrets never backed up, restored people re-pair via Add Person
93- com/vayunmathur/findfamily/domain/PairAuth.kt
94- com/vayunmathur/findfamily/domain/NoShowPolicy.kt
95- com/vayunmathur/findfamily/domain/MovementDetector.kt — sender moving/still state machine (acceleration + fix speed + displacement)
96- com/vayunmathur/findfamily/domain/ForcedFixPolicy.kt — when a "still" sender forces a one-off fix
97### sync/ — wear companion (both sides in this APK)
98- com/vayunmathur/findfamily/sync/WearFindFamilySync.kt — phone conduit client node; all-people snapshot publish from decrypted Room state, watch-state receive, request-sync + op handling
99- com/vayunmathur/findfamily/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive into `data/WearFindFamilyStore`, watch-state publish, stop-sharing/refresh/request-sync messages to the phone
100### Watch experience (ui/ + data/ + domain/)
101- com/vayunmathur/findfamily/ui/WearMainActivity.kt — watch entry (WearShellActivity, exported=false)
102- com/vayunmathur/findfamily/ui/WearRoute.kt, WearPeopleScreen.kt, WearPersonScreen.kt, WearAllMapScreen.kt, WearRelativeCanvas.kt
103- com/vayunmathur/findfamily/data/WearFindFamilyStore.kt
104- com/vayunmathur/findfamily/domain/WearRelative.kt
105### intents/ — assistant IPC
106- com/vayunmathur/findfamily/intents/GetIntent.kt
107- com/vayunmathur/findfamily/intents/CreateLinkIntent.kt
108### ipc/ — cross-app family-location protocol
109- com/vayunmathur/findfamily/ipc/FamilyLocationProtocol.kt
110- com/vayunmathur/findfamily/ipc/FamilyLocationService.kt
111### platform/ — reporters + schedulers
112- com/vayunmathur/findfamily/platform/AppBackupAgent.kt — stock-OS backup agent (manifest `backupAgent`): sanitized `passwords-db` only via `data/FindFamilyDbBackupCodec`; no DataStore/prefs/files; raw DB + `secure_prefs` + identity DataStore excluded by `res/xml/data_extraction_rules.xml` on both channels
113- com/vayunmathur/findfamily/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`) for the single merged APK
114- com/vayunmathur/findfamily/platform/FinalLocationReporter.kt
115- com/vayunmathur/findfamily/platform/NoShowCheckScheduler.kt
116- com/vayunmathur/findfamily/platform/PoweredOffBeacon.kt
117- com/vayunmathur/findfamily/platform/LocationKeepAlive.kt — sender keep-alive: single fix intake, low-power/passive requests, forced fix
118### service/ — Quick Settings tile
119- com/vayunmathur/findfamily/service/SharingTileService.kt
120### tracker/ — BLE tracker protocol + powered-off finding
121- com/vayunmathur/findfamily/tracker/TrackerProtocol.kt
122- com/vayunmathur/findfamily/tracker/TrackerBle.kt
123- com/vayunmathur/findfamily/tracker/TrackerProvisioner.kt
124- com/vayunmathur/findfamily/tracker/TrackerStore.kt
125- com/vayunmathur/findfamily/tracker/TrackerReporting.kt
126- com/vayunmathur/findfamily/tracker/TrackerFeature.kt
127- com/vayunmathur/findfamily/tracker/TrackerBeaconScanner.kt
128- com/vayunmathur/findfamily/tracker/TrackerBinder.kt
129- com/vayunmathur/findfamily/tracker/TrackerUwbGatt.kt
130- com/vayunmathur/findfamily/tracker/TrackerUwbKeys.kt
131- com/vayunmathur/findfamily/tracker/PoweredOffProtocol.kt
132- com/vayunmathur/findfamily/tracker/PoweredOffBle.kt
133- com/vayunmathur/findfamily/tracker/PoweredOffScanner.kt
134- com/vayunmathur/findfamily/tracker/PoweredOffReporting.kt
135- com/vayunmathur/findfamily/tracker/PoweredOffRecovery.kt
136- com/vayunmathur/findfamily/tracker/PoweredOffKeyStore.kt
137### uwb/ — UWB ranging stack
138- com/vayunmathur/findfamily/uwb/UwbController.kt
139- com/vayunmathur/findfamily/uwb/UwbEnvelope.kt
140- com/vayunmathur/findfamily/uwb/UwbInbox.kt
141- com/vayunmathur/findfamily/uwb/UwbAccessoryProtocol.kt
142### ui/ — main page + dialogs + UWB screen
143- com/vayunmathur/findfamily/ui/MainPage.kt
144- com/vayunmathur/findfamily/ui/MainPageContent.kt
145- com/vayunmathur/findfamily/ui/MainPageActions.kt
146- com/vayunmathur/findfamily/ui/MainPageCards.kt
147- com/vayunmathur/findfamily/ui/MainPageEffects.kt
148- com/vayunmathur/findfamily/ui/MainPageOverlays.kt
149- com/vayunmathur/findfamily/ui/MainMapSlot.kt
150- com/vayunmathur/findfamily/ui/MainSheetContent.kt
151- com/vayunmathur/findfamily/ui/MapView.kt
152- com/vayunmathur/findfamily/ui/MainFabOverlay.kt — history FAB over the map (selected person only; pushes `Route.PersonHistory`; the history screen itself shows no FAB)
153- com/vayunmathur/findfamily/ui/MainPageOverlays.kt — transparent `TopAppBarOverlay` over the map: back button for a selection plus the Find Nearby action for a selected non-self UWB person and the GPS warning
154- com/vayunmathur/findfamily/ui/FamilyListSheet.kt
155- com/vayunmathur/findfamily/ui/PersonDetailSheet.kt
156- com/vayunmathur/findfamily/ui/PersonSheet.kt — bottom-panel person detail content for `Route.PersonSheet`, hosted by `MainPage`'s panel, not a dialog; Find Nearby is an action in the map's transparent top bar and entering history is the history FAB over the map
157- com/vayunmathur/findfamily/ui/PersonHistoryPage.kt — full-screen history for `Route.PersonHistory`: its own pannable map centred on the scrubbed position plus the history scrubber; back pops to the live map
158- com/vayunmathur/findfamily/ui/PersonHistoryContent.kt — stateless history page layout (scaffold + map/scrubber slots) for previews
159- com/vayunmathur/findfamily/ui/WaypointSheet.kt — bottom-panel saved-place editor for `Route.WaypointSheet` (name/range/delete; place moves with the map centre), hosted by `MainPage`'s panel, not a dialog
160- com/vayunmathur/findfamily/ui/UserCard.kt
161- com/vayunmathur/findfamily/ui/UserPicture.kt — face icons via `peopleFaceRequest`: stable SHA-256 memory+disk cache keys and explicit decode size through `:library:image`, so scrolling the people list does not refetch/re-decode faces
162- com/vayunmathur/findfamily/ui/AutoToggleRow.kt
163- com/vayunmathur/findfamily/ui/FindFamilyWideLayout.kt
164- com/vayunmathur/findfamily/ui/UwbRangingScreen.kt
165- com/vayunmathur/findfamily/ui/dialogs/AddPersonDialog.kt — also hosts `decodeBase26`; stateless `AddPersonContent` for previews
166- com/vayunmathur/findfamily/ui/dialogs/AddLinkDialog.kt — stateless `AddLinkContent` for previews
167- com/vayunmathur/findfamily/ui/dialogs/AddTrackerDialog.kt — dev-only; stateless `AddTrackerContent` for previews
168- com/vayunmathur/findfamily/ui/dialogs/NoShowAlertDialog.kt — stateless `NoShowAlertContent` for previews
169- com/vayunmathur/findfamily/ui/dialogs/GpsFallbackWarningDialog.kt
170- com/vayunmathur/findfamily/ui/dialogs/KeyMismatchDialog.kt
171- com/vayunmathur/findfamily/ui/dialogs/OutdatedPeerDialog.kt
172### util/ — ViewModel, tracking service, networking
173- com/vayunmathur/findfamily/util/FindFamilyViewModel.kt
174- com/vayunmathur/findfamily/util/FindFamilyUiContract.kt
175- com/vayunmathur/findfamily/util/MapPageState.kt
176- com/vayunmathur/findfamily/util/LocationTrackingService.kt
177- com/vayunmathur/findfamily/util/LocationServiceController.kt
178- com/vayunmathur/findfamily/util/LocationTrackingHeartbeat.kt
179- com/vayunmathur/findfamily/util/LocationTrackingInbound.kt
180- com/vayunmathur/findfamily/util/LocationTrackingDirectBoot.kt
181- com/vayunmathur/findfamily/util/LocationTrackingCrowdFinding.kt
182- com/vayunmathur/findfamily/util/LocationTrackingNotifications.kt
183- com/vayunmathur/findfamily/util/LocationProviderStatus.kt
184- com/vayunmathur/findfamily/util/Networking.kt
185- com/vayunmathur/findfamily/util/NetworkingLive.kt
186- com/vayunmathur/findfamily/util/NetworkingHelper.kt
187- com/vayunmathur/findfamily/util/NetworkingTracker.kt
188- com/vayunmathur/findfamily/util/UwbSessionManager.kt
189- com/vayunmathur/findfamily/util/Platform.kt
190- com/vayunmathur/findfamily/util/FindFamilyNotificationChannels.kt
191- com/vayunmathur/findfamily/util/TrackingTileService.kt
192- com/vayunmathur/findfamily/util/BootReceiver.kt
193
194## Verify (this module only)
195```
196./gradlew :findfamily:compileDevKotlin
197./gradlew :findfamily:lint
198./gradlew :findfamily:checkMetadata
199```
200- Wear Tile: `service/FindFamilyTileService` (a `MaTileService` in `:library:weartiles`) renders the nearest person's distance from self (freshest person when no self fix) from `WearFindFamilyStore`; the store requests a tile update on every new snapshot, plus 15-minute freshness. Tap opens `WearMainActivity`.