From 9b78db41a0f2230001535b3ca33a3ebc31e6c6c1 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 1 Jun 2016 18:19:24 -0700 Subject: [PATCH] Work on issue #29042642: Watchdog going off Have FastPrintWriter note all cases where an exception is thrown, and stop trying to push more data into the output stream when this happens. Change-Id: I51a1eeb26578f02b2a6f45ef7bc2513dfde702a2 --- .../internal/util/FastPrintWriter.java | 51 ++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/core/java/com/android/internal/util/FastPrintWriter.java b/core/java/com/android/internal/util/FastPrintWriter.java index c74fea05b6d6c..e46e6b026fd90 100644 --- a/core/java/com/android/internal/util/FastPrintWriter.java +++ b/core/java/com/android/internal/util/FastPrintWriter.java @@ -1,5 +1,6 @@ package com.android.internal.util; +import android.util.Log; import android.util.Printer; import java.io.IOException; @@ -328,11 +329,13 @@ public class FastPrintWriter extends PrintWriter { } private void flushBytesLocked() throws IOException { - int position; - if ((position = mBytes.position()) > 0) { - mBytes.flip(); - mOutputStream.write(mBytes.array(), 0, position); - mBytes.clear(); + if (!mIoError) { + int position; + if ((position = mBytes.position()) > 0) { + mBytes.flip(); + mOutputStream.write(mBytes.array(), 0, position); + mBytes.clear(); + } } } @@ -352,11 +355,15 @@ public class FastPrintWriter extends PrintWriter { } break; } - flushBytesLocked(); - mOutputStream.flush(); + if (!mIoError) { + flushBytesLocked(); + mOutputStream.flush(); + } } else if (mWriter != null) { - mWriter.write(mText, 0, mPos); - mWriter.flush(); + if (!mIoError) { + mWriter.write(mText, 0, mPos); + mWriter.flush(); + } } else { int nonEolOff = 0; final int sepLen = mSeparator.length(); @@ -385,12 +392,15 @@ public class FastPrintWriter extends PrintWriter { synchronized (lock) { try { flushLocked(); - if (mOutputStream != null) { - mOutputStream.flush(); - } else if (mWriter != null) { - mWriter.flush(); + if (!mIoError) { + if (mOutputStream != null) { + mOutputStream.flush(); + } else if (mWriter != null) { + mWriter.flush(); + } } } catch (IOException e) { + Log.w("FastPrintWriter", "Write failure", e); setError(); } } @@ -407,6 +417,7 @@ public class FastPrintWriter extends PrintWriter { mWriter.close(); } } catch (IOException e) { + Log.w("FastPrintWriter", "Write failure", e); setError(); } } @@ -425,6 +436,8 @@ public class FastPrintWriter extends PrintWriter { try { appendLocked(charArray, 0, charArray.length); } catch (IOException e) { + Log.w("FastPrintWriter", "Write failure", e); + setError(); } } } @@ -442,6 +455,8 @@ public class FastPrintWriter extends PrintWriter { try { appendLocked(ch); } catch (IOException e) { + Log.w("FastPrintWriter", "Write failure", e); + setError(); } } } @@ -465,6 +480,7 @@ public class FastPrintWriter extends PrintWriter { try { appendLocked(str, 0, str.length()); } catch (IOException e) { + Log.w("FastPrintWriter", "Write failure", e); setError(); } } @@ -500,6 +516,7 @@ public class FastPrintWriter extends PrintWriter { flushLocked(); } } catch (IOException e) { + Log.w("FastPrintWriter", "Write failure", e); setError(); } } @@ -564,6 +581,8 @@ public class FastPrintWriter extends PrintWriter { try { appendLocked(buf, offset, count); } catch (IOException e) { + Log.w("FastPrintWriter", "Write failure", e); + setError(); } } } @@ -584,6 +603,8 @@ public class FastPrintWriter extends PrintWriter { try { appendLocked((char) oneChar); } catch (IOException e) { + Log.w("FastPrintWriter", "Write failure", e); + setError(); } } } @@ -600,6 +621,8 @@ public class FastPrintWriter extends PrintWriter { try { appendLocked(str, 0, str.length()); } catch (IOException e) { + Log.w("FastPrintWriter", "Write failure", e); + setError(); } } } @@ -624,6 +647,8 @@ public class FastPrintWriter extends PrintWriter { try { appendLocked(str, offset, count); } catch (IOException e) { + Log.w("FastPrintWriter", "Write failure", e); + setError(); } } }