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

Modern-Apps.git / contacts / AGENTS.md

AGENTS.md13.3 KiBRenderedCodeRaw
1# AGENTS.md — contacts/ (':contacts')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `contacts/` + allowed shared modules. Do not root-scan.
4
5_Install: ./install contacts (dev by default)._
6- Gradle: :contacts / dir: contacts/
7- Package roots present: ui, data, domain, intents, platform, sync
8- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt
9- Deps: :library:wearlink, Wear Compose (material + foundation), androidx.work — plus contacts provider + account framework
10- Metadata: metadata_data/contacts.md (present)
11- Rust: no / screenshotTest: yes
12
13## Overview
14**Purpose:** Offline system contacts app — Google Contacts replacement minus cloud sync; handles system pick/view/edit/create intents, vCard import/export, SIM contacts, groups.
15**Key features:**
16- List/detail/edit with groups, favorites, photo crop, birthdays/dates, per-account storage via `platform/Authenticator`
17- vCard import/export + SIM import; quick actions into WhatsApp/Telegram; assistant read/add via `intents/`
18- WhatsApp/Signal/Telegram provider accounts (`data/MessengerAccounts`) never appear in Settings or as contacts; their data rows only join a visible contact through the provider aggregate for call/message actions
19- Optional calendar birthday sync (`CalendarSyncHelper` + `CalendarWorker`); everysync is the sync story, not this app
20**Architecture / data-flow:** `ui/` list/detail/edit pages (+ `ui/dialogs/`) → `util/ContactViewModel` (+ split `Accounts`/`Draft` helpers, `ContactsUiContract`) → `data/` models over the system contacts provider (`Contact`/`ContactGroup`, `ContactPrefill`, `SimContacts`); persistence is the provider, not Room — there is no database here.
21**Entry points + reading order:** `MainActivity.kt` → `ui/ContactListScreen.kt` → `ui/ContactDetailsPage.kt` → `ui/EditContactPage.kt` → `util/ContactViewModel.kt` → `data/Contact.kt`.
22
23## One APK, two form factors (phone + watch)
24This module is the single Contacts APK for phones and watches: same
25`applicationId = "com.vayunmathur.contacts"` and signing on both.
26The manifest deliberately declares no
27`android.hardware.type.watch` feature (required=true would block
28phones; required=false is disallowed for this feature), plus
29touchscreen not-required and
30`com.google.android.wearable.standalone=true`; distribution is
31sideload/F-Droid, not Play's watch channel, so the APK installs on
32phones and watches alike. `platform/FormFactor.kt`
33reads `PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the
34sole launcher entry) forwards watches to `ui/WearMainActivity` before
35any phone state loads; phones get the list/detail/edit UI. The watch
36activity has no launcher entry of its own (`exported=false`). The watch-related receivers are the conduit sync-trigger and
37open-on-phone receivers in `sync/` (both `CONDUIT` signature permission).
38
39## Wear sync (Watch conduit client)
40**Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.contacts.WearContactsProtocol`; the golden-JSON test in this module (`domain/WearContactsProtocolTest`) pins the shared code's wire format.
41- Snapshot: phone -> watch as chunked conduit data items plus a manifest (`/contacts/snapshot/...`); each row carries capped phones/emails, the messenger platforms the phone joins for that contact (call/message/video, `WearContactPlatforms`), and a downscaled photo (`photoBase64`: ≤96 px, ≤8,192 decoded bytes per contact, ≤512,000 decoded photo bytes per snapshot; absent/too-large degrades to the letter avatar); watch state: watch -> phone (`/contacts/watch-state`); snapshot request, call/message/video/email handoff (with platform + contact id, phone re-joins provider rows), and contact delete (`/contacts/delete`, phone deletes from the provider book and republishes) are watch -> phone conduit messages.
42- **Transport: Watch conduit client** — phone side `sync/WearContactsSync.kt` and watch side `sync/WearLinkBridge.kt` (with `sync/WearWatchStatePublisher.kt` publishing watch state / requests / handoffs) use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `contacts`); 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 and never crashes the phone UI; snapshots republish on conduit `Connected` and on book changes.
43- **Push triggers:** the snapshot publish runs on (1) the phone Watch app's scheduled sync-trigger intent (`sync/ConduitSyncTriggerReceiver`, exported only under the `CONDUIT` signature permission, invoking `WearContactsSync.triggerPush()` — no UI, no prompt), (2) book changes (immediate publish from `MainActivity`), and (3) conduit `Connected`. The watch side's user-data mutation is the contact-delete request: its outbound pushes are the immediate watch-state publish, call/message handoff requests, and delete requests via `WearWatchStatePublisher`. Snapshots arriving while the watch process is dead land in the watch conduit's persistent store and replay on registration; the watch copy itself persists in `data/WearContactsStore`.
44- **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.
45
46## Watch experience (in this module)
47- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over the contact list and a detail carrying the contact id.
48- `ui/WearContactsApp` dispatches that route to `ui/WearContactListScreen` (local search over the synced copy; photo/letter avatar per row) and `ui/WearContactDetailScreen` (photo/letter avatar plus the phone-parity call, message, video call and email actions — system and WhatsApp/Signal/Telegram/Meet platforms — filtered by `WearActionPolicy` to only what this watch can complete itself or hand off to a reachable phone; no dead taps, via `platform/WearDeviceCapabilities` including the Meet video-handler probe; Open on phone is the last action button, followed only by the red Delete contact button, which asks the phone to delete the contact after an inline confirmation).
49- Watch state persists in `data/WearContactsStore` (`contacts_snapshot.json` + `contacts_manifest.json` in filesDir).
50- Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:contacts:metadata` into `metadata_data/photos/contacts/wear/`; phone shots use the `phone` bucket.
51**Gotchas:**
52- Contact load is per-source isolated (`data/ContactSourceLoader`): device and SIM contacts publish independently under a per-source timeout, the loaded flag flips as soon as the contacts land, and the one-time migrations plus provider-accounts/default-account refresh run after that under the same timeout — a throwing or never-answering SIM/provider source reads as empty for that source only and never blanks the list or holds the loading state. A timeout only stops the wait: a source that lands late still publishes the completed merge (a stale late result from a superseded load is dropped), so a slow-but-healthy provider never reads as a permanently empty book
53- SIM email rows in the contacts provider hold the ICC delimited string verbatim (trailing `,` separator, possibly EF padding); `data/SimContacts` normalisation decodes them on read and re-encodes them on write for SIM accounts only (the app's virtual ADN account and provider-registered SIM accounts), never for device/cloud accounts
54- SIM sync triggers: ContactsContract and ADN content observers, the subscription (SIM swap) listener, a foreground re-read on resume (`refreshOnForeground` — external SIM edits fire no observer, so without it only a SIM swap refreshed them), pull-to-refresh on the list, and a delayed convergence re-read after every SIM write path (save, delete, move, VCF import, add-phone); there is no polling
55- `util/` is NOT a closed package root — don't add more files there
56- Write paths go through the contacts provider + account (`platform/`), not a local DB — account picker dialogs matter
57- `ImportActivity` + `ImportVcfScreen` handle VIEW intents; `ContactListPick`/`ContactItemPick` serve picker callers
58
59## Key files
60### Root + platform/ — entry and account framework
61- com/vayunmathur/contacts/MainActivity.kt
62- com/vayunmathur/contacts/platform/Authenticator.kt
63- com/vayunmathur/contacts/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)
64- com/vayunmathur/contacts/platform/WearDeviceCapabilities.kt — watch telephony/handler/reachability probe
65### data/ — provider-backed models (no Room)
66- com/vayunmathur/contacts/data/Contact.kt
67- com/vayunmathur/contacts/data/MessengerAccounts.kt — messenger account types hidden from UI, kept only for aggregate joins
68- com/vayunmathur/contacts/data/ContactGroup.kt
69- com/vayunmathur/contacts/data/ContactPrefill.kt
70- com/vayunmathur/contacts/data/SimContacts.kt
71### util/ — ViewModel + helpers
72- com/vayunmathur/contacts/util/ContactViewModel.kt
73- com/vayunmathur/contacts/util/ContactViewModelAccounts.kt
74- com/vayunmathur/contacts/util/ContactViewModelDraft.kt
75- com/vayunmathur/contacts/util/ContactsUiContract.kt
76- com/vayunmathur/contacts/util/ContactSorting.kt
77- com/vayunmathur/contacts/util/VcfUtils.kt
78- com/vayunmathur/contacts/util/CalendarSyncHelper.kt
79- com/vayunmathur/contacts/util/CalendarWorker.kt
80- com/vayunmathur/contacts/util/PackageUtils.kt
81### ui/ + ui/dialogs/ — list/detail/edit/import
82- com/vayunmathur/contacts/ui/ContactListScreen.kt
83- com/vayunmathur/contacts/ui/ContactList.kt
84- com/vayunmathur/contacts/ui/ContactSectionScroller.kt — list fast-scroll pill; its travel and drag scale exclude the FAB zone (bottom window inset + FAB clearance), so the scale's end is the true list end and stays grabbable
85- com/vayunmathur/contacts/ui/ContactItem.kt
86- com/vayunmathur/contacts/ui/ContactListPick.kt
87- com/vayunmathur/contacts/ui/ContactItemPick.kt
88- com/vayunmathur/contacts/ui/GroupedContactSection.kt
89- com/vayunmathur/contacts/ui/GroupsPage.kt
90- com/vayunmathur/contacts/ui/FavoritesHeader.kt
91- com/vayunmathur/contacts/ui/LetterHeader.kt
92- com/vayunmathur/contacts/ui/AvatarColors.kt
93- com/vayunmathur/contacts/ui/ContactUiHelpers.kt
94- com/vayunmathur/contacts/ui/ContactDetailsPage.kt
95- com/vayunmathur/contacts/ui/ContactDetailsHeader.kt
96- com/vayunmathur/contacts/ui/ContactDetailsRows.kt
97- com/vayunmathur/contacts/ui/ContactDetailsSections.kt
98- com/vayunmathur/contacts/ui/ContactDetailsComms.kt
99- com/vayunmathur/contacts/ui/ContactDetailsFormat.kt
100- com/vayunmathur/contacts/ui/EditContactPage.kt
101- com/vayunmathur/contacts/ui/EditContactNameSection.kt
102- com/vayunmathur/contacts/ui/EditContactPhotoSection.kt
103- com/vayunmathur/contacts/ui/EditContactAccountSection.kt
104- com/vayunmathur/contacts/ui/EditContactBirthday.kt
105- com/vayunmathur/contacts/ui/EditContactDateDetails.kt
106- com/vayunmathur/contacts/ui/EditContactDetailGroups.kt
107- com/vayunmathur/contacts/ui/EditContactGroupSection.kt
108- com/vayunmathur/contacts/ui/CropPhotoScreen.kt
109- com/vayunmathur/contacts/ui/CropPhotoSection.kt
110- com/vayunmathur/contacts/ui/NamePrefixChooser.kt
111- com/vayunmathur/contacts/ui/NameSuffixChooser.kt
112- com/vayunmathur/contacts/ui/ImportActivity.kt
113- com/vayunmathur/contacts/ui/ImportVcfScreen.kt
114- com/vayunmathur/contacts/ui/InsertOrEditContactScreen.kt
115- com/vayunmathur/contacts/ui/SettingsPage.kt
116- com/vayunmathur/contacts/ui/dialogs/AddAccountDialog.kt
117- com/vayunmathur/contacts/ui/dialogs/AddToGroupDialog.kt
118- com/vayunmathur/contacts/ui/dialogs/EventDatePickerDialog.kt
119- com/vayunmathur/contacts/ui/dialogs/EventDeleteConfirmDialog.kt
120- com/vayunmathur/contacts/ui/dialogs/AddGroupDialog.kt
121- com/vayunmathur/contacts/ui/dialogs/DeleteGroupDialog.kt
122- com/vayunmathur/contacts/ui/dialogs/DeleteSelectedContactsDialog.kt
123### Watch experience (ui/ + data/ + sync/)
124- com/vayunmathur/contacts/ui/WearMainActivity.kt — watch entry (WearShellActivity, exported=false)
125- com/vayunmathur/contacts/ui/WearRoute.kt, WearContactsApp.kt, WearContactListScreen.kt, WearContactDetailScreen.kt
126- com/vayunmathur/contacts/data/WearContactsStore.kt — watch snapshot store + reassembler
127- com/vayunmathur/contacts/data/WearContactPhoto.kt — phone-side photo downscale into the snapshot caps
128- com/vayunmathur/contacts/ui/WearContactAvatar.kt — watch photo/letter avatar (list + detail)
129- com/vayunmathur/contacts/sync/WearContactsSync.kt — phone conduit client node; snapshot publish (platforms + photo per contact), watch-state receive, request/handoff handling (call/message/video/email, messenger-aware)
130- com/vayunmathur/contacts/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive into the store reassembler
131- com/vayunmathur/contacts/sync/WearWatchStatePublisher.kt — watch state / request / handoff publisher over the conduit client
132### intents/ — assistant IPC
133- com/vayunmathur/contacts/intents/GetIntent.kt
134- com/vayunmathur/contacts/intents/InsertIntent.kt
135
136## Verify (this module only)
137```
138./gradlew :contacts:compileDevKotlin
139./gradlew :contacts:lint :contacts:lintVitalRelease :contacts:testDevUnitTest
140./gradlew :contacts:checkMetadata
141```