Merge branch 'support-platform-signature' into 'master'

* tag 'mergeeme':
  remove unused import
  Fixed bug package signature info not included
  Changed to static property
  Fixed "apply suggestion" error
  Replaced `equalsIgnoreCase()` with `equals()`
  Apply 1 suggestion(s) to 1 file(s)
  Added check platform signature available

fdroid/fdroidclient!943
This commit is contained in:
Hans-Christoph Steiner 2021-02-23 13:10:52 +01:00
commit a1827f6266
No known key found for this signature in database
GPG Key ID: 3E177817BA1B9BFA
2 changed files with 26 additions and 1 deletions

View File

@ -24,7 +24,7 @@ package org.fdroid.fdroid;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageInfo;
import androidx.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
@ -92,6 +92,8 @@ public class IndexV1Updater extends IndexUpdater {
public static final String SIGNED_FILE_NAME = "index-v1.jar";
public static final String DATA_FILE_NAME = "index-v1.json";
private static String platformSigCache;
public IndexV1Updater(@NonNull Context context, @NonNull Repo repo) {
super(context, repo);
}
@ -298,6 +300,11 @@ public class IndexV1Updater extends IndexUpdater {
repo.maxage = getIntRepoValue(repoMap, "maxage");
repo.version = getIntRepoValue(repoMap, "version");
if (TextUtils.isEmpty(platformSigCache)) {
PackageInfo androidPackageInfo = Utils.getPackageInfoWithSignatures(context, "android");
platformSigCache = Utils.getPackageSig(androidPackageInfo);
}
RepoPersister repoPersister = new RepoPersister(context, repo);
if (apps != null && apps.length > 0) {
int appCount = 0;
@ -319,6 +326,8 @@ public class IndexV1Updater extends IndexUpdater {
for (Apk apk : apks) {
if (!apk.isApk()) {
app.isApk = false;
} else if (apk.sig.equals(platformSigCache)) {
app.preferredSigner = platformSigCache;
}
}
}

View File

@ -19,6 +19,7 @@
package org.fdroid.fdroid;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@ -808,6 +809,21 @@ public final class Utils {
return null;
}
/**
* Try to get the {@link PackageInfo} with signature info for the {@code packageName} provided.
*
* @return null on failure
*/
@SuppressLint("PackageManagerGetSignatures")
public static PackageInfo getPackageInfoWithSignatures(Context context, String packageName) {
try {
return context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
} catch (PackageManager.NameNotFoundException e) {
debugLog(TAG, "Could not get PackageInfo: ", e);
}
return null;
}
/**
* Useful for debugging during development, so that arbitrary queries can be made, and their
* results inspected in the debugger.