Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7c2fec1

Browse files
PR Updates.
1 parent fe4e934 commit 7c2fec1

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.*;
2727

2828
/**
29-
* This class finds Flutter resources in an application APK and also loads Flutter's native library.
29+
* Finds Flutter resources in an application APK and also loads Flutter's native library.
3030
*/
3131
public class FlutterLoader {
3232
private static final String TAG = "FlutterLoader";
@@ -39,13 +39,13 @@ public class FlutterLoader {
3939
private static final String FLUTTER_ASSETS_DIR_KEY = "flutter-assets-dir";
4040

4141
// XML Attribute keys supported in AndroidManifest.xml
42-
public static final String PUBLIC_AOT_SHARED_LIBRARY_NAME =
42+
private static final String PUBLIC_AOT_SHARED_LIBRARY_NAME =
4343
FlutterLoader.class.getName() + '.' + AOT_SHARED_LIBRARY_NAME;
44-
public static final String PUBLIC_VM_SNAPSHOT_DATA_KEY =
44+
private static final String PUBLIC_VM_SNAPSHOT_DATA_KEY =
4545
FlutterLoader.class.getName() + '.' + VM_SNAPSHOT_DATA_KEY;
46-
public static final String PUBLIC_ISOLATE_SNAPSHOT_DATA_KEY =
46+
private static final String PUBLIC_ISOLATE_SNAPSHOT_DATA_KEY =
4747
FlutterLoader.class.getName() + '.' + ISOLATE_SNAPSHOT_DATA_KEY;
48-
public static final String PUBLIC_FLUTTER_ASSETS_DIR_KEY =
48+
private static final String PUBLIC_FLUTTER_ASSETS_DIR_KEY =
4949
FlutterLoader.class.getName() + '.' + FLUTTER_ASSETS_DIR_KEY;
5050

5151
// Resource names used for components of the precompiled snapshot.
@@ -64,6 +64,13 @@ public class FlutterLoader {
6464

6565
private static FlutterLoader instance;
6666

67+
/**
68+
* Returns a singleton {@code FlutterLoader} instance.
69+
* <p>
70+
* The returned instance loads Flutter native libraries in the standard way. A singleton object
71+
* is used instead of static methods to facilitate testing without actually running native
72+
* library linking.
73+
*/
6774
@NonNull
6875
public static FlutterLoader getInstance() {
6976
if (instance == null) {
@@ -98,13 +105,13 @@ public void startInitialization(@NonNull Context applicationContext) {
98105
* @param settings Configuration settings.
99106
*/
100107
public void startInitialization(@NonNull Context applicationContext, @NonNull Settings settings) {
101-
if (Looper.myLooper() != Looper.getMainLooper()) {
102-
throw new IllegalStateException("startInitialization must be called on the main thread");
103-
}
104108
// Do not run startInitialization more than once.
105109
if (this.settings != null) {
106110
return;
107111
}
112+
if (Looper.myLooper() != Looper.getMainLooper()) {
113+
throw new IllegalStateException("startInitialization must be called on the main thread");
114+
}
108115

109116
this.settings = settings;
110117

@@ -136,15 +143,15 @@ public void startInitialization(@NonNull Context applicationContext, @NonNull Se
136143
* @param args Flags sent to the Flutter runtime.
137144
*/
138145
public void ensureInitializationComplete(@NonNull Context applicationContext, @Nullable String[] args) {
146+
if (initialized) {
147+
return;
148+
}
139149
if (Looper.myLooper() != Looper.getMainLooper()) {
140150
throw new IllegalStateException("ensureInitializationComplete must be called on the main thread");
141151
}
142152
if (settings == null) {
143153
throw new IllegalStateException("ensureInitializationComplete must be called after startInitialization");
144154
}
145-
if (initialized) {
146-
return;
147-
}
148155
try {
149156
if (resourceExtractor != null) {
150157
resourceExtractor.waitForCompletion();

0 commit comments

Comments
 (0)