From f2a198dd83882461dc7beb2daaf9e28f43b890cb Mon Sep 17 00:00:00 2001 From: qinyige1 Date: Thu, 4 May 2023 15:11:08 +0800 Subject: [PATCH] [Monkey][Bugfix] Do not report crash in monkey proc. It's not necessary to report crash to system for monkey process, which even causes system deadlock. So we override it. Bug: 279527651 Test: Manual Change-Id: I2672a372dfe445a4f2400db01ec837ec6b528303 --- .../src/com/android/commands/monkey/Monkey.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmds/monkey/src/com/android/commands/monkey/Monkey.java b/cmds/monkey/src/com/android/commands/monkey/Monkey.java index c35d9a799..25048276f 100644 --- a/cmds/monkey/src/com/android/commands/monkey/Monkey.java +++ b/cmds/monkey/src/com/android/commands/monkey/Monkey.java @@ -550,6 +550,16 @@ public class Monkey { commandLineReport(bugreportName + ".txt", "bugreport"); } + // UncaughtExceptionHandler set by RuntimeInit will report crash to system_server, which + // is not necessary for monkey and even causes deadlock. So we override it. + private static class KillSelfHandler implements Thread.UncaughtExceptionHandler { + @Override + public void uncaughtException(Thread t, Throwable e) { + Process.killProcess(Process.myPid()); + System.exit(10); + } + } + /** * Command-line entry point. * @@ -559,6 +569,7 @@ public class Monkey { // Set the process name showing in "ps" or "top" Process.setArgV0("com.android.commands.monkey"); + Thread.setDefaultUncaughtExceptionHandler(new KillSelfHandler()); Logger.err.println("args: " + Arrays.toString(args)); int resultCode = (new Monkey()).run(args); System.exit(resultCode);