diff --git a/cmds/monkey/src/com/android/commands/monkey/Monkey.java b/cmds/monkey/src/com/android/commands/monkey/Monkey.java index 4de86cfcd..2f8d87459 100644 --- a/cmds/monkey/src/com/android/commands/monkey/Monkey.java +++ b/cmds/monkey/src/com/android/commands/monkey/Monkey.java @@ -857,6 +857,9 @@ public class Monkey { int eventCounter = 0; int cycleCounter = 0; + boolean shouldReportAnrTraces = false; + boolean shouldReportDumpsysMemInfo = false; + boolean shouldAbort = false; boolean systemCrashed = false; while (!systemCrashed && cycleCounter < mCount) { @@ -866,12 +869,12 @@ public class Monkey { mRequestProcRank = false; } if (mRequestAnrTraces) { - reportAnrTraces(); mRequestAnrTraces = false; + shouldReportAnrTraces = true; } if (mRequestDumpsysMemInfo) { - reportDumpsysMemInfo(); mRequestDumpsysMemInfo = false; + shouldReportDumpsysMemInfo = true; } if (mMonitorNativeCrashes) { // first time through, when eventCounter == 0, just set up @@ -882,12 +885,29 @@ public class Monkey { } } if (mAbort) { - System.out.println("** Monkey aborted due to error."); - System.out.println("Events injected: " + eventCounter); - return eventCounter; + shouldAbort = true; } } + // Report ANR, dumpsys after releasing lock on this. + // This ensures the availability of the lock to Activity controller's appNotResponding + if (shouldReportAnrTraces) { + shouldReportAnrTraces = false; + reportAnrTraces(); + } + + if (shouldReportDumpsysMemInfo) { + shouldReportDumpsysMemInfo = false; + reportDumpsysMemInfo(); + } + + if (shouldAbort) { + shouldAbort = false; + System.out.println("** Monkey aborted due to error."); + System.out.println("Events injected: " + eventCounter); + return eventCounter; + } + // In this debugging mode, we never send any events. This is // primarily here so you can manually test the package or category // limits, while manually exercising the system.