Modern Apps git

← Modern-Apps.git

contacts: hide WhatsApp, Signal and Telegram accounts and contacts

Commit
24a1997d99dec08503007d3dcd7b55307861127b
Author
Vayun Mathur <[email protected]>
When
2026-12-05 13:30 UTC (23 hours ago)
Parents
f3a30ea
Messenger provider accounts were listed in Settings as toggleable
accounts and their raw contacts could appear as contacts of their
own. They must only join a visible contact so call/message quick
actions work.

Account types (each is the app package, also its provider account
type and vnd.<package> data-row prefix, as in PackageUtils):
com.whatsapp, org.thoughtcrime.securesms, org.telegram.messenger.
New data/MessengerAccounts.kt holds the types, isMessengerAccountType
and filterOutMessengerContacts.

Visibility: Contact.getContacts drops messenger-only raw contacts;
the ViewModel contacts flow drops them too, so list, search,
pickers and groups never show them, and the wear snapshot publish
filters them out. A person with a real-account raw contact keeps
showing through that row alone (no duplicate), and its detail
screen still resolves the messenger rows through the provider
aggregate contact (PackageUtils.getContactPlatforms, unchanged),
so WhatsApp/Signal/Telegram call, video and message actions keep
working. Settings: accountsState now goes through visibleAccounts,
so the three messenger accounts are absent entirely (also from
the edit/import/move account pickers that share that flow), and a
messenger account can no longer be the new-contact default.

Tests: pure/MessengerAccountsTest covers the three account types,
messenger-only exclusion, the joined-contact single row, real
accounts staying visible, and the settings account list.
Verified: :contacts:lint :contacts:lintVitalRelease green;
:contacts:testDevUnitTest 631 tests, 6 new tests pass, only the
2 pre-existing failures (InsertOrEditIntentActivityPass2Test and
DeepInteractionsPass2Test compose timeouts), reproduced identically
on the clean 13a8849f3 baseline.

Diff

contacts/AGENTS.md
diff --git a/contacts/AGENTS.md b/contacts/AGENTS.mdindex 2fae304077..832df1c1ef 100644--- a/contacts/AGENTS.md+++ b/contacts/AGENTS.md@@ -15,6 +15,7 @@ _Install: ./install contacts (dev by default)._ **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`.@@ -62,6 +63,7 @@ are no watch receivers in this module. - 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
contacts/src/main/java/com/vayunmathur/contacts/data/Contact.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/data/Contact.kt b/contacts/src/main/java/com/vayunmathur/contacts/data/Contact.ktindex cbfa002fff..db3fe3fce6 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/data/Contact.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/data/Contact.kt@@ -737,7 +737,8 @@ data class Contact(             if (rawContacts.isEmpty()) return emptyList()              val allDetails = getDetailsInternal(context, contactId)-            return rawContacts.mapNotNull { raw ->+            // Messenger-only raw contacts never surface; their rows join via the provider aggregate.+            return filterOutMessengerContacts(rawContacts.mapNotNull { raw ->                 // SIM-account email rows are decoded like ADN rows (#935, see                 // normalizeSimEmailsForAccount); other rows are read as stored.                 val decoded = normalizeSimEmailsForAccount(@@ -754,7 +755,7 @@ data class Contact(                     details,                     raw.customRingtone                 )-            }+            })         }          fun getContact(context: Context, contactId: Long): Contact? = getContacts(context, contactId).firstOrNull()
contacts/src/main/java/com/vayunmathur/contacts/data/MessengerAccounts.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/data/MessengerAccounts.kt b/contacts/src/main/java/com/vayunmathur/contacts/data/MessengerAccounts.ktnew file mode 100644index 0000000000..a9c698b90d--- /dev/null+++ b/contacts/src/main/java/com/vayunmathur/contacts/data/MessengerAccounts.kt@@ -0,0 +1,38 @@+package com.vayunmathur.contacts.data++/**+ * Provider account types of the three messenger apps whose contacts join a+ * visible contact for call/message actions but must never surface as+ * contacts or accounts of their own. Each type is the app's package name,+ * which is also the account type its sync adapter registers with the+ * contacts provider (the same packages [com.vayunmathur.contacts.platform.PackageUtils]+ * probes for installed apps and whose `vnd.<package>.*` data-row MIME types+ * the platform lookup matches).+ */+const val WHATSAPP_ACCOUNT_TYPE = "com.whatsapp"++/** Signal account type; see [WHATSAPP_ACCOUNT_TYPE]. */+const val SIGNAL_ACCOUNT_TYPE = "org.thoughtcrime.securesms"++/** Telegram account type; see [WHATSAPP_ACCOUNT_TYPE]. */+const val TELEGRAM_ACCOUNT_TYPE = "org.telegram.messenger"++/** Every messenger account type hidden from contacts and settings. */+val MESSENGER_ACCOUNT_TYPES: Set<String> = setOf(+    WHATSAPP_ACCOUNT_TYPE,+    SIGNAL_ACCOUNT_TYPE,+    TELEGRAM_ACCOUNT_TYPE,+)++/** True when [type] is a WhatsApp, Signal or Telegram provider account type. */+fun isMessengerAccountType(type: String?): Boolean = type in MESSENGER_ACCOUNT_TYPES++/**+ * The contacts allowed to appear in the UI: every contact except raw+ * contacts that exist only in a messenger account. A person who also has a+ * raw contact in a real account keeps showing through that account's row+ * alone (no duplicate), and the messenger data rows still join that row at+ * the provider's aggregate contact for call/message quick actions.+ */+fun filterOutMessengerContacts(contacts: List<Contact>): List<Contact> =+    contacts.filterNot { isMessengerAccountType(it.accountType) }
contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModel.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModel.kt b/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModel.ktindex 1b311148fb..aa197a476e 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModel.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModel.kt@@ -155,6 +155,9 @@ class ContactViewModel internal constructor(         hiddenAccounts     ) { indexed, query, hidden ->         val visible = indexed.filter { (c, _) ->+            // Messenger-only contacts never appear (list, search, pickers,+            // groups); their rows join via the provider aggregate instead.+            if (com.vayunmathur.contacts.data.isMessengerAccountType(c.accountType)) return@filter false             val key = accountKey(c.accountType, c.accountName)             val encodedKey = encodedAccountKey(c.accountType, c.accountName)             // Support legacy hidden entries that stored only accountName, raw "type|name"
contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelAccounts.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelAccounts.kt b/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelAccounts.ktindex b779b09ff5..8b9b11f49c 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelAccounts.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelAccounts.kt@@ -15,6 +15,7 @@ import com.vayunmathur.contacts.data.SIM_ACCOUNT_TYPE import com.vayunmathur.contacts.data.SimContactsDataSource import com.vayunmathur.contacts.data.isDefaultLocalAccount import com.vayunmathur.contacts.data.isLocalAccountType+import com.vayunmathur.contacts.data.isMessengerAccountType import com.vayunmathur.contacts.data.isSimAccountType import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow@@ -158,6 +159,8 @@ internal suspend fun ContactViewModel.cloudDefaultRejectionMessage(): String {  */ internal fun ContactViewModel.newContactDefaultAccount(): ContactAccount {     val last = lastSelectedAccountState.value ?: ContactAccount("", "")+    // A messenger account is never a save target; fall back to on-device.+    if (isMessengerAccountType(last.type)) return ContactAccount("", "")     val restriction = newContactRestrictionState.value ?: return last     if (!restriction.blocks(last.name, last.type)) return last     return ContactAccount(restriction.cloudAccount.name, restriction.cloudAccount.type)@@ -216,10 +219,18 @@ private fun simAccountsOf(     ContactAccount(SimContactsDataSource.accountNameFor(info), SIM_ACCOUNT_TYPE) } +/**+ * Accounts offered to the user (settings list and account pickers):+ * messenger accounts are absent entirely, whether or not the messenger+ * apps are installed; every other account is unchanged.+ */+internal fun visibleAccounts(accounts: List<ContactAccount>): List<ContactAccount> =+    accounts.filterNot { isMessengerAccountType(it.type) }+ private fun ContactViewModel.sortAccountsIntoState(all: List<ContactAccount>) {     // Sort: SIM accounts by display label, others by name     val collator = ContactSorting.collator()-    accountsState.value = all.sortedWith(+    accountsState.value = visibleAccounts(all).sortedWith(         compareBy(collator) { acc -> sortKeyFor(acc) }     ) }
contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.ktindex c2b2ab5db5..74be1707c0 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt@@ -124,7 +124,9 @@ class WearContactsSync(     }      /** Publish the current address book as a capped, chunked snapshot. */-    fun publish(contacts: List<Contact>) = publishWearContacts(contacts.map { it.toWearContact() })+    fun publish(contacts: List<Contact>) = publishWearContacts(+        com.vayunmathur.contacts.data.filterOutMessengerContacts(contacts).map { it.toWearContact() }+    )      /** Publish already-mapped watch rows (the watch-request republish path). */     fun publishWearContacts(rows: List<WearContact>) {
contacts/src/test/java/com/vayunmathur/contacts/pure/MessengerAccountsTest.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/pure/MessengerAccountsTest.kt b/contacts/src/test/java/com/vayunmathur/contacts/pure/MessengerAccountsTest.ktnew file mode 100644index 0000000000..f254140f63--- /dev/null+++ b/contacts/src/test/java/com/vayunmathur/contacts/pure/MessengerAccountsTest.kt@@ -0,0 +1,108 @@+package com.vayunmathur.contacts.pure++import com.vayunmathur.contacts.data.Contact+import com.vayunmathur.contacts.data.ContactDetails+import com.vayunmathur.contacts.data.LOCAL_ACCOUNT_TYPE+import com.vayunmathur.contacts.data.Name+import com.vayunmathur.contacts.data.SIGNAL_ACCOUNT_TYPE+import com.vayunmathur.contacts.data.SIM_ACCOUNT_TYPE+import com.vayunmathur.contacts.data.TELEGRAM_ACCOUNT_TYPE+import com.vayunmathur.contacts.data.WHATSAPP_ACCOUNT_TYPE+import com.vayunmathur.contacts.data.filterOutMessengerContacts+import com.vayunmathur.contacts.data.isMessengerAccountType+import com.vayunmathur.contacts.platform.ContactAccount+import com.vayunmathur.contacts.platform.visibleAccounts+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue++/**+ * Messenger accounts (WhatsApp/Signal/Telegram) must never surface as+ * contacts or as settings accounts; their provider rows only join, via the+ * aggregate contact, to a visible contact for call/message actions.+ */+class MessengerAccountsTest {++    private fun contact(id: Long, accountType: String?, name: String = "Aisha Rahman"): Contact {+        val details = ContactDetails.empty().copy(+            names = listOf(Name(id, "", "Aisha", "", "Rahman", "")),+        )+        return Contact(id = id, accountType = accountType, accountName = name, isFavorite = false, details = details)+    }++    @Test+    fun `messenger account types are the three provider account types`() {+        assertTrue(isMessengerAccountType(WHATSAPP_ACCOUNT_TYPE))+        assertTrue(isMessengerAccountType(SIGNAL_ACCOUNT_TYPE))+        assertTrue(isMessengerAccountType(TELEGRAM_ACCOUNT_TYPE))+        assertEquals("com.whatsapp", WHATSAPP_ACCOUNT_TYPE)+        assertEquals("org.thoughtcrime.securesms", SIGNAL_ACCOUNT_TYPE)+        assertEquals("org.telegram.messenger", TELEGRAM_ACCOUNT_TYPE)+    }++    @Test+    fun `non messenger account types are not messenger accounts`() {+        assertFalse(isMessengerAccountType(null))+        assertFalse(isMessengerAccountType(""))+        assertFalse(isMessengerAccountType(SIM_ACCOUNT_TYPE))+        assertFalse(isMessengerAccountType(LOCAL_ACCOUNT_TYPE))+        assertFalse(isMessengerAccountType("com.google"))+        assertFalse(isMessengerAccountType("com.android.contacts"))+    }++    @Test+    fun `messenger only contacts are excluded`() {+        val book = listOf(+            contact(1, WHATSAPP_ACCOUNT_TYPE),+            contact(2, SIGNAL_ACCOUNT_TYPE),+            contact(3, TELEGRAM_ACCOUNT_TYPE),+        )+        assertEquals(emptyList(), filterOutMessengerContacts(book))+    }++    @Test+    fun `joined contact keeps its visible row and no duplicate appears`() {+        // Same person in a device account and in WhatsApp: only the device+        // row remains, under its own id, so the detail screen's aggregate+        // platform lookup (keyed by that id) still finds the WhatsApp rows.+        val device = contact(10, null)+        val whatsApp = contact(11, WHATSAPP_ACCOUNT_TYPE)+        val visible = filterOutMessengerContacts(listOf(device, whatsApp))+        assertEquals(listOf(device), visible)+        assertEquals(10L, visible.single().id)+    }++    @Test+    fun `real accounts contacts stay visible`() {+        val book = listOf(+            contact(1, null),+            contact(2, SIM_ACCOUNT_TYPE),+            contact(3, LOCAL_ACCOUNT_TYPE),+            contact(4, "com.google"),+        )+        assertEquals(book, filterOutMessengerContacts(book))+    }++    @Test+    fun `settings account list excludes the three messengers entirely`() {+        val accounts = listOf(+            ContactAccount("", ""),+            ContactAccount("SIM 1", SIM_ACCOUNT_TYPE),+            ContactAccount("Phone", LOCAL_ACCOUNT_TYPE),+            ContactAccount("[email protected]", "com.google"),+            ContactAccount("+15551234567", WHATSAPP_ACCOUNT_TYPE),+            ContactAccount("+15551234567", SIGNAL_ACCOUNT_TYPE),+            ContactAccount("Aisha Rahman", TELEGRAM_ACCOUNT_TYPE),+        )+        assertEquals(+            listOf(+                ContactAccount("", ""),+                ContactAccount("SIM 1", SIM_ACCOUNT_TYPE),+                ContactAccount("Phone", LOCAL_ACCOUNT_TYPE),+                ContactAccount("[email protected]", "com.google"),+            ),+            visibleAccounts(accounts),+        )+    }+}