Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make it simpler
  • Loading branch information
dnfield committed Sep 21, 2020
commit f2a9f8488e1bbf9693e331262916cdca5caa3b08
90 changes: 47 additions & 43 deletions shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ultra-nit: Loads the libflutter.so Flutter engine native library.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libflutter.so C++ library good?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SG

*
* <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.
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public FlutterLoader() {
this(null);
}

public FlutterLoader(@Nullable FlutterJNI.FlutterJNILoader flutterJNILoader) {
public FlutterLoader(@Nullable FlutterJNI flutterJNILoader) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace all flutterJNILoader with just flutterJNI. Since there's nothing else called jni loader here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, also made this @nonnullable and made the default ctor new one up.

if (flutterJNILoader == null) {
flutterJNILoader = new FlutterJNI.FlutterJNILoader();
flutterJNILoader = new FlutterJNI();
}
this.flutterJNILoader = flutterJNILoader;
}
Expand All @@ -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;
Expand Down Expand Up @@ -242,7 +242,7 @@ public void ensureInitializationComplete(

long initTimeMillis = SystemClock.uptimeMillis() - initStartTimestampMillis;

flutterJNILoader.nativeInit(
flutterJNILoader.init(
applicationContext,
shellArgs.toArray(new String[0]),
kernelPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new FlutterInjector.Builder()
.setFlutterLoader(new FlutterLoader(mockFlutterJNILoader))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void itReportsUninitializedAfterCreating() {

@Test
public void itReportsInitializedAfterInitializing() {
FlutterJNI.FlutterJNILoader mockFlutterJNILoader = mock(FlutterJNI.FlutterJNILoader.class);
FlutterJNI mockFlutterJNILoader = mock(FlutterJNI.class);
FlutterLoader flutterLoader = new FlutterLoader(mockFlutterJNILoader);

assertFalse(flutterLoader.initialized());
Expand All @@ -53,7 +53,7 @@ public void itReportsInitializedAfterInitializing() {
final String oldGenHeapArg = "--old-gen-heap-size=" + activityManager.getLargeMemoryClass();
ArgumentCaptor<String[]> shellArgsCaptor = ArgumentCaptor.forClass(String[].class);
verify(mockFlutterJNILoader, times(1))
.nativeInit(
.init(
eq(RuntimeEnvironment.application),
shellArgsCaptor.capture(),
anyString(),
Expand Down