Better reporting of update errors

This commit is contained in:
Ciaran Gultnieks 2012-09-12 16:56:04 +01:00
parent 951bf603fd
commit a2de56e2a5
3 changed files with 37 additions and 13 deletions

View File

@ -436,8 +436,7 @@ public class FDroid extends TabActivity implements OnItemClickListener,
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
if (resultCode == 1) {
Toast.makeText(FDroid.this,
getString(R.string.connection_error_msg),
Toast.makeText(FDroid.this, resultData.getString("errmsg"),
Toast.LENGTH_LONG).show();
} else {
populateLists(true);

View File

@ -38,6 +38,7 @@ import java.util.Vector;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import javax.net.ssl.SSLHandshakeException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
@ -292,8 +293,10 @@ public class RepoXMLHandler extends DefaultHandler {
// Do an update from the given repo. All applications found, and their
// APKs, are added to 'apps'. (If 'apps' already contains an app, its
// APKs are merged into the existing one)
public static boolean doUpdate(Context ctx, DB.Repo repo,
// APKs are merged into the existing one).
// Returns null if successful, otherwise an error message to be displayed
// to the user (if there is an interactive user!)
public static String doUpdate(Context ctx, DB.Repo repo,
Vector<DB.App> apps) {
try {
@ -333,13 +336,13 @@ public class RepoXMLHandler extends DefaultHandler {
in.close();
} catch (SecurityException e) {
Log.e("FDroid", "Invalid hash for index file");
return false;
return "Invalid hash for index file";
}
Certificate[] certs = je.getCertificates();
jar.close();
if (certs == null) {
Log.d("FDroid", "No signature found in index");
return false;
return "No signature found in index";
}
Log.d("FDroid", "Index has " + certs.length + " signature"
+ (certs.length > 1 ? "s." : "."));
@ -354,7 +357,7 @@ public class RepoXMLHandler extends DefaultHandler {
}
if (!match) {
Log.d("FDroid", "Index signature mismatch");
return false;
return "Index signature mismatch";
}
} else {
@ -390,16 +393,20 @@ public class RepoXMLHandler extends DefaultHandler {
}
}
} catch (SSLHandshakeException sslex) {
Log.e("FDroid", "SSLHandShakeException updating from " + repo.address + ":\n"
+ Log.getStackTraceString(sslex));
return "A problem occurred while establishing an SSL connection. If this problem persists, AND you have a very old device, you could try using http instead of https for the repo URL.";
} catch (Exception e) {
Log.e("FDroid", "Exception updating from " + repo.address + ":\n"
+ Log.getStackTraceString(e));
return false;
return "Failed to update - " + e.getMessage();
} finally {
ctx.deleteFile("tempindex.xml");
ctx.deleteFile("tempindex.jar");
}
return true;
return null;
}
}

View File

@ -73,6 +73,7 @@ public class UpdateService extends IntentService {
ResultReceiver receiver = intent.getParcelableExtra("receiver");
long startTime = System.currentTimeMillis();
String errmsg = "";
try {
@ -120,10 +121,16 @@ public class UpdateService extends IntentService {
boolean success = true;
for (DB.Repo repo : repos) {
if (repo.inuse) {
if (!RepoXMLHandler.doUpdate(getBaseContext(), repo, apps)) {
Log.d("FDroid", "Update failed for repo "
+ repo.address);
String err = RepoXMLHandler.doUpdate(getBaseContext(),
repo, apps);
if (err != null) {
success = false;
err = "Update failed for " + repo.address + " - " + err;
Log.d("FDroid", err);
if (errmsg.length() == 0)
errmsg = err;
else
errmsg += "\n" + err;
}
}
}
@ -142,6 +149,7 @@ public class UpdateService extends IntentService {
db.cancelUpdate();
Log.e("FDroid", "Exception during update processing:\n"
+ Log.getStackTraceString(ex));
errmsg = "Exception during processing - " + ex.getMessage();
success = false;
} finally {
DB.releaseDB();
@ -173,8 +181,15 @@ public class UpdateService extends IntentService {
if (receiver != null) {
Bundle resultData = new Bundle();
if (!success) {
if (errmsg.length() == 0)
errmsg = "Unknown error";
resultData.putString("errmsg", errmsg);
receiver.send(1, resultData);
} else {
receiver.send(0, resultData);
}
}
} catch (Exception e) {
Log.e("FDroid",
@ -182,6 +197,9 @@ public class UpdateService extends IntentService {
+ Log.getStackTraceString(e));
if (receiver != null) {
Bundle resultData = new Bundle();
if (errmsg.length() == 0)
errmsg = "Unknown error";
resultData.putString("errmsg", errmsg);
receiver.send(1, resultData);
}
} finally {