make App.apks List into a single Apk instance at App.installedApk

This then serves to represent the APK that is installed for this app. It
needs to be filled out by the Providers then also.  This then becomes a
place for data specific to the an installed App, like installedVersionCode
and installedVersionName, instead of having it both stored in an App
instance and a related Apk instance.
This commit is contained in:
Hans-Christoph Steiner 2014-05-06 19:34:59 -04:00
parent b11232b607
commit 3352d83102
2 changed files with 56 additions and 70 deletions

View File

@ -96,7 +96,7 @@ public class App extends ValueObject implements Comparable<App> {
public int installedVersionCode;
public ApplicationInfo appInfo;
public List<Apk> apks;
public Apk installedApk; // might be null if not installed
@Override
public int compareTo(App app) {
@ -216,7 +216,6 @@ public class App extends ValueObject implements Comparable<App> {
this.name = (String) appInfo.loadLabel(pm);
this.appInfo = appInfo;
this.apks = new ArrayList<Apk>();
File apkFile = new File(appInfo.publicSourceDir);
Apk apk = new Apk();
@ -298,7 +297,7 @@ public class App extends ValueObject implements Comparable<App> {
}
apk.sig = Utils.hashBytes(fdroidSig, "md5");
this.apks.add(apk);
this.installedApk = apk;
}
public boolean isValid() {
@ -306,14 +305,13 @@ public class App extends ValueObject implements Comparable<App> {
|| TextUtils.isEmpty(this.id))
return false;
if (this.apks == null || this.apks.size() != 1)
if (this.installedApk == null)
return false;
Apk apk = this.apks.get(0);
if (TextUtils.isEmpty(apk.sig))
if (TextUtils.isEmpty(this.installedApk.sig))
return false;
File apkFile = apk.installedFile;
File apkFile = this.installedApk.installedFile;
if (apkFile == null || !apkFile.canRead())
return false;

View File

@ -166,14 +166,13 @@ public class LocalRepoManager {
for (String packageName : appsToCopy) {
App app = apps.get(packageName);
for (Apk apk : app.apks) {
File outFile = new File(repoDir, apk.apkName);
if (!Utils.symlinkOrCopyFile(apk.installedFile, outFile)) {
File outFile = new File(repoDir, app.installedApk.apkName);
if (app.installedApk == null
|| !Utils.symlinkOrCopyFile(app.installedApk.installedFile, outFile)) {
throw new IllegalStateException("Unable to copy APK");
}
}
}
}
public interface ScanListener {
public void processedApp(String packageName, int index, int total);
@ -211,12 +210,9 @@ public class LocalRepoManager {
}
public void copyIconsToRepo() {
for (App app : apps.values()) {
if (app.apks.size() > 0) {
Apk apk = app.apks.get(0);
copyIconToRepo(app.appInfo.loadIcon(pm), app.id, apk.vercode);
}
}
for (App app : apps.values())
if (app.installedApk != null)
copyIconToRepo(app.appInfo.loadIcon(pm), app.id, app.installedApk.vercode);
}
/**
@ -281,8 +277,6 @@ public class LocalRepoManager {
SimpleDateFormat dateToStr = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
for (Entry<String, App> entry : apps.entrySet()) {
String latestVersion = "0";
String latestVerCode = "0";
App app = entry.getValue();
Element application = doc.createElement("application");
application.setAttribute("id", app.id);
@ -338,60 +332,59 @@ public class LocalRepoManager {
application.appendChild(tracker);
Element marketVersion = doc.createElement("marketversion");
marketVersion.setTextContent(app.installedApk.version);
application.appendChild(marketVersion);
Element marketVerCode = doc.createElement("marketvercode");
marketVerCode.setTextContent(String.valueOf(app.installedApk.vercode));
application.appendChild(marketVerCode);
for (Apk apk : app.apks) {
Element packageNode = doc.createElement("package");
Element version = doc.createElement("version");
latestVersion = apk.version;
version.setTextContent(apk.version);
version.setTextContent(app.installedApk.version);
packageNode.appendChild(version);
// F-Droid unfortunately calls versionCode versioncode...
Element versioncode = doc.createElement("versioncode");
latestVerCode = String.valueOf(apk.vercode);
versioncode.setTextContent(latestVerCode);
versioncode.setTextContent(String.valueOf(app.installedApk.vercode));
packageNode.appendChild(versioncode);
Element apkname = doc.createElement("apkname");
apkname.setTextContent(apk.apkName);
apkname.setTextContent(app.installedApk.apkName);
packageNode.appendChild(apkname);
Element hash = doc.createElement("hash");
hash.setAttribute("type", apk.hashType);
hash.setTextContent(apk.hash.toLowerCase(Locale.US));
hash.setAttribute("type", app.installedApk.hashType);
hash.setTextContent(app.installedApk.hash.toLowerCase(Locale.US));
packageNode.appendChild(hash);
Element sig = doc.createElement("sig");
sig.setTextContent(apk.sig.toLowerCase(Locale.US));
sig.setTextContent(app.installedApk.sig.toLowerCase(Locale.US));
packageNode.appendChild(sig);
Element size = doc.createElement("size");
size.setTextContent(String.valueOf(apk.installedFile.length()));
size.setTextContent(String.valueOf(app.installedApk.installedFile.length()));
packageNode.appendChild(size);
Element sdkver = doc.createElement("sdkver");
sdkver.setTextContent(String.valueOf(apk.minSdkVersion));
sdkver.setTextContent(String.valueOf(app.installedApk.minSdkVersion));
packageNode.appendChild(sdkver);
Element apkAdded = doc.createElement("added");
apkAdded.setTextContent(dateToStr.format(apk.added));
apkAdded.setTextContent(dateToStr.format(app.installedApk.added));
packageNode.appendChild(apkAdded);
Element features = doc.createElement("features");
if (apk.features != null)
features.setTextContent(Utils.CommaSeparatedList.str(apk.features));
if (app.installedApk.features != null)
features.setTextContent(Utils.CommaSeparatedList.str(app.installedApk.features));
packageNode.appendChild(features);
Element permissions = doc.createElement("permissions");
if (apk.permissions != null) {
if (app.installedApk.permissions != null) {
StringBuilder buff = new StringBuilder();
for (String permission : apk.permissions) {
for (String permission : app.installedApk.permissions) {
buff.append(permission.replace("android.permission.", ""));
buff.append(",");
}
@ -404,11 +397,6 @@ public class LocalRepoManager {
application.appendChild(packageNode);
}
// now mark the latest version in the feed for this particular app
marketVersion.setTextContent(latestVersion);
marketVerCode.setTextContent(latestVerCode);
}
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();