[app] Fix release channel logic in App#findSuggestedApk()

Stable updates are always allowed, even if we also allow beta updates.
This commit is contained in:
Torsten Grote
2023-01-11 13:58:38 -03:00
parent 4d359242ab
commit cbb8aa5a50
2 changed files with 22 additions and 1 deletions

View File

@@ -552,8 +552,13 @@ public class App implements Comparable<App>, 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;
}

View File

@@ -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<Apk> 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.