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

Modern-Apps.git / findfamily / AGENTS.md

AGENTS.md14.8 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 with key-fingerprint check, 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` / sheets / `AddPersonDialog` / `AddLinkDialog` / `AddTrackerDialog` / `MissingFeaturesDialog` / `SecurityCodeDialog` / `NoShowAlertDialog` / `PermissionUpgradeDialog` / `UwbRangingPage`, all `DialogPage()` except the two full screens) → `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/` (or the sheet content) unconditionally; `PersonDetailSheet` only requests the no-show dialog via its `onShowNoShowAlert` callback. 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
55## Watch experience (in this module)
56- `ui/WearMainActivity` (a `WearShellActivity`, `exported=false`, no
57 launcher filter) routes `ui/WearRoute` over people home (every
58 person, most-recent first) / per-person detail (precise fix
59 age/accuracy/place + relative view) / the all-people relative map
60 centred on the phone-supplied region. There is no vector basemap:
61 markers plot relative to the centre, stale fixes are labelled by
62 age, and precision is never faked.
63- Watch state persists in `data/WearFindFamilyStore`
64 (`wear-findfamily-snapshot.json`); presentation helpers live in
65 `domain/WearRelative.kt`; the watch sync side is
66 `sync/WearLinkBridge.kt`.
67- Watch listing screenshots are the `group = "wear"` previews in
68 `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by
69 `:findfamily:metadata` into `metadata_data/photos/findfamily/wear/`;
70 phone shots use the `phone` bucket.
71
72## Key files
73### Root — entry + navigation
74- com/vayunmathur/findfamily/MainActivity.kt — deep-link parsing, permission spec, permission-upgrade trigger
75- com/vayunmathur/findfamily/Route.kt — sealed `Route` destinations (sheets + dialog routes + UWB screen)
76- com/vayunmathur/findfamily/Navigation.kt — `MainNavigation` entries for every route
77### data/ — Room entities + repository
78- com/vayunmathur/findfamily/data/FindFamilyRepository.kt
79- com/vayunmathur/findfamily/data/FFDatabase.kt
80- com/vayunmathur/findfamily/data/User.kt
81- com/vayunmathur/findfamily/data/Waypoint.kt
82- com/vayunmathur/findfamily/data/TemporaryLink.kt
83- com/vayunmathur/findfamily/data/NoShowAlert.kt
84- com/vayunmathur/findfamily/data/NoShowAlertDao.kt
85- com/vayunmathur/findfamily/data/Coord.kt
86- com/vayunmathur/findfamily/data/LocationValue.kt
87- com/vayunmathur/findfamily/data/DirectBootStore.kt
88- com/vayunmathur/findfamily/data/FindFamilyDbBackupCodec.kt — platform-backup codec: `SqlCipherDbCodec` export/import plus plaintext-export sanitization (see `domain/PlatformBackup.kt`)
89### domain/ — pairing auth, no-show policy, sender movement policy (pure logic)
90- 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
91- com/vayunmathur/findfamily/domain/PairAuth.kt
92- com/vayunmathur/findfamily/domain/NoShowPolicy.kt
93- com/vayunmathur/findfamily/domain/MovementDetector.kt — sender moving/still state machine (acceleration + fix speed + displacement)
94- com/vayunmathur/findfamily/domain/ForcedFixPolicy.kt — when a "still" sender forces a one-off fix
95### sync/ — wear companion (both sides in this APK)
96- 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
97- 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
98### Watch experience (ui/ + data/ + domain/)
99- com/vayunmathur/findfamily/ui/WearMainActivity.kt — watch entry (WearShellActivity, exported=false)
100- com/vayunmathur/findfamily/ui/WearRoute.kt, WearPeopleScreen.kt, WearPersonScreen.kt, WearAllMapScreen.kt, WearRelativeCanvas.kt
101- com/vayunmathur/findfamily/data/WearFindFamilyStore.kt
102- com/vayunmathur/findfamily/domain/WearRelative.kt
103### intents/ — assistant IPC
104- com/vayunmathur/findfamily/intents/GetIntent.kt
105- com/vayunmathur/findfamily/intents/CreateLinkIntent.kt
106### ipc/ — cross-app family-location protocol
107- com/vayunmathur/findfamily/ipc/FamilyLocationProtocol.kt
108- com/vayunmathur/findfamily/ipc/FamilyLocationService.kt
109### platform/ — reporters + schedulers
110- 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
111- com/vayunmathur/findfamily/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`) for the single merged APK
112- com/vayunmathur/findfamily/platform/FinalLocationReporter.kt
113- com/vayunmathur/findfamily/platform/NoShowCheckScheduler.kt
114- com/vayunmathur/findfamily/platform/PoweredOffBeacon.kt
115- com/vayunmathur/findfamily/platform/LocationKeepAlive.kt — sender keep-alive: single fix intake, low-power/passive requests, forced fix
116### service/ — Quick Settings tile
117- com/vayunmathur/findfamily/service/SharingTileService.kt
118### tracker/ — BLE tracker protocol + powered-off finding
119- com/vayunmathur/findfamily/tracker/TrackerProtocol.kt
120- com/vayunmathur/findfamily/tracker/TrackerBle.kt
121- com/vayunmathur/findfamily/tracker/TrackerProvisioner.kt
122- com/vayunmathur/findfamily/tracker/TrackerStore.kt
123- com/vayunmathur/findfamily/tracker/TrackerReporting.kt
124- com/vayunmathur/findfamily/tracker/TrackerFeature.kt
125- com/vayunmathur/findfamily/tracker/TrackerBeaconScanner.kt
126- com/vayunmathur/findfamily/tracker/TrackerBinder.kt
127- com/vayunmathur/findfamily/tracker/TrackerUwbGatt.kt
128- com/vayunmathur/findfamily/tracker/TrackerUwbKeys.kt
129- com/vayunmathur/findfamily/tracker/PoweredOffProtocol.kt
130- com/vayunmathur/findfamily/tracker/PoweredOffBle.kt
131- com/vayunmathur/findfamily/tracker/PoweredOffScanner.kt
132- com/vayunmathur/findfamily/tracker/PoweredOffReporting.kt
133- com/vayunmathur/findfamily/tracker/PoweredOffRecovery.kt
134- com/vayunmathur/findfamily/tracker/PoweredOffKeyStore.kt
135### uwb/ — UWB ranging stack
136- com/vayunmathur/findfamily/uwb/UwbController.kt
137- com/vayunmathur/findfamily/uwb/UwbEnvelope.kt
138- com/vayunmathur/findfamily/uwb/UwbInbox.kt
139- com/vayunmathur/findfamily/uwb/UwbAccessoryProtocol.kt
140### ui/ — main page + dialogs + UWB screen
141- com/vayunmathur/findfamily/ui/MainPage.kt
142- com/vayunmathur/findfamily/ui/MainPageContent.kt
143- com/vayunmathur/findfamily/ui/MainPageActions.kt
144- com/vayunmathur/findfamily/ui/MainPageCards.kt
145- com/vayunmathur/findfamily/ui/MainPageEffects.kt
146- com/vayunmathur/findfamily/ui/MainPageOverlays.kt
147- com/vayunmathur/findfamily/ui/MainMapSlot.kt
148- com/vayunmathur/findfamily/ui/MainSheetContent.kt
149- com/vayunmathur/findfamily/ui/MapView.kt
150- com/vayunmathur/findfamily/ui/MainFabOverlay.kt
151- com/vayunmathur/findfamily/ui/FamilyListSheet.kt
152- com/vayunmathur/findfamily/ui/PersonDetailSheet.kt
153- com/vayunmathur/findfamily/ui/UserCard.kt
154- 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
155- com/vayunmathur/findfamily/ui/AutoToggleRow.kt
156- com/vayunmathur/findfamily/ui/FindFamilyWideLayout.kt
157- com/vayunmathur/findfamily/ui/UwbRangingScreen.kt
158- com/vayunmathur/findfamily/ui/dialogs/AddPersonDialog.kt — also hosts `decodeBase26`; stateless `AddPersonContent` for previews
159- com/vayunmathur/findfamily/ui/dialogs/AddLinkDialog.kt — stateless `AddLinkContent` for previews
160- com/vayunmathur/findfamily/ui/dialogs/AddTrackerDialog.kt — dev-only; stateless `AddTrackerContent` for previews
161- com/vayunmathur/findfamily/ui/dialogs/NoShowAlertDialog.kt — stateless `NoShowAlertContent` for previews
162- com/vayunmathur/findfamily/ui/dialogs/GpsFallbackWarningDialog.kt
163- com/vayunmathur/findfamily/ui/dialogs/KeyMismatchDialog.kt
164- com/vayunmathur/findfamily/ui/dialogs/OutdatedPeerDialog.kt
165- com/vayunmathur/findfamily/ui/dialogs/SecurityCodeDialog.kt — stateless `SecurityCodeContent` for previews
166### util/ — ViewModel, tracking service, networking
167- com/vayunmathur/findfamily/util/FindFamilyViewModel.kt
168- com/vayunmathur/findfamily/util/FindFamilyUiContract.kt
169- com/vayunmathur/findfamily/util/MapPageState.kt
170- com/vayunmathur/findfamily/util/LocationTrackingService.kt
171- com/vayunmathur/findfamily/util/LocationServiceController.kt
172- com/vayunmathur/findfamily/util/LocationTrackingHeartbeat.kt
173- com/vayunmathur/findfamily/util/LocationTrackingInbound.kt
174- com/vayunmathur/findfamily/util/LocationTrackingDirectBoot.kt
175- com/vayunmathur/findfamily/util/LocationTrackingCrowdFinding.kt
176- com/vayunmathur/findfamily/util/LocationTrackingNotifications.kt
177- com/vayunmathur/findfamily/util/LocationProviderStatus.kt
178- com/vayunmathur/findfamily/util/Networking.kt
179- com/vayunmathur/findfamily/util/NetworkingLive.kt
180- com/vayunmathur/findfamily/util/NetworkingHelper.kt
181- com/vayunmathur/findfamily/util/NetworkingTracker.kt
182- com/vayunmathur/findfamily/util/UwbSessionManager.kt
183- com/vayunmathur/findfamily/util/Platform.kt
184- com/vayunmathur/findfamily/util/FindFamilyNotificationChannels.kt
185- com/vayunmathur/findfamily/util/TrackingTileService.kt
186- com/vayunmathur/findfamily/util/BootReceiver.kt
187
188## Verify (this module only)
189```
190./gradlew :findfamily:compileDevKotlin
191./gradlew :findfamily:lint
192./gradlew :findfamily:checkMetadata
193```