Move LogWriter to only consuming artifact

Deprecate and prevent new users of the version in core.

Bug: 112188798
Test: :fra:fra:conCh
Change-Id: I19600866e26acb2093c38d07cabbef3fac5f1cf0
diff --git a/core/core/api/restricted_1.3.0-alpha01.txt b/core/core/api/restricted_1.3.0-alpha01.txt
index 9350f1d..7296a86 100644
--- a/core/core/api/restricted_1.3.0-alpha01.txt
+++ b/core/core/api/restricted_1.3.0-alpha01.txt
@@ -1932,11 +1932,11 @@
     method public static void buildShortClassTag(Object!, StringBuilder!);
   }
 
-  @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public class LogWriter extends java.io.Writer {
-    ctor public LogWriter(String!);
-    method public void close();
-    method public void flush();
-    method public void write(char[]!, int, int);
+  @Deprecated @RestrictTo(androidx.annotation.RestrictTo.Scope.TESTS) public class LogWriter extends java.io.Writer {
+    ctor @Deprecated public LogWriter(String!);
+    method @Deprecated public void close();
+    method @Deprecated public void flush();
+    method @Deprecated public void write(char[]!, int, int);
   }
 
   public class ObjectsCompat {
diff --git a/core/core/api/restricted_current.txt b/core/core/api/restricted_current.txt
index 9350f1d..7296a86 100644
--- a/core/core/api/restricted_current.txt
+++ b/core/core/api/restricted_current.txt
@@ -1932,11 +1932,11 @@
     method public static void buildShortClassTag(Object!, StringBuilder!);
   }
 
-  @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public class LogWriter extends java.io.Writer {
-    ctor public LogWriter(String!);
-    method public void close();
-    method public void flush();
-    method public void write(char[]!, int, int);
+  @Deprecated @RestrictTo(androidx.annotation.RestrictTo.Scope.TESTS) public class LogWriter extends java.io.Writer {
+    ctor @Deprecated public LogWriter(String!);
+    method @Deprecated public void close();
+    method @Deprecated public void flush();
+    method @Deprecated public void write(char[]!, int, int);
   }
 
   public class ObjectsCompat {
diff --git a/core/core/src/main/java/androidx/core/util/LogWriter.java b/core/core/src/main/java/androidx/core/util/LogWriter.java
index 4359659..bb3bcd2 100644
--- a/core/core/src/main/java/androidx/core/util/LogWriter.java
+++ b/core/core/src/main/java/androidx/core/util/LogWriter.java
@@ -16,7 +16,7 @@
 
 package androidx.core.util;
 
-import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX;
+import static androidx.annotation.RestrictTo.Scope.TESTS;
 
 import android.util.Log;
 
@@ -25,11 +25,11 @@
 import java.io.Writer;
 
 /**
- * Helper for accessing features in {@link android.util.LogWriter}.
- *
  * @hide
+ * @deprecated Copied to use sites. Do not use.
  */
-@RestrictTo(LIBRARY_GROUP_PREFIX)
+@RestrictTo(TESTS) // Prevent new users.
+@Deprecated
 public class LogWriter extends Writer {
     private final String mTag;
     private StringBuilder mBuilder = new StringBuilder(128);
diff --git a/fragment/fragment/src/main/java/androidx/fragment/app/BackStackRecord.java b/fragment/fragment/src/main/java/androidx/fragment/app/BackStackRecord.java
index 3c35d63..39c2cd7 100644
--- a/fragment/fragment/src/main/java/androidx/fragment/app/BackStackRecord.java
+++ b/fragment/fragment/src/main/java/androidx/fragment/app/BackStackRecord.java
@@ -20,7 +20,6 @@
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
-import androidx.core.util.LogWriter;
 import androidx.lifecycle.Lifecycle;
 
 import java.io.PrintWriter;
diff --git a/fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java b/fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
index 9b29be4..6eb46f5 100644
--- a/fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
+++ b/fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
@@ -46,7 +46,6 @@
 import androidx.annotation.StringRes;
 import androidx.collection.ArraySet;
 import androidx.core.os.CancellationSignal;
-import androidx.core.util.LogWriter;
 import androidx.fragment.R;
 import androidx.lifecycle.Lifecycle;
 import androidx.lifecycle.LifecycleOwner;
diff --git a/fragment/fragment/src/main/java/androidx/fragment/app/LogWriter.java b/fragment/fragment/src/main/java/androidx/fragment/app/LogWriter.java
new file mode 100644
index 0000000..91418cb
--- /dev/null
+++ b/fragment/fragment/src/main/java/androidx/fragment/app/LogWriter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.fragment.app;
+
+import android.util.Log;
+
+import java.io.Writer;
+
+final class LogWriter extends Writer {
+    private final String mTag;
+    private StringBuilder mBuilder = new StringBuilder(128);
+
+    /**
+     * Create a new Writer that sends to the log with the given tag.
+     */
+    LogWriter(String tag) {
+        mTag = tag;
+    }
+
+    @Override public void close() {
+        flushBuilder();
+    }
+
+    @Override public void flush() {
+        flushBuilder();
+    }
+
+    @Override public void write(char[] buf, int offset, int count) {
+        for(int i = 0; i < count; i++) {
+            char c = buf[offset + i];
+            if ( c == '\n') {
+                flushBuilder();
+            }
+            else {
+                mBuilder.append(c);
+            }
+        }
+    }
+
+    private void flushBuilder() {
+        if (mBuilder.length() > 0) {
+            Log.d(mTag, mBuilder.toString());
+            mBuilder.delete(0, mBuilder.length());
+        }
+    }
+}
diff --git a/jetifier/jetifier/migration.config b/jetifier/jetifier/migration.config
index ee45838..6496fe6 100644
--- a/jetifier/jetifier/migration.config
+++ b/jetifier/jetifier/migration.config
@@ -425,6 +425,10 @@
       "to": "ignore"
     },
     {
+      "from": "androidx/fragment/app/LogWriter(.*)",
+      "to": "ignore"
+    },
+    {
       "from": "androidx/gridlayout/widget/GridLayout(.*)",
       "to": "ignore"
     },