Use temporary local storage while downloading and processing index, instead of SD

This commit is contained in:
Ciaran Gultnieks 2010-11-13 11:59:24 +00:00
parent 87ea1dfc3f
commit d6c4402356
3 changed files with 27 additions and 23 deletions

View File

@ -410,7 +410,7 @@ public class FDroid extends TabActivity implements OnItemClickListener {
|| netstate.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED) {
new Thread() {
public void run() {
RepoXMLHandler.doUpdates(db);
RepoXMLHandler.doUpdates(FDroid.this, db);
update_handler.sendEmptyMessage(0);
}
}.start();

View File

@ -37,6 +37,7 @@ import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import android.content.Context;
import android.util.Log;
public class RepoXMLHandler extends DefaultHandler {
@ -181,11 +182,8 @@ public class RepoXMLHandler extends DefaultHandler {
}
}
private static String LOCAL_PATH = "/sdcard/.fdroid";
private static String XML_PATH = LOCAL_PATH + "/repotemp.xml";
// Returns the number of applications with updates.
public static int doUpdates(DB db) {
public static int doUpdates(Context ctx, DB db) {
db.beginUpdate();
Vector<DB.Repo> repos = db.getRepos();
for (DB.Repo repo : repos) {
@ -193,17 +191,15 @@ public class RepoXMLHandler extends DefaultHandler {
try {
File f = new File(XML_PATH);
if (f.exists())
f.delete();
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());
FileOutputStream saveit = new FileOutputStream(XML_PATH);
BufferedOutputStream bout = new BufferedOutputStream(
saveit, 1024);
BufferedOutputStream bout = new BufferedOutputStream(f,
1024);
byte data[] = new byte[1024];
int readed = getit.read(data, 0, 1024);
@ -213,24 +209,27 @@ public class RepoXMLHandler extends DefaultHandler {
}
bout.close();
getit.close();
saveit.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);
RepoXMLHandler handler = new RepoXMLHandler(repo.address,
db);
xr.setContentHandler(handler);
InputStreamReader isr = new FileReader(new File(XML_PATH));
InputStreamReader isr = new FileReader(new File(ctx
.getFilesDir()
+ "/tempindex.xml"));
InputSource is = new InputSource(isr);
xr.parse(is);
File xml_file = new File(XML_PATH);
xml_file.delete();
} catch (Exception e) {
Log.d("FDroid", "Exception updating from " + repo.address
+ " - " + e.getMessage());
} finally {
ctx.deleteFile("tempindex.xml");
}
}

View File

@ -106,7 +106,8 @@ public class UpdateService extends Service {
DB db = null;
try {
db = new DB(getBaseContext());
int updateNum = RepoXMLHandler.doUpdates(db);
int updateNum = RepoXMLHandler.doUpdates(getBaseContext(),
db);
if (updateNum != 0) {
// We have updates.
@ -120,9 +121,13 @@ public class UpdateService extends Service {
Context context = getApplicationContext();
CharSequence contentTitle = "FDroid";
CharSequence contentText = "Updates are available.";
Intent notificationIntent = new Intent(UpdateService.this, FDroid.class);
PendingIntent contentIntent = PendingIntent.getActivity(UpdateService.this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
Intent notificationIntent = new Intent(
UpdateService.this, FDroid.class);
PendingIntent contentIntent = PendingIntent
.getActivity(UpdateService.this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context,
contentTitle, contentText, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
n.notify(1, notification);
}