From be849d13639467448106e323f80df2397b506f2c Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Thu, 14 Nov 2019 04:09:08 +0000 Subject: [PATCH] Add support for --dart-flags in FlutterShellArgs. (#44855) (flutter/engine#13855) --- .../flutter/shell/platform/android/BUILD.gn | 1 + .../embedding/engine/FlutterShellArgs.java | 10 +++++++ .../test/io/flutter/FlutterTestSuite.java | 2 ++ .../engine/FlutterShellArgsTest.java | 30 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/FlutterShellArgsTest.java diff --git a/engine/src/flutter/shell/platform/android/BUILD.gn b/engine/src/flutter/shell/platform/android/BUILD.gn index ecd1d7ff81..b33bd15d12 100644 --- a/engine/src/flutter/shell/platform/android/BUILD.gn +++ b/engine/src/flutter/shell/platform/android/BUILD.gn @@ -422,6 +422,7 @@ action("robolectric_tests") { "test/io/flutter/embedding/engine/FlutterEngineCacheTest.java", "test/io/flutter/embedding/engine/FlutterEngineTest.java", "test/io/flutter/embedding/engine/FlutterJNITest.java", + "test/io/flutter/embedding/engine/FlutterShellArgsTest.java", "test/io/flutter/embedding/engine/PluginComponentTest.java", "test/io/flutter/embedding/engine/RenderingComponentTest.java", "test/io/flutter/embedding/engine/dart/DartExecutorTest.java", diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java index 65c25d5a9f..0887211553 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java @@ -44,6 +44,8 @@ public class FlutterShellArgs { public static final String ARG_VERBOSE_LOGGING = "--verbose-logging"; public static final String ARG_KEY_OBSERVATORY_PORT = "observatory-port"; public static final String ARG_OBSERVATORY_PORT = "--observatory-port="; + public static final String ARG_KEY_DART_FLAGS = "dart-flags"; + public static final String ARG_DART_FLAGS = "--dart-flags"; @NonNull public static FlutterShellArgs fromIntent(@NonNull Intent intent) { @@ -91,6 +93,14 @@ public class FlutterShellArgs { args.add(ARG_VERBOSE_LOGGING); } + // NOTE: all flags provided with this argument are subject to filtering + // based on a whitelist in shell/common/switches.cc. If any flag provided + // is not present in the whitelist, the process will immediately + // terminate. + if (intent.hasExtra(ARG_KEY_DART_FLAGS)) { + args.add(ARG_DART_FLAGS + "=" + intent.getStringExtra(ARG_KEY_DART_FLAGS)); + } + return new FlutterShellArgs(args); } diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/FlutterTestSuite.java b/engine/src/flutter/shell/platform/android/test/io/flutter/FlutterTestSuite.java index ac99a9b45a..3868bf628a 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/FlutterTestSuite.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/FlutterTestSuite.java @@ -23,6 +23,7 @@ import io.flutter.plugin.editing.TextInputPluginTest; import io.flutter.plugin.platform.SingleViewPresentationTest; import io.flutter.util.PreconditionsTest; import test.io.flutter.embedding.engine.FlutterEngineTest; +import test.io.flutter.embedding.engine.FlutterShellArgsTest; import test.io.flutter.embedding.engine.PluginComponentTest; import test.io.flutter.embedding.engine.dart.DartExecutorTest; @@ -36,6 +37,7 @@ import test.io.flutter.embedding.engine.dart.DartExecutorTest; FlutterEngineTest.class, FlutterFragmentTest.class, FlutterJNITest.class, + FlutterShellArgsTest.class, FlutterRendererTest.class, FlutterViewTest.class, PlatformChannelTest.class, diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/FlutterShellArgsTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/FlutterShellArgsTest.java new file mode 100644 index 0000000000..535980dc5e --- /dev/null +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/FlutterShellArgsTest.java @@ -0,0 +1,30 @@ +package test.io.flutter.embedding.engine; + +import android.content.Intent; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import io.flutter.embedding.engine.FlutterShellArgs; + +import static org.junit.Assert.assertEquals; + +@Config(manifest=Config.NONE) +@RunWith(RobolectricTestRunner.class) +public class FlutterShellArgsTest { + @Test + public void itProcessesDartFlags() { + // Setup the test. + Intent intent = new Intent(); + intent.putExtra("dart-flags", "--observe --no-hot --no-pub"); + + // Execute the behavior under test. + FlutterShellArgs args = FlutterShellArgs.fromIntent(intent); + + // Verify results. + assertEquals(1, args.toArray().length); + assertEquals("--dart-flags=--observe --no-hot --no-pub", args.toArray()[0]); + } +}