diff options
Diffstat (limited to 'core/java/android/os/Binder.java')
| -rw-r--r-- | core/java/android/os/Binder.java | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java index 7ffd30b0c3b1..f4a83910e652 100644 --- a/core/java/android/os/Binder.java +++ b/core/java/android/os/Binder.java @@ -17,6 +17,7 @@ package android.os; import android.util.Log; +import com.android.internal.util.FastPrintWriter; import java.io.FileDescriptor; import java.io.FileOutputStream; @@ -288,14 +289,27 @@ public class Binder implements IBinder { */ public void dump(FileDescriptor fd, String[] args) { FileOutputStream fout = new FileOutputStream(fd); - PrintWriter pw = new PrintWriter(fout); + PrintWriter pw = new FastPrintWriter(fout); try { final String disabled; synchronized (Binder.class) { disabled = sDumpDisabled; } if (disabled == null) { - dump(fd, pw, args); + try { + dump(fd, pw, args); + } catch (SecurityException e) { + pw.println("Security exception: " + e.getMessage()); + throw e; + } catch (Throwable e) { + // Unlike usual calls, in this case if an exception gets thrown + // back to us we want to print it back in to the dump data, since + // that is where the caller expects all interesting information to + // go. + pw.println(); + pw.println("Exception occurred while dumping:"); + e.printStackTrace(pw); + } } else { pw.println(sDumpDisabled); } @@ -310,7 +324,7 @@ public class Binder implements IBinder { */ public void dumpAsync(final FileDescriptor fd, final String[] args) { final FileOutputStream fout = new FileOutputStream(fd); - final PrintWriter pw = new PrintWriter(fout); + final PrintWriter pw = new FastPrintWriter(fout); Thread thr = new Thread("Binder.dumpAsync") { public void run() { try { @@ -384,17 +398,27 @@ public class Binder implements IBinder { // but all that does is rewind it, and we just got these from an IPC, // so we'll just call it directly. boolean res; + // Log any exceptions as warnings, don't silently suppress them. + // If the call was FLAG_ONEWAY then these exceptions disappear into the ether. try { res = onTransact(code, data, reply, flags); } catch (RemoteException e) { + if ((flags & FLAG_ONEWAY) != 0) { + Log.w(TAG, "Binder call failed.", e); + } reply.setDataPosition(0); reply.writeException(e); res = true; } catch (RuntimeException e) { + if ((flags & FLAG_ONEWAY) != 0) { + Log.w(TAG, "Caught a RuntimeException from the binder stub implementation.", e); + } reply.setDataPosition(0); reply.writeException(e); res = true; } catch (OutOfMemoryError e) { + // Unconditionally log this, since this is generally unrecoverable. + Log.e(TAG, "Caught an OutOfMemoryError from the binder stub implementation.", e); RuntimeException re = new RuntimeException("Out of memory", e); reply.setDataPosition(0); reply.writeException(re); @@ -442,7 +466,6 @@ final class BinderProxy implements IBinder { data.writeStringArray(args); try { transact(DUMP_TRANSACTION, data, reply, FLAG_ONEWAY); - reply.readException(); } finally { data.recycle(); reply.recycle(); |
