From cbb8aa5a50d90a2dba8edfa135b568fcc1425bb6 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 11 Jan 2023 13:58:38 -0300 Subject: [PATCH] [app] Fix release channel logic in App#findSuggestedApk() Stable updates are always allowed, even if we also allow beta updates. --- .../main/java/org/fdroid/fdroid/data/App.java | 7 ++++++- .../fdroid/fdroid/data/SuggestedVersionTest.java | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/fdroid/fdroid/data/App.java b/app/src/main/java/org/fdroid/fdroid/data/App.java index 333784548..f07baf3eb 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/App.java +++ b/app/src/main/java/org/fdroid/fdroid/data/App.java @@ -552,8 +552,13 @@ public class App implements Comparable, Parcelable { if (!a.compatible) continue; // if we have a signature, but it doesn't match, don't use this APK if (mostAppropriateSignature != null && !a.sig.equals(mostAppropriateSignature)) continue; + // stable release channel is always allowed, otherwise must include given channel + final String stable = Apk.RELEASE_CHANNEL_STABLE; + boolean isReleaseChannelAllowed = stable.equals(releaseChannel) ? + a.releaseChannels.contains(stable) : + a.releaseChannels.contains(stable) || a.releaseChannels.contains(releaseChannel); // if the signature matches and we want the highest version code, take this as list is sorted. - if (a.releaseChannels.contains(releaseChannel)) { + if (isReleaseChannelAllowed) { apk = a; break; } diff --git a/app/src/test/java/org/fdroid/fdroid/data/SuggestedVersionTest.java b/app/src/test/java/org/fdroid/fdroid/data/SuggestedVersionTest.java index af73be714..744e2e5c8 100644 --- a/app/src/test/java/org/fdroid/fdroid/data/SuggestedVersionTest.java +++ b/app/src/test/java/org/fdroid/fdroid/data/SuggestedVersionTest.java @@ -102,6 +102,22 @@ public class SuggestedVersionTest { assertSuggested(app, apks, suggestedVersion, releaseChannel, true); } + @Test + public void testIncompatibleWithBeta() { + App singleApp = TestUtils.getApp(); + singleApp.installedVersionCode = 1; + singleApp.installedSig = TestUtils.FDROID_SIG; + Apk apk1 = TestUtils.getApk(1, TestUtils.FDROID_SIG, Apk.RELEASE_CHANNEL_STABLE); + Apk apk2 = TestUtils.getApk(2, TestUtils.FDROID_SIG, Apk.RELEASE_CHANNEL_STABLE); + Apk apk3 = TestUtils.getApk(3, TestUtils.FDROID_SIG, Apk.RELEASE_CHANNEL_STABLE); + apk3.compatible = false; + List apks = new ArrayList<>(); + apks.add(apk3); + apks.add(apk2); + apks.add(apk1); + assertSuggested(singleApp, apks, 2, Apk.RELEASE_CHANNEL_BETA); + } + /** * Checks that the app exists, that its suggested version code is correct, and that the apk which is "suggested" * has the correct signature.