appstore: version selection ranks the release first, ABI only within it
- Commit
fbc6b564ec4a3c31346eb4d91240de3a1fda5a0e- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 08:48 UTC (5 days ago)
- Parents
580eb0c
selectVersion sorted every build by ABI fitness before versionCode. ABI preference is valid only within one release (per-ABI builds share a versionName with offset versionCodes); applied across releases, an older arm64 build outranked a newer universal release, so the catalogue advertised the old build forever and no update to the newer release was ever offered (versionCode never exceeded the installed one). The doc even said 'newest release first'. Selection now groups builds by versionName, ranks releases by their highest versionCode then index-added date โ only releases with a runnable build compete, so a newest release with no build for this device still falls back to an older runnable one โ and applies the existing ABI -> versionCode -> added -> split -> size ordering unchanged within the winning release. Three new tests failed 2/3 pre-fix (newer universal and newer secondary-ABI both shadowed); a guard pins ABI preference within one release. Update partitioning, search, fingerprint and install verification were audited and cleared. Verified: :appstore:testDevUnitTest 506 tests pass; lint errors are pre-existing on untouched files.
Diff
appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.ktindex 5982778cbf..814d185591 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.kt@@ -647,16 +647,42 @@ object FDroidRepository { val splitSetCodes = candidates .filter { it.requiredSplitTypes.isNotEmpty() } .mapTo(mutableSetOf()) { it.versionCode }- return candidates+ val installable = candidates .filter { it.requiredSplitTypes.isNotEmpty() || it.versionCode !in splitSetCodes }+ val runnable = installable .mapNotNull { candidate -> abiRank(candidate.nativeCode, deviceAbis)?.let { candidate to it } }+ if (runnable.isEmpty()) return null++ // ABI fitness decides only *within* a release. Per-ABI builds of one+ // release share a versionName but carry different versionCodes (per-ABI+ // offsets), so the specific build may carry the lower code โ that is+ // why fitness outranks versionCode inside a release. Across releases+ // it must not: a newer universal (or secondary-ABI) release runs on+ // this device, and letting an older specific build outrank it would+ // advertise the old release forever and never offer the update.+ // Releases are therefore ranked first, by the highest versionCode any+ // of their builds carries (so a re-indexed older release, whose+ // `added` is newer, cannot shadow the latest), then by `added`; only+ // a release with a runnable build competes, so a newest release with+ // no build for this device still falls back to an older runnable one.+ // A missing versionName names no release, so all such builds form one+ // group and keep the previous within-group ordering.+ fun releaseKey(candidate: VersionCandidate): String =+ candidate.versionName?.trim().orEmpty()+ val releaseRank = installable.groupBy(::releaseKey).mapValues { (_, builds) ->+ builds.maxOf { it.versionCode } to builds.maxOf { it.added }+ }+ val newestRelease = runnable+ .map { releaseKey(it.first) }+ .distinct()+ .maxWithOrNull(+ compareBy<String> { releaseRank.getValue(it).first }+ .thenBy { releaseRank.getValue(it).second }+ ) ?: return null++ return runnable+ .filter { releaseKey(it.first) == newestRelease } .minWithOrNull(- // ABI fitness first (a build for the wrong ABI cannot be used- // at all), then the highest versionCode - `added` alone used- // to win here, so a re-indexed older release could shadow the- // latest versionCode and the store offered a downgrade. `added`- // is now only the tie-break between equal versionCodes, ahead- // of the split-base and size tie-breaks as before. compareBy<Pair<VersionCandidate, Int>> { it.second } .thenByDescending { it.first.versionCode } .thenByDescending { it.first.added }
appstore/src/test/java/com/vayunmathur/appstore/data/FDroidVersionSelectionTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/data/FDroidVersionSelectionTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/data/FDroidVersionSelectionTest.ktindex 713740c34c..ac472822e2 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/data/FDroidVersionSelectionTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/data/FDroidVersionSelectionTest.kt@@ -62,6 +62,77 @@ class FDroidVersionSelectionTest { assertEquals("/app_arm64.apk", FDroidRepository.selectVersion(release, arm64Device)?.fileName) } + @Test+ fun `a newer universal release beats an older architecture-specific release`() {+ // Distinct versionNames are distinct releases: the universal 2.0 build+ // runs on this device, so the older ABI-specific 1.0 must not shadow it+ // merely because a specific build ranks ahead of a universal one+ // *within* a release.+ val versions = listOf(+ FDroidRepository.VersionCandidate(+ added = 100,+ fileName = "/app_old_arm64.apk",+ versionName = "1.0",+ versionCode = 100,+ nativeCode = listOf("arm64-v8a"),+ ),+ FDroidRepository.VersionCandidate(+ added = 200,+ fileName = "/app_new_universal.apk",+ versionName = "2.0",+ versionCode = 200,+ ),+ )++ assertEquals("/app_new_universal.apk", FDroidRepository.selectVersion(versions, arm64Device)?.fileName)+ }++ @Test+ fun `a newer release on a secondary ABI beats an older release on the primary ABI`() {+ val versions = listOf(+ FDroidRepository.VersionCandidate(+ added = 100,+ fileName = "/app_old_arm64.apk",+ versionName = "1.0",+ versionCode = 100,+ nativeCode = listOf("arm64-v8a"),+ ),+ FDroidRepository.VersionCandidate(+ added = 200,+ fileName = "/app_new_armv7.apk",+ versionName = "2.0",+ versionCode = 200,+ nativeCode = listOf("armeabi-v7a"),+ ),+ )++ assertEquals("/app_new_armv7.apk", FDroidRepository.selectVersion(versions, arm64Device)?.fileName)+ }++ @Test+ fun `architecture preference still applies within one release`() {+ // Same versionName: one release published per-ABI, where the specific+ // build may carry the lower versionCode (per-ABI offsets). The ABI+ // preference must survive the cross-release fix.+ val versions = listOf(+ FDroidRepository.VersionCandidate(+ added = 200,+ fileName = "/app_universal.apk",+ versionName = "2.0",+ versionCode = 210,+ ),+ FDroidRepository.VersionCandidate(+ added = 200,+ fileName = "/app_arm64.apk",+ versionName = "2.0",+ versionCode = 200,+ nativeCode = listOf("arm64-v8a"),+ ),+ )++ assertEquals("/app_arm64.apk", FDroidRepository.selectVersion(versions, arm64Device)?.fileName)+ }+ @Test fun `falls back to the universal build when no variant matches`() { val release = listOf(