Modern Apps git

← Modern-Apps.git

contacts: update and delete SIM contacts by their full ADN record (#934)

Commit
d1382d926f03a52429251f54fc6fb2bf9028bfe2
Author
Vayun Mathur <[email protected]>
When
2026-11-21 15:51 UTC (15 days ago)
Parents
7bae09c
Three reported SIM bugs shared one layer. IccProvider
matches ADN records by the whole old record, but the app
matched on tag+number only: an emailed contact never matched,
so updates silently inserted a duplicate - and on Android 16
an unmatched update inserts too (#936); deletes of emailed
contacts matched nothing and only appeared to work once a SIM
swap invalidated the telephony cache (#934). Updates now send
the full old record (emails/ANRs included, ANRs preserved) and
the delete+insert fallback only proceeds when the delete
actually succeeded. Deletes carry the full selection and
schedule the same convergence re-read as saves, and writes now
notify ContactsContract so other apps re-read.

The trailing comma (#935): IccProvider.loadRecord appends a
comma after every email, and the app stored '[email protected],'
verbatim. Delimited fields are normalised on read, on write,
and in the unified projection; insert writes only the
canonical 'emails' key.

Tests: a new AOSP-faithful fake ICC provider (the old fake
accepted every write, hiding all three bugs) with 6 semantic
tests. Verified: contacts 571 tests pass. Real-SIM behaviour
still needs one hardware confirmation pass.

Diff

contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.kt b/contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.ktindex 6bdcfa54cc..c6c7b9f897 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.kt@@ -6,6 +6,7 @@ import android.content.Context import android.content.pm.PackageManager import android.net.Uri import androidx.core.net.toUri+import android.provider.ContactsContract import android.telephony.SubscriptionManager import com.vayunmathur.library.log.Log import androidx.core.content.ContextCompat@@ -24,9 +25,26 @@ data class SimContact(     val name: String,     val number: String,     val emails: String? = null,-    val subscriptionId: Int? = null+    val subscriptionId: Int? = null,+    /** Additional numbers (ADN ANRs), `:`-joined without a trailing separator, when the provider exposes them. */+    val anrs: String? = null ) +/**+ * Normalises one delimited ADN field as the ICC provider encodes it on the wire.+ *+ * On read the provider joins each value *followed* by the separator+ * (`IccProvider.loadRecord` appends `,` after every email and `:` after every+ * ANR), so a single email arrives as `"[email protected],"`. Taking that verbatim as an+ * address is #935: it shows in the editor and in other apps, and it breaks+ * exact-match lookups of the row. Splitting and re-joining without empty+ * segments strips the trailing separator while preserving any extra values+ * another app stored, which the update/delete old-record match needs intact.+ */+internal fun normalizeSimDelimited(raw: String?, separator: Char): String? =+    raw?.split(separator)?.map { it.trim() }?.filter { it.isNotEmpty() }+        ?.joinToString(separator.toString())?.takeIf { it.isNotEmpty() }+ const val SIM_ACCOUNT_TYPE = "com.vayunmathur.contacts.sim"  /**@@ -131,7 +149,7 @@ object SimContactsDataSource {             Log.status(TAG, "listSimContacts failed", e)         }         // Deduplicate by (subId, name, number, emails)-        return result.distinctBy { "${it.subscriptionId}|${it.name}|${it.number}|${it.emails}" }+        return result.distinctBy { "${it.subscriptionId}|${it.name}|${it.number}|${it.emails}|${it.anrs}" }     }      // Broad catch is deliberate: OEM ICC providers throw undocumented@@ -163,6 +181,7 @@ object SimContactsDataSource {         val nameIdx = pickColumn(cursor, "name", "tag")         val numberIdx = pickColumn(cursor, "number", "newNumber")         val emailsIdx = pickColumn(cursor, "emails", "email")+        val anrsIdx = cursor.getColumnIndex("anrs")         val idIdx = cursor.getColumnIndex("_id")          private fun pickColumn(@@ -191,6 +210,8 @@ object SimContactsDataSource {                 if (indexes.numberIdx != -1) cursor.getString(indexes.numberIdx) else null             val rawEmails =                 if (indexes.emailsIdx != -1) cursor.getString(indexes.emailsIdx) else null+            val rawAnrs =+                if (indexes.anrsIdx != -1) cursor.getString(indexes.anrsIdx) else null             val name = rawName?.trim().orEmpty()             val number = rawNumber?.trim().orEmpty()             if (name.isEmpty() && number.isEmpty()) return null@@ -199,8 +220,9 @@ object SimContactsDataSource {                 id = id,                 name = name,                 number = number,-                emails = rawEmails?.trim()?.takeIf { it.isNotEmpty() },-                subscriptionId = subId+                emails = normalizeSimDelimited(rawEmails, ','),+                subscriptionId = subId,+                anrs = normalizeSimDelimited(rawAnrs, ':')             )         } catch (e: Exception) {             Log.status(TAG, "Skipping SIM row", e)@@ -242,15 +264,14 @@ object SimContactsDataSource {                 BASE_URI.toUri()             }             val values = ContentValues().apply {-                // Most devices accept "tag" for name+                // The ICC provider's only keys are tag/number/emails/anrs+                // (IccProvider.STR_*); aliases such as "email" are ignored by+                // AOSP and, on OEM variants that do read them, risk being+                // stored as a second address. Write the canonical key only,+                // with any provider trailing separator stripped first.                 put("tag", name)                 put("number", number)-                // Some accept "name" alias-                if (!containsKey("tag")) put("name", name)-                if (!email.isNullOrBlank()) {-                    put("emails", email)-                    put("email", email)-                }+                normalizeSimDelimited(email, ',')?.let { put("emails", it) }             }             val inserted = context.contentResolver.insert(uri, values)             if (inserted != null) notifySimChanged(context, uri)@@ -265,8 +286,14 @@ object SimContactsDataSource {     }      /**-     * Edits a row in place. The provider identifies the existing row by `tag`/`number` in the-     * values and replaces it with `newTag`/`newNumber`.+     * Edits a row in place. The provider identifies the existing row by the *whole*+     * old record in the values (`tag`/`number`/`emails`/`anrs`) and replaces it with+     * `newTag`/`newNumber`/`newEmails`/`newAnrs`: telephony's update-by-search+     * compares every field (`AdnRecord.isEqual`), so omitting the old email leaves+     * an emailed row unmatched. On the legacy cache that reads as a failed update;+     * on the Android 16 modem phonebook cache an unmatched search is treated as+     * an insert, duplicating the contact (#936). ANRs the editor does not model+     * are carried over unchanged rather than dropped by the edit.      *      * Preferred over delete-then-insert, which cannot be made reliable: the ICC provider parses      * the selection string itself and ignores selectionArgs (see [deleteSingle]).@@ -291,14 +318,18 @@ object SimContactsDataSource {             } else {                 BASE_URI.toUri()             }+            val oldAnrs = normalizeSimDelimited(old.anrs, ':').orEmpty()             val values = ContentValues().apply {                 put("tag", old.name)                 put("number", old.number)+                put("emails", normalizeSimDelimited(old.emails, ',').orEmpty())+                put("anrs", oldAnrs)                 put("newTag", name)                 put("newNumber", number)                 // Unconditional: an omitted key leaves the old address in place, so clearing an                 // email would report success without changing anything.-                put("newEmails", email.orEmpty())+                put("newEmails", normalizeSimDelimited(email, ',').orEmpty())+                put("newAnrs", oldAnrs)             }             val updated = context.contentResolver.update(uri, values, null, null) > 0             if (updated) notifySimChanged(context, uri)@@ -351,7 +382,20 @@ object SimContactsDataSource {         // literally and matches nothing. The values have to be inlined.         val tag = simContact.name.asIccLiteral()         val number = simContact.number.asIccLiteral()+        // The provider rebuilds the old record from this selection and matches+        // it whole (see updateSimContact), so the primary variant must carry+        // the row's emails/ANRs too; tag+number alone cannot match an emailed+        // row and the delete silently leaves it in place (#934). The looser+        // variants remain for OEM providers that match on fewer fields.+        val emails = normalizeSimDelimited(simContact.emails, ',')+        val anrs = normalizeSimDelimited(simContact.anrs, ':')+        val full = buildString {+            append("tag=$tag AND number=$number")+            if (emails != null) append(" AND emails=${emails.asIccLiteral()}")+            if (anrs != null) append(" AND anrs=${anrs.asIccLiteral()}")+        }         val variants = listOfNotNull(+            full,             "tag=$tag AND number=$number",             "name=$tag AND number=$number",             // The fallback uses the number alone and is skipped for a contact with no@@ -392,6 +436,15 @@ object SimContactsDataSource {             context.contentResolver.notifyChange(uri, null)             val base = BASE_URI.toUri()             if (uri != base) context.contentResolver.notifyChange(base, null)+            // Other contacts apps watch the contacts provider, not the ICC+            // provider, and re-read (including any SIM aggregation their+            // provider performs) only when it changes. A SIM write never+            // touches that provider, so without this hint they keep showing+            // the pre-write snapshot until a SIM swap forces a reload (#934).+            // This also re-triggers our own contacts observer, whose debounced+            // re-sync is a second chance if the immediate post-write ADN read+            // still serves the provider's pre-write cache.+            context.contentResolver.notifyChange(ContactsContract.Contacts.CONTENT_URI, null)         } catch (_: Exception) { }     } @@ -487,7 +540,7 @@ object SimContactsDataSource {      * a different row before it in the cursor. Hash is on (subId|name|number|email).      */     fun syntheticIdFor(sc: SimContact): Long {-        val h = "${sc.subscriptionId}|${sc.name}|${sc.number}|${sc.emails}".hashCode()+        val h = "${sc.subscriptionId}|${sc.name}|${sc.number}|${sc.emails}|${sc.anrs}".hashCode()         // Map signed int hash into a negative Long away from -1..-N used by AutoIncrement edge.         return SIM_SYNTHETIC_ID_BASE - (h.toLong() and ID_HASH_MASK)     }@@ -517,7 +570,10 @@ object SimContactsDataSource {         } else {             emptyList()         }-        val emails = sc.emails?.takeIf { it.isNotBlank() }?.let {+        // ADN can hold several addresses, but the unified model's SIM shape+        // (and the editor) carries one; extras stay in the row and are matched+        // on update/delete via SimContact.emails, not shown as one long address.+        val emails = normalizeSimDelimited(sc.emails, ',')?.substringBefore(',')?.let {             val homeType = android.provider.ContactsContract.CommonDataKinds.Email.TYPE_HOME             listOf(com.vayunmathur.contacts.data.Email(0, it, homeType))         } ?: emptyList()
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 85d144cb44..4dc6d53657 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModel.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModel.kt@@ -488,8 +488,12 @@ class ContactViewModel internal constructor(         val sc = SimContactsDataSource.findBackingSimContact(app, contact)             ?: fallbackSimContact(contact)         val subId = sc.subscriptionId ?: contact.accountName?.toIntOrNull()-        SimContactsDataSource.deleteSimContact(app, sc.copy(subscriptionId = subId))+        val deleted = SimContactsDataSource.deleteSimContact(app, sc.copy(subscriptionId = subId))         syncFromSystem()+        // Same delayed convergence re-read as SIM saves: the immediate read+        // can still serve the provider's pre-write cache, leaving a deleted+        // contact visible until a SIM swap (#934).+        if (deleted) scheduleSimConvergenceSync()     }      private suspend fun deleteProviderContact(contact: com.vayunmathur.contacts.data.Contact) {
contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelSim.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelSim.kt b/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelSim.ktindex 660989f9d4..7bf7979596 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelSim.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelSim.kt@@ -101,7 +101,15 @@ internal suspend fun ContactViewModel.updateExistingSimContact(             return true         }     }-    SimContactsDataSource.deleteSimContact(app, oldSc)+    // Delete-then-insert is only a safe fallback when the old row is actually+    // gone. Previously the delete result was discarded and the caller inserted+    // unconditionally, so any failed delete (e.g. an emailed row the old+    // tag+number-only match could not find) turned an edit into a duplicate:+    // the original plus the edited copy (#936). Report the failure instead.+    if (!SimContactsDataSource.deleteSimContact(app, oldSc)) {+        Log.error("ContactViewModel", "SIM edit aborted: could not remove the old SIM row")+        return false+    }     return null } 
contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelTransfer.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelTransfer.kt b/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelTransfer.ktindex 3fa6e3e299..00371cd7e3 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelTransfer.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/platform/ContactViewModelTransfer.kt@@ -224,8 +224,8 @@ private suspend fun ContactViewModel.deleteTransferSource(contact: Contact) {     val app = getApplication<Application>()     if (isSimAccountType(contact.accountType)) {         val sc = SimContactsDataSource.findBackingSimContact(app, contact)-        if (sc != null) {-            SimContactsDataSource.deleteSimContact(app, sc)+        if (sc != null && SimContactsDataSource.deleteSimContact(app, sc)) {+            scheduleSimConvergenceSync()         }     } else {         // Fresh-read details so the delete path sees current rows.
contacts/src/test/java/com/vayunmathur/contacts/data/SimAdnSemanticsTest.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/data/SimAdnSemanticsTest.kt b/contacts/src/test/java/com/vayunmathur/contacts/data/SimAdnSemanticsTest.ktnew file mode 100644index 0000000000..72bd4d6833--- /dev/null+++ b/contacts/src/test/java/com/vayunmathur/contacts/data/SimAdnSemanticsTest.kt@@ -0,0 +1,233 @@+package com.vayunmathur.contacts.data++import android.app.Application+import android.content.ContentProvider+import android.content.ContentValues+import android.content.Context+import android.database.Cursor+import android.database.MatrixCursor+import android.net.Uri+import androidx.core.net.toUri+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.contacts.platform.ContactViewModel+import com.vayunmathur.contacts.platform.persistSimContact+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.ExperimentalCoroutinesApi+import kotlinx.coroutines.runBlocking+import kotlinx.coroutines.test.resetMain+import kotlinx.coroutines.test.setMain+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.shadows.ShadowContentResolver+import kotlin.test.AfterTest+import kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue++/**+ * Issues #934/#935/#936 against a fake ICC provider that reproduces the two+ * AOSP behaviours the old fake glossed over:+ *+ *  - query returns each email followed by a comma and each ANR followed by a+ *    colon (`IccProvider.loadRecord`), so one address arrives as `"[email protected],"`;+ *  - update/delete-by-search match the *whole* old record+ *    (`AdnRecord.isEqual` over tag, number, emails and ANRs), so an+ *    incomplete old record matches nothing.+ *+ * The old fake accepted every write, so these bugs were invisible host-side.+ */+@OptIn(ExperimentalCoroutinesApi::class)+@RunWith(RobolectricTestRunner::class)+class SimAdnSemanticsTest {++    data class Row(+        val name: String,+        val number: String,+        val emails: List<String> = emptyList(),+        val anrs: List<String> = emptyList(),+    )++    class AospIccProvider : ContentProvider() {+        override fun onCreate(): Boolean = true++        override fun query(+            uri: Uri, projection: Array<out String>?, selection: String?,+            selectionArgs: Array<out String>?, sortOrder: String?,+        ): Cursor {+            val cursor = MatrixCursor(arrayOf("name", "number", "emails", "anrs", "_id"))+            rows.forEachIndexed { index, row ->+                cursor.addRow(+                    arrayOf<Any?>(+                        row.name,+                        row.number,+                        row.emails.takeIf { it.isNotEmpty() }+                            ?.joinToString("") { "$it," },+                        row.anrs.takeIf { it.isNotEmpty() }+                            ?.joinToString("") { "$it:" },+                        index.toLong(),+                    )+                )+            }+            return cursor+        }++        override fun insert(uri: Uri, values: ContentValues?): Uri {+            insertCount+++            rows += Row(+                name = values?.getAsString("tag").orEmpty(),+                number = values?.getAsString("number").orEmpty(),+                emails = split(values?.getAsString("emails"), ','),+                anrs = split(values?.getAsString("anrs"), ':'),+            )+            return "content://icc/adn/0".toUri()+        }++        override fun update(+            uri: Uri, values: ContentValues?, selection: String?,+            selectionArgs: Array<out String>?,+        ): Int {+            if (refuseWrites) return 0+            val old = Row(+                name = values?.getAsString("tag").orEmpty(),+                number = values?.getAsString("number").orEmpty(),+                emails = split(values?.getAsString("emails"), ','),+                anrs = split(values?.getAsString("anrs"), ':'),+            )+            val index = rows.indexOf(old)+            if (index == -1) return 0+            rows[index] = Row(+                name = values?.getAsString("newTag").orEmpty(),+                number = values?.getAsString("newNumber").orEmpty(),+                emails = split(values?.getAsString("newEmails"), ','),+                anrs = split(values?.getAsString("newAnrs"), ':'),+            )+            return 1+        }++        override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int {+            if (refuseWrites) return 0+            var name = ""+            var number = ""+            var emails = emptyList<String>()+            var anrs = emptyList<String>()+            selection.orEmpty().split(" AND ").forEach { param ->+                val pair = param.split("=", limit = 2)+                if (pair.size != 2) return@forEach+                val value = pair[1].trim().removeSurrounding("'")+                when (pair[0].trim()) {+                    "tag", "name" -> name = value+                    "number" -> number = value+                    "emails" -> emails = split(value, ',')+                    "anrs" -> anrs = split(value, ':')+                }+            }+            return if (rows.remove(Row(name, number, emails, anrs))) 1 else 0+        }++        override fun getType(uri: Uri): String? = null++        companion object {+            val rows = mutableListOf<Row>()+            var insertCount = 0+            var refuseWrites = false++            fun split(raw: String?, separator: Char): List<String> =+                raw?.split(separator)?.map { it.trim() }?.filter { it.isNotEmpty() }.orEmpty()++            fun reset(seed: List<Row>) {+                rows.clear()+                rows += seed+                insertCount = 0+                refuseWrites = false+            }+        }+    }++    private val ctx get() = ApplicationProvider.getApplicationContext<Context>()+    private val app get() = ApplicationProvider.getApplicationContext<Application>()++    @BeforeTest+    fun setUp() {+        Dispatchers.setMain(Dispatchers.Unconfined)+        ShadowContentResolver.registerProviderInternal("icc", AospIccProvider())+        AospIccProvider.reset(+            listOf(Row("Aisha Rahman", "+14155550102", listOf("[email protected]"), listOf("+999")))+        )+    }++    @AfterTest+    fun tearDown() {+        Dispatchers.resetMain()+    }++    @Test+    fun providerTrailingCommaIsNotPartOfTheEmail() {+        val listed = SimContactsDataSource.listSimContacts(ctx)+        assertEquals(1, listed.size)+        assertEquals("[email protected]", listed.single().emails)+        assertEquals("+999", listed.single().anrs)+        val projected = SimContactsDataSource.simContactToContact(listed.single())+        assertEquals(listOf("[email protected]"), projected.details.emails.map { it.address })+    }++    @Test+    fun editingAnEmailedSimContactReplacesItInsteadOfDuplicating() {+        val old = SimContactsDataSource.listSimContacts(ctx).single()+        assertTrue(+            SimContactsDataSource.updateSimContact(+                ctx, old, "Aisha Khan", "+222", "[email protected]", old.subscriptionId+            )+        )+        assertEquals(+            listOf(Row("Aisha Khan", "+222", listOf("[email protected]"), listOf("+999"))),+            AospIccProvider.rows.toList(),+        )+        assertEquals(1, SimContactsDataSource.listSimContacts(ctx).size)+    }++    @Test+    fun addingAnEmailToASimContactStoresItWithoutATrailingComma() {+        AospIccProvider.reset(listOf(Row("Bob", "+111")))+        val old = SimContactsDataSource.listSimContacts(ctx).single()+        assertTrue(SimContactsDataSource.updateSimContact(ctx, old, "Bob", "+111", "[email protected]"))+        assertEquals(listOf("[email protected]"), AospIccProvider.rows.single().emails)+        // and the re-read that feeds the edit screen is clean, not "[email protected],"+        assertEquals("[email protected]", SimContactsDataSource.listSimContacts(ctx).single().emails)+    }++    @Test+    fun deletingAnEmailedSimContactRemovesIt() {+        val old = SimContactsDataSource.listSimContacts(ctx).single()+        assertTrue(SimContactsDataSource.deleteSimContact(ctx, old))+        assertTrue(AospIccProvider.rows.isEmpty())+        assertTrue(SimContactsDataSource.listSimContacts(ctx).isEmpty())+    }++    @Test+    fun insertingAnEmailedSimContactReadsBackCleanAndDeletable() {+        assertTrue(SimContactsDataSource.insertSimContact(ctx, "New Person", "+333", "[email protected],"))+        val listed = SimContactsDataSource.listSimContacts(ctx)+        assertEquals("[email protected]", listed.first { it.name == "New Person" }.emails)+        assertTrue(SimContactsDataSource.deleteSimContact(ctx, listed.first { it.name == "New Person" }))+    }++    @Test+    fun anEditWhoseOldRowCannotBeRemovedDoesNotInsertADuplicate() {+        val vm = ContactViewModel(app)+        runBlocking { vm.syncFromSystem() }+        val projected = SimContactsDataSource.simContactsAsContacts(ctx).single()+        val renamed = projected.copy(+            details = projected.details.copy(+                names = listOf(Name(0, "", "Aisha", "", "Khan", ""))+            )+        )+        // Provider now refuses update and delete (wedged radio/OEM variant):+        // the save must fail, never fall through to insert-and-leave-the-old.+        AospIccProvider.refuseWrites = true+        assertFalse(runBlocking { vm.persistSimContact(renamed) })+        assertEquals(0, AospIccProvider.insertCount)+        assertEquals(1, AospIccProvider.rows.size)+    }+}
contacts/src/test/java/com/vayunmathur/contacts/data/SimProviderPass2Test.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/data/SimProviderPass2Test.kt b/contacts/src/test/java/com/vayunmathur/contacts/data/SimProviderPass2Test.ktindex 954301ff19..486f7e8966 100644--- a/contacts/src/test/java/com/vayunmathur/contacts/data/SimProviderPass2Test.kt+++ b/contacts/src/test/java/com/vayunmathur/contacts/data/SimProviderPass2Test.kt@@ -177,6 +177,8 @@ class SimProviderPass2Test {         assertEquals("New Person", FakeIccProvider.lastInsertValues?.getAsString("tag"))         assertEquals("+14155550199", FakeIccProvider.lastInsertValues?.getAsString("number"))         assertEquals("[email protected]", FakeIccProvider.lastInsertValues?.getAsString("emails"))+        // only the provider's canonical key is written, never the "email" alias+        assertEquals(null, FakeIccProvider.lastInsertValues?.getAsString("email"))          // blank name and number never reach the provider         val before = FakeIccProvider.lastInsertUri@@ -195,6 +197,11 @@ class SimProviderPass2Test {         assertEquals("New Name", FakeIccProvider.lastUpdateValues?.getAsString("newTag"))         assertEquals("+222", FakeIccProvider.lastUpdateValues?.getAsString("newNumber"))         assertEquals("", FakeIccProvider.lastUpdateValues?.getAsString("newEmails"))+        // the whole old record must be supplied for the provider's by-search+        // match, and ANRs the editor does not model are preserved+        assertEquals("[email protected]", FakeIccProvider.lastUpdateValues?.getAsString("emails"))+        assertEquals("", FakeIccProvider.lastUpdateValues?.getAsString("anrs"))+        assertEquals("", FakeIccProvider.lastUpdateValues?.getAsString("newAnrs"))          assertFalse(SimContactsDataSource.updateSimContact(ctx, old, "", ""))     }@@ -205,5 +212,9 @@ class SimProviderPass2Test {         val contact = SimContact(1, "Aisha Rahman", "+14155550102", "[email protected]", 5)         assertTrue(SimContactsDataSource.deleteSimContact(ctx, contact))         assertEquals("content://icc/adn/subId/5", FakeIccProvider.lastDeleteUri.toString())+        assertTrue(+            FakeIccProvider.lastDeleteSelection.orEmpty().contains("emails='[email protected]'"),+            "delete selection must carry the old email for the whole-record match, was ${FakeIccProvider.lastDeleteSelection}",+        )     } }