Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1099)

Unified Diff: content/public/android/java/src/org/chromium/content/app/KillChildUncaughtExceptionHandler.java

Issue 2675013002: android: Crash child immediately on uncaught exception (Closed)
Patch Set: comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/app/KillChildUncaughtExceptionHandler.java
diff --git a/content/public/android/java/src/org/chromium/content/app/KillChildUncaughtExceptionHandler.java b/content/public/android/java/src/org/chromium/content/app/KillChildUncaughtExceptionHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..31a762eb7db5efbe19d327b48e8cd33fa79a332c
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/app/KillChildUncaughtExceptionHandler.java
@@ -0,0 +1,50 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.app;
+
+import android.os.Process;
+
+import org.chromium.base.BuildInfo;
+import org.chromium.base.annotations.MainDex;
+import org.chromium.base.annotations.SuppressFBWarnings;
+
+/**
+ * Handler that immediately kills the current process on an uncaught exception.
+ * This is intended to override Android's default exception handler, which pops up a dialog
+ * and does not finish until user dismisses that dialog.
+ *
+ * Notes:
+ * This does not chain the existing handler.
+ * This does not have any exception handling or crash reporting. Such handlers should be
+ * chained before this handler.
+ */
+@MainDex
+class KillChildUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
+ private boolean mCrashing;
+
+ // Should be called early on start up.
+ static void maybeInstallHandler() {
+ // Only suppress default dialog on release builds. This matches behavior for native crashes
+ // in breakpad::FinalizeCrashDoneAndroid, where the dialog is suppressed on release builds
+ // due to bad user experience. Note this is also the reason the exception stack is not
+ // printed here, to avoid the stack being printed twice in release builds where breakpad
+ // is also enabled.
+ if (BuildInfo.isDebugAndroid()) return;
+ Thread.setDefaultUncaughtExceptionHandler(new KillChildUncaughtExceptionHandler());
+ }
+
+ @Override
+ @SuppressFBWarnings("DM_EXIT")
+ public void uncaughtException(Thread t, Throwable e) {
+ // Never re-enter.
+ if (mCrashing) return;
+ mCrashing = true;
+
+ // Copyed from Android KillApplicationHandler in RuntimeInit.java. This is how the default
+ // Android handler kills this process.
+ Process.killProcess(Process.myPid());
+ System.exit(10);
+ }
+}
« no previous file with comments | « content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698