Modern Apps git

← Modern-Apps.git

emergency: a contact flickering on the first read no longer vanishes for that load

Commit
25abc512c6a2c9f333c6b6be1223fdebc425269f
Author
Vayun Mathur <[email protected]>
When
2026-12-01 04:08 UTC (5 days ago)
Parents
4fd95db
load() resolves stored contact URIs twice: readStored() for
display (which silently drops a transiently failing URI),
then readAllForPrune(), the authoritative tri-state read the
earlier prune fix built. When the second read was conclusive
and found nothing to prune, its result was discarded and the
first pass's list returned — so when the display read
flickered (one SecurityException from the provider) but the
validation read succeeded in the same load, the contact never
reached the emergency card for that load (e.g. the lock-screen
resume load), though storage was correctly left intact.

A conclusive readAllForPrune result is now always published;
persistence still happens only on an actual prune, and an
inconclusive read still leaves storage and the prior list
untouched. The regression test makes the provider fail once
for a stored URI and asserts the contact publishes with its
name resolved and the URI unpruned (empty pre-fix). SOS flow,
medical-info gating and emergency numbers were audited and
cleared. Verified: :emergency:testDevUnitTest — the new test
passes; the 2 failures are identical pre-existing
scaffold-loading assertion failures on untouched files, and
the lint errors are pre-existing RouteScreenshotCoverage.

Diff

emergency/src/main/java/com/vayunmathur/emergency/data/EmergencyRepository.kt
diff --git a/emergency/src/main/java/com/vayunmathur/emergency/data/EmergencyRepository.kt b/emergency/src/main/java/com/vayunmathur/emergency/data/EmergencyRepository.ktindex a8dd72633e..8b87a39f05 100644--- a/emergency/src/main/java/com/vayunmathur/emergency/data/EmergencyRepository.kt+++ b/emergency/src/main/java/com/vayunmathur/emergency/data/EmergencyRepository.kt@@ -133,14 +133,19 @@ class EmergencyRepository private constructor(      * dropped dead URIs from) that list, so comparing against it could never      * observe a prune and the stored list was never cleaned. An inconclusive      * read (see [ContactReader.readAllForPrune]) leaves storage untouched.+     *+     * A conclusive read is published as-is, pruned or not: it is the+     * authoritative resolution of [storedUris], whereas [info]'s list came+     * from an earlier, separate [readStored] pass - keeping that list when+     * nothing was pruned would discard contacts this read just validated+     * (e.g. one whose first-pass query flickered and dropped it).      */     private fun resolveAndPrune(info: EmergencyInfo, storedUris: List<Uri>): EmergencyInfo {         val resolved = contacts.readAllForPrune(storedUris) ?: return info         if (resolved.map { it.phoneUri } != storedUris) {             persistUris(resolved.map { it.phoneUri })-            return info.copy(contacts = resolved)         }-        return info+        return info.copy(contacts = resolved)     }      private fun persistUris(uris: List<Uri>) {
emergency/src/test/java/com/vayunmathur/emergency/platform/FakeContactsProvider.kt
diff --git a/emergency/src/test/java/com/vayunmathur/emergency/platform/FakeContactsProvider.kt b/emergency/src/test/java/com/vayunmathur/emergency/platform/FakeContactsProvider.ktindex 72d6fce58e..464378a205 100644--- a/emergency/src/test/java/com/vayunmathur/emergency/platform/FakeContactsProvider.kt+++ b/emergency/src/test/java/com/vayunmathur/emergency/platform/FakeContactsProvider.kt@@ -34,12 +34,15 @@ class FakeContactsProvider : ContentProvider() {         var photoBytes: ByteArray? = makePhotoBytes()         /** URIs whose query throws SecurityException (permission revoked mid-read). */         val failUris = mutableSetOf<String>()+        /** URIs whose next query throws SecurityException, then reads normally. */+        val failOnceUris = mutableSetOf<String>()         /** URIs whose query returns a null cursor. */         val nullUris = mutableSetOf<String>()          fun reset() {             phones.clear()             failUris.clear()+            failOnceUris.clear()             nullUris.clear()             ownerName = "Jamie Owner"             rawIdForContact = 7L@@ -80,6 +83,10 @@ class FakeContactsProvider : ContentProvider() {         selectionArgs: Array<out String>?,         sortOrder: String?,     ): Cursor? {+        if (uri.toString() in failOnceUris) {+            failOnceUris -= uri.toString()+            throw SecurityException("transient provider failure for $uri")+        }         if (uri.toString() in failUris) {             throw SecurityException("READ_CONTACTS revoked for $uri")         }
emergency/src/test/java/com/vayunmathur/emergency/platform/RepositoryAndServiceTest.kt
diff --git a/emergency/src/test/java/com/vayunmathur/emergency/platform/RepositoryAndServiceTest.kt b/emergency/src/test/java/com/vayunmathur/emergency/platform/RepositoryAndServiceTest.ktindex e518b769ad..d117dbec78 100644--- a/emergency/src/test/java/com/vayunmathur/emergency/platform/RepositoryAndServiceTest.kt+++ b/emergency/src/test/java/com/vayunmathur/emergency/platform/RepositoryAndServiceTest.kt@@ -128,6 +128,25 @@ class RepositoryTest {         Unit     } +    @Test+    fun `repository keeps contact when first read fails but validation read succeeds`() = runBlocking {+        val repo = EmergencyRepository.get(ctx)+        repo.info.value.contacts.toList().forEach { repo.removeContact(it.phoneUri) }+        assertTrue(repo.addContact(phoneUri))+        assertTrue(storedContacts().contains(phoneUri.toString()))++        // One transient failure on the load's display read, then reads work:+        // the validation read in the same load resolves the contact, so the+        // published list must carry it - a flicker on the first of the two+        // reads must not blank a contact the second read just validated.+        FakeContactsProvider.failOnceUris += phoneUri.toString()+        repo.load()+        assertEquals(listOf(phoneUri), repo.info.value.contacts.map { it.phoneUri })+        assertEquals("Alex Rivera", repo.info.value.contacts.first().displayName)+        assertTrue(storedContacts().contains(phoneUri.toString()))+        Unit+    }+     @Test     fun `repository keeps stored contacts when a load cannot resolve them`() = runBlocking {         val repo = EmergencyRepository.get(ctx)