Cleaned up the update process a bit

This commit is contained in:
Ciaran Gultnieks 2011-11-29 17:51:11 +00:00
parent aa58a8aad1
commit 23109ca778
3 changed files with 47 additions and 44 deletions

View File

@ -128,7 +128,7 @@ public class DB {
if (marketVersion != null && marketVercode > 0) { if (marketVersion != null && marketVercode > 0) {
for (Apk apk : apks) { for (Apk apk : apks) {
if (apk.vercode == marketVercode if (apk.vercode == marketVercode
&& (checker == null || checker.isCompatible(apk))) && (checker == null || checker.isCompatible(apk)))
return apk; return apk;
} }
} }
@ -139,7 +139,7 @@ public class DB {
Apk latestapk = null; Apk latestapk = null;
for (Apk apk : apks) { for (Apk apk : apks) {
if (apk.vercode > latestcode if (apk.vercode > latestcode
&& (checker == null || checker.isCompatible(apk))) { && (checker == null || checker.isCompatible(apk))) {
latestapk = apk; latestapk = apk;
latestcode = apk.vercode; latestcode = apk.vercode;
} }
@ -174,9 +174,9 @@ public class DB {
public String server; public String server;
public String hash; public String hash;
public String hashType; public String hashType;
public int minSdkVersion; // 0 if unknown public int minSdkVersion; // 0 if unknown
public CommaSeparatedList permissions; // null if empty or unknown public CommaSeparatedList permissions; // null if empty or unknown
public CommaSeparatedList features; // null if empty or unknown public CommaSeparatedList features; // null if empty or unknown
// ID (md5 sum of public key) of signature. Might be null, in the // ID (md5 sum of public key) of signature. Might be null, in the
// transition to this field existing. // transition to this field existing.
@ -206,8 +206,8 @@ public class DB {
public static abstract class CompatibilityChecker { public static abstract class CompatibilityChecker {
// Because Build.VERSION.SDK_INT requires API level 5 // Because Build.VERSION.SDK_INT requires API level 5
protected final static int SDK_INT protected final static int SDK_INT = Integer
= Integer.parseInt(Build.VERSION.SDK); .parseInt(Build.VERSION.SDK);
public abstract boolean isCompatible(Apk apk); public abstract boolean isCompatible(Apk apk);
@ -218,7 +218,7 @@ public class DB {
else else
checker = new BasicChecker(); checker = new BasicChecker();
Log.d("FDroid", "Compatibility checker for API level " Log.d("FDroid", "Compatibility checker for API level "
+ SDK_INT + ": " + checker.getClass().getName()); + SDK_INT + ": " + checker.getClass().getName());
return checker; return checker;
} }
} }
@ -252,7 +252,8 @@ public class DB {
if (apk.features != null) { if (apk.features != null) {
for (String feat : apk.features) { for (String feat : apk.features) {
if (!features.contains(feat)) { if (!features.contains(feat)) {
Log.d("FDroid","Incompatible based on lack of " + feat); Log.d("FDroid", "Incompatible based on lack of "
+ feat);
return false; return false;
} }
} }
@ -298,9 +299,9 @@ public class DB {
// //
private static final String[][] DB_UPGRADES = { private static final String[][] DB_UPGRADES = {
// Version 2... // Version 2...
{ "alter table " + TABLE_APP + " add marketVersion text", { "alter table " + TABLE_APP + " add marketVersion text",
"alter table " + TABLE_APP + " add marketVercode integer" }, "alter table " + TABLE_APP + " add marketVercode integer" },
// Version 3... // Version 3...
{ "alter table " + TABLE_APK + " add apkSource text" }, { "alter table " + TABLE_APK + " add apkSource text" },
@ -325,18 +326,18 @@ public class DB {
// Version 10... // Version 10...
{ "alter table " + TABLE_APK + " add minSdkVersion integer", { "alter table " + TABLE_APK + " add minSdkVersion integer",
"alter table " + TABLE_APK + " add permissions string", "alter table " + TABLE_APK + " add permissions string",
"alter table " + TABLE_APK + " add features string" }, "alter table " + TABLE_APK + " add features string" },
// Version 11... // Version 11...
{ "alter table " + TABLE_APP + " add requirements string" }, { "alter table " + TABLE_APP + " add requirements string" },
// Version 12... // Version 12...
{ "alter table " + TABLE_APK + " add hashType string", { "alter table " + TABLE_APK + " add hashType string",
"update " + TABLE_APK + " set hashType = 'MD5'" }, "update " + TABLE_APK + " set hashType = 'MD5'" },
// Version 13... // Version 13...
{ "alter table " + TABLE_APP + " add category string" }}; { "alter table " + TABLE_APP + " add category string" } };
private class DBHelper extends SQLiteOpenHelper { private class DBHelper extends SQLiteOpenHelper {
@ -351,10 +352,10 @@ public class DB {
db.execSQL(CREATE_TABLE_APK); db.execSQL(CREATE_TABLE_APK);
onUpgrade(db, 1, DB_UPGRADES.length + 1); onUpgrade(db, 1, DB_UPGRADES.length + 1);
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put("address", values.put("address", mContext
mContext.getString(R.string.default_repo_address)); .getString(R.string.default_repo_address));
values.put("pubkey", values.put("pubkey", mContext
mContext.getString(R.string.default_repo_pubkey)); .getString(R.string.default_repo_pubkey));
values.put("inuse", 1); values.put("inuse", 1);
values.put("priority", 10); values.put("priority", 10);
db.insert(TABLE_REPO, null, values); db.insert(TABLE_REPO, null, values);
@ -433,7 +434,8 @@ public class DB {
result.add("All"); result.add("All");
Cursor c = null; Cursor c = null;
try { try {
c = db.rawQuery("select distinct category from " + TABLE_APP + " order by category", null); c = db.rawQuery("select distinct category from " + TABLE_APP
+ " order by category", null);
c.moveToFirst(); c.moveToFirst();
while (!c.isAfterLast()) { while (!c.isAfterLast()) {
String s = c.getString(c.getColumnIndex("category")); String s = c.getString(c.getColumnIndex("category"));
@ -464,7 +466,7 @@ public class DB {
// simply using values cached in the database. Slower. // simply using values cached in the database. Slower.
// 'exclusions' - apply filtering for compatibility, anti-features, etc. // 'exclusions' - apply filtering for compatibility, anti-features, etc.
public Vector<App> getApps(String appid, String filter, boolean update, public Vector<App> getApps(String appid, String filter, boolean update,
boolean exclusions) { boolean exclusions) {
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(mContext); .getDefaultSharedPreferences(mContext);
@ -495,8 +497,8 @@ public class DB {
while (!c.isAfterLast()) { while (!c.isAfterLast()) {
App app = new App(); App app = new App();
app.antiFeatures = DB.CommaSeparatedList.make(c app.antiFeatures = DB.CommaSeparatedList.make(c.getString(c
.getString(c.getColumnIndex("antiFeatures"))); .getColumnIndex("antiFeatures")));
boolean include = true; boolean include = true;
if (app.antiFeatures != null && exclusions) { if (app.antiFeatures != null && exclusions) {
for (String af : app.antiFeatures) { for (String af : app.antiFeatures) {
@ -515,8 +517,8 @@ public class DB {
include = false; include = false;
} }
} }
app.requirements = DB.CommaSeparatedList.make(c app.requirements = DB.CommaSeparatedList.make(c.getString(c
.getString(c.getColumnIndex("requirements"))); .getColumnIndex("requirements")));
if (app.requirements != null && exclusions) { if (app.requirements != null && exclusions) {
for (String r : app.requirements) { for (String r : app.requirements) {
if (r.equals("root") && !pref_rooted) { if (r.equals("root") && !pref_rooted) {
@ -565,7 +567,8 @@ public class DB {
apk.hashType = c2.getString(c2 apk.hashType = c2.getString(c2
.getColumnIndex("hashType")); .getColumnIndex("hashType"));
apk.sig = c2.getString(c2.getColumnIndex("sig")); apk.sig = c2.getString(c2.getColumnIndex("sig"));
apk.srcname = c2.getString(c2.getColumnIndex("srcname")); apk.srcname = c2
.getString(c2.getColumnIndex("srcname"));
apk.size = c2.getInt(c2.getColumnIndex("size")); apk.size = c2.getInt(c2.getColumnIndex("size"));
apk.apkName = c2 apk.apkName = c2
.getString(c2.getColumnIndex("apkName")); .getString(c2.getColumnIndex("apkName"));
@ -575,8 +578,8 @@ public class DB {
.getColumnIndex("minSdkVersion")); .getColumnIndex("minSdkVersion"));
apk.permissions = CommaSeparatedList.make(c2 apk.permissions = CommaSeparatedList.make(c2
.getString(c2.getColumnIndex("permissions"))); .getString(c2.getColumnIndex("permissions")));
apk.features = CommaSeparatedList.make(c2 apk.features = CommaSeparatedList.make(c2.getString(c2
.getString(c2.getColumnIndex("features"))); .getColumnIndex("features")));
app.apks.add(apk); app.apks.add(apk);
if (!compatible && compatChecker.isCompatible(apk)) { if (!compatible && compatChecker.isCompatible(apk)) {
// At least one compatible APK. // At least one compatible APK.
@ -588,10 +591,9 @@ public class DB {
if (compatible) { if (compatible) {
result.add(app); result.add(app);
} } else {
else {
Log.d("FDroid", "Excluding incompatible application: " Log.d("FDroid", "Excluding incompatible application: "
+ app.id); + app.id);
} }
} }
@ -615,6 +617,9 @@ public class DB {
try { try {
getUpdates(result); getUpdates(result);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (Exception e) {
Log.e("FDroid", "Exception while getting updates: "
+ Log.getStackTraceString(e));
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
@ -750,7 +755,10 @@ public class DB {
// Called instead of endUpdate if the update failed. // Called instead of endUpdate if the update failed.
public void cancelUpdate() { public void cancelUpdate() {
db.endTransaction(); if (updateApps != null) {
db.endTransaction();
updateApps = null;
}
} }
// Called during update to supply new details for an application (or // Called during update to supply new details for an application (or

View File

@ -260,7 +260,6 @@ public class RepoXMLHandler extends DefaultHandler {
db.beginUpdate(); db.beginUpdate();
Vector<DB.Repo> repos = db.getRepos(); Vector<DB.Repo> repos = db.getRepos();
for (DB.Repo repo : repos) { for (DB.Repo repo : repos) {
boolean success = false;
if (repo.inuse) { if (repo.inuse) {
try { try {
@ -272,9 +271,8 @@ public class RepoXMLHandler extends DefaultHandler {
Log.d("FDroid", "Getting signed index from " Log.d("FDroid", "Getting signed index from "
+ repo.address); + repo.address);
getRemoteFile(ctx, repo.address + "/index.jar", getRemoteFile(ctx, repo.address + "/index.jar",
"tempindex.jar"); "tempindex.jar");
String jarpath = ctx.getFilesDir() String jarpath = ctx.getFilesDir() + "/tempindex.jar";
+ "/tempindex.jar";
JarFile jar; JarFile jar;
JarEntry je; JarEntry je;
try { try {
@ -306,9 +304,9 @@ public class RepoXMLHandler extends DefaultHandler {
Log.d("FDroid", "No signature found in index"); Log.d("FDroid", "No signature found in index");
return false; return false;
} }
Log.d("FDroid", "Index has " Log.d("FDroid", "Index has " + certs.length
+ certs.length + " signature" + " signature"
+ (certs.length > 1 ? "s." : ".")); + (certs.length > 1 ? "s." : "."));
boolean match = false; boolean match = false;
for (Certificate cert : certs) { for (Certificate cert : certs) {
@ -355,25 +353,23 @@ public class RepoXMLHandler extends DefaultHandler {
repo.pubkey = handler.pubkey; repo.pubkey = handler.pubkey;
db.updateRepoByAddress(repo); db.updateRepoByAddress(repo);
} }
success = true;
} catch (Exception e) { } catch (Exception e) {
Log.e("FDroid", "Exception updating from " + repo.address Log.e("FDroid", "Exception updating from " + repo.address
+ ":\n" + Log.getStackTraceString(e)); + ":\n" + Log.getStackTraceString(e));
db.cancelUpdate();
return false; return false;
} finally { } finally {
ctx.deleteFile("tempindex.xml"); ctx.deleteFile("tempindex.xml");
ctx.deleteFile("tempindex.jar"); ctx.deleteFile("tempindex.jar");
if (!success)
db.cancelUpdate();
} }
} }
} }
db.endUpdate(); db.endUpdate();
Log.d("FDroid", "Update completed in " Log.d("FDroid", "Update completed in "
+ ((System.currentTimeMillis() - startTime) / 1000) + ((System.currentTimeMillis() - startTime) / 1000)
+ " seconds."); + " seconds.");
return true; return true;
} }

View File

@ -113,7 +113,6 @@ public class UpdateService extends Service {
if (success && notify) { if (success && notify) {
if (db.getNumUpdates() > prevUpdates) { if (db.getNumUpdates() > prevUpdates) {
// And the user wants to know.
NotificationManager n = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager n = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification( Notification notification = new Notification(
R.drawable.icon, R.drawable.icon,