From a9eba18fa6ee4208ad8283c8fea598ce5b40f255 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Wed, 7 Mar 2012 11:19:05 -0800 Subject: [PATCH] Bug 733434 - Part 1: Register a global UncaughtExceptionHandler that calls Breakpad. r=blassey --- mobile/android/base/GeckoApp.java | 2 ++ mobile/android/base/GeckoAppShell.java | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index e3ba2ef3672..97f2fb55eb0 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1608,6 +1608,8 @@ abstract public class GeckoApp @Override public void onCreate(Bundle savedInstanceState) { + GeckoAppShell.registerGlobalExceptionHandler(); + mAppContext = this; // StrictMode is set by defaults resource flag |enableStrictMode|. diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index eecdfc822a4..b3ba0651b12 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -143,13 +143,27 @@ public class GeckoAppShell public static native void loadSQLiteLibsNative(String apkName, boolean shouldExtract); public static native void onChangeNetworkLinkStatus(String status); + public static void registerGlobalExceptionHandler() { + Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + public void uncaughtException(Thread thread, Throwable e) { + Log.e(LOGTAG, ">>> REPORTING UNCAUGHT EXCEPTION FROM THREAD " + + thread.getId() + " (\"" + thread.getName() + "\")", e); + reportJavaCrash(getStackTraceString(e)); + } + }); + } + public static void reportJavaCrash(Throwable e) { Log.e(LOGTAG, "top level exception", e); + reportJavaCrash(getStackTraceString(e)); + } + + private static String getStackTraceString(Throwable e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); - reportJavaCrash(sw.toString()); + return sw.toString(); } private static native void reportJavaCrash(String stackTrace);