aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/nullwire
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2009-12-17 06:18:39 +0000
committerKenny Root <kenny@the-b.org>2009-12-17 06:18:39 +0000
commit1557b52f5e39f61b53300cb881127ef7a0d7a325 (patch)
tree5b91e17ff76f9ff8a9e8bdd0fabce4a0ae0af791 /src/com/nullwire
parentf485e61fb8d2325fd1c43ab383a9ca34e84d2cd8 (diff)
downloadconnectbot-1557b52f5e39f61b53300cb881127ef7a0d7a325.tar.gz
connectbot-1557b52f5e39f61b53300cb881127ef7a0d7a325.tar.bz2
connectbot-1557b52f5e39f61b53300cb881127ef7a0d7a325.zip
Update Nullwire error reporting
Old version didn't chain to the default Android exception handler whereas this version does. Also add in OS version and phone type reporting to aid in triage. git-svn-id: https://connectbot.googlecode.com/svn/trunk/connectbot@438 df292f66-193f-0410-a5fc-6d59da041ff2
Diffstat (limited to 'src/com/nullwire')
-rw-r--r--src/com/nullwire/trace/DefaultExceptionHandler.java19
-rw-r--r--src/com/nullwire/trace/ExceptionClickListener.java13
-rw-r--r--src/com/nullwire/trace/ExceptionHandler.java74
-rw-r--r--src/com/nullwire/trace/G.java2
4 files changed, 63 insertions, 45 deletions
diff --git a/src/com/nullwire/trace/DefaultExceptionHandler.java b/src/com/nullwire/trace/DefaultExceptionHandler.java
index 7ca04e8..f9abe70 100644
--- a/src/com/nullwire/trace/DefaultExceptionHandler.java
+++ b/src/com/nullwire/trace/DefaultExceptionHandler.java
@@ -12,8 +12,16 @@ import android.util.Log;
public class DefaultExceptionHandler implements UncaughtExceptionHandler {
+ private UncaughtExceptionHandler defaultExceptionHandler;
+
private static final String TAG = "UNHANDLED_EXCEPTION";
+ // constructor
+ public DefaultExceptionHandler(UncaughtExceptionHandler pDefaultExceptionHandler)
+ {
+ defaultExceptionHandler = pDefaultExceptionHandler;
+ }
+
// Default exception handler
public void uncaughtException(Thread t, Throwable e) {
// Here you should have a more robust, permanent record of problems
@@ -31,9 +39,10 @@ public class DefaultExceptionHandler implements UncaughtExceptionHandler {
// Write the stacktrace to disk
BufferedWriter bos = new BufferedWriter(new FileWriter(G.FILES_PATH
+ "/" + filename + ".stacktrace"));
- bos.write(G.APP_VERSION);
- bos.write(G.APP_DESCRIPTION);
- bos.write('\n');
+ bos.write(G.APP_VERSION + "\n");
+ bos.write(G.APP_DESCRIPTION + "\n");
+ bos.write(G.ANDROID_VERSION + "\n");
+ bos.write(G.PHONE_MODEL + "\n");
bos.write(result.toString());
bos.flush();
// Close up everything
@@ -43,7 +52,7 @@ public class DefaultExceptionHandler implements UncaughtExceptionHandler {
ebos.printStackTrace();
}
Log.d(TAG, result.toString());
- // FlurryAgent session has ended
- t.getThreadGroup().destroy();
+ //call original handler
+ defaultExceptionHandler.uncaughtException(t, e);
}
}
diff --git a/src/com/nullwire/trace/ExceptionClickListener.java b/src/com/nullwire/trace/ExceptionClickListener.java
index 2646db1..3bf7adc 100644
--- a/src/com/nullwire/trace/ExceptionClickListener.java
+++ b/src/com/nullwire/trace/ExceptionClickListener.java
@@ -19,28 +19,27 @@ public class ExceptionClickListener implements OnClickListener {
WeakReference<Context> context;
- public ExceptionClickListener(Context context) {
- this.context = new WeakReference<Context>(context);
- }
+ public ExceptionClickListener() { }
public void onClick(DialogInterface dialog, int whichButton) {
switch (whichButton) {
case DialogInterface.BUTTON_POSITIVE:
+ dialog.dismiss();
Log.d(TAG, "Trying to submit stack traces");
new Thread(new Runnable() {
public void run() {
- ExceptionHandler.submitStackTraces(context.get());
+ ExceptionHandler.submitStackTraces();
}
}).run();
- dialog.dismiss();
break;
case DialogInterface.BUTTON_NEGATIVE:
+ dialog.dismiss();
+ Log.d(TAG, "Deleting old stack traces.");
new Thread(new Runnable() {
public void run() {
- ExceptionHandler.removeStackTraces(context.get());
+ ExceptionHandler.removeStackTraces();
}
}).run();
- dialog.dismiss();
break;
default:
Log.d("ExceptionClickListener", "Got unknown button click: " + whichButton);
diff --git a/src/com/nullwire/trace/ExceptionHandler.java b/src/com/nullwire/trace/ExceptionHandler.java
index a48303d..779ec13 100644
--- a/src/com/nullwire/trace/ExceptionHandler.java
+++ b/src/com/nullwire/trace/ExceptionHandler.java
@@ -36,20 +36,24 @@ public class ExceptionHandler {
public static void checkForTraces(final Context context) {
new Thread(new Runnable() {
public void run() {
- String[] stackTraces = searchForStackTraces(context);
+ String[] stackTraces = searchForStackTraces();
if (stackTraces != null && stackTraces.length > 0) {
Log.d(TAG, "number of stack traces: " + stackTraces.length);
- submissionHandler.sendMessage(
- submissionHandler.obtainMessage(-1, context));
+ submissionHandler.sendMessage(submissionHandler
+ .obtainMessage(-1, context));
}
}
}).start();
}
+
/**
- * @param context
- */
- private static void getPackageInfo(Context context) {
+ * Register handler for unhandled exceptions.
+ *
+ * @param context
+ */
+ public static boolean register(Context context) {
+ Log.i(TAG, "Registering default exceptions handler");
// Get information about the Package
PackageManager pm = context.getPackageManager();
try {
@@ -63,6 +67,10 @@ public class ExceptionHandler {
G.APP_DESCRIPTION = context.getString(R.string.msg_version);
// Files dir for storing the stack traces
G.FILES_PATH = context.getFilesDir().getAbsolutePath();
+ // Device model
+ G.PHONE_MODEL = android.os.Build.MODEL;
+ // Android version
+ G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
@@ -71,35 +79,41 @@ public class ExceptionHandler {
Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE);
Log.d(TAG, "FILES_PATH: " + G.FILES_PATH);
Log.d(TAG, "URL: " + G.URL);
- }
- public static void register(Context context) {
- Log.i(TAG, "Registering default exceptions handler");
+ boolean stackTracesFound = false;
+ // We'll return true if any stack traces were found
+ if (searchForStackTraces().length > 0) {
+ stackTracesFound = true;
+ }
new Thread() {
@Override
public void run() {
- // Register default exceptions handler
- Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());
+ UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler();
+
+ if (currentHandler != null) {
+ Log.d(TAG, "current handler class="+currentHandler.getClass().getName());
+ }
+ // don't register again if already registered
+ if (!(currentHandler instanceof DefaultExceptionHandler)) {
+ // Register default exceptions handler
+ Thread.setDefaultUncaughtExceptionHandler(
+ new DefaultExceptionHandler(currentHandler));
+ }
}
}.start();
+
+ return stackTracesFound;
}
/**
* Search for stack trace files.
- *
* @return
*/
- private static String[] searchForStackTraces(Context context) {
- if (stackTraceFileList != null && stackTraceFileList.length > 0)
+ private static String[] searchForStackTraces() {
+ if (stackTraceFileList != null) {
return stackTraceFileList;
-
- if (context == null)
- return null;
-
- if (G.FILES_PATH == null)
- getPackageInfo(context);
-
+ }
File dir = new File(G.FILES_PATH + "/");
// Try to create the files folder if it doesn't exist
dir.mkdir();
@@ -116,7 +130,7 @@ public class ExceptionHandler {
@Override
public void handleMessage(Message msg) {
Context context = (Context) msg.obj;
- ExceptionClickListener clickListener = new ExceptionClickListener(context);
+ ExceptionClickListener clickListener = new ExceptionClickListener();
new AlertDialog.Builder(context)
.setMessage(R.string.exceptions_submit_message)
.setPositiveButton(android.R.string.yes, clickListener)
@@ -129,13 +143,10 @@ public class ExceptionHandler {
* Look into the files folder to see if there are any "*.stacktrace" files.
* If any are present, submit them to the trace server.
*/
- public static void submitStackTraces(Context context) {
- if (context == null)
- return;
-
+ public static void submitStackTraces() {
try {
Log.d(TAG, "Looking for exceptions in: " + G.FILES_PATH);
- String[] list = searchForStackTraces(context);
+ String[] list = searchForStackTraces();
if (list != null && list.length > 0) {
Log.d(TAG, "Found " + list.length + " stacktrace(s)");
StringBuilder contents = new StringBuilder();
@@ -179,16 +190,13 @@ public class ExceptionHandler {
} catch (Exception e) {
e.printStackTrace();
} finally {
- removeStackTraces(context);
+ removeStackTraces();
}
}
- public synchronized static void removeStackTraces(Context context) {
- if (context == null)
- return;
-
+ public synchronized static void removeStackTraces() {
try {
- String[] list = searchForStackTraces(context);
+ String[] list = searchForStackTraces();
if (list == null)
return;
diff --git a/src/com/nullwire/trace/G.java b/src/com/nullwire/trace/G.java
index cf38f9b..2e63aa1 100644
--- a/src/com/nullwire/trace/G.java
+++ b/src/com/nullwire/trace/G.java
@@ -7,6 +7,8 @@ public class G {
public static String APP_PACKAGE = "unknown";
public static String APP_VERSION = "unknown";
public static String APP_DESCRIPTION = "unknown";
+ public static String PHONE_MODEL = "unknown";
+ public static String ANDROID_VERSION = "unknown";
// Where are the stack traces posted?
public static String URL = "http://connectbot.the-b.org/trace/";
}