parse APK for <nativecode> info in local repos

This parses the APKs for swapping, looking for what kinds of native code it
includes.  This is used in the compatibility check.

closes #30 https://gitlab.com/fdroid/fdroidclient/issues/30
This commit is contained in:
Hans-Christoph Steiner 2016-05-17 23:49:33 +02:00
parent 4224d6df81
commit 23ab7046bc
2 changed files with 32 additions and 5 deletions

View File

@ -21,8 +21,12 @@ import java.io.InputStream;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class App extends ValueObject implements Comparable<App> {
@ -113,7 +117,8 @@ public class App extends ValueObject implements Comparable<App> {
return name.compareToIgnoreCase(app.name);
}
public App() { }
public App() {
}
public App(Cursor cursor) {
@ -274,20 +279,33 @@ public class App extends ValueObject implements Comparable<App> {
this.name = (String) appInfo.loadLabel(pm);
final SanitizedFile apkFile = SanitizedFile.knownSanitized(appInfo.publicSourceDir);
final Apk apk = new Apk();
apk.versionName = packageInfo.versionName;
apk.versionCode = packageInfo.versionCode;
apk.hashType = "sha256";
apk.hash = Utils.getBinaryHash(apkFile, apk.hashType);
apk.added = this.added;
apk.minSdkVersion = Utils.getMinSdkVersion(context, packageName);
apk.maxSdkVersion = Utils.getMaxSdkVersion(context, packageName);
apk.packageName = this.packageName;
apk.installedFile = apkFile;
apk.permissions = Utils.CommaSeparatedList.make(packageInfo.requestedPermissions);
apk.apkName = apk.packageName + "_" + apk.versionCode + ".apk";
final SanitizedFile apkFile = SanitizedFile.knownSanitized(appInfo.publicSourceDir);
apk.hashType = "sha256";
apk.hash = Utils.getBinaryHash(apkFile, apk.hashType);
apk.installedFile = apkFile;
JarFile jarFile = new JarFile(apkFile);
HashSet<String> abis = new HashSet<>(3);
Pattern pattern = Pattern.compile("^lib/([a-z0-9-]+)/.*");
for (Enumeration<JarEntry> jarEntries = jarFile.entries(); jarEntries.hasMoreElements();) {
JarEntry jarEntry = jarEntries.nextElement();
Matcher matcher = pattern.matcher(jarEntry.getName());
if (matcher.matches()) {
abis.add(matcher.group(1));
}
}
apk.nativecode = Utils.CommaSeparatedList.make(abis.toArray(new String[abis.size()]));
final FeatureInfo[] features = packageInfo.reqFeatures;
if (features != null && features.length > 0) {
final String[] featureNames = new String[features.length];

View File

@ -456,6 +456,7 @@ public final class LocalRepoManager {
tag("added", app.installedApk.added);
tagFeatures(app);
tagPermissions(app);
tagNativecode(app);
serializer.endTag("", "package");
}
@ -485,6 +486,14 @@ public final class LocalRepoManager {
serializer.endTag("", "features");
}
private void tagNativecode(App app) throws IOException {
if (app.installedApk.nativecode != null) {
serializer.startTag("", "nativecode");
serializer.text(Utils.CommaSeparatedList.str(app.installedApk.nativecode));
serializer.endTag("", "nativecode");
}
}
private void tagHash(App app) throws IOException {
serializer.startTag("", "hash");
serializer.attribute("", "type", app.installedApk.hashType);