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

Modern-Apps.git / contacts / AGENTS.md

AGENTS.md10.6 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- Optional calendar birthday sync (`CalendarSyncHelper` + `CalendarWorker`); everysync is the sync story, not this app
19**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.
20**Entry points + reading order:** `MainActivity.kt` → `ui/ContactListScreen.kt` → `ui/ContactDetailsPage.kt` → `ui/EditContactPage.kt` → `util/ContactViewModel.kt` → `data/Contact.kt`.
21
22## One APK, two form factors (phone + watch)
23This module is the single Contacts APK for phones and watches: same
24`applicationId = "com.vayunmathur.contacts"` and signing on both.
25The manifest deliberately declares no
26`android.hardware.type.watch` feature (required=true would block
27phones; required=false is disallowed for this feature), plus
28touchscreen not-required and
29`com.google.android.wearable.standalone=true`; distribution is
30sideload/F-Droid, not Play's watch channel, so the APK installs on
31phones and watches alike. `platform/FormFactor.kt`
32reads `PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the
33sole launcher entry) forwards watches to `ui/WearMainActivity` before
34any phone state loads; phones get the list/detail/edit UI. The watch
35activity has no launcher entry of its own (`exported=false`). There
36are no watch receivers in this module.
37
38## Wear sync (Watch conduit client)
39**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.
40- Snapshot: phone -> watch as chunked conduit data items plus a manifest (`/contacts/snapshot/...`); watch state: watch -> phone (`/contacts/watch-state`); snapshot request and call/message handoff are watch -> phone conduit messages.
41- **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.
42
43## Watch experience (in this module)
44- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over the contact list and a detail carrying the contact id.
45- `ui/WearContactsApp` dispatches that route to `ui/WearContactListScreen` (local search over the synced copy) and `ui/WearContactDetailScreen` (only actions `WearActionPolicy` says this watch can complete; no dead taps, via `platform/WearDeviceCapabilities`).
46- Watch state persists in `data/WearContactsStore` (`contacts_snapshot.json` + `contacts_manifest.json` in filesDir).
47- 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.
48**Gotchas:**
49- 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
50- 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
51- 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
52- `util/` is NOT a closed package root — don't add more files there
53- Write paths go through the contacts provider + account (`platform/`), not a local DB — account picker dialogs matter
54- `ImportActivity` + `ImportVcfScreen` handle VIEW intents; `ContactListPick`/`ContactItemPick` serve picker callers
55
56## Key files
57### Root + platform/ — entry and account framework
58- com/vayunmathur/contacts/MainActivity.kt
59- com/vayunmathur/contacts/platform/Authenticator.kt
60- com/vayunmathur/contacts/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)
61- com/vayunmathur/contacts/platform/WearDeviceCapabilities.kt — watch telephony/handler/reachability probe
62### data/ — provider-backed models (no Room)
63- com/vayunmathur/contacts/data/Contact.kt
64- com/vayunmathur/contacts/data/ContactGroup.kt
65- com/vayunmathur/contacts/data/ContactPrefill.kt
66- com/vayunmathur/contacts/data/SimContacts.kt
67### util/ — ViewModel + helpers
68- com/vayunmathur/contacts/util/ContactViewModel.kt
69- com/vayunmathur/contacts/util/ContactViewModelAccounts.kt
70- com/vayunmathur/contacts/util/ContactViewModelDraft.kt
71- com/vayunmathur/contacts/util/ContactsUiContract.kt
72- com/vayunmathur/contacts/util/ContactSorting.kt
73- com/vayunmathur/contacts/util/VcfUtils.kt
74- com/vayunmathur/contacts/util/CalendarSyncHelper.kt
75- com/vayunmathur/contacts/util/CalendarWorker.kt
76- com/vayunmathur/contacts/util/PackageUtils.kt
77### ui/ + ui/dialogs/ — list/detail/edit/import
78- com/vayunmathur/contacts/ui/ContactListScreen.kt
79- com/vayunmathur/contacts/ui/ContactList.kt
80- 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
81- com/vayunmathur/contacts/ui/ContactItem.kt
82- com/vayunmathur/contacts/ui/ContactListPick.kt
83- com/vayunmathur/contacts/ui/ContactItemPick.kt
84- com/vayunmathur/contacts/ui/GroupedContactSection.kt
85- com/vayunmathur/contacts/ui/GroupsPage.kt
86- com/vayunmathur/contacts/ui/FavoritesHeader.kt
87- com/vayunmathur/contacts/ui/LetterHeader.kt
88- com/vayunmathur/contacts/ui/AvatarColors.kt
89- com/vayunmathur/contacts/ui/ContactUiHelpers.kt
90- com/vayunmathur/contacts/ui/ContactDetailsPage.kt
91- com/vayunmathur/contacts/ui/ContactDetailsHeader.kt
92- com/vayunmathur/contacts/ui/ContactDetailsRows.kt
93- com/vayunmathur/contacts/ui/ContactDetailsSections.kt
94- com/vayunmathur/contacts/ui/ContactDetailsComms.kt
95- com/vayunmathur/contacts/ui/ContactDetailsFormat.kt
96- com/vayunmathur/contacts/ui/EditContactPage.kt
97- com/vayunmathur/contacts/ui/EditContactNameSection.kt
98- com/vayunmathur/contacts/ui/EditContactPhotoSection.kt
99- com/vayunmathur/contacts/ui/EditContactAccountSection.kt
100- com/vayunmathur/contacts/ui/EditContactBirthday.kt
101- com/vayunmathur/contacts/ui/EditContactDateDetails.kt
102- com/vayunmathur/contacts/ui/EditContactDetailGroups.kt
103- com/vayunmathur/contacts/ui/EditContactGroupSection.kt
104- com/vayunmathur/contacts/ui/CropPhotoScreen.kt
105- com/vayunmathur/contacts/ui/CropPhotoSection.kt
106- com/vayunmathur/contacts/ui/NamePrefixChooser.kt
107- com/vayunmathur/contacts/ui/NameSuffixChooser.kt
108- com/vayunmathur/contacts/ui/ImportActivity.kt
109- com/vayunmathur/contacts/ui/ImportVcfScreen.kt
110- com/vayunmathur/contacts/ui/InsertOrEditContactScreen.kt
111- com/vayunmathur/contacts/ui/SettingsPage.kt
112- com/vayunmathur/contacts/ui/dialogs/AddAccountDialog.kt
113- com/vayunmathur/contacts/ui/dialogs/AddToGroupDialog.kt
114- com/vayunmathur/contacts/ui/dialogs/EventDatePickerDialog.kt
115- com/vayunmathur/contacts/ui/dialogs/EventDeleteConfirmDialog.kt
116- com/vayunmathur/contacts/ui/dialogs/AddGroupDialog.kt
117- com/vayunmathur/contacts/ui/dialogs/DeleteGroupDialog.kt
118- com/vayunmathur/contacts/ui/dialogs/DeleteSelectedContactsDialog.kt
119### Watch experience (ui/ + data/ + sync/)
120- com/vayunmathur/contacts/ui/WearMainActivity.kt — watch entry (WearShellActivity, exported=false)
121- com/vayunmathur/contacts/ui/WearRoute.kt, WearContactsApp.kt, WearContactListScreen.kt, WearContactDetailScreen.kt
122- com/vayunmathur/contacts/data/WearContactsStore.kt — watch snapshot store + reassembler
123- com/vayunmathur/contacts/sync/WearContactsSync.kt — phone conduit client node; snapshot publish, watch-state receive, request/handoff handling
124- com/vayunmathur/contacts/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive into the store reassembler
125- com/vayunmathur/contacts/sync/WearWatchStatePublisher.kt — watch state / request / handoff publisher over the conduit client
126### intents/ — assistant IPC
127- com/vayunmathur/contacts/intents/GetIntent.kt
128- com/vayunmathur/contacts/intents/InsertIntent.kt
129
130## Verify (this module only)
131```
132./gradlew :contacts:compileDevKotlin
133./gradlew :contacts:lint :contacts:lintVitalRelease :contacts:testDevUnitTest
134./gradlew :contacts:checkMetadata
135```