From 953135ffa5f73d4cb8d1b122b2cacc1a7a839180 Mon Sep 17 00:00:00 2001 From: felkachang Date: Thu, 12 Jan 2023 21:27:39 +0800 Subject: [PATCH] Fix hang of `adb shell cmd resources dump ...` The process creates a pipe and dup the output file descriptor passed to the app process. The dup output file descriptor is not closed after the app has finished the dumping tasks. But, the console is blocked for reading from the input file descriptor. That's why `adb shell cmd resources dump com.android.systemui` hangs in very high frequency. This patch makes sure the dup output file descriptor is closed after the app process has finished the dumping tasks. Fixes: 265098734 Bug: 243579631 Test: adb shell cmd resources dump com.android.systemui Change-Id: I02eb316e32f27ead25ec37ccbf661a422f137e50 --- .../server/resources/ResourcesManagerShellCommand.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/resources/ResourcesManagerShellCommand.java b/services/core/java/com/android/server/resources/ResourcesManagerShellCommand.java index 7d8336a0d3e95..a75d110e3cd12 100644 --- a/services/core/java/com/android/server/resources/ResourcesManagerShellCommand.java +++ b/services/core/java/com/android/server/resources/ResourcesManagerShellCommand.java @@ -62,13 +62,12 @@ public class ResourcesManagerShellCommand extends ShellCommand { private int dumpResources() throws RemoteException { String processId = getNextArgRequired(); - try { + try (ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(getOutFileDescriptor())) { ConditionVariable lock = new ConditionVariable(); RemoteCallback finishCallback = new RemoteCallback(result -> lock.open(), null); - if (!mInterface.dumpResources(processId, - ParcelFileDescriptor.dup(getOutFileDescriptor()), finishCallback)) { + if (!mInterface.dumpResources(processId, pfd, finishCallback)) { getErrPrintWriter().println("RESOURCES DUMP FAILED on process " + processId); return -1; }