From e927037d179e9a0775a92dd161fdd6d03a9fc002 Mon Sep 17 00:00:00 2001 From: Olivier Gaillard Date: Tue, 19 Jul 2022 22:13:06 +0100 Subject: [PATCH] Do not run /system/bin/logcat when running on the ActivityManager thread to avoid blocking the ActivityManager thread. Bug: 239527352 Test: ran locally Change-Id: I318c7d15f685a2a6e5cc5eac1f454da20bc0034c --- .../com/android/server/am/ActivityManagerService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 4aec577c65d6e..562750b10c46e 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -8858,6 +8858,10 @@ public class ActivityManagerService extends IActivityManager.Stub // Do the rest in a worker thread to avoid blocking the caller on I/O // (After this point, we shouldn't access AMS internal data structures.) + // + // If process is null, we are being called from some internal code + // and may be about to die -- run this synchronously. + final boolean runSynchronously = process == null; Thread worker = new Thread("Error dump: " + dropboxTag) { @Override public void run() { @@ -8885,7 +8889,7 @@ public class ActivityManagerService extends IActivityManager.Stub sb.append(crashInfo.stackTrace); } - if (lines > 0) { + if (lines > 0 && !runSynchronously) { sb.append("\n"); InputStreamReader input = null; @@ -8917,9 +8921,7 @@ public class ActivityManagerService extends IActivityManager.Stub } }; - if (process == null) { - // If process is null, we are being called from some internal code - // and may be about to die -- run this synchronously. + if (runSynchronously) { final int oldMask = StrictMode.allowThreadDiskWritesMask(); try { worker.run();