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

Commit ca22807

Browse files
committed
Javadocs, API adjustments
1 parent f94dd3a commit ca22807

File tree

3 files changed

+57
-20
lines changed

3 files changed

+57
-20
lines changed

shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -951,21 +951,40 @@ public void setDynamicFeatureManager(@NonNull DynamicFeatureManager dynamicFeatu
951951
this.dynamicFeatureManager = dynamicFeatureManager;
952952
}
953953

954+
/**
955+
* Called by dart's deferred load handler to request that a dart deferred library corresponding
956+
* to loadingUnitId be downloaded (if necessary) and loaded into the dart vm.
957+
*
958+
* <p>This method delegates the task to DynamicFeatureManager, which handles the download and
959+
* loading of the dart library and any assets.
960+
*
961+
* @param loadingUnitId The loadingUnitId is assigned during compile time by gen_snapshot and is
962+
* automatically retrieved when loadLibrary() is called on a dart deferred
963+
* library.
964+
*/
954965
@SuppressWarnings("unused")
955966
@UiThread
956967
public void RequestDartDeferredLibrary(int loadingUnitId) {
957968
dynamicFeatureManager.downloadDynamicFeature(loadingUnitId, null);
958969
}
959970

960971
/**
961-
* This should be called for every loading unit to be loaded into the dart isolate.
972+
* Searches each of the provided paths for a valid dart shared library .so file and resolves
973+
* symbols to load into the dart VM.
962974
*
963-
* <p>abi, libName, and apkPaths are used together to search the installed apks for the desired
964-
* .so library. If not found, soPath may be provided as a fallback if a pre-extracted .so exists,
965-
* especially on older devices with libs compressed in the apk.
966-
*
967-
* <p>Successful loading of the dart library also completes the loadLibrary() future that
975+
* <p>Successful loading of the dart library completes the future returned by loadLibrary() that
968976
* triggered the install/load process.
977+
*
978+
* @param loadingUnitId The loadingUnitId is assigned during compile time by gen_snapshot and is
979+
* automatically retrieved when loadLibrary() is called on a dart deferred
980+
* library. This is used to identify which dart deferred library the resolved
981+
* correspond to.
982+
*
983+
* @param searchPaths An array of paths in which to look for valid dart shared libraries. This
984+
* supports paths within zipped apks as long as the apks are not compressed
985+
* using the `path/to/apk.apk!path/inside/apk/lib.so` format. Paths will be
986+
* tried first to last and ends when a library is sucessfully found. When the
987+
* found library is invalid, no additional paths will be attempted.
969988
*/
970989
@UiThread
971990
public void loadDartDeferredLibrary(
@@ -985,8 +1004,10 @@ private native void nativeLoadDartDeferredLibrary(
9851004
* Specifies a new AssetManager that has access to the dynamic feature's assets in addition to the
9861005
* base module's assets.
9871006
*
988-
* <p>assetBundlePath is the subdirectory that the flutter assets are stored in. The typical value
989-
* is `flutter_assets`.
1007+
* @param assetManager An android AssetManager that is able to access the newly downloaded assets.
1008+
*
1009+
* @param assetBundlePath The subdirectory that the flutter assets are stored in. The typical value
1010+
* is `flutter_assets`.
9901011
*/
9911012
@UiThread
9921013
public void updateAssetManager(
@@ -1001,19 +1022,33 @@ private native void nativeUpdateAssetManager(
10011022
@NonNull AssetManager assetManager,
10021023
@NonNull String assetBundlePath);
10031024

1004-
// Called when an install encounters a failure during the Android portion of installing a module.
1005-
// When transient is false, new attempts to install will automatically result in same error in
1006-
// dart before the request is passed to Android.
1025+
/**
1026+
* Indicates that a failure was encountered during the Android portion of downloading and installing
1027+
* a dynamic feature module.
1028+
*
1029+
* <p>This will inform dart that the future returned by loadLibrary() should complete with an error.
1030+
*
1031+
* @param loadingUnitId The loadingUnitId that corresponds to the dart deferred library that
1032+
* failed to install.
1033+
*
1034+
* @param moduleName The name of the module that includes the loadingUnitId. This parameter is
1035+
* not necessary and used for logging purposes.
1036+
*
1037+
* @param error The error message to display.
1038+
*
1039+
* @param isTransient When isTransient is false, new attempts to install will automatically result in
1040+
* same error in dart before the request is passed to Android.
1041+
*/
10071042
@SuppressWarnings("unused")
10081043
@UiThread
10091044
public void dynamicFeatureInstallFailure(
1010-
@NonNull String moduleName, int loadingUnitId, @NonNull String error, boolean isTransient) {
1045+
int loadingUnitId, String moduleName, @NonNull String error, boolean isTransient) {
10111046
ensureRunningOnMainThread();
1012-
nativeDynamicFeatureInstallFailure(moduleName, loadingUnitId, error, isTransient);
1047+
nativeDynamicFeatureInstallFailure(loadingUnitId, moduleName, error, isTransient);
10131048
}
10141049

10151050
private native void nativeDynamicFeatureInstallFailure(
1016-
@NonNull String moduleName, int loadingUnitId, @NonNull String error, boolean isTransient);
1051+
int loadingUnitId, String moduleName, @NonNull String error, boolean isTransient);
10171052

10181053
// ----- End Dynamic Features Support ----
10191054

shell/platform/android/io/flutter/embedding/engine/dynamicfeatures/PlayStoreDynamicFeatureManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public void onStateUpdate(SplitInstallSessionState state) {
5858
state.sessionId(),
5959
state.errorCode()));
6060
flutterJNI.dynamicFeatureInstallFailure(
61-
sessionIdToName.get(state.sessionId()),
6261
sessionIdToLoadingUnitId.get(state.sessionId()),
62+
sessionIdToName.get(state.sessionId()),
6363
"Module install failed with " + state.errorCode(),
6464
true);
6565
sessionIdToName.remove(state.sessionId());
@@ -204,26 +204,26 @@ public void downloadDynamicFeature(int loadingUnitId, String moduleName) {
204204
switch (((SplitInstallException) exception).getErrorCode()) {
205205
case SplitInstallErrorCode.NETWORK_ERROR:
206206
flutterJNI.dynamicFeatureInstallFailure(
207-
moduleName,
208207
loadingUnitId,
208+
moduleName,
209209
String.format(
210210
"Install of dynamic feature module \"%s\" failed with a network error",
211211
moduleName),
212212
true);
213213
break;
214214
case SplitInstallErrorCode.MODULE_UNAVAILABLE:
215215
flutterJNI.dynamicFeatureInstallFailure(
216-
moduleName,
217216
loadingUnitId,
217+
moduleName,
218218
String.format(
219219
"Install of dynamic feature module \"%s\" failed as it is unavailable",
220220
moduleName),
221221
false);
222222
break;
223223
default:
224224
flutterJNI.dynamicFeatureInstallFailure(
225-
moduleName,
226225
loadingUnitId,
226+
moduleName,
227227
String.format(
228228
"Install of dynamic feature module \"%s\" failed with error %d: %s",
229229
moduleName,

shell/platform/android/platform_view_android_jni_impl.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,8 @@ static void LoadLoadingUnitFailure(intptr_t loading_unit_id,
521521

522522
static void DynamicFeatureInstallFailure(JNIEnv* env,
523523
jobject obj,
524-
jstring moduleName,
525524
jint jLoadingUnitId,
525+
jstring moduleName,
526526
jstring jError,
527527
jboolean jTransient) {
528528
LoadLoadingUnitFailure(static_cast<intptr_t>(jLoadingUnitId),
@@ -599,6 +599,8 @@ static void LoadDartDeferredLibrary(JNIEnv* env,
599599
// TODO(garyq): fallback on soPath.
600600
}
601601

602+
// TODO(garyq): persist additional asset resolvers by updating instead of
603+
// replacing with newly created asset_manager
602604
static void UpdateAssetManager(JNIEnv* env,
603605
jobject obj,
604606
jlong shell_holder,
@@ -786,7 +788,7 @@ bool RegisterApi(JNIEnv* env) {
786788
},
787789
{
788790
.name = "nativeDynamicFeatureInstallFailure",
789-
.signature = "(Ljava/lang/String;ILjava/lang/String;Z)V",
791+
.signature = "(ILjava/lang/String;Ljava/lang/String;Z)V",
790792
.fnPtr = reinterpret_cast<void*>(&DynamicFeatureInstallFailure),
791793
},
792794
};

0 commit comments

Comments
 (0)