Modern Apps git

← Modern-Apps.git

contacts: strip trailing comma from provider SIM emails (#935)

Commit
7ba93921885b19d334650906585503fee8fa66d1
Author
Vayun Mathur <[email protected]>
When
2026-12-04 18:26 UTC (1 day ago)
Parents
36d6eae
A physical SIM contact's email showed a trailing comma in every
app, and this app's edit screen kept it. The ICC ADN provider encodes
a record's addresses as one delimited string with the separator
after every value ("[email protected],"), and the contacts provider copies
that string verbatim into the SIM contact's Email data row, so any
app reading the provider — including this app, which loads
provider-backed SIM contacts (Android 16 SimContacts accounts) as
ordinary RawContacts — displayed the separator as part of the
address and saved it back unchanged.

The direct ADN read/write path was already normalised, so this
change covers the provider path, which is the one other apps read:

- Read: Contact.getContacts decodes the email rows of SIM-account
  raw contacts (the app's virtual ADN account type, or a SIM
  account registered with the provider) with the same delimited
  normalisation used for ADN rows. A stored row is split back into
  its real addresses: the first keeps the data-row id so an edit
  updates it in place, further addresses become new rows, and
  separator-only rows are dropped. Device and cloud contacts are
  read exactly as stored.
- Write: Contact.saveWithOutcome re-encodes email rows the same
  way when the target account is a SIM account, so an address that
  still carries the separator (or several addresses joined into
  one row) is never written back to the provider for other apps
  to read. Other accounts are written exactly as given.
- The shared normaliser now also strips EF record padding
  (0x00/0xFF runs) from each segment: ADN/EF fields are
  fixed-length and FF-padded, and a provider that surfaces the
  padding run instead of stopping at it left it trailing the
  separator, where a whitespace-only trim kept it.

Tests: new SimProviderEmailCommaTest (7 tests) covers the
provider-SIM read split, clean insert and update writes for SIM
accounts, byte-identical read/write for a non-SIM account, the
separator/padding normaliser, and the SIM-account predicate.

Verified: :contacts:lint and :contacts:lintVitalRelease pass.
:contacts:testDevUnitTest runs 609 tests with 2 failures
(DeepInteractionsPass2Test.insertOrEditShowsContactsAndCreateNewRoutes
and InsertOrEditIntentActivityPass2Test.insertOrEditShowsNumber,
both asserting the prefill number text in the insert-or-edit
scaffold title); both fail identically on pristine HEAD
de47de281, so they are pre-existing and unrelated to this change.

Diff

contacts/AGENTS.md
diff --git a/contacts/AGENTS.md b/contacts/AGENTS.mdindex 81270274b3..1342d9464f 100644--- a/contacts/AGENTS.md+++ b/contacts/AGENTS.md@@ -47,6 +47,7 @@ are no watch receivers in this module. - 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
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 c5b8b17b70..cbfa002fff 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/data/Contact.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/data/Contact.kt@@ -356,7 +356,27 @@ data class Contact(      * failures: on Android 16+ a new contact in the device or a provider SIM account is      * rejected while the default account is a cloud account (see [NewContactRestriction]).      */-    fun saveWithOutcome(context: Context, newDetails: ContactDetails, oldDetails: ContactDetails): SaveOutcome {+    fun saveWithOutcome(context: Context, newDetails: ContactDetails, oldDetails: ContactDetails): SaveOutcome =+        saveWithOutcome(context, newDetails, oldDetails, null)++    /**+     * [saveWithOutcome] with the provider's SIM accounts supplied by the caller+     * (null queries them). SIM-account email rows are re-encoded first (#935,+     * see [normalizeSimEmailsForAccount]); other accounts are written as given.+     */+    internal fun saveWithOutcome(+        context: Context,+        newDetails: ContactDetails,+        oldDetails: ContactDetails,+        providerSimAccounts: List<ProviderAccount>?,+    ): SaveOutcome {+        val simAccounts = providerSimAccounts ?: if (accountType.isNullOrBlank()) {+            emptyList()+        } else {+            SystemDefaultAccountSource(context).providerSimAccounts()+        }+        val effectiveDetails =+            normalizeSimEmailsForAccount(accountName, accountType, simAccounts, newDetails)         val ops = ArrayList<ContentProviderOperation>()         if (id == 0L) {             ops += ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)@@ -366,7 +386,7 @@ data class Contact(                 .withValue(ContactsContract.RawContacts.CUSTOM_RINGTONE, ringtoneToProvider(customRingtone))                 .build() -            ops += newDetails.all().map { createInsertOperation(it) }+            ops += effectiveDetails.all().map { createInsertOperation(it) }         } else {             // Favorite and ringtone             ops += ContentProviderOperation.newUpdate(ContactsContract.RawContacts.CONTENT_URI)@@ -376,7 +396,7 @@ data class Contact(                 .build()              // details-            ops += handleDetailUpdates(oldDetails.all(), newDetails.all(), id.toString())+            ops += handleDetailUpdates(oldDetails.all(), effectiveDetails.all(), id.toString())         }         return try {             context.contentResolver.applyBatch(ContactsContract.AUTHORITY, ops)@@ -681,7 +701,12 @@ data class Contact(             }         } -        private fun getContacts(context: Context, contactId: Long?): List<Contact> {+        private fun getContacts(context: Context, contactId: Long?): List<Contact> =+            getContacts(context, contactId, SystemDefaultAccountSource(context).providerSimAccounts())++        internal fun getContacts(+            context: Context, contactId: Long?, providerSimAccounts: List<ProviderAccount>,+        ): List<Contact> {             val contentResolver = context.contentResolver             val projection = arrayOf(                 ContactsContract.RawContacts._ID,@@ -713,10 +738,14 @@ data class Contact(              val allDetails = getDetailsInternal(context, contactId)             return rawContacts.mapNotNull { raw ->-                val details = processDetails(-                    allDetails[raw.id] ?: ContactDetails.empty(),-                    raw.displayName-                ) ?: return@mapNotNull null+                // SIM-account email rows are decoded like ADN rows (#935, see+                // normalizeSimEmailsForAccount); other rows are read as stored.+                val decoded = normalizeSimEmailsForAccount(+                    raw.accountName, raw.accountType, providerSimAccounts,+                    allDetails[raw.id] ?: ContactDetails.empty()+                )+                val details = processDetails(decoded, raw.displayName)+                    ?: return@mapNotNull null                 Contact(                     raw.id,                     raw.accountType,
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 c6c7b9f897..b5f94de0c1 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.kt@@ -40,11 +40,84 @@ data class SimContact(  * 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.+ * Segments are also stripped of EF record padding: ADN/EF fields are+ * fixed-length and `0xFF`-padded, and a provider that surfaces the padding+ * run instead of stopping at it leaves it trailing the separator (or the+ * address itself), where a plain whitespace trim would keep it.  */ internal fun normalizeSimDelimited(raw: String?, separator: Char): String? =-    raw?.split(separator)?.map { it.trim() }?.filter { it.isNotEmpty() }+    raw?.split(separator)?.map { it.trimSimFieldPadding() }?.filter { it.isNotEmpty() }         ?.joinToString(separator.toString())?.takeIf { it.isNotEmpty() } +/** Trims whitespace and EF padding (`0x00` / `0xFF` runs, surfaced as U+0000 / U+00FF / U+FFFF). */+private fun String.trimSimFieldPadding(): String =+    trim { it.isWhitespace() || it == '\u0000' || it == '\u00FF' || it == '\uFFFF' }++/** One SIM email address from a delimited value: the first address, separator- and padding-free. */+internal fun normalizeSimEmail(raw: String?): String? =+    normalizeSimDelimited(raw, ',')?.substringBefore(',')++/**+ * True when ([name], [type]) names a SIM account: the app's virtual ADN+ * account ([SIM_ACCOUNT_TYPE]) or a SIM account registered with the contacts+ * provider (Android 16 `SimContacts.getSimAccounts`, passed in as+ * [providerSimAccounts] so callers control when that query runs).+ */+internal fun isSimAccount(+    name: String?,+    type: String?,+    providerSimAccounts: List<ProviderAccount>,+): Boolean =+    isSimAccountType(type) ||+        ProviderAccount(name.orEmpty(), type.orEmpty()) in providerSimAccounts++/**+ * Decodes (on read) or re-encodes (on write) the email rows of a SIM+ * contact: [normalizeSimProviderEmails] when ([name], [type]) is a SIM+ * account, [details] unchanged otherwise.+ */+internal fun normalizeSimEmailsForAccount(+    name: String?,+    type: String?,+    providerSimAccounts: List<ProviderAccount>,+    details: com.vayunmathur.contacts.data.ContactDetails,+): com.vayunmathur.contacts.data.ContactDetails =+    if (isSimAccount(name, type, providerSimAccounts)) {+        normalizeSimProviderEmails(details)+    } else {+        details+    }++/**+ * Repairs the email rows of a provider-backed SIM contact (#935). The+ * contacts provider holds a SIM contact's addresses as ordinary Email data+ * rows, but the row it creates from the card is the ICC delimited string+ * verbatim — trailing comma included — so every app reading the provider+ * (and this app's editor, which loads provider contacts as-is) shows+ * `"[email protected],"`. Each stored row is split back into its real addresses:+ * the first keeps the row id (an edit then updates that row in place),+ * any further addresses become new rows, and separator/padding-only rows+ * are dropped. Non-SIM contacts are never passed through here: a device+ * or cloud address is stored by its own provider and is not ours to+ * rewrite.+ */+internal fun normalizeSimProviderEmails(+    details: com.vayunmathur.contacts.data.ContactDetails+): com.vayunmathur.contacts.data.ContactDetails =+    details.copy(+        emails = details.emails.flatMap { email ->+            val addresses = normalizeSimDelimited(email.address, ',')+                ?.split(',')?.filter { it.isNotEmpty() }.orEmpty()+            addresses.mapIndexed { index, address ->+                if (index == 0) {+                    email.copy(address = address)+                } else {+                    email.copy(id = 0, address = address)+                }+            }+        }+    )+ const val SIM_ACCOUNT_TYPE = "com.vayunmathur.contacts.sim"  /**@@ -573,7 +646,7 @@ object SimContactsDataSource {         // 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 emails = normalizeSimEmail(sc.emails)?.let {             val homeType = android.provider.ContactsContract.CommonDataKinds.Email.TYPE_HOME             listOf(com.vayunmathur.contacts.data.Email(0, it, homeType))         } ?: emptyList()
contacts/src/test/java/com/vayunmathur/contacts/data/SimProviderEmailCommaTest.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/data/SimProviderEmailCommaTest.kt b/contacts/src/test/java/com/vayunmathur/contacts/data/SimProviderEmailCommaTest.ktnew file mode 100644index 0000000000..4c58416ae0--- /dev/null+++ b/contacts/src/test/java/com/vayunmathur/contacts/data/SimProviderEmailCommaTest.kt@@ -0,0 +1,282 @@+package com.vayunmathur.contacts.data++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 android.provider.ContactsContract+import androidx.test.core.app.ApplicationProvider+import kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertNull+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.shadows.ShadowContentResolver++/**+ * Issue #935 for provider-backed SIM contacts (Android 16 SIM accounts+ * registered with the contacts provider). Those contacts are ordinary+ * RawContacts to this app, so neither the list/editor read path nor the+ * provider write path went through the ADN normalisation: the email row+ * the provider created from the card is the ICC delimited string verbatim+ * (`"[email protected],"`), which showed in this app's editor and in every other+ * app, and an edit saved it back unchanged.+ */+@RunWith(RobolectricTestRunner::class)+class SimProviderEmailCommaTest {++    class CapturingContactsProvider : 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 cols = projection ?: defaultColumns(uri)+            val cursor = MatrixCursor(cols)+            when {+                uri.toString().contains("raw_contacts") -> for (row in RAW_CONTACTS) {+                    cursor.addRow(cols.map { row[it] })+                }+                uri.toString().contains("data") -> for (row in DATA_ROWS) {+                    cursor.addRow(cols.map { row[it] })+                }+            }+            return cursor+        }++        private fun defaultColumns(uri: Uri): Array<String> = when {+            uri.toString().contains("raw_contacts") -> arrayOf(+                ContactsContract.RawContacts._ID,+                ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY,+                ContactsContract.RawContacts.STARRED,+                ContactsContract.RawContacts.ACCOUNT_NAME,+                ContactsContract.RawContacts.ACCOUNT_TYPE,+                ContactsContract.RawContacts.CUSTOM_RINGTONE,+            )+            else -> DETAILS_COLUMNS+        }++        override fun insert(uri: Uri, values: ContentValues?): Uri {+            values?.let { recordedInserts += uri to ContentValues(it) }+            return android.content.ContentUris.withAppendedId(uri, nextId++)+        }++        override fun update(+            uri: Uri, values: ContentValues?, selection: String?,+            selectionArgs: Array<out String>?,+        ): Int {+            values?.let { recordedUpdates += uri to ContentValues(it) }+            return 1+        }++        override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 1+        override fun getType(uri: Uri): String? = null++        companion object {+            val recordedInserts = mutableListOf<Pair<Uri, ContentValues>>()+            val recordedUpdates = mutableListOf<Pair<Uri, ContentValues>>()+            private var nextId = 900L++            fun reset() {+                recordedInserts.clear()+                recordedUpdates.clear()+                nextId = 900L+            }++            val DETAILS_COLUMNS = arrayOf(+                ContactsContract.Data.RAW_CONTACT_ID, ContactsContract.Data._ID,+                ContactsContract.Data.MIMETYPE, ContactsContract.Data.CONTACT_ID,+                ContactsContract.Data.DATA1, ContactsContract.Data.DATA2,+                ContactsContract.Data.DATA3, ContactsContract.Data.DATA4,+                ContactsContract.Data.DATA5, ContactsContract.Data.DATA6,+                ContactsContract.Data.DATA7, ContactsContract.Data.DATA8,+                ContactsContract.Data.DATA9, ContactsContract.Data.DATA10,+                ContactsContract.Data.DATA15,+            )++            private fun rawRow(+                id: Long, name: String, accountName: String?, accountType: String?,+            ): Map<String, Any?> = mapOf(+                ContactsContract.RawContacts._ID to id,+                ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY to name,+                ContactsContract.RawContacts.STARRED to 0,+                ContactsContract.RawContacts.ACCOUNT_NAME to accountName,+                ContactsContract.RawContacts.ACCOUNT_TYPE to accountType,+                ContactsContract.RawContacts.CUSTOM_RINGTONE to null,+                ContactsContract.RawContacts.CONTACT_ID to id,+            )++            private fun dataRow(+                rawId: Long, dataId: Long, mime: String,+                d1: Any? = null, d2: Any? = null, d3: Any? = null,+            ): Map<String, Any?> = mapOf(+                ContactsContract.Data.RAW_CONTACT_ID to rawId,+                ContactsContract.Data._ID to dataId,+                ContactsContract.Data.MIMETYPE to mime,+                ContactsContract.Data.CONTACT_ID to rawId,+                ContactsContract.Data.DATA1 to d1,+                ContactsContract.Data.DATA2 to d2,+                ContactsContract.Data.DATA3 to d3,+                ContactsContract.Data.DATA4 to null,+                ContactsContract.Data.DATA5 to null,+                ContactsContract.Data.DATA6 to null,+                ContactsContract.Data.DATA7 to null,+                ContactsContract.Data.DATA8 to null,+                ContactsContract.Data.DATA9 to null,+                ContactsContract.Data.DATA10 to null,+                ContactsContract.Data.DATA15 to null,+            )++            val RAW_CONTACTS = listOf(+                rawRow(21L, "Sim Person", SIM_ACCOUNT_NAME, SIM_ACCOUNT_PROVIDER_TYPE),+                rawRow(22L, "Cloud Person", "[email protected]", "com.google"),+            )++            val DATA_ROWS = listOf(+                dataRow(21L, 300L, CDKSName.CONTENT_ITEM_TYPE, d2 = "Sim", d3 = "Person"),+                // The provider's verbatim copy of the ICC delimited field:+                // two addresses, each followed by the separator.+                dataRow(21L, 301L, CDKEmail.CONTENT_ITEM_TYPE, d1 = "[email protected], [email protected],", d2 = CDKEmail.TYPE_HOME),+                dataRow(21L, 302L, CDKPhone.CONTENT_ITEM_TYPE, d1 = "+14155550102", d2 = CDKPhone.TYPE_MOBILE),+                dataRow(22L, 303L, CDKSName.CONTENT_ITEM_TYPE, d2 = "Cloud", d3 = "Person"),+                dataRow(22L, 304L, CDKEmail.CONTENT_ITEM_TYPE, d1 = "[email protected],", d2 = CDKEmail.TYPE_HOME),+            )+        }+    }++    private val ctx get() = ApplicationProvider.getApplicationContext<Context>()++    @BeforeTest+    fun register() {+        CapturingContactsProvider.reset()+        ShadowContentResolver.registerProviderInternal(+            ContactsContract.AUTHORITY, CapturingContactsProvider()+        )+    }++    @Test+    fun providerSimEmailRowReadsBackAsCleanSeparateAddresses() {+        val contacts = Contact.getContacts(+            ctx, null, listOf(ProviderAccount(SIM_ACCOUNT_NAME, SIM_ACCOUNT_PROVIDER_TYPE))+        )+        val sim = contacts.first { it.id == 21L }+        assertEquals(listOf("[email protected]", "[email protected]"), sim.details.emails.map { it.address })+        // The first address keeps the stored row id so an edit updates it in+        // place; the split-off address is a new row.+        assertEquals(listOf(301L, 0L), sim.details.emails.map { it.id })+    }++    @Test+    fun nonSimProviderEmailIsReadExactlyAsStored() {+        val contacts = Contact.getContacts(+            ctx, null, listOf(ProviderAccount(SIM_ACCOUNT_NAME, SIM_ACCOUNT_PROVIDER_TYPE))+        )+        val cloud = contacts.first { it.id == 22L }+        assertEquals(listOf("[email protected],"), cloud.details.emails.map { it.address })+    }++    @Test+    fun savingNewProviderSimContactStripsTheTrailingSeparator() {+        val details = ContactDetails.empty().copy(+            emails = listOf(Email(0, "[email protected],", CDKEmail.TYPE_HOME)),+            names = listOf(Name(0, "", "New", "", "Person", "")),+        )+        val contact = Contact(+            id = 0, accountType = SIM_ACCOUNT_PROVIDER_TYPE, accountName = SIM_ACCOUNT_NAME,+            isFavorite = false, details = details,+        )+        val outcome = contact.saveWithOutcome(+            ctx, details, ContactDetails.empty(),+            listOf(ProviderAccount(SIM_ACCOUNT_NAME, SIM_ACCOUNT_PROVIDER_TYPE)),+        )+        assertEquals(SaveOutcome.SAVED, outcome)+        val emailWrites = CapturingContactsProvider.recordedInserts+            .filter { it.second.getAsString(ContactsContract.Data.MIMETYPE) == CDKEmail.CONTENT_ITEM_TYPE }+        assertEquals(listOf("[email protected]"), emailWrites.map { it.second.getAsString(CDKEmail.ADDRESS) })+    }++    @Test+    fun savingEditedProviderSimContactWritesACleanAddress() {+        val oldDetails = ContactDetails.empty().copy(+            emails = listOf(Email(301, "[email protected],", CDKEmail.TYPE_HOME)),+            names = listOf(Name(300, "", "Sim", "", "Person", "")),+        )+        val newDetails = oldDetails.copy(+            emails = listOf(Email(301, "[email protected],", CDKEmail.TYPE_HOME)),+        )+        val contact = Contact(+            id = 21, accountType = SIM_ACCOUNT_PROVIDER_TYPE, accountName = SIM_ACCOUNT_NAME,+            isFavorite = false, details = newDetails,+        )+        val outcome = contact.saveWithOutcome(+            ctx, newDetails, oldDetails,+            listOf(ProviderAccount(SIM_ACCOUNT_NAME, SIM_ACCOUNT_PROVIDER_TYPE)),+        )+        assertEquals(SaveOutcome.SAVED, outcome)+        val emailWrites = CapturingContactsProvider.recordedUpdates+            .filter { it.second.getAsString(CDKEmail.ADDRESS) != null }+        assertEquals(listOf("[email protected]"), emailWrites.map { it.second.getAsString(CDKEmail.ADDRESS) })+    }++    @Test+    fun savingNonSimContactWritesTheAddressExactlyAsGiven() {+        val details = ContactDetails.empty().copy(+            emails = listOf(Email(0, "[email protected],", CDKEmail.TYPE_HOME)),+            names = listOf(Name(0, "", "Cloud", "", "Person", "")),+        )+        val contact = Contact(+            id = 0, accountType = "com.google", accountName = "[email protected]",+            isFavorite = false, details = details,+        )+        val outcome = contact.saveWithOutcome(+            ctx, details, ContactDetails.empty(),+            listOf(ProviderAccount(SIM_ACCOUNT_NAME, SIM_ACCOUNT_PROVIDER_TYPE)),+        )+        assertEquals(SaveOutcome.SAVED, outcome)+        val emailWrites = CapturingContactsProvider.recordedInserts+            .filter { it.second.getAsString(ContactsContract.Data.MIMETYPE) == CDKEmail.CONTENT_ITEM_TYPE }+        assertEquals(listOf("[email protected],"), emailWrites.map { it.second.getAsString(CDKEmail.ADDRESS) })+    }++    @Test+    fun delimitedNormalisationStripsSeparatorAndEfPadding() {+        assertEquals("[email protected]", normalizeSimDelimited("[email protected],", ','))+        assertEquals("[email protected],[email protected]", normalizeSimDelimited("[email protected], [email protected],", ','))+        assertEquals("[email protected]", normalizeSimDelimited("[email protected],\u00FF", ','))+        assertEquals("[email protected]", normalizeSimDelimited("[email protected]\u0000,", ','))+        assertEquals("+999", normalizeSimDelimited("+999:\uFFFF", ':'))+        assertNull(normalizeSimDelimited(",,", ','))+        assertNull(normalizeSimDelimited(null, ','))+        assertEquals("[email protected]", normalizeSimEmail("[email protected],[email protected],"))+        assertNull(normalizeSimEmail(","))+    }++    @Test+    fun simAccountPredicateCoversVirtualAndProviderSimAccounts() {+        assertTrue(isSimAccount("5", SIM_ACCOUNT_TYPE, emptyList()))+        assertTrue(+            isSimAccount(+                SIM_ACCOUNT_NAME, SIM_ACCOUNT_PROVIDER_TYPE,+                listOf(ProviderAccount(SIM_ACCOUNT_NAME, SIM_ACCOUNT_PROVIDER_TYPE)),+            )+        )+        assertFalse(isSimAccount("[email protected]", "com.google", emptyList()))+        assertFalse(+            isSimAccount(+                SIM_ACCOUNT_NAME, "com.google",+                listOf(ProviderAccount(SIM_ACCOUNT_NAME, SIM_ACCOUNT_PROVIDER_TYPE)),+            )+        )+    }++    private companion object {+        const val SIM_ACCOUNT_NAME = "SIM1"+        const val SIM_ACCOUNT_PROVIDER_TYPE = "com.example.provider.sim"+    }+}