@@ -38,20 +38,26 @@ public static class Flag {
3838 /**
3939 * The metadata key name used to specify the flag in AndroidManifest.xml.
4040 *
41- * <p>To specify a flag in a manifest, it must be prefixed with {@code
41+ * <p>To specify a flag in a manifest, it should be prefixed with {@code
4242 * io.flutter.embedding.android.}. This is enforced to avoid potential naming collisions with
43- * other metadata keys.
43+ * other metadata keys. The only exception are flags that have already been deprecated.
4444 */
4545 public final String metadataKey ;
4646
4747 /** Whether this flag is allowed to be set in release mode. */
4848 public final boolean allowedInRelease ;
4949
50- private String flagPrefix = "io.flutter.embedding.android." ;
51-
52- /** Creates a new Flutter shell flag that is not allowed in release mode. */
50+ /**
51+ * Creates a new Flutter shell flag that is not allowed in release mode with the default flag
52+ * prefix.
53+ */
5354 private Flag (String commandLineArgument , String metaDataName ) {
54- this (commandLineArgument , metaDataName , false );
55+ this (commandLineArgument , metaDataName , "io.flutter.embedding.android." , false );
56+ }
57+
58+ /** Creates a new Flutter shell flag with the default flag prefix. */
59+ private Flag (String commandLineArgument , String metaDataName , boolean allowedInRelease ) {
60+ this (commandLineArgument , metaDataName , "io.flutter.embedding.android." , allowedInRelease );
5561 }
5662
5763 /**
@@ -65,7 +71,11 @@ private Flag(String commandLineArgument, String metaDataName) {
6571 * <p>If creating a flag that will be allowed in release, please leave a comment in the Javadoc
6672 * explaining why it should be allowed in release.
6773 */
68- private Flag (String commandLineArgument , String metaDataName , boolean allowedInRelease ) {
74+ private Flag (
75+ String commandLineArgument ,
76+ String metaDataName ,
77+ String flagPrefix ,
78+ boolean allowedInRelease ) {
6979 this .commandLineArgument = commandLineArgument ;
7080 this .metadataKey = flagPrefix + metaDataName ;
7181 this .allowedInRelease = allowedInRelease ;
@@ -91,6 +101,20 @@ public boolean hasValue() {
91101 public static final Flag AOT_SHARED_LIBRARY_NAME =
92102 new Flag ("--aot-shared-library-name=" , "AOTSharedLibraryName" , true );
93103
104+ /**
105+ * Deprecated flag that specifies the path to the AOT shared library containing compiled Dart
106+ * code.
107+ *
108+ * <p>Please use {@link AOT_SHARED_LIBRARY_NAME} instead.
109+ */
110+ @ Deprecated
111+ public static final Flag DEPRECATED_AOT_SHARED_LIBRARY_NAME =
112+ new Flag (
113+ "--aot-shared-library-name=" ,
114+ "aot-shared-library-name" ,
115+ "io.flutter.embedding.engine.loader.FlutterLoader." ,
116+ true );
117+
94118 /**
95119 * Sets the directory containing Flutter assets.
96120 *
@@ -99,6 +123,19 @@ public boolean hasValue() {
99123 public static final Flag FLUTTER_ASSETS_DIR =
100124 new Flag ("--flutter-assets-dir=" , "FlutterAssetsDir" , true );
101125
126+ /**
127+ * The deprecated flag that sets the directory containing Flutter assets.
128+ *
129+ * <p>Please use {@link DEPRECATED_FLUTTER_ASSETS_DIR} instead.
130+ */
131+ @ Deprecated
132+ public static final Flag DEPRECATED_FLUTTER_ASSETS_DIR =
133+ new Flag (
134+ "--flutter-assets-dir=" ,
135+ "flutter-assets-dir" ,
136+ "io.flutter.embedding.engine.loader.FlutterLoader." ,
137+ true );
138+
102139 /**
103140 * Sets the old generation heap size for the Dart VM in megabytes.
104141 *
@@ -317,10 +354,26 @@ public boolean hasValue() {
317354 PURGE_PERSISTENT_CACHE ,
318355 VERBOSE_LOGGING ,
319356 DART_FLAGS ,
320- DISABLE_MERGED_PLATFORM_UI_THREAD ));
357+ DISABLE_MERGED_PLATFORM_UI_THREAD ,
358+ DEPRECATED_AOT_SHARED_LIBRARY_NAME ,
359+ DEPRECATED_FLUTTER_ASSETS_DIR ));
321360
322- private static final List <Flag > DEPRECATED_FLAGS =
323- Collections .unmodifiableList (Arrays .asList (DISABLE_MERGED_PLATFORM_UI_THREAD ));
361+ // Flags that have been turned off.
362+ private static final List <Flag > DISABLED_FLAGS =
363+ Collections .unmodifiableList (
364+ Arrays .asList (
365+ DISABLE_MERGED_PLATFORM_UI_THREAD ,
366+ DEPRECATED_AOT_SHARED_LIBRARY_NAME ,
367+ DEPRECATED_FLUTTER_ASSETS_DIR ));
368+
369+ // Lookup map for current flags that replace deprecated ones.
370+ private static final Map <Flag , Flag > DEPRECATED_FLAGS_BY_REPLACEMENT =
371+ new HashMap <Flag , Flag >() {
372+ {
373+ put (DEPRECATED_AOT_SHARED_LIBRARY_NAME , AOT_SHARED_LIBRARY_NAME );
374+ put (DEPRECATED_FLUTTER_ASSETS_DIR , FLUTTER_ASSETS_DIR );
375+ }
376+ };
324377
325378 // Lookup map for retrieving the Flag corresponding to a specific command line argument.
326379 private static final Map <String , Flag > FLAG_BY_COMMAND_LINE_ARG ;
@@ -341,17 +394,18 @@ public boolean hasValue() {
341394
342395 /** Looks up a {@link Flag} by its metadataKey. */
343396 public static Flag getFlagByMetadataKey (String key ) {
344- return FLAG_BY_META_DATA_KEY .get (key );
397+ Flag flag = FLAG_BY_META_DATA_KEY .get (key );
398+ Flag replacementFlag = getReplacementFlagIfDeprecated (flag );
399+ return replacementFlag != null ? replacementFlag : flag ;
345400 }
346401
347402 /** Looks up a {@link Flag} by its commandLineArgument. */
348403 public static Flag getFlagByCommandLineArgument (String arg ) {
349404 int equalsIndex = arg .indexOf ('=' );
350- if (equalsIndex == -1 ) {
351- return FLAG_BY_COMMAND_LINE_ARG .get (arg );
352- }
353- // Return the part of the string including the '='
354- return FLAG_BY_COMMAND_LINE_ARG .get (arg .substring (0 , equalsIndex + 1 ));
405+ Flag flag =
406+ FLAG_BY_COMMAND_LINE_ARG .get (equalsIndex == -1 ? arg : arg .substring (0 , equalsIndex + 1 ));
407+ Flag replacementFlag = getReplacementFlagIfDeprecated (flag );
408+ return replacementFlag != null ? replacementFlag : flag ;
355409 }
356410
357411 /**
@@ -375,8 +429,13 @@ public static Flag getFlagFromIntentKey(String intentKey) {
375429 return null ;
376430 }
377431
378- /** Returns whether or not a flag is deprecated and should raise an exception if used. */
379- public static boolean isDeprecated (Flag flag ) {
380- return DEPRECATED_FLAGS .contains (flag );
432+ /** Returns whether or not a flag is disabled and should raise an exception if used. */
433+ public static boolean isDisabled (Flag flag ) {
434+ return DISABLED_FLAGS .contains (flag );
435+ }
436+
437+ /** Returns the replacement flag of that given if it is deprecated. */
438+ public static Flag getReplacementFlagIfDeprecated (Flag flag ) {
439+ return DEPRECATED_FLAGS_BY_REPLACEMENT .get (flag );
381440 }
382441}
0 commit comments