Skip to content

Commit

Permalink
Guard Android logs (flutter#8824)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored May 3, 2019
1 parent 8584da2 commit 7ce2666
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class FlutterJNI {

@UiThread
public static native String nativeGetObservatoryUri();

private Long nativePlatformViewId;
private FlutterRenderer.RenderSurface renderSurface;
private AccessibilityDelegate accessibilityDelegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.plugin.common;

import io.flutter.BuildConfig;

import android.support.annotation.Nullable;
import android.util.Log;

Expand All @@ -30,11 +32,15 @@ public void success(@Nullable Object result) {}
@Override
public void error(String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) {
String details = (errorDetails != null) ? " details: " + errorDetails : "";
Log.println(level, tag, errorMessage + details);
if (level >= Log.WARN || BuildConfig.DEBUG) {
Log.println(level, tag, errorMessage + details);
}
}

@Override
public void notImplemented() {
Log.println(level, tag, "method not implemented");
if (level >= Log.WARN || BuildConfig.DEBUG) {
Log.println(level, tag, "method not implemented");
}
}
}
22 changes: 12 additions & 10 deletions shell/platform/android/io/flutter/view/AccessibilityBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -1821,16 +1821,18 @@ private boolean didChangeLabel() {
}

private void log(@NonNull String indent, boolean recursive) {
Log.i(TAG,
indent + "SemanticsNode id=" + id + " label=" + label + " actions=" + actions
+ " flags=" + flags + "\n" + indent + " +-- textDirection="
+ textDirection + "\n" + indent + " +-- rect.ltrb=(" + left + ", "
+ top + ", " + right + ", " + bottom + ")\n" + indent
+ " +-- transform=" + Arrays.toString(transform) + "\n");
if (childrenInTraversalOrder != null && recursive) {
String childIndent = indent + " ";
for (SemanticsNode child : childrenInTraversalOrder) {
child.log(childIndent, recursive);
if (BuildConfig.DEBUG) {
Log.i(TAG,
indent + "SemanticsNode id=" + id + " label=" + label + " actions=" + actions
+ " flags=" + flags + "\n" + indent + " +-- textDirection="
+ textDirection + "\n" + indent + " +-- rect.ltrb=(" + left + ", "
+ top + ", " + right + ", " + bottom + ")\n" + indent
+ " +-- transform=" + Arrays.toString(transform) + "\n");
if (childrenInTraversalOrder != null && recursive) {
String childIndent = indent + " ";
for (SemanticsNode child : childrenInTraversalOrder) {
child.log(childIndent, recursive);
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion shell/platform/android/io/flutter/view/ResourceCleaner.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.os.Handler;
import android.util.Log;

import io.flutter.BuildConfig;

import java.io.File;
import java.io.FilenameFilter;

Expand All @@ -32,7 +34,9 @@ boolean hasFilesToDelete() {

@Override
protected Void doInBackground(Void... unused) {
Log.i(TAG, "Cleaning " + mFilesToDelete.length + " resources.");
if (BuildConfig.DEBUG) {
Log.i(TAG, "Cleaning " + mFilesToDelete.length + " resources.");
}
for (File file : mFilesToDelete) {
if (file.exists()) {
deleteRecursively(file);
Expand Down
18 changes: 12 additions & 6 deletions shell/platform/android/io/flutter/view/ResourceExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ private boolean extractAPK(File dataDir) {
OutputStream os = new FileOutputStream(output)) {
copy(is, os);
}

Log.i(TAG, "Extracted baseline resource " + resource);

if (BuildConfig.DEBUG) {
Log.i(TAG, "Extracted baseline resource " + resource);
}
} catch (FileNotFoundException fnfe) {
continue;

Expand Down Expand Up @@ -202,17 +202,23 @@ private String checkTimestamp(File dataDir) {
final String[] existingTimestamps = getExistingTimestamps(dataDir);

if (existingTimestamps == null) {
Log.i(TAG, "No extracted resources found");
if (BuildConfig.DEBUG) {
Log.i(TAG, "No extracted resources found");
}
return expectedTimestamp;
}

if (existingTimestamps.length == 1) {
Log.i(TAG, "Found extracted resources " + existingTimestamps[0]);
if (BuildConfig.DEBUG) {
Log.i(TAG, "Found extracted resources " + existingTimestamps[0]);
}
}

if (existingTimestamps.length != 1
|| !expectedTimestamp.equals(existingTimestamps[0])) {
Log.i(TAG, "Resource version mismatch " + expectedTimestamp);
if (BuildConfig.DEBUG) {
Log.i(TAG, "Resource version mismatch " + expectedTimestamp);
}
return expectedTimestamp;
}

Expand Down
2 changes: 2 additions & 0 deletions third_party/bsdiff/io/flutter/util/BSDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.util;

import io.flutter.BuildConfig;

import java.io.*;
import java.util.zip.GZIPInputStream;

Expand Down
48 changes: 2 additions & 46 deletions tools/android_lint/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
errorLine2=" ~~~~~~~~~">
<location
file="../../../flutter/shell/platform/android/io/flutter/view/ResourceCleaner.java"
line="22"
line="24"
column="19"/>
</issue>

Expand All @@ -129,54 +129,10 @@
errorLine2=" ~~~~~~~~~~~">
<location
file="../../../flutter/shell/platform/android/io/flutter/view/ResourceExtractor.java"
line="51"
line="52"
column="19"/>
</issue>

<issue
id="LogConditional"
message="The log call Log.i(...) should be conditional: surround with `if (Log.isLoggable(...))` or `if (BuildConfig.DEBUG) { ... }`"
errorLine1=" Log.i(TAG,"
errorLine2=" ^">
<location
file="../../../flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java"
line="1824"
column="13"/>
</issue>

<issue
id="LogConditional"
message="The log call Log.println(...) should be conditional: surround with `if (Log.isLoggable(...))` or `if (BuildConfig.DEBUG) { ... }`"
errorLine1=" Log.println(level, tag, errorMessage + details);"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="../../../flutter/shell/platform/android/io/flutter/plugin/common/ErrorLogResult.java"
line="33"
column="9"/>
</issue>

<issue
id="LogConditional"
message="The log call Log.i(...) should be conditional: surround with `if (Log.isLoggable(...))` or `if (BuildConfig.DEBUG) { ... }`"
errorLine1=" Log.i(TAG, &quot;Cleaning &quot; + mFilesToDelete.length + &quot; resources.&quot;);"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="../../../flutter/shell/platform/android/io/flutter/view/ResourceCleaner.java"
line="35"
column="13"/>
</issue>

<issue
id="LogConditional"
message="The log call Log.i(...) should be conditional: surround with `if (Log.isLoggable(...))` or `if (BuildConfig.DEBUG) { ... }`"
errorLine1=" Log.i(TAG, &quot;Extracted baseline resource &quot; + resource);"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="../../../flutter/shell/platform/android/io/flutter/view/ResourceExtractor.java"
line="168"
column="17"/>
</issue>

<issue
id="UseSparseArrays"
message="Use `new SparseArray&lt;SemanticsNode>(...)` instead for better performance"
Expand Down

0 comments on commit 7ce2666

Please sign in to comment.