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

Modern-Apps.git / contacts / AGENTS.md

AGENTS.md13.3 KiBRenderedCodeRaw

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/
  • 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
  • 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). The watch-related receivers are the conduit sync-trigger and open-on-phone receivers in sync/ (both CONDUIT signature permission).

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/...); 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.
  • 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.
  • 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.
  • 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.

Watch experience (in this module)

  • ui/WearMainActivity (a WearShellActivity) routes ui/WearRoute over the contact list and a detail carrying the contact id.
  • 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).
  • Watch state persists in data/WearContactsStore (contacts_snapshot.json + contacts_manifest.json in filesDir).
  • 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.

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/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
  • 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 + ImportVcfScreen handle VIEW intents; ContactListPick/ContactItemPick serve 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/MessengerAccounts.kt — messenger account types hidden from UI, kept only for aggregate joins
  • 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/data/WearContactPhoto.kt — phone-side photo downscale into the snapshot caps
  • com/vayunmathur/contacts/ui/WearContactAvatar.kt — watch photo/letter avatar (list + detail)
  • 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)
  • 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