Rename moduleName to componentName for consistency (flutter/engine#24906)
This commit is contained in:
@@ -21,7 +21,7 @@ import io.flutter.embedding.engine.systemchannels.DeferredComponentChannel;
|
||||
* on deferred imported library. See https://dart.dev/guides/language/language-tour#deferred-loading
|
||||
* This call retrieves a unique identifier called the loading unit id, which is assigned by
|
||||
* gen_snapshot during compilation. The loading unit id is passed down through the engine and
|
||||
* invokes installDeferredComponent. Once the feature module is downloaded, loadAssets and
|
||||
* invokes installDeferredComponent. Once the component is downloaded, loadAssets and
|
||||
* loadDartLibrary should be invoked. loadDartLibrary should find shared library .so files for the
|
||||
* engine to open and pass the .so path to FlutterJNI.loadDartDeferredLibrary. loadAssets should
|
||||
* typically ensure the new assets are available to the engine's asset manager by passing an updated
|
||||
@@ -31,9 +31,9 @@ import io.flutter.embedding.engine.systemchannels.DeferredComponentChannel;
|
||||
* manually via platform channel messages. A full installDeferredComponent implementation should
|
||||
* call these two methods as needed.
|
||||
*
|
||||
* <p>A deferred component module is uniquely identified by a module name as defined in
|
||||
* bundle_config.yaml. Each feature module may contain one or more loading units, uniquely
|
||||
* identified by the loading unit ID and assets.
|
||||
* <p>A deferred component is uniquely identified by a component name as defined in
|
||||
* bundle_config.yaml. Each component may contain one or more loading units, uniquely identified by
|
||||
* the loading unit ID and assets.
|
||||
*/
|
||||
public interface DeferredComponentManager {
|
||||
/**
|
||||
@@ -69,31 +69,33 @@ public interface DeferredComponentManager {
|
||||
public abstract void setDeferredComponentChannel(DeferredComponentChannel channel);
|
||||
|
||||
/**
|
||||
* Request that the feature module be downloaded and installed.
|
||||
* Request that the deferred component be downloaded and installed.
|
||||
*
|
||||
* <p>This method begins the download and installation of the specified feature module. For
|
||||
* <p>This method begins the download and installation of the specified deferred component. For
|
||||
* example, the Play Store dynamic delivery implementation uses SplitInstallManager to request the
|
||||
* download of the module. Download is not complete when this method returns. The download process
|
||||
* should be listened for and upon completion of download, listeners should invoke loadAssets
|
||||
* first and then loadDartLibrary to complete the deferred component load process. Assets-only
|
||||
* deferred components should also call {@link DeferredComponentChannel.completeInstallSuccess} or
|
||||
* {@link DeferredComponentChannel.completeInstallError} to complete the method channel
|
||||
* invocation's dart Future.
|
||||
* download of the component. Download is not complete when this method returns. The download
|
||||
* process should be listened for and upon completion of download, listeners should invoke
|
||||
* loadAssets first and then loadDartLibrary to complete the deferred component load process.
|
||||
* Assets-only deferred components should also call {@link
|
||||
* DeferredComponentChannel.completeInstallSuccess} or {@link
|
||||
* DeferredComponentChannel.completeInstallError} to complete the method channel invocation's dart
|
||||
* Future.
|
||||
*
|
||||
* <p>Both parameters are not always necessary to identify which module to install. Asset-only
|
||||
* modules do not have an associated loadingUnitId. Instead, an invalid ID like -1 may be passed
|
||||
* to download only with moduleName. On the other hand, it can be possible to resolve the
|
||||
* moduleName based on the loadingUnitId. This resolution is done if moduleName is null. At least
|
||||
* one of loadingUnitId or moduleName must be valid or non-null.
|
||||
* <p>Both parameters are not always necessary to identify which component to install. Asset-only
|
||||
* components do not have an associated loadingUnitId. Instead, an invalid ID like -1 may be
|
||||
* passed to download only with componentName. On the other hand, it can be possible to resolve
|
||||
* the componentName based on the loadingUnitId. This resolution is done if componentName is null.
|
||||
* At least one of loadingUnitId or componentName must be valid or non-null.
|
||||
*
|
||||
* <p>Flutter will typically call this method in two ways. When invoked as part of a dart
|
||||
* `loadLibrary()` call, a valid loadingUnitId is passed in while the moduleName is null. In this
|
||||
* case, this method is responsible for figuring out what module the loadingUnitId corresponds to.
|
||||
* `loadLibrary()` call, a valid loadingUnitId is passed in while the componentName is null. In
|
||||
* this case, this method is responsible for figuring out what component the loadingUnitId
|
||||
* corresponds to.
|
||||
*
|
||||
* <p>When invoked manually as part of loading an assets-only module, loadingUnitId is -1
|
||||
* (invalid) and moduleName is supplied. Without a loadingUnitId, this method just downloads the
|
||||
* module by name and attempts to load assets via loadAssets while loadDartLibrary is skipped,
|
||||
* even if the deferred component module includes valid dart libs. To load dart libs, call
|
||||
* <p>When invoked manually as part of loading an assets-only component, loadingUnitId is -1
|
||||
* (invalid) and componentName is supplied. Without a loadingUnitId, this method just downloads
|
||||
* the component by name and attempts to load assets via loadAssets while loadDartLibrary is
|
||||
* skipped, even if the deferred component includes valid dart libs. To load dart libs, call
|
||||
* `loadLibrary()` using the first way described in the previous paragraph as the method channel
|
||||
* invocation will not load dart shared libraries.
|
||||
*
|
||||
@@ -108,22 +110,22 @@ public interface DeferredComponentManager {
|
||||
* primarily used in loadDartLibrary to indicate to Dart which Dart library is being loaded.
|
||||
* Loading unit ids range from 0 to the number existing loading units. Passing a negative
|
||||
* loading unit id indicates that no Dart deferred library should be loaded after download
|
||||
* completes. This is the case when the deferred component module is an assets-only module. If
|
||||
* a negative loadingUnitId is passed, then moduleName must not be null. Passing a
|
||||
* completes. This is the case when the deferred component is an assets-only component. If a
|
||||
* negative loadingUnitId is passed, then componentName must not be null. Passing a
|
||||
* loadingUnitId larger than the highest valid loading unit's id will cause the Dart
|
||||
* loadLibrary() to complete with a failure.
|
||||
* @param moduleName The deferred component module name as defined in bundle_config.yaml. This may
|
||||
* be null if the deferred component to be loaded is associated with a loading unit/deferred
|
||||
* dart library. In this case, it is this method's responsibility to map the loadingUnitId to
|
||||
* its corresponding moduleName. When loading asset-only or other deferred components without
|
||||
* an associated Dart deferred library, loading unit id should a negative value and moduleName
|
||||
* must be non-null.
|
||||
* @param componentName The deferred component component name as defined in bundle_config.yaml.
|
||||
* This may be null if the deferred component to be loaded is associated with a loading
|
||||
* unit/deferred dart library. In this case, it is this method's responsibility to map the
|
||||
* loadingUnitId to its corresponding componentName. When loading asset-only or other deferred
|
||||
* components without an associated Dart deferred library, loading unit id should a negative
|
||||
* value and componentName must be non-null.
|
||||
*/
|
||||
public abstract void installDeferredComponent(int loadingUnitId, String moduleName);
|
||||
public abstract void installDeferredComponent(int loadingUnitId, String componentName);
|
||||
|
||||
/**
|
||||
* Gets the current state of the installation session corresponding to the specified loadingUnitId
|
||||
* and/or moduleName.
|
||||
* and/or componentName.
|
||||
*
|
||||
* <p>Invocations of {@link installDeferredComponent} typically result in asynchronous downloading
|
||||
* and other tasks. This method enables querying of the state of the installation. Querying the
|
||||
@@ -134,30 +136,30 @@ public interface DeferredComponentManager {
|
||||
* component.
|
||||
*
|
||||
* <p>If no deferred component has been installed or requested to be installed by the provided
|
||||
* loadingUnitId or moduleName, then this method will return null.
|
||||
* loadingUnitId or componentName, then this method will return null.
|
||||
*
|
||||
* <p>Depending on the implementation, the returned String may vary. The Play store default
|
||||
* implementation begins in the "requested" state before transitioning to the "downloading" and
|
||||
* "installed" states.
|
||||
*
|
||||
* <p>Only sucessfully requested modules have state. Modules that are invalid or have not been
|
||||
* <p>Only sucessfully requested components have state. Modules that are invalid or have not been
|
||||
* requested with {@link installDeferredComponent} will not have a state. Due to the asynchronous
|
||||
* nature of the download process, modules may not immediately have a valid state upon return of
|
||||
* {@link installDeferredComponent}, though valid modules will eventually obtain a state.
|
||||
* nature of the download process, components may not immediately have a valid state upon return
|
||||
* of {@link installDeferredComponent}, though valid components will eventually obtain a state.
|
||||
*
|
||||
* <p>Both parameters are not always necessary to identify which module to install. Asset-only
|
||||
* modules do not have an associated loadingUnitId. Instead, an invalid ID like -1 may be passed
|
||||
* to query only with moduleName. On the other hand, it can be possible to resolve the moduleName
|
||||
* based on the loadingUnitId. This resolution is done if moduleName is null. At least one of
|
||||
* loadingUnitId or moduleName must be valid or non-null.
|
||||
* <p>Both parameters are not always necessary to identify which component to install. Asset-only
|
||||
* components do not have an associated loadingUnitId. Instead, an invalid ID like -1 may be
|
||||
* passed to query only with componentName. On the other hand, it can be possible to resolve the
|
||||
* componentName based on the loadingUnitId. This resolution is done if componentName is null. At
|
||||
* least one of loadingUnitId or componentName must be valid or non-null.
|
||||
*
|
||||
* @param loadingUnitId The unique identifier associated with a Dart deferred library.
|
||||
* @param moduleName The deferred component module name as defined in bundle_config.yaml.
|
||||
* @param componentName The deferred component name as defined in bundle_config.yaml.
|
||||
*/
|
||||
public abstract String getDeferredComponentInstallState(int loadingUnitId, String moduleName);
|
||||
public abstract String getDeferredComponentInstallState(int loadingUnitId, String componentName);
|
||||
|
||||
/**
|
||||
* Extract and load any assets and resources from the module for use by Flutter.
|
||||
* Extract and load any assets and resources from the deferred component for use by Flutter.
|
||||
*
|
||||
* <p>This method should provide a refreshed AssetManager to FlutterJNI.updateAssetManager that
|
||||
* can access the new assets. If no assets are included as part of the deferred component, then
|
||||
@@ -166,7 +168,7 @@ public interface DeferredComponentManager {
|
||||
* <p>If using the Play Store deferred component delivery, refresh the context via: {@code
|
||||
* context.createPackageContext(context.getPackageName(), 0);} This returns a new context, from
|
||||
* which an updated asset manager may be obtained and passed to updateAssetManager in FlutterJNI.
|
||||
* This process does not require loadingUnitId or moduleName, however, the two parameters are
|
||||
* This process does not require loadingUnitId or componentName, however, the two parameters are
|
||||
* still present for custom implementations that store assets outside of Android's native system.
|
||||
*
|
||||
* <p>Assets shoud be loaded before the Dart deferred library is loaded, as successful loading of
|
||||
@@ -174,15 +176,15 @@ public interface DeferredComponentManager {
|
||||
* installDeferredComponent should invoke this after successful download.
|
||||
*
|
||||
* @param loadingUnitId The unique identifier associated with a Dart deferred library.
|
||||
* @param moduleName The deferred component module name as defined in bundle_config.yaml.
|
||||
* @param componentName The deferred component name as defined in bundle_config.yaml.
|
||||
*/
|
||||
public abstract void loadAssets(int loadingUnitId, String moduleName);
|
||||
public abstract void loadAssets(int loadingUnitId, String componentName);
|
||||
|
||||
/**
|
||||
* Load the .so shared library file into the Dart VM.
|
||||
*
|
||||
* <p>When the download of a deferred component module completes, this method should be called to
|
||||
* find the path .so library file. The path(s) should then be passed to
|
||||
* <p>When the download of a deferred component completes, this method should be called to find
|
||||
* the path .so library file. The path(s) should then be passed to
|
||||
* FlutterJNI.loadDartDeferredLibrary to be dlopen-ed and loaded into the Dart VM.
|
||||
*
|
||||
* <p>Specifically, APKs distributed by Android's app bundle format may vary by device and API
|
||||
@@ -192,21 +194,21 @@ public interface DeferredComponentManager {
|
||||
* until a shared library is found. This allows for the developer to avoid unpacking the apk zip.
|
||||
*
|
||||
* <p>Upon successful load of the Dart library, the Dart future from the originating loadLibary()
|
||||
* call completes and developers are able to use symbols and assets from the feature module.
|
||||
* call completes and developers are able to use symbols and assets from the deferred component.
|
||||
*
|
||||
* @param loadingUnitId The unique identifier associated with a Dart deferred library. This id is
|
||||
* assigned by the compiler and can be seen for reference in bundle_config.yaml. This ID is
|
||||
* primarily used in loadDartLibrary to indicate to Dart which Dart library is being loaded.
|
||||
* Loading unit ids range from 0 to the number existing loading units. Negative loading unit
|
||||
* ids are considered invalid and this method will result in a no-op.
|
||||
* @param moduleName The deferred component module name as defined in bundle_config.yaml. If using
|
||||
* @param componentName The deferred component name as defined in bundle_config.yaml. If using
|
||||
* Play Store deferred component delivery, this name corresponds to the root name on the
|
||||
* installed APKs in which to search for the desired shared library .so file.
|
||||
*/
|
||||
public abstract void loadDartLibrary(int loadingUnitId, String moduleName);
|
||||
public abstract void loadDartLibrary(int loadingUnitId, String componentName);
|
||||
|
||||
/**
|
||||
* Request that the specified feature module be uninstalled.
|
||||
* Request that the specified component be uninstalled.
|
||||
*
|
||||
* <p>Since uninstallation requires significant disk i/o, this method only signals the intent to
|
||||
* uninstall. Actual uninstallation (eg, removal of assets and files) may occur at a later time.
|
||||
@@ -216,18 +218,18 @@ public interface DeferredComponentManager {
|
||||
* <p>Uninstallation, once complete, removes downloaded files and will require redownloading to
|
||||
* install again.
|
||||
*
|
||||
* <p>Both parameters are not always necessary to identify which module to uninstall. Asset-only
|
||||
* modules do not have an associated loadingUnitId. Instead, an invalid ID like -1 may be passed
|
||||
* to download only with moduleName. On the other hand, it can be possible to resolve the
|
||||
* moduleName based on the loadingUnitId. This resolution is done if moduleName is null. At least
|
||||
* one of loadingUnitId or moduleName must be valid or non-null.
|
||||
* <p>Both parameters are not always necessary to identify which component to uninstall.
|
||||
* Asset-only components do not have an associated loadingUnitId. Instead, an invalid ID like -1
|
||||
* may be passed to download only with componentName. On the other hand, it can be possible to
|
||||
* resolve the componentName based on the loadingUnitId. This resolution is done if componentName
|
||||
* is null. At least one of loadingUnitId or componentName must be valid or non-null.
|
||||
*
|
||||
* @return false if no deferred component was found matching the input, true if an uninstall was
|
||||
* successfully requested.
|
||||
* @param loadingUnitId The unique identifier associated with a Dart deferred library.
|
||||
* @param moduleName The deferred component module name as defined in bundle_config.yaml.
|
||||
* @param componentName The deferred component name as defined in bundle_config.yaml.
|
||||
*/
|
||||
public abstract boolean uninstallDeferredComponent(int loadingUnitId, String moduleName);
|
||||
public abstract boolean uninstallDeferredComponent(int loadingUnitId, String componentName);
|
||||
|
||||
/**
|
||||
* Cleans up and releases resources. This object is no longer usable after calling this method.
|
||||
|
||||
@@ -38,8 +38,8 @@ import java.util.Map;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* Flutter default implementation of DeferredComponentManager that downloads deferred component
|
||||
* modules from the Google Play store.
|
||||
* Flutter default implementation of DeferredComponentManager that downloads deferred component from
|
||||
* the Google Play store as a dynamic feature module.
|
||||
*/
|
||||
public class PlayStoreDeferredComponentManager implements DeferredComponentManager {
|
||||
private static final String TAG = "PlayStoreDeferredComponentManager";
|
||||
@@ -53,13 +53,13 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
private @NonNull Context context;
|
||||
private @NonNull FlutterApplicationInfo flutterApplicationInfo;
|
||||
// Each request to install a feature module gets a session ID. These maps associate
|
||||
// the session ID with the loading unit and module name that was requested.
|
||||
// the session ID with the loading unit and component name that was requested.
|
||||
private @NonNull SparseArray<String> sessionIdToName;
|
||||
private @NonNull SparseIntArray sessionIdToLoadingUnitId;
|
||||
private @NonNull SparseArray<String> sessionIdToState;
|
||||
private @NonNull Map<String, Integer> nameToSessionId;
|
||||
|
||||
protected @NonNull SparseArray<String> loadingUnitIdToModuleNames;
|
||||
protected @NonNull SparseArray<String> loadingUnitIdToComponentNames;
|
||||
protected @NonNull SparseArray<String> loadingUnitIdToSharedLibraryNames;
|
||||
|
||||
private FeatureInstallStateUpdatedListener listener;
|
||||
@@ -100,7 +100,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
sessionIdToName.get(sessionId), sessionId));
|
||||
loadAssets(sessionIdToLoadingUnitId.get(sessionId), sessionIdToName.get(sessionId));
|
||||
// We only load Dart shared lib for the loading unit id requested. Other loading units
|
||||
// (if present) in the deferred component module are not loaded, but can be loaded by
|
||||
// (if present) in the deferred component are not loaded, but can be loaded by
|
||||
// calling again with their loading unit id. If no valid loadingUnitId was included in
|
||||
// the installation request such as for an asset only feature, then we can skip this.
|
||||
if (sessionIdToLoadingUnitId.get(sessionId) > 0) {
|
||||
@@ -212,9 +212,9 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
sessionIdToState = new SparseArray<>();
|
||||
nameToSessionId = new HashMap<>();
|
||||
|
||||
loadingUnitIdToModuleNames = new SparseArray<>();
|
||||
loadingUnitIdToComponentNames = new SparseArray<>();
|
||||
loadingUnitIdToSharedLibraryNames = new SparseArray<>();
|
||||
initLoadingUnitMappingToModuleNames();
|
||||
initLoadingUnitMappingToComponentNames();
|
||||
}
|
||||
|
||||
public void setJNI(@NonNull FlutterJNI flutterJNI) {
|
||||
@@ -248,13 +248,13 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
|
||||
// Obtain and parses the metadata string. An example encoded string is:
|
||||
//
|
||||
// "2:module2,3:module3,4:module1:libmodule4.so"
|
||||
// "2:component2,3:component3,4:component1:libcomponent4.so"
|
||||
//
|
||||
// Where loading unit 2 is included in module2, loading unit 3 is
|
||||
// included in module3, and loading unit 4 is included in module1.
|
||||
// Where loading unit 2 is included in component2, loading unit 3 is
|
||||
// included in component3, and loading unit 4 is included in component1.
|
||||
// An optional third parameter can be added to indicate the name of
|
||||
// the shared library of the loading unit.
|
||||
private void initLoadingUnitMappingToModuleNames() {
|
||||
private void initLoadingUnitMappingToComponentNames() {
|
||||
String mappingKey = DeferredComponentManager.class.getName() + ".loadingUnitMapping";
|
||||
ApplicationInfo applicationInfo = getApplicationInfo();
|
||||
if (applicationInfo != null) {
|
||||
@@ -271,7 +271,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
for (String entry : rawMappingString.split(",")) {
|
||||
String[] splitEntry = entry.split(":");
|
||||
int loadingUnitId = Integer.parseInt(splitEntry[0]);
|
||||
loadingUnitIdToModuleNames.put(loadingUnitId, splitEntry[1]);
|
||||
loadingUnitIdToComponentNames.put(loadingUnitId, splitEntry[1]);
|
||||
if (splitEntry.length > 2) {
|
||||
loadingUnitIdToSharedLibraryNames.put(loadingUnitId, splitEntry[2]);
|
||||
}
|
||||
@@ -281,18 +281,17 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
}
|
||||
}
|
||||
|
||||
public void installDeferredComponent(int loadingUnitId, String moduleName) {
|
||||
String resolvedModuleName =
|
||||
moduleName != null ? moduleName : loadingUnitIdToModuleNames.get(loadingUnitId);
|
||||
if (resolvedModuleName == null) {
|
||||
public void installDeferredComponent(int loadingUnitId, String componentName) {
|
||||
String resolvedComponentName =
|
||||
componentName != null ? componentName : loadingUnitIdToComponentNames.get(loadingUnitId);
|
||||
if (resolvedComponentName == null) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Deferred component module name was null and could not be resolved from loading unit id.");
|
||||
TAG, "Deferred component name was null and could not be resolved from loading unit id.");
|
||||
return;
|
||||
}
|
||||
|
||||
SplitInstallRequest request =
|
||||
SplitInstallRequest.newBuilder().addModule(resolvedModuleName).build();
|
||||
SplitInstallRequest.newBuilder().addModule(resolvedComponentName).build();
|
||||
|
||||
splitInstallManager
|
||||
// Submits the request to install the module through the
|
||||
@@ -303,12 +302,12 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
// install which is handled in FeatureInstallStateUpdatedListener.
|
||||
.addOnSuccessListener(
|
||||
sessionId -> {
|
||||
sessionIdToName.put(sessionId, resolvedModuleName);
|
||||
sessionIdToName.put(sessionId, resolvedComponentName);
|
||||
sessionIdToLoadingUnitId.put(sessionId, loadingUnitId);
|
||||
if (nameToSessionId.containsKey(resolvedModuleName)) {
|
||||
sessionIdToState.remove(nameToSessionId.get(resolvedModuleName));
|
||||
if (nameToSessionId.containsKey(resolvedComponentName)) {
|
||||
sessionIdToState.remove(nameToSessionId.get(resolvedComponentName));
|
||||
}
|
||||
nameToSessionId.put(resolvedModuleName, sessionId);
|
||||
nameToSessionId.put(resolvedComponentName, sessionId);
|
||||
sessionIdToState.put(sessionId, "Requested");
|
||||
})
|
||||
.addOnFailureListener(
|
||||
@@ -319,7 +318,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
loadingUnitId,
|
||||
String.format(
|
||||
"Install of deferred component module \"%s\" failed with a network error",
|
||||
moduleName),
|
||||
componentName),
|
||||
true);
|
||||
break;
|
||||
case SplitInstallErrorCode.MODULE_UNAVAILABLE:
|
||||
@@ -327,7 +326,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
loadingUnitId,
|
||||
String.format(
|
||||
"Install of deferred component module \"%s\" failed as it is unavailable",
|
||||
moduleName),
|
||||
componentName),
|
||||
false);
|
||||
break;
|
||||
default:
|
||||
@@ -335,7 +334,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
loadingUnitId,
|
||||
String.format(
|
||||
"Install of deferred component module \"%s\" failed with error %d: %s",
|
||||
moduleName,
|
||||
componentName,
|
||||
((SplitInstallException) exception).getErrorCode(),
|
||||
((SplitInstallException) exception).getMessage()),
|
||||
false);
|
||||
@@ -344,26 +343,25 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
});
|
||||
}
|
||||
|
||||
public String getDeferredComponentInstallState(int loadingUnitId, String moduleName) {
|
||||
String resolvedModuleName =
|
||||
moduleName != null ? moduleName : loadingUnitIdToModuleNames.get(loadingUnitId);
|
||||
if (resolvedModuleName == null) {
|
||||
public String getDeferredComponentInstallState(int loadingUnitId, String componentName) {
|
||||
String resolvedComponentName =
|
||||
componentName != null ? componentName : loadingUnitIdToComponentNames.get(loadingUnitId);
|
||||
if (resolvedComponentName == null) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Deferred component module name was null and could not be resolved from loading unit id.");
|
||||
TAG, "Deferred component name was null and could not be resolved from loading unit id.");
|
||||
return "unknown";
|
||||
}
|
||||
if (!nameToSessionId.containsKey(resolvedModuleName)) {
|
||||
if (splitInstallManager.getInstalledModules().contains(resolvedModuleName)) {
|
||||
if (!nameToSessionId.containsKey(resolvedComponentName)) {
|
||||
if (splitInstallManager.getInstalledModules().contains(resolvedComponentName)) {
|
||||
return "installedPendingLoad";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
int sessionId = nameToSessionId.get(resolvedModuleName);
|
||||
int sessionId = nameToSessionId.get(resolvedComponentName);
|
||||
return sessionIdToState.get(sessionId);
|
||||
}
|
||||
|
||||
public void loadAssets(int loadingUnitId, String moduleName) {
|
||||
public void loadAssets(int loadingUnitId, String componentName) {
|
||||
if (!verifyJNI()) {
|
||||
return;
|
||||
}
|
||||
@@ -381,7 +379,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
}
|
||||
}
|
||||
|
||||
public void loadDartLibrary(int loadingUnitId, String moduleName) {
|
||||
public void loadDartLibrary(int loadingUnitId, String componentName) {
|
||||
if (!verifyJNI()) {
|
||||
return;
|
||||
}
|
||||
@@ -424,7 +422,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
continue;
|
||||
}
|
||||
String name = file.getName();
|
||||
if (name.endsWith(".apk") && name.startsWith(moduleName) && name.contains(pathAbi)) {
|
||||
if (name.endsWith(".apk") && name.startsWith(componentName) && name.contains(pathAbi)) {
|
||||
apkPaths.add(file.getAbsolutePath());
|
||||
continue;
|
||||
}
|
||||
@@ -450,20 +448,19 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
|
||||
loadingUnitId, searchPaths.toArray(new String[apkPaths.size()]));
|
||||
}
|
||||
|
||||
public boolean uninstallDeferredComponent(int loadingUnitId, String moduleName) {
|
||||
String resolvedModuleName =
|
||||
moduleName != null ? moduleName : loadingUnitIdToModuleNames.get(loadingUnitId);
|
||||
if (resolvedModuleName == null) {
|
||||
public boolean uninstallDeferredComponent(int loadingUnitId, String componentName) {
|
||||
String resolvedComponentName =
|
||||
componentName != null ? componentName : loadingUnitIdToComponentNames.get(loadingUnitId);
|
||||
if (resolvedComponentName == null) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Deferred component module name was null and could not be resolved from loading unit id.");
|
||||
TAG, "Deferred component name was null and could not be resolved from loading unit id.");
|
||||
return false;
|
||||
}
|
||||
List<String> modulesToUninstall = new ArrayList<>();
|
||||
modulesToUninstall.add(resolvedModuleName);
|
||||
modulesToUninstall.add(resolvedComponentName);
|
||||
splitInstallManager.deferredUninstall(modulesToUninstall);
|
||||
if (nameToSessionId.get(resolvedModuleName) != null) {
|
||||
sessionIdToState.delete(nameToSessionId.get(resolvedModuleName));
|
||||
if (nameToSessionId.get(resolvedComponentName) != null) {
|
||||
sessionIdToState.delete(nameToSessionId.get(resolvedComponentName));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* Method channel that handles manual installation requests and queries for installation state for
|
||||
* deferred component modules.
|
||||
* deferred components.
|
||||
*
|
||||
* <p>This channel is able to handle multiple simultaneous installation requests
|
||||
*/
|
||||
@@ -31,9 +31,9 @@ public class DeferredComponentChannel {
|
||||
@NonNull private final MethodChannel channel;
|
||||
@Nullable private DeferredComponentManager deferredComponentManager;
|
||||
// Track the Result objects to be able to handle multiple install requests of
|
||||
// the same module at a time. When installation enters a terminal state, either
|
||||
// the same components at a time. When installation enters a terminal state, either
|
||||
// completeInstallSuccess or completeInstallError can be called.
|
||||
@NonNull private Map<String, List<MethodChannel.Result>> moduleNameToResults;
|
||||
@NonNull private Map<String, List<MethodChannel.Result>> componentNameToResults;
|
||||
|
||||
@NonNull @VisibleForTesting
|
||||
final MethodChannel.MethodCallHandler parsingMethodHandler =
|
||||
@@ -48,22 +48,22 @@ public class DeferredComponentChannel {
|
||||
Map<String, Object> args = call.arguments();
|
||||
Log.v(TAG, "Received '" + method + "' message.");
|
||||
final int loadingUnitId = (int) args.get("loadingUnitId");
|
||||
final String moduleName = (String) args.get("moduleName");
|
||||
final String componentName = (String) args.get("componentName");
|
||||
switch (method) {
|
||||
case "installDeferredComponent":
|
||||
deferredComponentManager.installDeferredComponent(loadingUnitId, moduleName);
|
||||
if (!moduleNameToResults.containsKey(moduleName)) {
|
||||
moduleNameToResults.put(moduleName, new ArrayList<>());
|
||||
deferredComponentManager.installDeferredComponent(loadingUnitId, componentName);
|
||||
if (!componentNameToResults.containsKey(componentName)) {
|
||||
componentNameToResults.put(componentName, new ArrayList<>());
|
||||
}
|
||||
moduleNameToResults.get(moduleName).add(result);
|
||||
componentNameToResults.get(componentName).add(result);
|
||||
break;
|
||||
case "getDeferredComponentInstallState":
|
||||
result.success(
|
||||
deferredComponentManager.getDeferredComponentInstallState(
|
||||
loadingUnitId, moduleName));
|
||||
loadingUnitId, componentName));
|
||||
break;
|
||||
case "uninstallDeferredComponent":
|
||||
deferredComponentManager.uninstallDeferredComponent(loadingUnitId, moduleName);
|
||||
deferredComponentManager.uninstallDeferredComponent(loadingUnitId, componentName);
|
||||
result.success(null);
|
||||
break;
|
||||
default:
|
||||
@@ -86,7 +86,7 @@ public class DeferredComponentChannel {
|
||||
new MethodChannel(dartExecutor, "flutter/deferredcomponent", StandardMethodCodec.INSTANCE);
|
||||
channel.setMethodCallHandler(parsingMethodHandler);
|
||||
deferredComponentManager = FlutterInjector.instance().deferredComponentManager();
|
||||
moduleNameToResults = new HashMap<>();
|
||||
componentNameToResults = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,36 +101,34 @@ public class DeferredComponentChannel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes the `installDeferredComponent` method channel call for the specified moduleName with a
|
||||
* success.
|
||||
* Finishes the `installDeferredComponent` method channel call for the specified componentName
|
||||
* with a success.
|
||||
*
|
||||
* @param moduleName The name of the android deferred component module install request to
|
||||
* complete.
|
||||
* @param componentName The name of the android deferred component install request to complete.
|
||||
*/
|
||||
public void completeInstallSuccess(String moduleName) {
|
||||
if (moduleNameToResults.containsKey(moduleName)) {
|
||||
for (MethodChannel.Result result : moduleNameToResults.get(moduleName)) {
|
||||
public void completeInstallSuccess(String componentName) {
|
||||
if (componentNameToResults.containsKey(componentName)) {
|
||||
for (MethodChannel.Result result : componentNameToResults.get(componentName)) {
|
||||
result.success(null);
|
||||
}
|
||||
moduleNameToResults.get(moduleName).clear();
|
||||
componentNameToResults.get(componentName).clear();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes the `installDeferredComponent` method channel call for the specified moduleName with
|
||||
* an error/failure.
|
||||
* Finishes the `installDeferredComponent` method channel call for the specified componentName
|
||||
* with an error/failure.
|
||||
*
|
||||
* @param moduleName The name of the android deferred component module install request to
|
||||
* complete.
|
||||
* @param componentName The name of the android deferred component install request to complete.
|
||||
* @param errorMessage The error message to display to complete the future with.
|
||||
*/
|
||||
public void completeInstallError(String moduleName, String errorMessage) {
|
||||
if (moduleNameToResults.containsKey(moduleName)) {
|
||||
for (MethodChannel.Result result : moduleNameToResults.get(moduleName)) {
|
||||
public void completeInstallError(String componentName, String errorMessage) {
|
||||
if (componentNameToResults.containsKey(componentName)) {
|
||||
for (MethodChannel.Result result : componentNameToResults.get(componentName)) {
|
||||
result.error("DeferredComponent Install failure", errorMessage, null);
|
||||
}
|
||||
moduleNameToResults.get(moduleName).clear();
|
||||
componentNameToResults.get(componentName).clear();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -74,10 +74,10 @@ public class PlayStoreDeferredComponentManagerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void installDeferredComponent(int loadingUnitId, String moduleName) {
|
||||
public void installDeferredComponent(int loadingUnitId, String componentName) {
|
||||
// Override this to skip the online SplitInstallManager portion.
|
||||
loadAssets(loadingUnitId, moduleName);
|
||||
loadDartLibrary(loadingUnitId, moduleName);
|
||||
loadAssets(loadingUnitId, componentName);
|
||||
loadDartLibrary(loadingUnitId, componentName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.robolectric.annotation.Config;
|
||||
|
||||
class TestDeferredComponentManager implements DeferredComponentManager {
|
||||
DeferredComponentChannel channel;
|
||||
String moduleName;
|
||||
String componentName;
|
||||
|
||||
public void setJNI(FlutterJNI flutterJNI) {}
|
||||
|
||||
@@ -26,23 +26,23 @@ class TestDeferredComponentManager implements DeferredComponentManager {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public void installDeferredComponent(int loadingUnitId, String moduleName) {
|
||||
this.moduleName = moduleName;
|
||||
public void installDeferredComponent(int loadingUnitId, String componentName) {
|
||||
this.componentName = componentName;
|
||||
}
|
||||
|
||||
public void completeInstall() {
|
||||
channel.completeInstallSuccess(moduleName);
|
||||
channel.completeInstallSuccess(componentName);
|
||||
}
|
||||
|
||||
public String getDeferredComponentInstallState(int loadingUnitId, String moduleName) {
|
||||
public String getDeferredComponentInstallState(int loadingUnitId, String componentName) {
|
||||
return "installed";
|
||||
}
|
||||
|
||||
public void loadAssets(int loadingUnitId, String moduleName) {}
|
||||
public void loadAssets(int loadingUnitId, String componentName) {}
|
||||
|
||||
public void loadDartLibrary(int loadingUnitId, String moduleName) {}
|
||||
public void loadDartLibrary(int loadingUnitId, String componentName) {}
|
||||
|
||||
public boolean uninstallDeferredComponent(int loadingUnitId, String moduleName) {
|
||||
public boolean uninstallDeferredComponent(int loadingUnitId, String componentName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class DeferredComponentChannelTest {
|
||||
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("loadingUnitId", -1);
|
||||
args.put("moduleName", "hello");
|
||||
args.put("componentName", "hello");
|
||||
MethodCall methodCall = new MethodCall("installDeferredComponent", args);
|
||||
MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
|
||||
fakeDeferredComponentChannel.parsingMethodHandler.onMethodCall(methodCall, mockResult);
|
||||
@@ -87,7 +87,7 @@ public class DeferredComponentChannelTest {
|
||||
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("loadingUnitId", -1);
|
||||
args.put("moduleName", "hello");
|
||||
args.put("componentName", "hello");
|
||||
MethodCall methodCall = new MethodCall("installDeferredComponent", args);
|
||||
MethodChannel.Result mockResult1 = mock(MethodChannel.Result.class);
|
||||
MethodChannel.Result mockResult2 = mock(MethodChannel.Result.class);
|
||||
@@ -112,7 +112,7 @@ public class DeferredComponentChannelTest {
|
||||
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("loadingUnitId", -1);
|
||||
args.put("moduleName", "hello");
|
||||
args.put("componentName", "hello");
|
||||
MethodCall methodCall = new MethodCall("getDeferredComponentInstallState", args);
|
||||
MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
|
||||
fakeDeferredComponentChannel.parsingMethodHandler.onMethodCall(methodCall, mockResult);
|
||||
|
||||
Reference in New Issue
Block a user