From 8c84109b9fbbf473b225707a38261ff5f99d95fb Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Mon, 24 Jun 2013 13:46:13 -0700 Subject: Use FastPrintWriter... everywhere. One problem this turned up is, because FastPrintWriter does its own buffering, a lot of code that used to use PrintWriter would fail -- if it pointed to a StringWriter, there was no buffering, so it could just immediately get the result. Now you need to first flush the FastPrintWriter. Also added some new constructors to specify the size of buffer that FastPrintWriter should use. Change-Id: If48cd28d7be0b6b3278bbb69a8357e6ce88cf54a --- core/java/android/app/ActivityManager.java | 11 +++++++---- core/java/android/app/ActivityThread.java | 14 +++++++++----- core/java/android/app/ApplicationErrorReport.java | 5 ++++- core/java/android/app/BackStackRecord.java | 7 +++++-- core/java/android/app/FragmentManager.java | 9 +++++++-- core/java/android/os/Debug.java | 5 +++-- core/java/android/os/StrictMode.java | 5 ++++- core/java/android/util/Log.java | 4 +++- core/java/android/view/WindowManagerGlobal.java | 3 ++- 9 files changed, 44 insertions(+), 19 deletions(-) (limited to 'core/java/android') diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 62ed697..d65a6a2 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -21,6 +21,7 @@ import android.os.IBinder; import com.android.internal.app.IUsageStats; import com.android.internal.os.PkgUsageStats; import com.android.internal.os.TransferPipe; +import com.android.internal.util.FastPrintWriter; import com.android.internal.util.MemInfoReader; import android.content.ComponentName; @@ -2206,12 +2207,14 @@ public class ActivityManager { */ public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) { FileOutputStream fout = new FileOutputStream(fd); - PrintWriter pw = new PrintWriter(fout); - dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] { "package", packageName}); + PrintWriter pw = new FastPrintWriter(fout); + dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] { "package", packageName }); pw.println(); - dumpService(pw, fd, "package", new String[] { packageName}); + dumpService(pw, fd, "procstats", new String[] { packageName }); pw.println(); - dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName}); + dumpService(pw, fd, "package", new String[] { packageName }); + pw.println(); + dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName }); pw.flush(); } diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 066775d..bf89fa6 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -93,6 +93,7 @@ import android.security.AndroidKeyStoreProvider; import com.android.internal.os.BinderInternal; import com.android.internal.os.RuntimeInit; import com.android.internal.os.SamplingProfilerIntegration; +import com.android.internal.util.FastPrintWriter; import com.android.internal.util.Objects; import com.android.org.conscrypt.OpenSSLSocketImpl; @@ -899,7 +900,7 @@ public final class ActivityThread { public Debug.MemoryInfo dumpMemInfo(FileDescriptor fd, boolean checkin, boolean dumpInfo, boolean dumpDalvik, String[] args) { FileOutputStream fout = new FileOutputStream(fd); - PrintWriter pw = new PrintWriter(fout); + PrintWriter pw = new FastPrintWriter(fout); try { return dumpMemInfo(pw, checkin, dumpInfo, dumpDalvik); } finally { @@ -1176,7 +1177,7 @@ public final class ActivityThread { @Override public void dumpDbInfo(FileDescriptor fd, String[] args) { - PrintWriter pw = new PrintWriter(new FileOutputStream(fd)); + PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd)); PrintWriterPrinter printer = new PrintWriterPrinter(pw); SQLiteDebug.dump(printer, args); pw.flush(); @@ -2730,7 +2731,8 @@ public final class ActivityThread { try { Service s = mServices.get(info.token); if (s != null) { - PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor())); + PrintWriter pw = new FastPrintWriter(new FileOutputStream( + info.fd.getFileDescriptor())); s.dump(info.fd.getFileDescriptor(), pw, info.args); pw.flush(); } @@ -2745,7 +2747,8 @@ public final class ActivityThread { try { ActivityClientRecord r = mActivities.get(info.token); if (r != null && r.activity != null) { - PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor())); + PrintWriter pw = new FastPrintWriter(new FileOutputStream( + info.fd.getFileDescriptor())); r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); pw.flush(); } @@ -2760,7 +2763,8 @@ public final class ActivityThread { try { ProviderClientRecord r = mLocalProviders.get(info.token); if (r != null && r.mLocalProvider != null) { - PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor())); + PrintWriter pw = new FastPrintWriter(new FileOutputStream( + info.fd.getFileDescriptor())); r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); pw.flush(); } diff --git a/core/java/android/app/ApplicationErrorReport.java b/core/java/android/app/ApplicationErrorReport.java index 954476d..c117486 100644 --- a/core/java/android/app/ApplicationErrorReport.java +++ b/core/java/android/app/ApplicationErrorReport.java @@ -28,6 +28,7 @@ import android.os.SystemClock; import android.os.SystemProperties; import android.provider.Settings; import android.util.Printer; +import com.android.internal.util.FastPrintWriter; import java.io.PrintWriter; import java.io.StringWriter; @@ -327,7 +328,9 @@ public class ApplicationErrorReport implements Parcelable { */ public CrashInfo(Throwable tr) { StringWriter sw = new StringWriter(); - tr.printStackTrace(new PrintWriter(sw)); + PrintWriter pw = new FastPrintWriter(sw, false, 256); + tr.printStackTrace(pw); + pw.flush(); stackTrace = sw.toString(); exceptionMessage = tr.getMessage(); diff --git a/core/java/android/app/BackStackRecord.java b/core/java/android/app/BackStackRecord.java index 1b1d341..89ee145 100644 --- a/core/java/android/app/BackStackRecord.java +++ b/core/java/android/app/BackStackRecord.java @@ -21,6 +21,7 @@ import android.os.Parcelable; import android.text.TextUtils; import android.util.Log; import android.util.LogWriter; +import com.android.internal.util.FastPrintWriter; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -583,8 +584,9 @@ final class BackStackRecord extends FragmentTransaction implements if (FragmentManagerImpl.DEBUG) { Log.v(TAG, "Commit: " + this); LogWriter logw = new LogWriter(Log.VERBOSE, TAG); - PrintWriter pw = new PrintWriter(logw); + PrintWriter pw = new FastPrintWriter(logw, false, 1024); dump(" ", null, pw, null); + pw.flush(); } mCommitted = true; if (mAddToBackStack) { @@ -691,8 +693,9 @@ final class BackStackRecord extends FragmentTransaction implements if (FragmentManagerImpl.DEBUG) { Log.v(TAG, "popFromBackStack: " + this); LogWriter logw = new LogWriter(Log.VERBOSE, TAG); - PrintWriter pw = new PrintWriter(logw); + PrintWriter pw = new FastPrintWriter(logw, false, 1024); dump(" ", null, pw, null); + pw.flush(); } bumpBackStackNesting(-1); diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index 72c9156..7358f73 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -36,6 +36,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import com.android.internal.util.FastPrintWriter; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -445,12 +446,13 @@ final class FragmentManagerImpl extends FragmentManager { private void throwException(RuntimeException ex) { Log.e(TAG, ex.getMessage()); LogWriter logw = new LogWriter(Log.ERROR, TAG); - PrintWriter pw = new PrintWriter(logw); + PrintWriter pw = new FastPrintWriter(logw, false, 1024); if (mActivity != null) { Log.e(TAG, "Activity state:"); try { mActivity.dump(" ", null, pw, new String[] { }); } catch (Exception e) { + pw.flush(); Log.e(TAG, "Failed dumping state", e); } } else { @@ -458,9 +460,11 @@ final class FragmentManagerImpl extends FragmentManager { try { dump(" ", null, pw, new String[] { }); } catch (Exception e) { + pw.flush(); Log.e(TAG, "Failed dumping state", e); } } + pw.flush(); throw ex; } @@ -1806,8 +1810,9 @@ final class FragmentManagerImpl extends FragmentManager { Log.v(TAG, "restoreAllState: back stack #" + i + " (index " + bse.mIndex + "): " + bse); LogWriter logw = new LogWriter(Log.VERBOSE, TAG); - PrintWriter pw = new PrintWriter(logw); + PrintWriter pw = new FastPrintWriter(logw, false, 1024); bse.dump(" ", pw, false); + pw.flush(); } mBackStack.add(bse); if (bse.mIndex >= 0) { diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java index 362ae29..c5f473e 100644 --- a/core/java/android/os/Debug.java +++ b/core/java/android/os/Debug.java @@ -16,6 +16,7 @@ package android.os; +import com.android.internal.util.FastPrintWriter; import com.android.internal.util.TypedProperties; import android.util.Log; @@ -476,7 +477,7 @@ public final class Debug PrintWriter outStream = null; try { FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE); - outStream = new PrintWriter(new OutputStreamWriter(fos)); + outStream = new FastPrintWriter(fos); outStream.println("1"); } catch (Exception e) { } finally { @@ -504,7 +505,7 @@ public final class Debug PrintWriter outStream = null; try { FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE); - outStream = new PrintWriter(new OutputStreamWriter(fos)); + outStream = new FastPrintWriter(fos); outStream.println("0"); } catch (Exception e) { // We could print an error message here but we probably want diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java index a9abdc5..d794ca6 100644 --- a/core/java/android/os/StrictMode.java +++ b/core/java/android/os/StrictMode.java @@ -32,6 +32,7 @@ import android.view.IWindowManager; import com.android.internal.os.RuntimeInit; +import com.android.internal.util.FastPrintWriter; import dalvik.system.BlockGuard; import dalvik.system.CloseGuard; import dalvik.system.VMDebug; @@ -1700,7 +1701,9 @@ public final class StrictMode { /* package */ static void readAndHandleBinderCallViolations(Parcel p) { // Our own stack trace to append StringWriter sw = new StringWriter(); - new LogStackTrace().printStackTrace(new PrintWriter(sw)); + PrintWriter pw = new FastPrintWriter(sw, false, 256); + new LogStackTrace().printStackTrace(pw); + pw.flush(); String ourStack = sw.toString(); int policyMask = getThreadPolicyMask(); diff --git a/core/java/android/util/Log.java b/core/java/android/util/Log.java index 1c3709f..6a6f027 100644 --- a/core/java/android/util/Log.java +++ b/core/java/android/util/Log.java @@ -17,6 +17,7 @@ package android.util; import com.android.internal.os.RuntimeInit; +import com.android.internal.util.FastPrintWriter; import java.io.PrintWriter; import java.io.StringWriter; @@ -315,8 +316,9 @@ public final class Log { } StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); + PrintWriter pw = new FastPrintWriter(sw, false, 256); tr.printStackTrace(pw); + pw.flush(); return sw.toString(); } diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java index 7cda01c..0eb6d63 100644 --- a/core/java/android/view/WindowManagerGlobal.java +++ b/core/java/android/view/WindowManagerGlobal.java @@ -29,6 +29,7 @@ import android.util.AndroidRuntimeException; import android.util.ArraySet; import android.util.Log; import android.view.inputmethod.InputMethodManager; +import com.android.internal.util.FastPrintWriter; import java.io.FileDescriptor; import java.io.FileOutputStream; @@ -414,7 +415,7 @@ public final class WindowManagerGlobal { public void dumpGfxInfo(FileDescriptor fd) { FileOutputStream fout = new FileOutputStream(fd); - PrintWriter pw = new PrintWriter(fout); + PrintWriter pw = new FastPrintWriter(fout); try { synchronized (mLock) { final int count = mViews.size(); -- cgit v1.1