Correctly check for 'suggestedApk' in app details.

Take into account the preferred/installed signature instead of just the
version code.
This commit is contained in:
Peter Serwylo 2017-06-30 12:14:15 +10:00
parent caac895442
commit 41f85f3c9d
3 changed files with 23 additions and 10 deletions

View File

@ -8,7 +8,6 @@ import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import org.fdroid.fdroid.data.Schema.ApkTable;
@ -84,14 +83,7 @@ public class ApkProvider extends FDroidProvider {
* </ul>
*/
public static Apk findSuggestedApk(Context context, App app) {
String preferredSignature = null;
if (!TextUtils.isEmpty(app.installedSig)) {
preferredSignature = app.installedSig;
} else if (!TextUtils.isEmpty(app.preferredSigner)) {
preferredSignature = app.preferredSigner;
}
return findApkFromAnyRepo(context, app.packageName, app.suggestedVersionCode, preferredSignature);
return findApkFromAnyRepo(context, app.packageName, app.suggestedVersionCode, app.getMostAppropriateSignature());
}
public static Apk findApkFromAnyRepo(Context context, String packageName, int versionCode) {

View File

@ -1098,4 +1098,24 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
return new App[size];
}
};
/**
* Choose the signature which we should encourage the user to install.
* Usually, we want the {@link #preferredSigner} rather than any random signature.
* However, if the app is installed, then we override this and instead want to only encourage
* the user to try and install versions with that signature (because thats all the OS will let
* them do).
* TODO: I don't think preferredSigner should ever be null, because if an app has apks then
* we should have chosen the first and used that. If so, then we should change to @NonNull and
* throw an exception if it is null.
*/
@Nullable
public String getMostAppropriateSignature() {
if (!TextUtils.isEmpty(installedSig)) {
return installedSig;
} else if (!TextUtils.isEmpty(preferredSigner)) {
return preferredSigner;
}
return null;
}
}

View File

@ -178,9 +178,10 @@ public class AppDetailsRecyclerViewAdapter
private Apk getSuggestedApk() {
Apk curApk = null;
String appropriateSig = app.getMostAppropriateSignature();
for (int i = 0; i < versions.size(); i++) {
final Apk apk = versions.get(i);
if (apk.versionCode == app.suggestedVersionCode) {
if (apk.versionCode == app.suggestedVersionCode && TextUtils.equals(apk.sig, appropriateSig)) {
curApk = apk;
break;
}