Get and store anti-features data from repo

This commit is contained in:
Ciaran Gultnieks 2010-12-16 21:47:58 +00:00
parent e1f3c2eb78
commit bec725da56
2 changed files with 182 additions and 169 deletions

View File

@ -61,6 +61,7 @@ public class DB {
trackerURL = ""; trackerURL = "";
sourceURL = ""; sourceURL = "";
webURL = ""; webURL = "";
antiFeatures = null;
hasUpdates = false; hasUpdates = false;
updated = false; updated = false;
apks = new Vector<Apk>(); apks = new Vector<Apk>();
@ -80,6 +81,10 @@ public class DB {
public String marketVersion; public String marketVersion;
public int marketVercode; public int marketVercode;
// Comma-separated list of anti-features (as defined in the metadata
// documentation) or null if there aren't any.
public String antiFeatures;
// True if there are new versions (apks) that the user hasn't // True if there are new versions (apks) that the user hasn't
// explicitly ignored. (We're currently not using the database // explicitly ignored. (We're currently not using the database
// field for this - we make the decision on the fly in getApps(). // field for this - we make the decision on the fly in getApps().
@ -197,7 +202,10 @@ public class DB {
{ "alter table " + TABLE_APK + " add apkSource text" }, { "alter table " + TABLE_APK + " add apkSource text" },
// Version 4... // Version 4...
{ "alter table " + TABLE_APP + " add installedVerCode integer" } { "alter table " + TABLE_APP + " add installedVerCode integer" },
// Version 5...
{ "alter table " + TABLE_APP + " add antiFeatures string" }
}; };
@ -311,6 +319,8 @@ public class DB {
app.marketVersion = c.getString(c app.marketVersion = c.getString(c
.getColumnIndex("marketVersion")); .getColumnIndex("marketVersion"));
app.marketVercode = c.getInt(c.getColumnIndex("marketVercode")); app.marketVercode = c.getInt(c.getColumnIndex("marketVercode"));
app.antiFeatures = c
.getString(c.getColumnIndex("antiFeatures"));
app.hasUpdates = false; app.hasUpdates = false;
c2 = db.rawQuery("select * from " + TABLE_APK c2 = db.rawQuery("select * from " + TABLE_APK
@ -523,6 +533,7 @@ public class DB {
values.put("installedVerCode", upapp.installedVerCode); values.put("installedVerCode", upapp.installedVerCode);
values.put("marketVersion", upapp.marketVersion); values.put("marketVersion", upapp.marketVersion);
values.put("marketVercode", upapp.marketVercode); values.put("marketVercode", upapp.marketVercode);
values.put("antiFeatures", upapp.antiFeatures);
values.put("hasUpdates", upapp.hasUpdates ? 1 : 0); values.put("hasUpdates", upapp.hasUpdates ? 1 : 0);
if (oldapp != null) { if (oldapp != null) {
db.update(TABLE_APP, values, "id = ?", new String[] { oldapp.id }); db.update(TABLE_APP, values, "id = ?", new String[] { oldapp.id });

View File

@ -42,201 +42,203 @@ import android.util.Log;
public class RepoXMLHandler extends DefaultHandler { public class RepoXMLHandler extends DefaultHandler {
String mserver; String mserver;
private DB db; private DB db;
private DB.App curapp = null; private DB.App curapp = null;
private DB.Apk curapk = null; private DB.Apk curapk = null;
private String curchars = null; private String curchars = null;
public RepoXMLHandler(String srv, DB db) { public RepoXMLHandler(String srv, DB db) {
mserver = srv; mserver = srv;
this.db = db; this.db = db;
} }
@Override @Override
public void characters(char[] ch, int start, int length) public void characters(char[] ch, int start, int length)
throws SAXException { throws SAXException {
super.characters(ch, start, length); super.characters(ch, start, length);
String str = new String(ch).substring(start, start + length); String str = new String(ch).substring(start, start + length);
if (curchars == null) if (curchars == null)
curchars = str; curchars = str;
else else
curchars += str; curchars += str;
} }
@Override @Override
public void endElement(String uri, String localName, String qName) public void endElement(String uri, String localName, String qName)
throws SAXException { throws SAXException {
super.endElement(uri, localName, qName); super.endElement(uri, localName, qName);
String curel = localName; String curel = localName;
String str = curchars; String str = curchars;
if (curel == "application" && curapp != null) { if (curel == "application" && curapp != null) {
Log.d("FDroid", "Repo: Updating application " + curapp.id); Log.d("FDroid", "Repo: Updating application " + curapp.id);
db.updateApplication(curapp); db.updateApplication(curapp);
getIcon(curapp); getIcon(curapp);
curapp = null; curapp = null;
} else if (curel == "package" && curapk != null && curapp != null) { } else if (curel == "package" && curapk != null && curapp != null) {
Log.d("FDroid", "Repo: Package added (" + curapk.version + ")"); Log.d("FDroid", "Repo: Package added (" + curapk.version + ")");
curapp.apks.add(curapk); curapp.apks.add(curapk);
curapk = null; curapk = null;
} else if (curapk != null && str != null) { } else if (curapk != null && str != null) {
if (curel == "version") { if (curel == "version") {
curapk.version = str; curapk.version = str;
} else if (curel == "versioncode") { } else if (curel == "versioncode") {
try { try {
curapk.vercode = Integer.parseInt(str); curapk.vercode = Integer.parseInt(str);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
curapk.vercode = 0; curapk.vercode = 0;
} }
} else if (curel == "size") { } else if (curel == "size") {
try { try {
curapk.size = Integer.parseInt(str); curapk.size = Integer.parseInt(str);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
curapk.size = 0; curapk.size = 0;
} }
} else if (curel == "hash") { } else if (curel == "hash") {
curapk.hash = str; curapk.hash = str;
} else if (curel == "apkname") { } else if (curel == "apkname") {
curapk.apkName = str; curapk.apkName = str;
} else if (curel == "apksource") { } else if (curel == "apksource") {
curapk.apkSource = str; curapk.apkSource = str;
} }
} else if (curapp != null && str != null) { } else if (curapp != null && str != null) {
if (curel == "id") { if (curel == "id") {
Log.d("FDroid", "App id is " + str); Log.d("FDroid", "App id is " + str);
curapp.id = str; curapp.id = str;
} else if (curel == "name") { } else if (curel == "name") {
curapp.name = str; curapp.name = str;
} else if (curel == "icon") { } else if (curel == "icon") {
curapp.icon = str; curapp.icon = str;
} else if (curel == "description") { } else if (curel == "description") {
curapp.description = str; curapp.description = str;
} else if (curel == "summary") { } else if (curel == "summary") {
curapp.summary = str; curapp.summary = str;
} else if (curel == "license") { } else if (curel == "license") {
curapp.license = str; curapp.license = str;
} else if (curel == "source") { } else if (curel == "source") {
curapp.sourceURL = str; curapp.sourceURL = str;
} else if (curel == "web") { } else if (curel == "web") {
curapp.webURL = str; curapp.webURL = str;
} else if (curel == "tracker") { } else if (curel == "tracker") {
curapp.trackerURL = str; curapp.trackerURL = str;
} else if (curel == "marketversion") { } else if (curel == "marketversion") {
curapp.marketVersion = str; curapp.marketVersion = str;
} else if (curel == "marketvercode") { } else if (curel == "marketvercode") {
try { try {
curapp.marketVercode = Integer.parseInt(str); curapp.marketVercode = Integer.parseInt(str);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
curapp.marketVercode = 0; curapp.marketVercode = 0;
} }
} } else if (curel == "antifeatures") {
} curapp.antiFeatures = str;
}
}
} }
@Override @Override
public void startElement(String uri, String localName, String qName, public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException { Attributes attributes) throws SAXException {
super.startElement(uri, localName, qName, attributes); super.startElement(uri, localName, qName, attributes);
if (localName == "application" && curapp == null) { if (localName == "application" && curapp == null) {
Log.d("FDroid", "Repo: Found application at " + mserver); Log.d("FDroid", "Repo: Found application at " + mserver);
curapp = new DB.App(); curapp = new DB.App();
} else if (localName == "package" && curapp != null && curapk == null) { } else if (localName == "package" && curapp != null && curapk == null) {
Log.d("FDroid", "Repo: Found package for " + curapp.id); Log.d("FDroid", "Repo: Found package for " + curapp.id);
curapk = new DB.Apk(); curapk = new DB.Apk();
curapk.id = curapp.id; curapk.id = curapp.id;
curapk.server = mserver; curapk.server = mserver;
} }
curchars = null; curchars = null;
} }
private void getIcon(DB.App app) { private void getIcon(DB.App app) {
try { try {
String destpath = DB.getIconsPath() + app.icon; String destpath = DB.getIconsPath() + app.icon;
File f = new File(destpath); File f = new File(destpath);
if (f.exists()) if (f.exists())
return; return;
BufferedInputStream getit = new BufferedInputStream(new URL(mserver BufferedInputStream getit = new BufferedInputStream(new URL(mserver
+ "/icons/" + app.icon).openStream()); + "/icons/" + app.icon).openStream());
FileOutputStream saveit = new FileOutputStream(destpath); FileOutputStream saveit = new FileOutputStream(destpath);
BufferedOutputStream bout = new BufferedOutputStream(saveit, 1024); BufferedOutputStream bout = new BufferedOutputStream(saveit, 1024);
byte data[] = new byte[1024]; byte data[] = new byte[1024];
int readed = getit.read(data, 0, 1024); int readed = getit.read(data, 0, 1024);
while (readed != -1) { while (readed != -1) {
bout.write(data, 0, readed); bout.write(data, 0, readed);
readed = getit.read(data, 0, 1024); readed = getit.read(data, 0, 1024);
} }
bout.close(); bout.close();
getit.close(); getit.close();
saveit.close(); saveit.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
public static void doUpdates(Context ctx, DB db) { public static void doUpdates(Context ctx, DB db) {
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) {
if (repo.inuse) { if (repo.inuse) {
try { try {
FileOutputStream f = ctx.openFileOutput( FileOutputStream f = ctx.openFileOutput("tempindex.xml",
"tempindex.xml", Context.MODE_PRIVATE); Context.MODE_PRIVATE);
// Download the index file from the repo... // Download the index file from the repo...
BufferedInputStream getit = new BufferedInputStream( BufferedInputStream getit = new BufferedInputStream(
new URL(repo.address + "/index.xml").openStream()); new URL(repo.address + "/index.xml").openStream());
BufferedOutputStream bout = new BufferedOutputStream(f, BufferedOutputStream bout = new BufferedOutputStream(f,
1024); 1024);
byte data[] = new byte[1024]; byte data[] = new byte[1024];
int readed = getit.read(data, 0, 1024); int readed = getit.read(data, 0, 1024);
while (readed != -1) { while (readed != -1) {
bout.write(data, 0, readed); bout.write(data, 0, readed);
readed = getit.read(data, 0, 1024); readed = getit.read(data, 0, 1024);
} }
bout.close(); bout.close();
getit.close(); getit.close();
f.close(); f.close();
// Process the index... // Process the index...
SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser(); SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader(); XMLReader xr = sp.getXMLReader();
RepoXMLHandler handler = new RepoXMLHandler(repo.address, RepoXMLHandler handler = new RepoXMLHandler(repo.address,
db); db);
xr.setContentHandler(handler); xr.setContentHandler(handler);
InputStreamReader isr = new FileReader(new File(ctx InputStreamReader isr = new FileReader(new File(ctx
.getFilesDir() .getFilesDir()
+ "/tempindex.xml")); + "/tempindex.xml"));
InputSource is = new InputSource(isr); InputSource is = new InputSource(isr);
xr.parse(is); xr.parse(is);
} catch (Exception e) { } catch (Exception e) {
Log.d("FDroid", "Exception updating from " + repo.address Log.d("FDroid", "Exception updating from " + repo.address
+ " - " + e.getMessage()); + " - " + e.getMessage());
} finally { } finally {
ctx.deleteFile("tempindex.xml"); ctx.deleteFile("tempindex.xml");
} }
} }
} }
db.endUpdate(); db.endUpdate();
} }
} }