From 29de4922dbfccbf1d6fd975a320f80ae7a28c7c4 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Tue, 7 Jun 2016 16:14:07 -0700 Subject: [PATCH] Duplicate file descriptor when dumping asynchronously. dumpDbInfo() uses an async task when dumping from the system thread, but then the file descriptor is closed by the time the task is executed. As such, the system databases are not dumped. BUG: 29123428 Change-Id: Ibb8bbe503aa03c3ca13b2b1789f0ead0b869e9d5 --- core/java/android/app/ActivityThread.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 7198146bee0f3..b220b2e23732a 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -1166,12 +1166,22 @@ public final class ActivityThread { @Override public void dumpDbInfo(final FileDescriptor fd, final String[] args) { if (mSystemThread) { - // Ensure this invocation is asynchronous to prevent - // writer waiting due to buffer cannot be consumed. + // Ensure this invocation is asynchronous to prevent writer waiting if buffer cannot + // be consumed. But it must duplicate the file descriptor first, since caller might + // be closing it. + final ParcelFileDescriptor dup; + try { + dup = ParcelFileDescriptor.dup(fd); + } catch (IOException e) { + Log.w(TAG, "Could not dup FD " + fd.getInt$()); + return; + } + AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { @Override public void run() { - dumpDatabaseInfo(fd, args); + dumpDatabaseInfo(dup.getFileDescriptor(), args); + IoUtils.closeQuietly(dup); } }); } else {