Cleaned up the update process a bit
This commit is contained in:
parent
aa58a8aad1
commit
23109ca778
@ -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);
|
||||||
|
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,7 +337,7 @@ public class DB {
|
|||||||
"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"));
|
||||||
@ -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,8 +591,7 @@ 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() {
|
||||||
|
if (updateApps != null) {
|
||||||
db.endTransaction();
|
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
|
||||||
|
@ -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 {
|
||||||
@ -273,8 +272,7 @@ public class RepoXMLHandler extends DefaultHandler {
|
|||||||
+ 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,8 +304,8 @@ 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;
|
||||||
@ -355,17 +353,15 @@ 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user