From 9b176753ccb567b2a9a040954d86d291e264cd7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Resul=20=C3=96v=C3=BCr?= <92828257+ovurrsl@users.noreply.github.com> Date: Mon, 19 Oct 2026 06:12:35 +0000 Subject: [PATCH] fix: keep ambiguous update-channel guesses temporary --- .../droiddeck/launcher/update/AppUpdates.kt | 12 ++++--- .../launcher/update/AppUpdatesTest.kt | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt b/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt index 00f60c5af4..3a86e28af3 100644 --- a/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt +++ b/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt @@ -200,9 +200,11 @@ object AppUpdates { fun message(context: Context): String = context.getString(text, *args) } - fun follow(context: Context, catalog: Catalog?): Follow { + fun follow(context: Context, catalog: Catalog?): Follow = follow(context, catalog, installed()) + + internal fun follow(context: Context, catalog: Catalog?, me: Installed): Follow { stored(context)?.let { return it } - val guess = guessFollow(catalog, installed()) + val guess = guessFollow(catalog, me) if (guess.certain) setFollow(context, guess.follow) return guess.follow } @@ -210,18 +212,18 @@ object AppUpdates { internal class Guess(val follow: Follow, val certain: Boolean) /** - * Stable and Preview builds of one commit are the same APK, so only the catalog can tell them apart. A guess that - * the catalog does not prove (a stale cache, the gap before a release is catalogued) is used for this run only. + * Stable and Preview builds of one commit are the same APK. Preview history can include older Stable releases, + * so an overlapping older-build guess keeps the Stable default for this run without persisting it. */ internal fun guessFollow(catalog: Catalog?, me: Installed): Guess { if (me.pr != 0) return Guess(Follow(Channel.TEST, me.pr), true) val stable = catalog?.stable if (stable != null && isRunning(stable, me)) return Guess(Follow(Channel.STABLE), true) - if (stable?.version?.let { compareVersions(me.version, it) < 0 } == true) return Guess(Follow(Channel.STABLE), true) val publishedPreview = catalog != null && me.updatable && ( catalog.preview?.let { isRunning(it, me) } == true || catalog.recentPreviews.any { matchesInstalledCommit(it.commit, me.commit) } ) + if (stable?.version?.let { compareVersions(me.version, it) < 0 } == true) return Guess(Follow(Channel.STABLE), !publishedPreview) return Guess(Follow(if (publishedPreview) Channel.NIGHTLY else Channel.STABLE), false) } diff --git a/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt b/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt index a2d07adbd9..4d3d906f51 100644 --- a/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt @@ -293,6 +293,37 @@ class AppUpdatesTest { assertTrue(g.certain) } + @Test fun anOlderBuildInPreviewHistoryKeepsStableAsAnUncertainGuess() { + val withHistory = AppUpdates.Catalog(stable, release("1111111"), emptyList(), 0L, recentPreview) + val g = AppUpdates.guessFollow(withHistory, me("2".repeat(40), version = "0.1.0")) + assertEquals(Channel.STABLE, g.follow.channel) + assertFalse(g.certain) + } + + @Test fun anOlderCataloguedBuildDoesNotPersistAGuessAndExplicitChoicesStillWin() { + val context = org.robolectric.RuntimeEnvironment.getApplication() + val preferences = context.getSharedPreferences("app_updates", android.content.Context.MODE_PRIVATE) + preferences.edit().clear().commit() + try { + val installed = me("2".repeat(40), version = "0.1.0") + val newerStable = release("0".repeat(40), version = "9999.0.0") + val currentPreview = release(installed.commit) + val newerCatalog = AppUpdates.Catalog(newerStable, currentPreview, emptyList(), 0L) + assertEquals(Channel.STABLE, AppUpdates.follow(context, newerCatalog, installed).channel) + assertNull(preferences.getString("channel", null)) + assertEquals(Channel.STABLE, AppUpdates.follow(context, null, installed).channel) + assertNull(preferences.getString("channel", null)) + for (choice in listOf(Follow(Channel.STABLE), Follow(Channel.NIGHTLY), Follow(Channel.TEST, 93))) { + AppUpdates.setFollow(context, choice) + val actual = AppUpdates.follow(context, newerCatalog, installed) + assertEquals(choice.channel, actual.channel) + assertEquals(choice.pr, actual.pr) + } + } finally { + preferences.edit().clear().commit() + } + } + @Test fun runningTheCatalogStableIsCertainStable() { val g = AppUpdates.guessFollow(catalog, me(stable.commit)) assertEquals(AppUpdates.Channel.STABLE, g.follow.channel)