Modern Apps git

← Modern-Apps.git

appstore: a caught-up preferred source no longer shadows a newer update elsewhere

Commit
449006ccaceeae861b665b9e3304b8b8a1f31757
Author
Vayun Mathur <[email protected]>
When
2026-12-01 03:37 UTC (5 days ago)
Parents
90963ee
partitionUpdates deduped per package by source priority
before re-checking versions against the device, so precedence
was chosen among all snapshot rows rather than among updates
still newer than installed. With app a installed at vc2 and
pending rows MODERN_APPS vc2 + PLAYSTORE vc3, distinctBy kept
the MODERN_APPS row, the re-check dropped it (2 > 2 false),
and the genuinely newer Play update was discarded with it.
Reachable in practice: the view models recombine stale
per-source snapshot flows against a fresh installed list โ€”
exactly why the re-check exists โ€” so once the device catches
up to the preferred source (its update installs), the other
source's still-newer version silently vanished.

The eligibility re-check now runs before sortedBy/distinctBy;
precedence among genuinely eligible rows is unchanged (a
guard test pins that the preferred source still wins when
both are newer). Three regression tests cover the caught-up
and older-preferred cases. Index parsing, install sessions
and download resume were audited and cleared. Verified:
:appstore:testDevUnitTest 503 tests pass; lint errors are
pre-existing on untouched files.

Diff

appstore/src/main/java/com/vayunmathur/appstore/data/UpdateLists.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateLists.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateLists.ktindex 6b449eaefe..7f3e4182c6 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateLists.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateLists.kt@@ -37,16 +37,20 @@ fun partitionUpdates(         // A disabled source contributes nothing, even if its in-memory snapshot         // has not been cleared yet (issue #845).         .filter { it.source in enabled }-        // The surviving row's source decides which download-and-verify path the-        // update takes, so this stays the same precedence search uses.-        .sortedBy { it.source.priority }-        .distinctBy { it.packageName }         // Re-check against what is on the device rather than trusting the-        // lists: the Play half is a snapshot from the last network check.+        // lists: the Play half is a snapshot from the last network check. This+        // runs BEFORE the per-package dedupe: a preferred source's snapshot row+        // that the device has since caught up with (or passed) must not shadow+        // another source's row that is still genuinely newer โ€” deduping first+        // would keep the stale row, drop it here, and lose the real update.         .filter { app ->             val installedVersion = installed[app.packageName]?.versionCode ?: return@filter false             app.versionCode > installedVersion         }+        // The surviving row's source decides which download-and-verify path the+        // update takes, so this stays the same precedence search uses.+        .sortedBy { it.source.priority }+        .distinctBy { it.packageName }         .sortedBy { it.name.lowercase() }     val (foreign, eligible) = fresh.partition { app ->         val info = installed.getValue(app.packageName)
appstore/src/test/java/com/vayunmathur/appstore/data/UpdateListsTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/data/UpdateListsTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/data/UpdateListsTest.ktindex c314268638..9179115a1e 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/data/UpdateListsTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/data/UpdateListsTest.kt@@ -73,6 +73,56 @@ class UpdateListsTest {         assertTrue(result.foreign.isEmpty())     } +    @Test+    fun `a caught-up preferred source does not shadow a newer update from another source`() {+        // The preferred source's snapshot matches what is now installed (the+        // device caught up after the check ran); another source's still-newer+        // row is a real update and must survive the merge.+        val result = partitionUpdates(+            pending = listOf(+                app("a", AppSource.MODERN_APPS, versionCode = 2L),+                app("a", AppSource.PLAYSTORE, versionCode = 3L),+            ),+            installed = mapOf("a" to installed("a", versionCode = 2L)),+            enabled = enabled,+            ownPackage = self,+        )+        assertEquals(+            listOf(3L),+            result.actionable.map { it.versionCode },+        )+        assertEquals(AppSource.PLAYSTORE, result.actionable.single().source)+    }++    @Test+    fun `an older preferred source does not shadow a newer update from another source`() {+        val result = partitionUpdates(+            pending = listOf(+                app("a", AppSource.MODERN_APPS, versionCode = 1L),+                app("a", AppSource.PLAYSTORE, versionCode = 3L),+            ),+            installed = mapOf("a" to installed("a", versionCode = 2L)),+            enabled = enabled,+            ownPackage = self,+        )+        assertEquals(listOf(3L), result.actionable.map { it.versionCode })+    }++    @Test+    fun `preferred source still wins when both sources offer a newer version`() {+        val result = partitionUpdates(+            pending = listOf(+                app("a", AppSource.PLAYSTORE, versionCode = 3L),+                app("a", AppSource.MODERN_APPS, versionCode = 2L),+            ),+            installed = mapOf("a" to installed("a", versionCode = 1L)),+            enabled = enabled,+            ownPackage = self,+        )+        assertEquals(listOf(2L), result.actionable.map { it.versionCode })+        assertEquals(AppSource.MODERN_APPS, result.actionable.single().source)+    }+     @Test     fun `update owner counts when installer does not`() {         val info = installed("a", installer = "com.android.vending").copy(