3
3
import java.io.PrintWriter;
4
4
import java.io.StringWriter;
5
import java.lang.Thread.UncaughtExceptionHandler;
7
import android.database.sqlite.SQLiteException;
9
import com.flurry.android.FlurryAgent;
7
12
* General purpose utilities for the Astrid project. Grab-bag of stuff.
20
public static String throwableToString(Throwable input) {
25
public static void reportFlurryError(String name, Throwable error) {
26
String message = error.toString();
21
28
StringWriter writer = new StringWriter();
22
29
PrintWriter writerPrinter = new PrintWriter(writer);
23
input.printStackTrace(writerPrinter);
30
error.printStackTrace(writerPrinter);
24
31
writerPrinter.flush();
25
32
writerPrinter.close();
27
return writer.toString();
34
String trace = writer.toString();
37
trace = trace.substring(message.length());
38
trace.replaceAll("android", "A");
39
trace.replaceAll("database", "db");
40
trace.replaceAll(IllegalStateException.class.getName(), "IlStEx");
41
trace.replaceAll(ClassCastException.class.getName(), "ClCaEx");
42
trace.replaceAll(NullPointerException.class.getName(), "NPE");
43
trace.replaceAll(SQLiteException.class.getName(), "SqLiEx");
44
trace.replaceAll("com.timsu.", "");
46
FlurryAgent.onError(name, message, trace);
51
* For reporting uncaught exceptions
56
public static class AstridUncaughtExceptionHandler implements UncaughtExceptionHandler {
57
private UncaughtExceptionHandler defaultUEH;
59
public AstridUncaughtExceptionHandler() {
60
defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
64
public void uncaughtException(Thread thread, Throwable ex) {
65
AstridUtilities.reportFlurryError("uncaught", ex);
66
defaultUEH.uncaughtException(thread, ex);