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:
parent
b11232b607
commit
3352d83102
@ -96,7 +96,7 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
public int installedVersionCode;
|
public int installedVersionCode;
|
||||||
|
|
||||||
public ApplicationInfo appInfo;
|
public ApplicationInfo appInfo;
|
||||||
public List<Apk> apks;
|
public Apk installedApk; // might be null if not installed
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(App app) {
|
public int compareTo(App app) {
|
||||||
@ -216,7 +216,6 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
|
|
||||||
this.name = (String) appInfo.loadLabel(pm);
|
this.name = (String) appInfo.loadLabel(pm);
|
||||||
this.appInfo = appInfo;
|
this.appInfo = appInfo;
|
||||||
this.apks = new ArrayList<Apk>();
|
|
||||||
|
|
||||||
File apkFile = new File(appInfo.publicSourceDir);
|
File apkFile = new File(appInfo.publicSourceDir);
|
||||||
Apk apk = new Apk();
|
Apk apk = new Apk();
|
||||||
@ -298,7 +297,7 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
}
|
}
|
||||||
apk.sig = Utils.hashBytes(fdroidSig, "md5");
|
apk.sig = Utils.hashBytes(fdroidSig, "md5");
|
||||||
|
|
||||||
this.apks.add(apk);
|
this.installedApk = apk;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
@ -306,14 +305,13 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
|| TextUtils.isEmpty(this.id))
|
|| TextUtils.isEmpty(this.id))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (this.apks == null || this.apks.size() != 1)
|
if (this.installedApk == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Apk apk = this.apks.get(0);
|
if (TextUtils.isEmpty(this.installedApk.sig))
|
||||||
if (TextUtils.isEmpty(apk.sig))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
File apkFile = apk.installedFile;
|
File apkFile = this.installedApk.installedFile;
|
||||||
if (apkFile == null || !apkFile.canRead())
|
if (apkFile == null || !apkFile.canRead())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -166,14 +166,13 @@ public class LocalRepoManager {
|
|||||||
for (String packageName : appsToCopy) {
|
for (String packageName : appsToCopy) {
|
||||||
App app = apps.get(packageName);
|
App app = apps.get(packageName);
|
||||||
|
|
||||||
for (Apk apk : app.apks) {
|
File outFile = new File(repoDir, app.installedApk.apkName);
|
||||||
File outFile = new File(repoDir, apk.apkName);
|
if (app.installedApk == null
|
||||||
if (!Utils.symlinkOrCopyFile(apk.installedFile, outFile)) {
|
|| !Utils.symlinkOrCopyFile(app.installedApk.installedFile, outFile)) {
|
||||||
throw new IllegalStateException("Unable to copy APK");
|
throw new IllegalStateException("Unable to copy APK");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public interface ScanListener {
|
public interface ScanListener {
|
||||||
public void processedApp(String packageName, int index, int total);
|
public void processedApp(String packageName, int index, int total);
|
||||||
@ -211,12 +210,9 @@ public class LocalRepoManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void copyIconsToRepo() {
|
public void copyIconsToRepo() {
|
||||||
for (App app : apps.values()) {
|
for (App app : apps.values())
|
||||||
if (app.apks.size() > 0) {
|
if (app.installedApk != null)
|
||||||
Apk apk = app.apks.get(0);
|
copyIconToRepo(app.appInfo.loadIcon(pm), app.id, app.installedApk.vercode);
|
||||||
copyIconToRepo(app.appInfo.loadIcon(pm), app.id, apk.vercode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -281,8 +277,6 @@ public class LocalRepoManager {
|
|||||||
|
|
||||||
SimpleDateFormat dateToStr = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
|
SimpleDateFormat dateToStr = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
|
||||||
for (Entry<String, App> entry : apps.entrySet()) {
|
for (Entry<String, App> entry : apps.entrySet()) {
|
||||||
String latestVersion = "0";
|
|
||||||
String latestVerCode = "0";
|
|
||||||
App app = entry.getValue();
|
App app = entry.getValue();
|
||||||
Element application = doc.createElement("application");
|
Element application = doc.createElement("application");
|
||||||
application.setAttribute("id", app.id);
|
application.setAttribute("id", app.id);
|
||||||
@ -338,60 +332,59 @@ public class LocalRepoManager {
|
|||||||
application.appendChild(tracker);
|
application.appendChild(tracker);
|
||||||
|
|
||||||
Element marketVersion = doc.createElement("marketversion");
|
Element marketVersion = doc.createElement("marketversion");
|
||||||
|
marketVersion.setTextContent(app.installedApk.version);
|
||||||
application.appendChild(marketVersion);
|
application.appendChild(marketVersion);
|
||||||
|
|
||||||
Element marketVerCode = doc.createElement("marketvercode");
|
Element marketVerCode = doc.createElement("marketvercode");
|
||||||
|
marketVerCode.setTextContent(String.valueOf(app.installedApk.vercode));
|
||||||
application.appendChild(marketVerCode);
|
application.appendChild(marketVerCode);
|
||||||
|
|
||||||
for (Apk apk : app.apks) {
|
|
||||||
Element packageNode = doc.createElement("package");
|
Element packageNode = doc.createElement("package");
|
||||||
|
|
||||||
Element version = doc.createElement("version");
|
Element version = doc.createElement("version");
|
||||||
latestVersion = apk.version;
|
version.setTextContent(app.installedApk.version);
|
||||||
version.setTextContent(apk.version);
|
|
||||||
packageNode.appendChild(version);
|
packageNode.appendChild(version);
|
||||||
|
|
||||||
// F-Droid unfortunately calls versionCode versioncode...
|
// F-Droid unfortunately calls versionCode versioncode...
|
||||||
Element versioncode = doc.createElement("versioncode");
|
Element versioncode = doc.createElement("versioncode");
|
||||||
latestVerCode = String.valueOf(apk.vercode);
|
versioncode.setTextContent(String.valueOf(app.installedApk.vercode));
|
||||||
versioncode.setTextContent(latestVerCode);
|
|
||||||
packageNode.appendChild(versioncode);
|
packageNode.appendChild(versioncode);
|
||||||
|
|
||||||
Element apkname = doc.createElement("apkname");
|
Element apkname = doc.createElement("apkname");
|
||||||
apkname.setTextContent(apk.apkName);
|
apkname.setTextContent(app.installedApk.apkName);
|
||||||
packageNode.appendChild(apkname);
|
packageNode.appendChild(apkname);
|
||||||
|
|
||||||
Element hash = doc.createElement("hash");
|
Element hash = doc.createElement("hash");
|
||||||
hash.setAttribute("type", apk.hashType);
|
hash.setAttribute("type", app.installedApk.hashType);
|
||||||
hash.setTextContent(apk.hash.toLowerCase(Locale.US));
|
hash.setTextContent(app.installedApk.hash.toLowerCase(Locale.US));
|
||||||
packageNode.appendChild(hash);
|
packageNode.appendChild(hash);
|
||||||
|
|
||||||
Element sig = doc.createElement("sig");
|
Element sig = doc.createElement("sig");
|
||||||
sig.setTextContent(apk.sig.toLowerCase(Locale.US));
|
sig.setTextContent(app.installedApk.sig.toLowerCase(Locale.US));
|
||||||
packageNode.appendChild(sig);
|
packageNode.appendChild(sig);
|
||||||
|
|
||||||
Element size = doc.createElement("size");
|
Element size = doc.createElement("size");
|
||||||
size.setTextContent(String.valueOf(apk.installedFile.length()));
|
size.setTextContent(String.valueOf(app.installedApk.installedFile.length()));
|
||||||
packageNode.appendChild(size);
|
packageNode.appendChild(size);
|
||||||
|
|
||||||
Element sdkver = doc.createElement("sdkver");
|
Element sdkver = doc.createElement("sdkver");
|
||||||
sdkver.setTextContent(String.valueOf(apk.minSdkVersion));
|
sdkver.setTextContent(String.valueOf(app.installedApk.minSdkVersion));
|
||||||
packageNode.appendChild(sdkver);
|
packageNode.appendChild(sdkver);
|
||||||
|
|
||||||
Element apkAdded = doc.createElement("added");
|
Element apkAdded = doc.createElement("added");
|
||||||
apkAdded.setTextContent(dateToStr.format(apk.added));
|
apkAdded.setTextContent(dateToStr.format(app.installedApk.added));
|
||||||
packageNode.appendChild(apkAdded);
|
packageNode.appendChild(apkAdded);
|
||||||
|
|
||||||
Element features = doc.createElement("features");
|
Element features = doc.createElement("features");
|
||||||
if (apk.features != null)
|
if (app.installedApk.features != null)
|
||||||
features.setTextContent(Utils.CommaSeparatedList.str(apk.features));
|
features.setTextContent(Utils.CommaSeparatedList.str(app.installedApk.features));
|
||||||
packageNode.appendChild(features);
|
packageNode.appendChild(features);
|
||||||
|
|
||||||
Element permissions = doc.createElement("permissions");
|
Element permissions = doc.createElement("permissions");
|
||||||
if (apk.permissions != null) {
|
if (app.installedApk.permissions != null) {
|
||||||
StringBuilder buff = new StringBuilder();
|
StringBuilder buff = new StringBuilder();
|
||||||
|
|
||||||
for (String permission : apk.permissions) {
|
for (String permission : app.installedApk.permissions) {
|
||||||
buff.append(permission.replace("android.permission.", ""));
|
buff.append(permission.replace("android.permission.", ""));
|
||||||
buff.append(",");
|
buff.append(",");
|
||||||
}
|
}
|
||||||
@ -404,11 +397,6 @@ public class LocalRepoManager {
|
|||||||
application.appendChild(packageNode);
|
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();
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
Transformer transformer = transformerFactory.newTransformer();
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user