From d67a843ba6c95130fac47ddc6a3873bce073c750 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 2 May 2019 14:51:43 -0700 Subject: [PATCH 1/8] remove asserts --- shell/platform/android/BUILD.gn | 104 ++++++++++-------- .../flutter/embedding/engine/FlutterJNI.java | 2 +- .../plugin/common/BasicMessageChannel.java | 15 ++- .../flutter/plugin/common/EventChannel.java | 15 ++- .../plugin/common/FlutterException.java | 6 +- .../io/flutter/plugin/common/MethodCall.java | 6 +- .../flutter/plugin/common/MethodChannel.java | 17 ++- .../plugin/common/StandardMessageCodec.java | 10 +- .../io/flutter/view/AccessibilityBridge.java | 53 +++++++-- .../io/flutter/view/ResourceExtractor.java | 7 +- tools/gen_android_buildconfig.py | 43 ++++++++ 11 files changed, 204 insertions(+), 74 deletions(-) create mode 100644 tools/gen_android_buildconfig.py diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 4dad12890cf81..a8fe62830fca1 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -3,7 +3,6 @@ # found in the LICENSE file. import("//build/config/android/config.gni") -import("//build/config/android/rules.gni") import("$flutter_root/common/config.gni") import("$flutter_root/shell/config.gni") import("$flutter_root/shell/gpu/gpu.gni") @@ -90,10 +89,33 @@ shared_library("flutter_shell_native") { ldflags = [ "-Wl,--version-script=" + rebase_path("android_exports.lst") ] } -java_library("flutter_shell_java") { - supports_android = true +action("gen_android_build_config_java") { + script = "$flutter_root/tools/gen_android_buildconfig.py" - java_files = [ + build_config_java = "$target_gen_dir/io/flutter/BuildConfig.java" + + outputs = [ + build_config_java, + ] + + args = [ + "--out", + rebase_path(build_config_java), + "--runtime-mode", + flutter_runtime_mode, + ] + + build_config = [] + assert(build_config == [] || true) +} + +action("flutter_shell_java") { + script = "//build/android/gyp/javac.py" + depfile = "$target_gen_dir/$target_name.d" + + jar_path = "$root_out_dir/flutter_java.jar" + + sources = [ "io/flutter/app/FlutterActivity.java", "io/flutter/app/FlutterActivityDelegate.java", "io/flutter/app/FlutterActivityEvents.java", @@ -171,56 +193,46 @@ java_library("flutter_shell_java") { "io/flutter/view/VsyncWaiter.java", ] - java_files += + sources += get_target_outputs(":gen_android_build_config_java") + + sources += [ "$flutter_root/third_party/bsdiff/io/flutter/util/BSDiff.java" ] - deps = [ - ":android_arch_lifecycle_common", - ":android_arch_lifecycle_viewmodel", - ":android_support_annotations", - ":android_support_compat", - ":android_support_fragment", - ":android_support_v13", + android_support_jars = [ + "//third_party/android_support/android_support_v13.jar", + "//third_party/android_support/android_support_compat.jar", + "//third_party/android_support/android_support_annotations.jar", + "//third_party/android_support/android_support_fragment.jar", + "//third_party/android_support/android_arch_lifecycle_common.jar", + "//third_party/android_support/android_arch_lifecycle_viewmodel.jar", ] - jar_path = "$root_out_dir/flutter_java.jar" -} - -java_prebuilt("android_support_v13") { - supports_android = true - - jar_path = "//third_party/android_support/android_support_v13.jar" -} - -java_prebuilt("android_support_compat") { - supports_android = true - - jar_path = "//third_party/android_support/android_support_compat.jar" -} - -java_prebuilt("android_support_annotations") { - supports_android = true - - jar_path = "//third_party/android_support/android_support_annotations.jar" -} - -java_prebuilt("android_support_fragment") { - supports_android = true - - jar_path = "//third_party/android_support/android_support_fragment.jar" -} + outputs = [ + depfile, + jar_path, + jar_path + ".md5.stamp", + ] + inputs = [ android_sdk_jar ] + inputs += android_support_jars -java_prebuilt("android_arch_lifecycle_common") { - supports_android = true + _rebased_jar_path = rebase_path(jar_path, root_build_dir) + _rebased_depfile = rebase_path(depfile, root_build_dir) + _rebased_android_sdk_jar = rebase_path(android_sdk_jar, root_build_dir) + _rebased_classpath = [ _rebased_android_sdk_jar ] + rebase_path(android_support_jars, root_build_dir) - jar_path = "//third_party/android_support/android_arch_lifecycle_common.jar" -} + args = [ + "--depfile=$_rebased_depfile", + "--jar-path=$_rebased_jar_path", + "--classpath=$_rebased_classpath", + # "--java-srcjars=$_rebased_java_srcjars", + "--bootclasspath=$_rebased_android_sdk_jar", + ] -java_prebuilt("android_arch_lifecycle_viewmodel") { - supports_android = true + args += rebase_path(sources, root_build_dir) - jar_path = - "//third_party/android_support/android_arch_lifecycle_viewmodel.jar" + deps = [ + ":gen_android_build_config_java", + ] } action("icudtl_object") { diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 66e98087c4e5c..a4fb16e88ce5a 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -95,7 +95,7 @@ public class FlutterJNI { @UiThread public static native String nativeGetObservatoryUri(); - + private Long nativePlatformViewId; private FlutterRenderer.RenderSurface renderSurface; private AccessibilityDelegate accessibilityDelegate; diff --git a/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java b/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java index 74a193880eb31..1014abfd4e9a9 100644 --- a/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java +++ b/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java @@ -9,6 +9,7 @@ import io.flutter.plugin.common.BinaryMessenger.BinaryReply; import io.flutter.plugin.common.BinaryMessenger.BinaryMessageHandler; +import io.flutter.BuildConfig; /** * A named channel for communicating with the Flutter application using basic, asynchronous message passing. @@ -39,9 +40,17 @@ public final class BasicMessageChannel { * @param codec a {@link MessageCodec}. */ public BasicMessageChannel(BinaryMessenger messenger, String name, MessageCodec codec) { - assert messenger != null; - assert name != null; - assert codec != null; + if (BuildConfig.DEBUG) { + if (messenger == null) { + throw new AssertionError("Parameter messenger must not be null."); + } + if (name == null) { + throw new AssertionError("Parameter name must not be null."); + } + if (codec == null) { + throw new AssertionError("Parameter codec must not be null."); + } + } this.messenger = messenger; this.name = name; this.codec = codec; diff --git a/shell/platform/android/io/flutter/plugin/common/EventChannel.java b/shell/platform/android/io/flutter/plugin/common/EventChannel.java index 57443a0aa1816..110c4e75d01e9 100644 --- a/shell/platform/android/io/flutter/plugin/common/EventChannel.java +++ b/shell/platform/android/io/flutter/plugin/common/EventChannel.java @@ -7,6 +7,7 @@ import android.util.Log; import io.flutter.plugin.common.BinaryMessenger.BinaryMessageHandler; import io.flutter.plugin.common.BinaryMessenger.BinaryReply; +import io.flutter.BuildConfig; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; @@ -55,9 +56,17 @@ public EventChannel(BinaryMessenger messenger, String name) { * @param codec a {@link MessageCodec}. */ public EventChannel(BinaryMessenger messenger, String name, MethodCodec codec) { - assert messenger != null; - assert name != null; - assert codec != null; + if (BuildConfig.DEBUG) { + if (messenger == null) { + throw new AssertionError("Parameter messenger must not be null."); + } + if (name == null) { + throw new AssertionError("Parameter name must not be null."); + } + if (codec == null) { + throw new AssertionError("Parameter codec must not be null."); + } + } this.messenger = messenger; this.name = name; this.codec = codec; diff --git a/shell/platform/android/io/flutter/plugin/common/FlutterException.java b/shell/platform/android/io/flutter/plugin/common/FlutterException.java index 61eb12c13c11b..5b643c7561e21 100644 --- a/shell/platform/android/io/flutter/plugin/common/FlutterException.java +++ b/shell/platform/android/io/flutter/plugin/common/FlutterException.java @@ -4,6 +4,8 @@ package io.flutter.plugin.common; +import io.flutter.BuildConfig; + /** * Thrown to indicate that a Flutter method invocation failed on the Flutter side. */ @@ -13,7 +15,9 @@ public class FlutterException extends RuntimeException { FlutterException(String code, String message, Object details) { super(message); - assert code != null; + if (BuildConfig.DEBUG && code == null) { + throw new AssertionError("Parameter code must not be null."); + } this.code = code; this.details = details; } diff --git a/shell/platform/android/io/flutter/plugin/common/MethodCall.java b/shell/platform/android/io/flutter/plugin/common/MethodCall.java index 9206ba5ecee25..376576d181f3c 100644 --- a/shell/platform/android/io/flutter/plugin/common/MethodCall.java +++ b/shell/platform/android/io/flutter/plugin/common/MethodCall.java @@ -8,6 +8,8 @@ import java.util.Map; import org.json.JSONObject; +import io.flutter.BuildConfig; + /** * Command object representing a method call on a {@link MethodChannel}. */ @@ -33,7 +35,9 @@ public final class MethodCall { * @param arguments the arguments, a value supported by the channel's message codec. */ public MethodCall(String method, Object arguments) { - assert method != null; + if (BuildConfig.DEBUG && method == null) { + throw new AssertionError("Parameter method must not be null."); + } this.method = method; this.arguments = arguments; } diff --git a/shell/platform/android/io/flutter/plugin/common/MethodChannel.java b/shell/platform/android/io/flutter/plugin/common/MethodChannel.java index 9f725e7bdf545..fe4bf38540a11 100644 --- a/shell/platform/android/io/flutter/plugin/common/MethodChannel.java +++ b/shell/platform/android/io/flutter/plugin/common/MethodChannel.java @@ -7,8 +7,11 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; + import io.flutter.plugin.common.BinaryMessenger.BinaryMessageHandler; import io.flutter.plugin.common.BinaryMessenger.BinaryReply; +import io.flutter.BuildConfig; + import java.nio.ByteBuffer; /** @@ -53,9 +56,17 @@ public MethodChannel(BinaryMessenger messenger, String name) { * @param codec a {@link MessageCodec}. */ public MethodChannel(BinaryMessenger messenger, String name, MethodCodec codec) { - assert messenger != null; - assert name != null; - assert codec != null; + if (BuildConfig.DEBUG) { + if (messenger == null) { + throw new AssertionError("Parameter messenger must not be null."); + } + if (name == null) { + throw new AssertionError("Parameter name must not be null."); + } + if (codec == null) { + throw new AssertionError("Parameter codec must not be null."); + } + } this.messenger = messenger; this.name = name; this.codec = codec; diff --git a/shell/platform/android/io/flutter/plugin/common/StandardMessageCodec.java b/shell/platform/android/io/flutter/plugin/common/StandardMessageCodec.java index c22ea07a9aa87..37bf94163299a 100644 --- a/shell/platform/android/io/flutter/plugin/common/StandardMessageCodec.java +++ b/shell/platform/android/io/flutter/plugin/common/StandardMessageCodec.java @@ -4,6 +4,10 @@ package io.flutter.plugin.common; +import android.util.Log; + +import io.flutter.BuildConfig; + import java.io.ByteArrayOutputStream; import java.math.BigInteger; import java.nio.ByteBuffer; @@ -15,8 +19,6 @@ import java.util.Map; import java.util.Map.Entry; -import android.util.Log; - /** * MessageCodec using the Flutter standard binary encoding. * @@ -109,7 +111,9 @@ public Object decodeMessage(ByteBuffer message) { * Uses an expanding code of 1 to 5 bytes to optimize for small values. */ protected static final void writeSize(ByteArrayOutputStream stream, int value) { - assert 0 <= value; + if (BuildConfig.DEBUG && 0 > value) { + throw new AssertionError("Attempted to write a negative size."); + } if (value < 254) { stream.write(value); } else if (value <= 0xffff) { diff --git a/shell/platform/android/io/flutter/view/AccessibilityBridge.java b/shell/platform/android/io/flutter/view/AccessibilityBridge.java index a589f54d4ca5d..0ad3321adc2e6 100644 --- a/shell/platform/android/io/flutter/view/AccessibilityBridge.java +++ b/shell/platform/android/io/flutter/view/AccessibilityBridge.java @@ -28,6 +28,7 @@ import io.flutter.embedding.engine.systemchannels.AccessibilityChannel; import io.flutter.plugin.platform.PlatformViewsAccessibilityDelegate; +import io.flutter.BuildConfig; import io.flutter.util.Predicate; import java.nio.ByteBuffer; @@ -594,10 +595,14 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { } if (semanticsNode.parent != null) { - assert semanticsNode.id > ROOT_NODE_ID; + if (BuildConfig.DEBUG && semanticsNode.id <= ROOT_NODE_ID) { + throw new AssertionError("Semantics node id is not > ROOT_NODE_ID."); + } result.setParent(rootAccessibilityView, semanticsNode.parent.id); } else { - assert semanticsNode.id == ROOT_NODE_ID; + if (BuildConfig.DEBUG && semanticsNode.id != ROOT_NODE_ID) { + throw new AssertionError("Semantics node id does not equal ROOT_NODE_ID."); + } result.setParent(rootAccessibilityView); } @@ -706,7 +711,9 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { boolean hasCheckedState = semanticsNode.hasFlag(Flag.HAS_CHECKED_STATE); boolean hasToggledState = semanticsNode.hasFlag(Flag.HAS_TOGGLED_STATE); - assert !(hasCheckedState && hasToggledState); + if (BuildConfig.DEBUG && (hasCheckedState && hasToggledState)) { + throw new AssertionError("Expected semanticsNode to have checked state and toggled state."); + } result.setCheckable(hasCheckedState || hasToggledState); if (hasCheckedState) { result.setChecked(semanticsNode.hasFlag(Flag.IS_CHECKED)); @@ -1055,7 +1062,9 @@ public AccessibilityNodeInfo findFocus(int focus) { * Returns the {@link SemanticsNode} at the root of Flutter's semantics tree. */ private SemanticsNode getRootSemanticsNode() { - assert flutterSemanticsTree.containsKey(0); + if (BuildConfig.DEBUG && !flutterSemanticsTree.containsKey(0)) { + throw new AssertionError("Attempted to getRootSemanticsNode without a root sematnics node."); + } return flutterSemanticsTree.get(0); } @@ -1470,7 +1479,9 @@ private void createAndSendWindowChangeEvent(@NonNull SemanticsNode route) { * invoked to create an {@link AccessibilityEvent} for the {@link #rootAccessibilityView}. */ private AccessibilityEvent obtainAccessibilityEvent(int virtualViewId, int eventType) { - assert virtualViewId != ROOT_NODE_ID; + if (BuildConfig.DEBUG && virtualViewId == ROOT_NODE_ID) { + throw new AssertionError("VirtualView node must not be the root node."); + } AccessibilityEvent event = AccessibilityEvent.obtain(eventType); event.setPackageName(rootAccessibilityView.getContext().getPackageName()); event.setSource(rootAccessibilityView, virtualViewId); @@ -1482,8 +1493,14 @@ private AccessibilityEvent obtainAccessibilityEvent(int virtualViewId, int event * semantics tree. */ private void willRemoveSemanticsNode(SemanticsNode semanticsNodeToBeRemoved) { - assert flutterSemanticsTree.containsKey(semanticsNodeToBeRemoved.id); - assert flutterSemanticsTree.get(semanticsNodeToBeRemoved.id) == semanticsNodeToBeRemoved; + if (BuildConfig.DEBUG) { + if (!flutterSemanticsTree.containsKey(semanticsNodeToBeRemoved.id)) { + throw new AssertionError("Attempted to remove a node that is not in the tree."); + } + if (flutterSemanticsTree.get(semanticsNodeToBeRemoved.id) != semanticsNodeToBeRemoved) { + throw new AssertionError("Flutter semantics tree failed to get expected node when searching by id."); + } + } // TODO(mattcarroll): should parent be set to "null" here? Changing the parent seems like the // behavior of a method called "removeSemanticsNode()". The same is true // for null'ing accessibilityFocusedSemanticsNode, inputFocusedSemanticsNode, @@ -1779,7 +1796,9 @@ private boolean hasFlag(@NonNull Flag flag) { } private boolean hadFlag(@NonNull Flag flag) { - assert hadPreviousConfig; + if (BuildConfig.DEBUG && !hadPreviousConfig) { + throw new AssertionError("Attempted to check hadFlag but had no previous config."); + } return (previousFlags & flag.value) != 0; } @@ -1909,7 +1928,9 @@ private void updateWith(@NonNull ByteBuffer buffer, @NonNull String[] strings) { } else { // If we receive a different overrideId it means that we were passed // a standard action to override that we don't yet support. - assert action.overrideId == -1; + if (BuildConfig.DEBUG && action.overrideId != -1) { + throw new AssertionError("Expected action.overrideId to be -1."); + } customAccessibilityActions.add(action); } customAccessibilityActions.add(action); @@ -1931,7 +1952,9 @@ private void ensureInverseTransform() { } private Rect getGlobalRect() { - assert !globalGeometryDirty; + if (BuildConfig.DEBUG && globalGeometryDirty) { + throw new AssertionError("Attempted to getGlobalRect with a dirty geometry."); + } return globalRect; } @@ -2052,8 +2075,14 @@ private void updateRecursively(float[] ancestorTransform, Set vis globalGeometryDirty = false; } - assert globalTransform != null; - assert globalRect != null; + if (BuildConfig.DEBUG) { + if (globalTransform == null) { + throw new AssertionError("Expected globalTransform to not be null."); + } + if (globalRect == null) { + throw new AssertionError("Expected globalRect to not be null."); + } + } if (childrenInTraversalOrder != null) { for (int i = 0; i < childrenInTraversalOrder.size(); ++i) { diff --git a/shell/platform/android/io/flutter/view/ResourceExtractor.java b/shell/platform/android/io/flutter/view/ResourceExtractor.java index 424ace596be93..a13ac84e964e9 100644 --- a/shell/platform/android/io/flutter/view/ResourceExtractor.java +++ b/shell/platform/android/io/flutter/view/ResourceExtractor.java @@ -13,8 +13,11 @@ import android.os.AsyncTask; import android.os.Build; import android.util.Log; + import io.flutter.util.BSDiff; +import io.flutter.BuildConfig; import io.flutter.util.PathUtils; + import org.json.JSONObject; import java.io.*; @@ -95,7 +98,9 @@ ResourceExtractor addResources(Collection resources) { } ResourceExtractor start() { - assert mExtractTask == null; + if (BuildConfig.DEBUG && mExtractTask != null) { + throw new AssertionError("Attempted to start resource extraction while another extraction was in progress."); + } mExtractTask = new ExtractTask(); mExtractTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); return this; diff --git a/tools/gen_android_buildconfig.py b/tools/gen_android_buildconfig.py new file mode 100644 index 0000000000000..c3a6b83b88598 --- /dev/null +++ b/tools/gen_android_buildconfig.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import argparse +import os +import sys + +BUILD_CONFIG_TEMPLATE = """ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +// THIS FILE IS AUTO_GENERATED +// DO NOT EDIT THE VALUES HERE - SEE $flutter_root/tools/gen_android_buildconfig.py +package io.flutter; + +public final class BuildConfig {{ + public final static boolean DEBUG = {0}; + public final static boolean PROFILE = {1}; + public final static boolean RELEASE = {2}; +}} +""" + +def main(): + parser = argparse.ArgumentParser(description='Generate BuildConfig.java for Android') + parser.add_argument('--runtime-mode', type=str, required=True) + parser.add_argument('--out', type=str, required=True) + + args = parser.parse_args() + + release ='release' in args.runtime_mode.lower() + profile = not release and 'profile' in args.runtime_mode.lower() + debug = not release and not profile and 'debug' in args.runtime_mode.lower() + assert debug or profile or release + + with open(os.path.abspath(args.out), 'w+') as output_file: + output_file.write(BUILD_CONFIG_TEMPLATE.format(str(debug).lower(), str(profile).lower(), str(release).lower())) + +if __name__ == '__main__': + sys.exit(main()) From c31d7a64fe488c363bbe7a0c219801a3b94f6289 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 2 May 2019 14:55:44 -0700 Subject: [PATCH 2/8] remove comment --- shell/platform/android/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index a8fe62830fca1..c93884f040b26 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -224,7 +224,6 @@ action("flutter_shell_java") { "--depfile=$_rebased_depfile", "--jar-path=$_rebased_jar_path", "--classpath=$_rebased_classpath", - # "--java-srcjars=$_rebased_java_srcjars", "--bootclasspath=$_rebased_android_sdk_jar", ] From 9af3fa5aedf0d39a16e39a98dc4fcdce5e690241 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 2 May 2019 15:09:01 -0700 Subject: [PATCH 3/8] format --- shell/platform/android/BUILD.gn | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index c93884f040b26..911d016c7464f 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -195,8 +195,7 @@ action("flutter_shell_java") { sources += get_target_outputs(":gen_android_build_config_java") - sources += - [ "$flutter_root/third_party/bsdiff/io/flutter/util/BSDiff.java" ] + sources += [ "$flutter_root/third_party/bsdiff/io/flutter/util/BSDiff.java" ] android_support_jars = [ "//third_party/android_support/android_support_v13.jar", @@ -212,13 +211,16 @@ action("flutter_shell_java") { jar_path, jar_path + ".md5.stamp", ] - inputs = [ android_sdk_jar ] + inputs = [ + android_sdk_jar, + ] inputs += android_support_jars _rebased_jar_path = rebase_path(jar_path, root_build_dir) _rebased_depfile = rebase_path(depfile, root_build_dir) _rebased_android_sdk_jar = rebase_path(android_sdk_jar, root_build_dir) - _rebased_classpath = [ _rebased_android_sdk_jar ] + rebase_path(android_support_jars, root_build_dir) + _rebased_classpath = [ _rebased_android_sdk_jar ] + + rebase_path(android_support_jars, root_build_dir) args = [ "--depfile=$_rebased_depfile", From 43db1493720104c49b535c7463f45d46e1328ffa Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 2 May 2019 15:39:31 -0700 Subject: [PATCH 4/8] Catch a few more missing asserts, update baseline --- .../io/flutter/view/AccessibilityBridge.java | 10 +- tools/android_lint/baseline.xml | 275 +----------------- tools/android_lint/project.xml | 18 +- 3 files changed, 29 insertions(+), 274 deletions(-) diff --git a/shell/platform/android/io/flutter/view/AccessibilityBridge.java b/shell/platform/android/io/flutter/view/AccessibilityBridge.java index 0ad3321adc2e6..57a3e98ae5406 100644 --- a/shell/platform/android/io/flutter/view/AccessibilityBridge.java +++ b/shell/platform/android/io/flutter/view/AccessibilityBridge.java @@ -1326,8 +1326,14 @@ void updateSemantics(@NonNull ByteBuffer buffer, @NonNull String[] strings) { visibleChildren += 1; } } - assert(object.scrollIndex + visibleChildren <= object.scrollChildren); - assert(!object.childrenInHitTestOrder.get(object.scrollIndex).hasFlag(Flag.IS_HIDDEN)); + if (BuildConfig.DEBUG) { + if (object.scrollIndex + visibleChildren > object.scrollChildren) { + throw new AssertionError("Scroll index is out of bounds."); + } + if (object.childrenInHitTestOrder.get(object.scrollIndex).hasFlag(Flag.IS_HIDDEN)) { + throw new AssertionError("Attempted to move Accessibility Focus to hidden child."); + } + } // The setToIndex should be the index of the last visible child. Because we counted all // children, including the first index we need to subtract one. // diff --git a/tools/android_lint/baseline.xml b/tools/android_lint/baseline.xml index bc6c463610096..15319be270cfb 100644 --- a/tools/android_lint/baseline.xml +++ b/tools/android_lint/baseline.xml @@ -1,160 +1,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -228,7 +74,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -254,28 +100,6 @@ column="82"/> - - - - - - - - @@ -305,18 +129,7 @@ errorLine2=" ~~~~~~~~~~~"> - - - - @@ -327,7 +140,7 @@ errorLine2=" ^"> @@ -360,76 +173,10 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> - - - - - - - - - - - - - - - - - - - - - - - - @@ -448,7 +195,7 @@ errorLine2=" ~~~~~~~~~~~~~~~"> @@ -470,7 +217,7 @@ errorLine2=" ~~~~~~~~~~~~~~~"> @@ -481,7 +228,7 @@ errorLine2=" ~~~~~~~~~~~~"> @@ -492,7 +239,7 @@ errorLine2=" ~~~~~~~~~~~~"> diff --git a/tools/android_lint/project.xml b/tools/android_lint/project.xml index 6d8fffe439f3e..ac975123ca266 100644 --- a/tools/android_lint/project.xml +++ b/tools/android_lint/project.xml @@ -13,6 +13,13 @@ + + + + + + + @@ -29,13 +36,6 @@ - - - - - - - @@ -43,7 +43,9 @@ + + @@ -66,7 +68,6 @@ - @@ -77,5 +78,6 @@ + From 2b36e51ffc03fadd847518600c8ae1fb4034eaa2 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 2 May 2019 15:53:41 -0700 Subject: [PATCH 5/8] Guard logging calls using BuildConfig --- .../flutter/plugin/common/ErrorLogResult.java | 8 +++- .../io/flutter/view/AccessibilityBridge.java | 22 +++++---- .../io/flutter/view/ResourceCleaner.java | 6 ++- .../io/flutter/view/ResourceExtractor.java | 18 +++++--- tools/android_lint/baseline.xml | 46 +------------------ 5 files changed, 36 insertions(+), 64 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/common/ErrorLogResult.java b/shell/platform/android/io/flutter/plugin/common/ErrorLogResult.java index bfa8c2fd0d458..1eb5b9f264ae4 100644 --- a/shell/platform/android/io/flutter/plugin/common/ErrorLogResult.java +++ b/shell/platform/android/io/flutter/plugin/common/ErrorLogResult.java @@ -30,11 +30,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"); + } } } diff --git a/shell/platform/android/io/flutter/view/AccessibilityBridge.java b/shell/platform/android/io/flutter/view/AccessibilityBridge.java index 57a3e98ae5406..550706fe5ac38 100644 --- a/shell/platform/android/io/flutter/view/AccessibilityBridge.java +++ b/shell/platform/android/io/flutter/view/AccessibilityBridge.java @@ -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); + } } } } diff --git a/shell/platform/android/io/flutter/view/ResourceCleaner.java b/shell/platform/android/io/flutter/view/ResourceCleaner.java index babc53f6e0dfd..f1a27f133e646 100644 --- a/shell/platform/android/io/flutter/view/ResourceCleaner.java +++ b/shell/platform/android/io/flutter/view/ResourceCleaner.java @@ -9,6 +9,8 @@ import android.os.Handler; import android.util.Log; +import io.flutter.BuildConfig; + import java.io.File; import java.io.FilenameFilter; @@ -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); diff --git a/shell/platform/android/io/flutter/view/ResourceExtractor.java b/shell/platform/android/io/flutter/view/ResourceExtractor.java index a13ac84e964e9..d51d81b5e5ee9 100644 --- a/shell/platform/android/io/flutter/view/ResourceExtractor.java +++ b/shell/platform/android/io/flutter/view/ResourceExtractor.java @@ -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; @@ -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; } diff --git a/tools/android_lint/baseline.xml b/tools/android_lint/baseline.xml index 15319be270cfb..20fc427b2f95a 100644 --- a/tools/android_lint/baseline.xml +++ b/tools/android_lint/baseline.xml @@ -118,7 +118,7 @@ errorLine2=" ~~~~~~~~~"> @@ -133,50 +133,6 @@ column="19"/> - - - - - - - - - - - - - - - - Date: Thu, 2 May 2019 16:00:55 -0700 Subject: [PATCH 6/8] missing imports --- .../android/io/flutter/plugin/common/ErrorLogResult.java | 2 ++ third_party/bsdiff/io/flutter/util/BSDiff.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/shell/platform/android/io/flutter/plugin/common/ErrorLogResult.java b/shell/platform/android/io/flutter/plugin/common/ErrorLogResult.java index 1eb5b9f264ae4..9c6aa67cc9d16 100644 --- a/shell/platform/android/io/flutter/plugin/common/ErrorLogResult.java +++ b/shell/platform/android/io/flutter/plugin/common/ErrorLogResult.java @@ -4,6 +4,8 @@ package io.flutter.plugin.common; +import io.flutter.BuildConfig; + import android.support.annotation.Nullable; import android.util.Log; diff --git a/third_party/bsdiff/io/flutter/util/BSDiff.java b/third_party/bsdiff/io/flutter/util/BSDiff.java index 135882033cbc8..231b5a729e8dd 100644 --- a/third_party/bsdiff/io/flutter/util/BSDiff.java +++ b/third_party/bsdiff/io/flutter/util/BSDiff.java @@ -4,6 +4,8 @@ package io.flutter.util; +import io.flutter.BuildConfig; + import java.io.*; import java.util.zip.GZIPInputStream; From 9e08955d0c05718749daa7fa73536d974085cd33 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 2 May 2019 19:08:40 -0700 Subject: [PATCH 7/8] cleanup --- .../android/io/flutter/plugin/common/BasicMessageChannel.java | 1 - .../platform/android/io/flutter/plugin/common/EventChannel.java | 1 - shell/platform/android/io/flutter/view/AccessibilityBridge.java | 1 - tools/android_lint/baseline.xml | 2 +- 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java b/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java index 22fd6d7edd81e..35200a22ed1c5 100644 --- a/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java +++ b/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java @@ -10,7 +10,6 @@ import io.flutter.BuildConfig; import io.flutter.plugin.common.BinaryMessenger.BinaryReply; import io.flutter.plugin.common.BinaryMessenger.BinaryMessageHandler; -import io.flutter.BuildConfig; /** * A named channel for communicating with the Flutter application using basic, asynchronous message passing. diff --git a/shell/platform/android/io/flutter/plugin/common/EventChannel.java b/shell/platform/android/io/flutter/plugin/common/EventChannel.java index 10a360df04e39..72fd371296cd0 100644 --- a/shell/platform/android/io/flutter/plugin/common/EventChannel.java +++ b/shell/platform/android/io/flutter/plugin/common/EventChannel.java @@ -9,7 +9,6 @@ import io.flutter.BuildConfig; import io.flutter.plugin.common.BinaryMessenger.BinaryMessageHandler; import io.flutter.plugin.common.BinaryMessenger.BinaryReply; -import io.flutter.BuildConfig; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/shell/platform/android/io/flutter/view/AccessibilityBridge.java b/shell/platform/android/io/flutter/view/AccessibilityBridge.java index f8ddb1028acfa..3aaf574eca698 100644 --- a/shell/platform/android/io/flutter/view/AccessibilityBridge.java +++ b/shell/platform/android/io/flutter/view/AccessibilityBridge.java @@ -29,7 +29,6 @@ import io.flutter.BuildConfig; import io.flutter.embedding.engine.systemchannels.AccessibilityChannel; import io.flutter.plugin.platform.PlatformViewsAccessibilityDelegate; -import io.flutter.BuildConfig; import io.flutter.util.Predicate; import java.nio.ByteBuffer; diff --git a/tools/android_lint/baseline.xml b/tools/android_lint/baseline.xml index 20fc427b2f95a..bf85990e5b034 100644 --- a/tools/android_lint/baseline.xml +++ b/tools/android_lint/baseline.xml @@ -129,7 +129,7 @@ errorLine2=" ~~~~~~~~~~~"> From f66638e7801001a798e08a79505d077bf92c42de Mon Sep 17 00:00:00 2001 From: Dan Field Date: Fri, 3 May 2019 09:23:24 -0700 Subject: [PATCH 8/8] stray import --- shell/platform/android/io/flutter/view/ResourceExtractor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/shell/platform/android/io/flutter/view/ResourceExtractor.java b/shell/platform/android/io/flutter/view/ResourceExtractor.java index 132a75f419d8a..44f9e93f213bc 100644 --- a/shell/platform/android/io/flutter/view/ResourceExtractor.java +++ b/shell/platform/android/io/flutter/view/ResourceExtractor.java @@ -16,7 +16,6 @@ import io.flutter.BuildConfig; import io.flutter.util.BSDiff; -import io.flutter.BuildConfig; import io.flutter.util.PathUtils; import org.json.JSONObject;