AGENTS.md — contacts/ (':contacts')
Scoped supplement. Global rules in root AGENTS.md apply. Stay inside contacts/ + allowed shared modules. Do not root-scan.
Install: ./install contacts (dev by default).
- Gradle: :contacts / dir: contacts/
- Package roots present: ui, data, domain, intents, platform, sync
- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt
- Deps: :library:wearlink, Wear Compose (material + foundation), androidx.work — plus contacts provider + account framework
- Metadata: metadata_data/contacts.md (present)
- Rust: no / screenshotTest: yes
Overview
Purpose: Offline system contacts app — Google Contacts replacement minus cloud sync; handles system pick/view/edit/create intents, vCard import/export, SIM contacts, groups. Key features:
- List/detail/edit with groups, favorites, photo crop, birthdays/dates, per-account storage via
platform/Authenticator - vCard import/export + SIM import; quick actions into WhatsApp/Telegram; assistant read/add via
intents/ - Optional calendar birthday sync (
CalendarSyncHelper+CalendarWorker); everysync is the sync story, not this app
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. Entry points + reading order: MainActivity.kt → ui/ContactListScreen.kt → ui/ContactDetailsPage.kt → ui/EditContactPage.kt → util/ContactViewModel.kt → data/Contact.kt.
One APK, two form factors (phone + watch)
This module is the single Contacts APK for phones and watches: same applicationId = "com.vayunmathur.contacts" and signing on both. The manifest deliberately declares no android.hardware.type.watch feature (required=true would block phones; required=false is disallowed for this feature), plus touchscreen not-required and com.google.android.wearable.standalone=true; distribution is sideload/F-Droid, not Play's watch channel, so the APK installs on phones and watches alike. platform/FormFactor.kt reads PackageManager.FEATURE_WATCH at runtime: MainActivity (the sole launcher entry) forwards watches to ui/WearMainActivity before any phone state loads; phones get the list/detail/edit UI. The watch activity has no launcher entry of its own (exported=false). There are no watch receivers in this module.
Wear sync (Watch conduit client)
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.
- 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. - Transport: Watch conduit client — phone side
sync/WearContactsSync.ktand watch sidesync/WearLinkBridge.kt(withsync/WearWatchStatePublisher.ktpublishing watch state / requests / handoffs) useWearLinkClientNode(Messenger to the Watch app'swatch_conduitservice, appIdcontacts); 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 reportsNotInstalled/Unavailableand the sync stays idle and never crashes the phone UI; snapshots republish on conduitConnectedand on book changes.
Watch experience (in this module)
ui/WearMainActivity(aWearShellActivity) routesui/WearRouteover the contact list and a detail carrying the contact id.ui/WearContactsAppdispatches that route toui/WearContactListScreen(local search over the synced copy) andui/WearContactDetailScreen(only actionsWearActionPolicysays this watch can complete; no dead taps, viaplatform/WearDeviceCapabilities).- Watch state persists in
data/WearContactsStore(contacts_snapshot.json+contacts_manifest.jsonin filesDir). - Watch listing screenshots are the
group = "wear"previews insrc/screenshotTest/.../ui/WearMetadataPreviews.kt, collected by:contacts:metadataintometadata_data/photos/contacts/wear/; phone shots use thephonebucket.
Gotchas:
- 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 - SIM email rows in the contacts provider hold the ICC delimited string verbatim (trailing
,separator, possibly EF padding);data/SimContactsnormalisation 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 - 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 util/is NOT a closed package root — don't add more files there- Write paths go through the contacts provider + account (
platform/), not a local DB — account picker dialogs matter ImportActivity+ImportVcfScreenhandle VIEW intents;ContactListPick/ContactItemPickserve picker callers
Key files
Root + platform/ — entry and account framework
- com/vayunmathur/contacts/MainActivity.kt
- com/vayunmathur/contacts/platform/Authenticator.kt
- com/vayunmathur/contacts/platform/FormFactor.kt — watch detection (
FEATURE_WATCH) - com/vayunmathur/contacts/platform/WearDeviceCapabilities.kt — watch telephony/handler/reachability probe
data/ — provider-backed models (no Room)
- com/vayunmathur/contacts/data/Contact.kt
- com/vayunmathur/contacts/data/ContactGroup.kt
- com/vayunmathur/contacts/data/ContactPrefill.kt
- com/vayunmathur/contacts/data/SimContacts.kt
util/ — ViewModel + helpers
- com/vayunmathur/contacts/util/ContactViewModel.kt
- com/vayunmathur/contacts/util/ContactViewModelAccounts.kt
- com/vayunmathur/contacts/util/ContactViewModelDraft.kt
- com/vayunmathur/contacts/util/ContactsUiContract.kt
- com/vayunmathur/contacts/util/ContactSorting.kt
- com/vayunmathur/contacts/util/VcfUtils.kt
- com/vayunmathur/contacts/util/CalendarSyncHelper.kt
- com/vayunmathur/contacts/util/CalendarWorker.kt
- com/vayunmathur/contacts/util/PackageUtils.kt
ui/ + ui/dialogs/ — list/detail/edit/import
- com/vayunmathur/contacts/ui/ContactListScreen.kt
- com/vayunmathur/contacts/ui/ContactList.kt
- 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
- com/vayunmathur/contacts/ui/ContactItem.kt
- com/vayunmathur/contacts/ui/ContactListPick.kt
- com/vayunmathur/contacts/ui/ContactItemPick.kt
- com/vayunmathur/contacts/ui/GroupedContactSection.kt
- com/vayunmathur/contacts/ui/GroupsPage.kt
- com/vayunmathur/contacts/ui/FavoritesHeader.kt
- com/vayunmathur/contacts/ui/LetterHeader.kt
- com/vayunmathur/contacts/ui/AvatarColors.kt
- com/vayunmathur/contacts/ui/ContactUiHelpers.kt
- com/vayunmathur/contacts/ui/ContactDetailsPage.kt
- com/vayunmathur/contacts/ui/ContactDetailsHeader.kt
- com/vayunmathur/contacts/ui/ContactDetailsRows.kt
- com/vayunmathur/contacts/ui/ContactDetailsSections.kt
- com/vayunmathur/contacts/ui/ContactDetailsComms.kt
- com/vayunmathur/contacts/ui/ContactDetailsFormat.kt
- com/vayunmathur/contacts/ui/EditContactPage.kt
- com/vayunmathur/contacts/ui/EditContactNameSection.kt
- com/vayunmathur/contacts/ui/EditContactPhotoSection.kt
- com/vayunmathur/contacts/ui/EditContactAccountSection.kt
- com/vayunmathur/contacts/ui/EditContactBirthday.kt
- com/vayunmathur/contacts/ui/EditContactDateDetails.kt
- com/vayunmathur/contacts/ui/EditContactDetailGroups.kt
- com/vayunmathur/contacts/ui/EditContactGroupSection.kt
- com/vayunmathur/contacts/ui/CropPhotoScreen.kt
- com/vayunmathur/contacts/ui/CropPhotoSection.kt
- com/vayunmathur/contacts/ui/NamePrefixChooser.kt
- com/vayunmathur/contacts/ui/NameSuffixChooser.kt
- com/vayunmathur/contacts/ui/ImportActivity.kt
- com/vayunmathur/contacts/ui/ImportVcfScreen.kt
- com/vayunmathur/contacts/ui/InsertOrEditContactScreen.kt
- com/vayunmathur/contacts/ui/SettingsPage.kt
- com/vayunmathur/contacts/ui/dialogs/AddAccountDialog.kt
- com/vayunmathur/contacts/ui/dialogs/AddToGroupDialog.kt
- com/vayunmathur/contacts/ui/dialogs/EventDatePickerDialog.kt
- com/vayunmathur/contacts/ui/dialogs/EventDeleteConfirmDialog.kt
- com/vayunmathur/contacts/ui/dialogs/AddGroupDialog.kt
- com/vayunmathur/contacts/ui/dialogs/DeleteGroupDialog.kt
- com/vayunmathur/contacts/ui/dialogs/DeleteSelectedContactsDialog.kt
Watch experience (ui/ + data/ + sync/)
- com/vayunmathur/contacts/ui/WearMainActivity.kt — watch entry (WearShellActivity, exported=false)
- com/vayunmathur/contacts/ui/WearRoute.kt, WearContactsApp.kt, WearContactListScreen.kt, WearContactDetailScreen.kt
- com/vayunmathur/contacts/data/WearContactsStore.kt — watch snapshot store + reassembler
- com/vayunmathur/contacts/sync/WearContactsSync.kt — phone conduit client node; snapshot publish, watch-state receive, request/handoff handling
- com/vayunmathur/contacts/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive into the store reassembler
- com/vayunmathur/contacts/sync/WearWatchStatePublisher.kt — watch state / request / handoff publisher over the conduit client
intents/ — assistant IPC
- com/vayunmathur/contacts/intents/GetIntent.kt
- com/vayunmathur/contacts/intents/InsertIntent.kt
Verify (this module only)
./gradlew :contacts:compileDevKotlin
./gradlew :contacts:lint :contacts:lintVitalRelease :contacts:testDevUnitTest
./gradlew :contacts:checkMetadata