stop crashing if the suggested version ends up being bogus

It is possible for repo operators to specify a bad CurrentVersionCode for
an app that is also in another repo, and cause confusion in the suggested
version calculation.  Or if one repo's index is very out of date.  This
adds a fallback for these cases, so at least it'll stop the crash and
attempt the user's requested install.
This commit is contained in:
Hans-Christoph Steiner 2019-05-29 15:20:18 +02:00
parent b400df3ac3
commit 3812331166

View File

@ -86,10 +86,28 @@ public class ApkProvider extends FDroidProvider {
* <li>If installed, limit to apks signed by the same signer as the installed apk.</li>
* <li>Otherwise, limit to apks signed by the "preferred" signer (see {@link App#preferredSigner}).</li>
* </ul>
* If all else fails, try to return some {@link Apk} that will install something,
* rather than returning a null and triggering a {@link NullPointerException}.
*/
@Nullable
public static Apk findSuggestedApk(Context context, App app) {
return findApkFromAnyRepo(context, app.packageName, app.suggestedVersionCode,
app.getMostAppropriateSignature());
String mostAppropriateSignature = app.getMostAppropriateSignature();
Apk apk = findApkFromAnyRepo(context, app.packageName, app.suggestedVersionCode,
mostAppropriateSignature);
if (apk == null && (mostAppropriateSignature == null || !app.isInstalled(context))) {
List<Apk> apks = findByPackageName(context, app.packageName);
for (Apk availableApk : apks) {
if (availableApk.sig.equals(mostAppropriateSignature)) {
apk = availableApk;
break;
}
}
if (apk == null && apks.size() > 0) {
apk = apks.get(0);
}
}
return apk;
}
public static Apk findApkFromAnyRepo(Context context, String packageName, int versionCode) {