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