-
Notifications
You must be signed in to change notification settings - Fork 6k
Limit heap growth on Android #20473
Limit heap growth on Android #20473
Changes from 1 commit
cd9045e
de357b2
834417b
1ed2d8d
5bebd55
eb485ef
0847dcd
f2a9f84
96ad46e
0a345dd
4612bac
a118c90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,51 +94,51 @@ | |
| */ | ||
| @Keep | ||
| public class FlutterJNI { | ||
| public static class FlutterJNILoader { | ||
| /** | ||
| * Loads the libflutter.so library. | ||
| * | ||
| * <p>This must be called before any other native methods, and can be overridden by tests to | ||
| * avoid loading native libraries. | ||
| */ | ||
| public void loadLibrary() { | ||
| System.loadLibrary("flutter"); | ||
| } | ||
| private static final String TAG = "FlutterJNI"; | ||
|
|
||
| /** | ||
| * Prefetch the default font manager provided by SkFontMgr::RefDefault() which is a process-wide | ||
| * singleton owned by Skia. Note that, the first call to SkFontMgr::RefDefault() will take | ||
| * noticeable time, but later calls will return a reference to the preexisting font manager. | ||
| */ | ||
| public void prefetchDefaultFontManager() { | ||
| FlutterJNI.nativePrefetchDefaultFontManager(); | ||
| } | ||
| // BEGIN Methods related to loading for FlutterLoader. | ||
| /** | ||
| * Loads the libflutter.so library. | ||
|
||
| * | ||
| * <p>This must be called before any other native methods, and can be overridden by tests to avoid | ||
| * loading native libraries. | ||
| */ | ||
| public void loadLibrary() { | ||
| System.loadLibrary("flutter"); | ||
| } | ||
|
|
||
| /** | ||
| * Perform one time initialization of the Dart VM and Flutter engine. | ||
| * | ||
| * <p>This method must be called only once. | ||
| * | ||
| * @param context The application context. | ||
| * @param args Arguments to the Dart VM/Flutter engine. | ||
| * @param bundlePath For JIT runtimes, the path to the Dart kernel file for the application. | ||
| * @param appStoragePath The path to the application data directory. | ||
| * @param engineCachesPath The path to the application cache directory. | ||
| * @param initTimeMillis The time, in milliseconds, taken for initialization. | ||
| */ | ||
| public void nativeInit( | ||
| @NonNull Context context, | ||
| @NonNull String[] args, | ||
| @Nullable String bundlePath, | ||
| @NonNull String appStoragePath, | ||
| @NonNull String engineCachesPath, | ||
| long initTimeMillis) { | ||
| FlutterJNI.nativeInit( | ||
| context, args, bundlePath, appStoragePath, engineCachesPath, initTimeMillis); | ||
| } | ||
| /** | ||
| * Prefetch the default font manager provided by SkFontMgr::RefDefault() which is a process-wide | ||
| * singleton owned by Skia. Note that, the first call to SkFontMgr::RefDefault() will take | ||
| * noticeable time, but later calls will return a reference to the preexisting font manager. | ||
| */ | ||
| public void prefetchDefaultFontManager() { | ||
| FlutterJNI.nativePrefetchDefaultFontManager(); | ||
| } | ||
|
|
||
| private static final String TAG = "FlutterJNI"; | ||
| /** | ||
| * Perform one time initialization of the Dart VM and Flutter engine. | ||
| * | ||
| * <p>This method must be called only once. | ||
| * | ||
| * @param context The application context. | ||
| * @param args Arguments to the Dart VM/Flutter engine. | ||
| * @param bundlePath For JIT runtimes, the path to the Dart kernel file for the application. | ||
| * @param appStoragePath The path to the application data directory. | ||
| * @param engineCachesPath The path to the application cache directory. | ||
| * @param initTimeMillis The time, in milliseconds, taken for initialization. | ||
| */ | ||
| public void init( | ||
| @NonNull Context context, | ||
| @NonNull String[] args, | ||
| @Nullable String bundlePath, | ||
| @NonNull String appStoragePath, | ||
| @NonNull String engineCachesPath, | ||
| long initTimeMillis) { | ||
| FlutterJNI.nativeInit( | ||
| context, args, bundlePath, appStoragePath, engineCachesPath, initTimeMillis); | ||
| } | ||
| // END methods related to FlutterLoader | ||
|
|
||
| @Nullable private static AsyncWaitForVsyncDelegate asyncWaitForVsyncDelegate; | ||
| // This should also be updated by FlutterView when it is attached to a Display. | ||
|
|
@@ -148,15 +148,19 @@ public void nativeInit( | |
| // This is set from native code via JNI. | ||
| @Nullable private static String observatoryUri; | ||
|
|
||
| private static native void nativeInit( | ||
| /** @deprecated Use {@link #init(Context, String[], String, String, String, long)} instead. */ | ||
| @Deprecated | ||
| public static native void nativeInit( | ||
| @NonNull Context context, | ||
| @NonNull String[] args, | ||
| @Nullable String bundlePath, | ||
| @NonNull String appStoragePath, | ||
| @NonNull String engineCachesPath, | ||
| long initTimeMillis); | ||
|
|
||
| private static native void nativePrefetchDefaultFontManager(); | ||
| /** @deprecated Use {@link #prefetchDefaultFontManager()} instead. */ | ||
| @Deprecated | ||
| public static native void nativePrefetchDefaultFontManager(); | ||
|
|
||
| private native boolean nativeGetIsSoftwareRenderingEnabled(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,9 +64,9 @@ public FlutterLoader() { | |
| this(null); | ||
| } | ||
|
|
||
| public FlutterLoader(@Nullable FlutterJNI.FlutterJNILoader flutterJNILoader) { | ||
| public FlutterLoader(@Nullable FlutterJNI flutterJNILoader) { | ||
|
||
| if (flutterJNILoader == null) { | ||
| flutterJNILoader = new FlutterJNI.FlutterJNILoader(); | ||
| flutterJNILoader = new FlutterJNI(); | ||
| } | ||
| this.flutterJNILoader = flutterJNILoader; | ||
| } | ||
|
|
@@ -75,7 +75,7 @@ public FlutterLoader(@Nullable FlutterJNI.FlutterJNILoader flutterJNILoader) { | |
| @Nullable private Settings settings; | ||
| private long initStartTimestampMillis; | ||
| private FlutterApplicationInfo flutterApplicationInfo; | ||
| private FlutterJNI.FlutterJNILoader flutterJNILoader; | ||
| private FlutterJNI flutterJNILoader; | ||
|
|
||
| private static class InitResult { | ||
| final String appStoragePath; | ||
|
|
@@ -242,7 +242,7 @@ public void ensureInitializationComplete( | |
|
|
||
| long initTimeMillis = SystemClock.uptimeMillis() - initStartTimestampMillis; | ||
|
|
||
| flutterJNILoader.nativeInit( | ||
| flutterJNILoader.init( | ||
| applicationContext, | ||
| shellArgs.toArray(new String[0]), | ||
| kernelPath, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ public void setUp() { | |
| @Test | ||
| public void pluginsCanAccessFlutterAssetPaths() { | ||
| // Setup test. | ||
| FlutterJNI.FlutterJNILoader mockFlutterJNILoader = mock(FlutterJNI.FlutterJNILoader.class); | ||
| FlutterJNI mockFlutterJNILoader = mock(FlutterJNI.class); | ||
| FlutterInjector.setInstance( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, lg. Can you push some changes to flutter/website#4561 directly for the new pattern?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| new FlutterInjector.Builder() | ||
| .setFlutterLoader(new FlutterLoader(mockFlutterJNILoader)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great. Thanks for adding docs