Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Allow disk I/O while performing dump().
Browse files Browse the repository at this point in the history
Add Closeable to ParcelFileDescriptor, and always close any incoming
PFDs when dumping.

Bug: 6106309
Change-Id: I25b465692d5e1da0a5980a307cb48a058bc2bca7
  • Loading branch information
jsharkey committed Mar 2, 2012
1 parent c81ec36 commit e861b42
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15088,7 +15088,7 @@ package android.os {
field public static final android.os.Parcelable.Creator STRING_CREATOR;
}

public class ParcelFileDescriptor implements android.os.Parcelable {
public class ParcelFileDescriptor implements java.io.Closeable android.os.Parcelable {
ctor public ParcelFileDescriptor(android.os.ParcelFileDescriptor);
method public static android.os.ParcelFileDescriptor adoptFd(int);
method public void close() throws java.io.IOException;
Expand Down
56 changes: 32 additions & 24 deletions core/java/android/app/ActivityThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
import java.util.TimeZone;
import java.util.regex.Pattern;

import libcore.io.IoUtils;

import dalvik.system.CloseGuard;

final class SuperNotCalledException extends AndroidRuntimeException {
Expand Down Expand Up @@ -2357,41 +2359,47 @@ private void handleUnbindService(BindServiceData data) {
}

private void handleDumpService(DumpComponentInfo info) {
Service s = mServices.get(info.token);
if (s != null) {
PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
s.dump(info.fd.getFileDescriptor(), pw, info.args);
pw.flush();
try {
info.fd.close();
} catch (IOException e) {
final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
Service s = mServices.get(info.token);
if (s != null) {
PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
s.dump(info.fd.getFileDescriptor(), pw, info.args);
pw.flush();
}
} finally {
IoUtils.closeQuietly(info.fd);
StrictMode.setThreadPolicy(oldPolicy);
}
}

private void handleDumpActivity(DumpComponentInfo info) {
ActivityClientRecord r = mActivities.get(info.token);
if (r != null && r.activity != null) {
PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args);
pw.flush();
try {
info.fd.close();
} catch (IOException e) {
final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
ActivityClientRecord r = mActivities.get(info.token);
if (r != null && r.activity != null) {
PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args);
pw.flush();
}
} finally {
IoUtils.closeQuietly(info.fd);
StrictMode.setThreadPolicy(oldPolicy);
}
}

private void handleDumpProvider(DumpComponentInfo info) {
ProviderClientRecord r = mLocalProviders.get(info.token);
if (r != null && r.mLocalProvider != null) {
PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args);
pw.flush();
try {
info.fd.close();
} catch (IOException e) {
final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
ProviderClientRecord r = mLocalProviders.get(info.token);
if (r != null && r.mLocalProvider != null) {
PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args);
pw.flush();
}
} finally {
IoUtils.closeQuietly(info.fd);
StrictMode.setThreadPolicy(oldPolicy);
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/java/android/os/ParcelFileDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

package android.os;
import java.io.Closeable;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
Expand All @@ -28,7 +29,7 @@
* The FileDescriptor returned by {@link Parcel#readFileDescriptor}, allowing
* you to close it when done with it.
*/
public class ParcelFileDescriptor implements Parcelable {
public class ParcelFileDescriptor implements Parcelable, Closeable {
private final FileDescriptor mFileDescriptor;
private boolean mClosed;
//this field is to create wrapper for ParcelFileDescriptor using another
Expand Down

0 comments on commit e861b42

Please sign in to comment.