mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
fix: keep ambiguous update-channel guesses temporary
This commit is contained in:
1 parent
ac8957ae56
commit
9b176753cc
2 files changed
+38
-5
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user