Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
FlutterShellArgs.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package io.flutter.embedding.engine;
6
7import android.content.Context;
8import android.content.Intent;
9import androidx.annotation.NonNull;
10import java.util.*;
11
12/**
13 * Arguments that can be delivered to the Flutter shell when it is created.
14 *
15 * <p>The term "shell" refers to the native code that adapts Flutter to different platforms.
16 * Flutter's Android Java code initializes a native "shell" and passes these arguments to that
17 * native shell when it is initialized. See {@link
18 * io.flutter.embedding.engine.loader.FlutterLoader#ensureInitializationComplete(Context, String[])}
19 * for more information.
20 */
21@SuppressWarnings({"WeakerAccess", "unused"})
22public class FlutterShellArgs {
23 public static final String ARG_KEY_TRACE_STARTUP = "trace-startup";
24 public static final String ARG_TRACE_STARTUP = "--trace-startup";
25 public static final String ARG_KEY_START_PAUSED = "start-paused";
26 public static final String ARG_START_PAUSED = "--start-paused";
27 public static final String ARG_KEY_DISABLE_SERVICE_AUTH_CODES = "disable-service-auth-codes";
28 public static final String ARG_DISABLE_SERVICE_AUTH_CODES = "--disable-service-auth-codes";
29 public static final String ARG_KEY_ENDLESS_TRACE_BUFFER = "endless-trace-buffer";
30 public static final String ARG_ENDLESS_TRACE_BUFFER = "--endless-trace-buffer";
31 public static final String ARG_KEY_USE_TEST_FONTS = "use-test-fonts";
32 public static final String ARG_USE_TEST_FONTS = "--use-test-fonts";
33 public static final String ARG_KEY_ENABLE_DART_PROFILING = "enable-dart-profiling";
34 public static final String ARG_ENABLE_DART_PROFILING = "--enable-dart-profiling";
35 public static final String ARG_KEY_ENABLE_SOFTWARE_RENDERING = "enable-software-rendering";
36 public static final String ARG_ENABLE_SOFTWARE_RENDERING = "--enable-software-rendering";
37 public static final String ARG_KEY_SKIA_DETERMINISTIC_RENDERING = "skia-deterministic-rendering";
38 public static final String ARG_SKIA_DETERMINISTIC_RENDERING = "--skia-deterministic-rendering";
39 public static final String ARG_KEY_TRACE_SKIA = "trace-skia";
40 public static final String ARG_TRACE_SKIA = "--trace-skia";
41 public static final String ARG_KEY_TRACE_SKIA_ALLOWLIST = "trace-skia-allowlist";
42 public static final String ARG_TRACE_SKIA_ALLOWLIST = "--trace-skia-allowlist=";
43 public static final String ARG_KEY_TRACE_SYSTRACE = "trace-systrace";
44 public static final String ARG_TRACE_SYSTRACE = "--trace-systrace";
45 public static final String ARG_KEY_TRACE_TO_FILE = "trace-to-file";
46 public static final String ARG_TRACE_TO_FILE = "--trace-to-file";
47 public static final String ARG_KEY_ENABLE_IMPELLER = "enable-impeller";
48 public static final String ARG_ENABLE_IMPELLER = "--enable-impeller";
49 public static final String ARG_KEY_ENABLE_VULKAN_VALIDATION = "enable-vulkan-validation";
50 public static final String ARG_ENABLE_VULKAN_VALIDATION = "--enable-vulkan-validation";
51 public static final String ARG_KEY_DUMP_SHADER_SKP_ON_SHADER_COMPILATION =
52 "dump-skp-on-shader-compilation";
53 public static final String ARG_DUMP_SHADER_SKP_ON_SHADER_COMPILATION =
54 "--dump-skp-on-shader-compilation";
55 public static final String ARG_KEY_CACHE_SKSL = "cache-sksl";
56 public static final String ARG_CACHE_SKSL = "--cache-sksl";
57 public static final String ARG_KEY_PURGE_PERSISTENT_CACHE = "purge-persistent-cache";
58 public static final String ARG_PURGE_PERSISTENT_CACHE = "--purge-persistent-cache";
59 public static final String ARG_KEY_VERBOSE_LOGGING = "verbose-logging";
60 public static final String ARG_VERBOSE_LOGGING = "--verbose-logging";
61 public static final String ARG_KEY_VM_SERVICE_PORT = "vm-service-port";
62 public static final String ARG_VM_SERVICE_PORT = "--vm-service-port=";
63 // TODO(bkonyi): remove once flutter_tools no longer uses this option.
64 // See https://github.com/dart-lang/sdk/issues/50233
65 public static final String ARG_KEY_OBSERVATORY_PORT = "observatory-port";
66 public static final String ARG_KEY_DART_FLAGS = "dart-flags";
67 public static final String ARG_DART_FLAGS = "--dart-flags";
68 public static final String ARG_KEY_MSAA_SAMPLES = "msaa-samples";
69 public static final String ARG_MSAA_SAMPLES = "--msaa-samples";
70
71 @NonNull
72 public static FlutterShellArgs fromIntent(@NonNull Intent intent) {
73 // Before adding more entries to this list, consider that arbitrary
74 // Android applications can generate intents with extra data and that
75 // there are many security-sensitive args in the binary.
76 // TODO(mattcarroll): I left this warning as-is, but we should clarify what exactly this warning
77 // is warning against.
78 ArrayList<String> args = new ArrayList<>();
79
80 if (intent.getBooleanExtra(ARG_KEY_TRACE_STARTUP, false)) {
81 args.add(ARG_TRACE_STARTUP);
82 }
83 if (intent.getBooleanExtra(ARG_KEY_START_PAUSED, false)) {
84 args.add(ARG_START_PAUSED);
85 }
86 int vmServicePort = intent.getIntExtra(ARG_KEY_VM_SERVICE_PORT, 0);
87 if (vmServicePort > 0) {
88 args.add(ARG_VM_SERVICE_PORT + Integer.toString(vmServicePort));
89 } else {
90 // TODO(bkonyi): remove once flutter_tools no longer uses this option.
91 // See https://github.com/dart-lang/sdk/issues/50233
92 vmServicePort = intent.getIntExtra(ARG_KEY_OBSERVATORY_PORT, 0);
93 if (vmServicePort > 0) {
94 args.add(ARG_VM_SERVICE_PORT + Integer.toString(vmServicePort));
95 }
96 }
97 if (intent.getBooleanExtra(ARG_KEY_DISABLE_SERVICE_AUTH_CODES, false)) {
98 args.add(ARG_DISABLE_SERVICE_AUTH_CODES);
99 }
100 if (intent.getBooleanExtra(ARG_KEY_ENDLESS_TRACE_BUFFER, false)) {
101 args.add(ARG_ENDLESS_TRACE_BUFFER);
102 }
103 if (intent.getBooleanExtra(ARG_KEY_USE_TEST_FONTS, false)) {
104 args.add(ARG_USE_TEST_FONTS);
105 }
106 if (intent.getBooleanExtra(ARG_KEY_ENABLE_DART_PROFILING, false)) {
107 args.add(ARG_ENABLE_DART_PROFILING);
108 }
109 if (intent.getBooleanExtra(ARG_KEY_ENABLE_SOFTWARE_RENDERING, false)) {
110 args.add(ARG_ENABLE_SOFTWARE_RENDERING);
111 }
112 if (intent.getBooleanExtra(ARG_KEY_SKIA_DETERMINISTIC_RENDERING, false)) {
113 args.add(ARG_SKIA_DETERMINISTIC_RENDERING);
114 }
115 if (intent.getBooleanExtra(ARG_KEY_TRACE_SKIA, false)) {
116 args.add(ARG_TRACE_SKIA);
117 }
118 String traceSkiaAllowlist = intent.getStringExtra(ARG_KEY_TRACE_SKIA_ALLOWLIST);
119 if (traceSkiaAllowlist != null) {
120 args.add(ARG_TRACE_SKIA_ALLOWLIST + traceSkiaAllowlist);
121 }
122 if (intent.getBooleanExtra(ARG_KEY_TRACE_SYSTRACE, false)) {
123 args.add(ARG_TRACE_SYSTRACE);
124 }
125 if (intent.hasExtra(ARG_KEY_TRACE_TO_FILE)) {
126 args.add(ARG_TRACE_TO_FILE + "=" + intent.getStringExtra(ARG_KEY_TRACE_TO_FILE));
127 }
128 if (intent.getBooleanExtra(ARG_KEY_ENABLE_IMPELLER, false)) {
129 args.add(ARG_ENABLE_IMPELLER);
130 }
131 if (intent.getBooleanExtra(ARG_KEY_ENABLE_VULKAN_VALIDATION, false)) {
132 args.add(ARG_ENABLE_VULKAN_VALIDATION);
133 }
134 if (intent.getBooleanExtra(ARG_KEY_DUMP_SHADER_SKP_ON_SHADER_COMPILATION, false)) {
135 args.add(ARG_DUMP_SHADER_SKP_ON_SHADER_COMPILATION);
136 }
137 if (intent.getBooleanExtra(ARG_KEY_CACHE_SKSL, false)) {
138 args.add(ARG_CACHE_SKSL);
139 }
140 if (intent.getBooleanExtra(ARG_KEY_PURGE_PERSISTENT_CACHE, false)) {
141 args.add(ARG_PURGE_PERSISTENT_CACHE);
142 }
143 if (intent.getBooleanExtra(ARG_KEY_VERBOSE_LOGGING, false)) {
144 args.add(ARG_VERBOSE_LOGGING);
145 }
146 final int msaaSamples = intent.getIntExtra("msaa-samples", 0);
147 if (msaaSamples > 1) {
148 args.add("--msaa-samples=" + Integer.toString(msaaSamples));
149 }
150
151 // NOTE: all flags provided with this argument are subject to filtering
152 // based on a list of allowed flags in shell/common/switches.cc. If any
153 // flag provided is not allowed, the process will immediately terminate.
154 if (intent.hasExtra(ARG_KEY_DART_FLAGS)) {
155 args.add(ARG_DART_FLAGS + "=" + intent.getStringExtra(ARG_KEY_DART_FLAGS));
156 }
157
158 return new FlutterShellArgs(args);
159 }
160
161 @NonNull private Set<String> args;
162
163 /**
164 * Creates a set of Flutter shell arguments from a given {@code String[]} array. The given
165 * arguments are automatically de-duplicated.
166 */
167 public FlutterShellArgs(@NonNull String[] args) {
168 this.args = new HashSet<>(Arrays.asList(args));
169 }
170
171 /**
172 * Creates a set of Flutter shell arguments from a given {@code List<String>}. The given arguments
173 * are automatically de-duplicated.
174 */
176 this.args = new HashSet<>(args);
177 }
178
179 /** Creates a set of Flutter shell arguments from a given {@code Set<String>}. */
180 public FlutterShellArgs(@NonNull Set<String> args) {
181 this.args = new HashSet<>(args);
182 }
183
184 /**
185 * Adds the given {@code arg} to this set of arguments.
186 *
187 * @param arg argument to add
188 */
189 public void add(@NonNull String arg) {
190 args.add(arg);
191 }
192
193 /**
194 * Removes the given {@code arg} from this set of arguments.
195 *
196 * @param arg argument to remove
197 */
198 public void remove(@NonNull String arg) {
199 args.remove(arg);
200 }
201
202 /**
203 * Returns a new {@code String[]} array which contains each of the arguments within this {@code
204 * FlutterShellArgs}.
205 *
206 * @return array of arguments
207 */
208 @NonNull
209 public String[] toArray() {
210 String[] argsArray = new String[args.size()];
211 return args.toArray(argsArray);
212 }
213}
static FlutterShellArgs fromIntent(@NonNull Intent intent)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args