Fix adb dumpsys resource hang

The process creates a pipe and dup the output file descriptor passed to
app processes. The dup output file descriptor is not closed after
all apps have finished 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
all apps processes have finished dumping tasks.

Fixes: 265228474
Bug: 243579631
Test: adb shell dumpsys -t 20 resources
Change-Id: I0c9d5556a03053256c9d4ed99858018627630075
This commit is contained in:
felkachang
2023-01-12 16:13:19 +08:00
parent 613dc26088
commit 4f6d3cb519

View File

@@ -74,8 +74,8 @@ public class ResourcesManagerService extends SystemService {
@Override
protected void dump(@NonNull FileDescriptor fd,
@NonNull PrintWriter pw, @Nullable String[] args) {
try {
mActivityManagerService.dumpAllResources(ParcelFileDescriptor.dup(fd), pw);
try (ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(fd)) {
mActivityManagerService.dumpAllResources(pfd, pw);
} catch (Exception e) {
pw.println("Exception while trying to dump all resources: " + e.getMessage());
e.printStackTrace(pw);