Skip to content

Commit

Permalink
Rename DynamicFeature->DeferredComponent and impl uninstall DeferredC…
Browse files Browse the repository at this point in the history
…omponents (flutter#23224)
  • Loading branch information
GaryQian authored Jan 8, 2021
1 parent f661e6d commit 3f20060
Show file tree
Hide file tree
Showing 15 changed files with 407 additions and 342 deletions.
6 changes: 3 additions & 3 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/Flutte
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dart/PlatformMessageHandler.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dynamicfeatures/DynamicFeatureManager.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dynamicfeatures/PlayStoreDynamicFeatureManager.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/deferredcomponents/DeferredComponentManager.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManager.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/loader/ApplicationInfoLoader.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterApplicationInfo.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java
Expand Down Expand Up @@ -788,7 +788,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/render
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/renderer/RenderSurface.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/renderer/SurfaceTextureWrapper.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/AccessibilityChannel.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/DynamicFeatureChannel.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/DeferredComponentChannel.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyEventChannel.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/LifecycleChannel.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/LocalizationChannel.java
Expand Down
10 changes: 5 additions & 5 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ android_java_sources = [
"io/flutter/embedding/engine/dart/DartExecutor.java",
"io/flutter/embedding/engine/dart/DartMessenger.java",
"io/flutter/embedding/engine/dart/PlatformMessageHandler.java",
"io/flutter/embedding/engine/dynamicfeatures/DynamicFeatureManager.java",
"io/flutter/embedding/engine/dynamicfeatures/PlayStoreDynamicFeatureManager.java",
"io/flutter/embedding/engine/deferredcomponents/DeferredComponentManager.java",
"io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManager.java",
"io/flutter/embedding/engine/loader/ApplicationInfoLoader.java",
"io/flutter/embedding/engine/loader/FlutterApplicationInfo.java",
"io/flutter/embedding/engine/loader/FlutterLoader.java",
Expand Down Expand Up @@ -188,7 +188,7 @@ android_java_sources = [
"io/flutter/embedding/engine/renderer/RenderSurface.java",
"io/flutter/embedding/engine/renderer/SurfaceTextureWrapper.java",
"io/flutter/embedding/engine/systemchannels/AccessibilityChannel.java",
"io/flutter/embedding/engine/systemchannels/DynamicFeatureChannel.java",
"io/flutter/embedding/engine/systemchannels/DeferredComponentChannel.java",
"io/flutter/embedding/engine/systemchannels/KeyEventChannel.java",
"io/flutter/embedding/engine/systemchannels/LifecycleChannel.java",
"io/flutter/embedding/engine/systemchannels/LocalizationChannel.java",
Expand Down Expand Up @@ -472,13 +472,13 @@ action("robolectric_tests") {
"test/io/flutter/embedding/engine/RenderingComponentTest.java",
"test/io/flutter/embedding/engine/dart/DartExecutorTest.java",
"test/io/flutter/embedding/engine/dart/DartMessengerTest.java",
"test/io/flutter/embedding/engine/dynamicfeatures/PlayStoreDynamicFeatureManagerTest.java",
"test/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManagerTest.java",
"test/io/flutter/embedding/engine/loader/ApplicationInfoLoaderTest.java",
"test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java",
"test/io/flutter/embedding/engine/mutatorsstack/FlutterMutatorViewTest.java",
"test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java",
"test/io/flutter/embedding/engine/renderer/FlutterRendererTest.java",
"test/io/flutter/embedding/engine/systemchannels/DynamicFeatureChannelTest.java",
"test/io/flutter/embedding/engine/systemchannels/DeferredComponentChannelTest.java",
"test/io/flutter/embedding/engine/systemchannels/KeyEventChannelTest.java",
"test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java",
"test/io/flutter/embedding/engine/systemchannels/RestorationChannelTest.java",
Expand Down
25 changes: 13 additions & 12 deletions shell/platform/android/io/flutter/FlutterInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import io.flutter.embedding.engine.dynamicfeatures.DynamicFeatureManager;
import io.flutter.embedding.engine.deferredcomponents.DeferredComponentManager;
import io.flutter.embedding.engine.loader.FlutterLoader;

/**
Expand Down Expand Up @@ -65,13 +65,13 @@ public static void reset() {
}

private FlutterInjector(
@NonNull FlutterLoader flutterLoader, DynamicFeatureManager dynamicFeatureManager) {
@NonNull FlutterLoader flutterLoader, DeferredComponentManager deferredComponentManager) {
this.flutterLoader = flutterLoader;
this.dynamicFeatureManager = dynamicFeatureManager;
this.deferredComponentManager = deferredComponentManager;
}

private FlutterLoader flutterLoader;
private DynamicFeatureManager dynamicFeatureManager;
private DeferredComponentManager deferredComponentManager;

/** Returns the {@link FlutterLoader} instance to use for the Flutter Android engine embedding. */
@NonNull
Expand All @@ -80,12 +80,12 @@ public FlutterLoader flutterLoader() {
}

/**
* Returns the {@link DynamicFeatureManager} instance to use for the Flutter Android engine
* Returns the {@link DeferredComponentManager} instance to use for the Flutter Android engine
* embedding.
*/
@Nullable
public DynamicFeatureManager dynamicFeatureManager() {
return dynamicFeatureManager;
public DeferredComponentManager deferredComponentManager() {
return deferredComponentManager;
}

/**
Expand All @@ -96,7 +96,7 @@ public DynamicFeatureManager dynamicFeatureManager() {
*/
public static final class Builder {
private FlutterLoader flutterLoader;
private DynamicFeatureManager dynamicFeatureManager;
private DeferredComponentManager deferredComponentManager;
/**
* Sets a {@link FlutterLoader} override.
*
Expand All @@ -107,16 +107,17 @@ public Builder setFlutterLoader(@NonNull FlutterLoader flutterLoader) {
return this;
}

public Builder setDynamicFeatureManager(@Nullable DynamicFeatureManager dynamicFeatureManager) {
this.dynamicFeatureManager = dynamicFeatureManager;
public Builder setDeferredComponentManager(
@Nullable DeferredComponentManager deferredComponentManager) {
this.deferredComponentManager = deferredComponentManager;
return this;
}

private void fillDefaults() {
if (flutterLoader == null) {
flutterLoader = new FlutterLoader();
}
// DynamicFeatureManager's intended default is null.
// DeferredComponentManager's intended default is null.
}

/**
Expand All @@ -126,7 +127,7 @@ private void fillDefaults() {
public FlutterInjector build() {
fillDefaults();

return new FlutterInjector(flutterLoader, dynamicFeatureManager);
return new FlutterInjector(flutterLoader, deferredComponentManager);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import androidx.annotation.CallSuper;
import com.google.android.play.core.splitcompat.SplitCompatApplication;
import io.flutter.FlutterInjector;
import io.flutter.embedding.engine.dynamicfeatures.PlayStoreDynamicFeatureManager;
import io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager;

/**
* Flutter's extension of {@link SplitCompatApplication} that injects a {@link
* PlayStoreDynamicFeatureManager} with {@link FlutterInjector} to enable Split AOT Flutter apps.
* PlayStoreDeferredComponentManager} with {@link FlutterInjector} to enable Split AOT Flutter apps.
*
* <p>To use this class, either have your custom application class extend
* FlutterPlayStoreSplitApplication or use it directly in the app's AndroidManifest.xml by adding
Expand All @@ -29,23 +29,25 @@
*
* This class is meant to be used with the Google Play store. Custom non-play store applications do
* not need to extend SplitCompatApplication and should inject a custom {@link
* io.flutter.embedding.engine.dynamicfeatures.DynamicFeatureManager} implementation like so:
* io.flutter.embedding.engine.deferredcomponents.DeferredComponentManager} implementation like so:
*
* <pre>{@code
* FlutterInjector.setInstance(
* new FlutterInjector.Builder().setDynamicFeatureManager(yourCustomManager).build());
* new FlutterInjector.Builder().setDeferredComponentManager(yourCustomManager).build());
* }</pre>
*/
public class FlutterPlayStoreSplitApplication extends SplitCompatApplication {
@Override
@CallSuper
public void onCreate() {
super.onCreate();
// Create and inject a PlayStoreDynamicFeatureManager, which is the default manager for
// Create and inject a PlayStoreDeferredComponentManager, which is the default manager for
// interacting with the Google Play Store.
PlayStoreDynamicFeatureManager dynamicFeatureManager =
new PlayStoreDynamicFeatureManager(this, null);
PlayStoreDeferredComponentManager deferredComponentManager =
new PlayStoreDeferredComponentManager(this, null);
FlutterInjector.setInstance(
new FlutterInjector.Builder().setDynamicFeatureManager(dynamicFeatureManager).build());
new FlutterInjector.Builder()
.setDeferredComponentManager(deferredComponentManager)
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io.flutter.FlutterInjector;
import io.flutter.Log;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.dynamicfeatures.DynamicFeatureManager;
import io.flutter.embedding.engine.deferredcomponents.DeferredComponentManager;
import io.flutter.embedding.engine.loader.FlutterLoader;
import io.flutter.embedding.engine.plugins.PluginRegistry;
import io.flutter.embedding.engine.plugins.activity.ActivityControlSurface;
Expand All @@ -22,7 +22,7 @@
import io.flutter.embedding.engine.renderer.FlutterRenderer;
import io.flutter.embedding.engine.renderer.RenderSurface;
import io.flutter.embedding.engine.systemchannels.AccessibilityChannel;
import io.flutter.embedding.engine.systemchannels.DynamicFeatureChannel;
import io.flutter.embedding.engine.systemchannels.DeferredComponentChannel;
import io.flutter.embedding.engine.systemchannels.KeyEventChannel;
import io.flutter.embedding.engine.systemchannels.LifecycleChannel;
import io.flutter.embedding.engine.systemchannels.LocalizationChannel;
Expand Down Expand Up @@ -83,7 +83,7 @@ public class FlutterEngine {

// System channels.
@NonNull private final AccessibilityChannel accessibilityChannel;
@NonNull private final DynamicFeatureChannel dynamicFeatureChannel;
@NonNull private final DeferredComponentChannel deferredComponentChannel;
@NonNull private final KeyEventChannel keyEventChannel;
@NonNull private final LifecycleChannel lifecycleChannel;
@NonNull private final LocalizationChannel localizationChannel;
Expand Down Expand Up @@ -278,11 +278,11 @@ public FlutterEngine(
this.dartExecutor = new DartExecutor(flutterJNI, assetManager);
this.dartExecutor.onAttachedToJNI();

DynamicFeatureManager dynamicFeatureManager =
FlutterInjector.instance().dynamicFeatureManager();
DeferredComponentManager deferredComponentManager =
FlutterInjector.instance().deferredComponentManager();

accessibilityChannel = new AccessibilityChannel(dartExecutor, flutterJNI);
dynamicFeatureChannel = new DynamicFeatureChannel(dartExecutor);
deferredComponentChannel = new DeferredComponentChannel(dartExecutor);
keyEventChannel = new KeyEventChannel(dartExecutor);
lifecycleChannel = new LifecycleChannel(dartExecutor);
localizationChannel = new LocalizationChannel(dartExecutor);
Expand All @@ -294,8 +294,8 @@ public FlutterEngine(
systemChannel = new SystemChannel(dartExecutor);
textInputChannel = new TextInputChannel(dartExecutor);

if (dynamicFeatureManager != null) {
dynamicFeatureManager.setDynamicFeatureChannel(dynamicFeatureChannel);
if (deferredComponentManager != null) {
deferredComponentManager.setDeferredComponentChannel(deferredComponentChannel);
}

this.localizationPlugin = new LocalizationPlugin(context, localizationChannel);
Expand All @@ -310,7 +310,7 @@ public FlutterEngine(
flutterJNI.addEngineLifecycleListener(engineLifecycleListener);
flutterJNI.setPlatformViewsController(platformViewsController);
flutterJNI.setLocalizationPlugin(localizationPlugin);
flutterJNI.setDynamicFeatureManager(FlutterInjector.instance().dynamicFeatureManager());
flutterJNI.setDeferredComponentManager(FlutterInjector.instance().deferredComponentManager());

attachToJni();

Expand Down Expand Up @@ -387,11 +387,11 @@ public void destroy() {
platformViewsController.onDetachedFromJNI();
dartExecutor.onDetachedFromJNI();
flutterJNI.removeEngineLifecycleListener(engineLifecycleListener);
flutterJNI.setDynamicFeatureManager(null);
flutterJNI.setDeferredComponentManager(null);
flutterJNI.detachFromNativeAndReleaseResources();
if (FlutterInjector.instance().dynamicFeatureManager() != null) {
FlutterInjector.instance().dynamicFeatureManager().destroy();
dynamicFeatureChannel.setDynamicFeatureManager(null);
if (FlutterInjector.instance().deferredComponentManager() != null) {
FlutterInjector.instance().deferredComponentManager().destroy();
deferredComponentChannel.setDeferredComponentManager(null);
}
}

Expand Down Expand Up @@ -496,10 +496,10 @@ public SettingsChannel getSettingsChannel() {
return settingsChannel;
}

/** System channel that allows manual installation and state querying of dynamic features. */
/** System channel that allows manual installation and state querying of deferred components. */
@NonNull
public DynamicFeatureChannel getDynamicFeatureChannel() {
return dynamicFeatureChannel;
public DeferredComponentChannel getDeferredComponentChannel() {
return deferredComponentChannel;
}

/** System channel that sends memory pressure warnings from Android to Flutter. */
Expand Down
39 changes: 20 additions & 19 deletions shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.flutter.Log;
import io.flutter.embedding.engine.FlutterEngine.EngineLifecycleListener;
import io.flutter.embedding.engine.dart.PlatformMessageHandler;
import io.flutter.embedding.engine.dynamicfeatures.DynamicFeatureManager;
import io.flutter.embedding.engine.deferredcomponents.DeferredComponentManager;
import io.flutter.embedding.engine.mutatorsstack.FlutterMutatorsStack;
import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
import io.flutter.embedding.engine.renderer.RenderSurface;
Expand Down Expand Up @@ -226,7 +226,7 @@ public static native void nativeOnVsync(
@Nullable private LocalizationPlugin localizationPlugin;
@Nullable private PlatformViewsController platformViewsController;

@Nullable private DynamicFeatureManager dynamicFeatureManager;
@Nullable private DeferredComponentManager deferredComponentManager;

@NonNull
private final Set<EngineLifecycleListener> engineLifecycleListeners = new CopyOnWriteArraySet<>();
Expand Down Expand Up @@ -984,23 +984,24 @@ String[] computePlatformResolvedLocale(@NonNull String[] strings) {

// ----- End Localization Support ----

// ----- Start Dynamic Features Support ----
// ----- Start Deferred Components Support ----

/** Sets the dynamic feature manager that is used to download and install split features. */
/** Sets the deferred component manager that is used to download and install split features. */
@UiThread
public void setDynamicFeatureManager(@Nullable DynamicFeatureManager dynamicFeatureManager) {
public void setDeferredComponentManager(
@Nullable DeferredComponentManager deferredComponentManager) {
ensureRunningOnMainThread();
this.dynamicFeatureManager = dynamicFeatureManager;
if (dynamicFeatureManager != null) {
dynamicFeatureManager.setJNI(this);
this.deferredComponentManager = deferredComponentManager;
if (deferredComponentManager != null) {
deferredComponentManager.setJNI(this);
}
}

/**
* Called by dart to request that a Dart deferred library corresponding to loadingUnitId be
* downloaded (if necessary) and loaded into the dart vm.
*
* <p>This method delegates the task to DynamicFeatureManager, which handles the download and
* <p>This method delegates the task to DeferredComponentManager, which handles the download and
* loading of the dart library and any assets.
*
* @param loadingUnitId The loadingUnitId is assigned during compile time by gen_snapshot and is
Expand All @@ -1009,13 +1010,13 @@ public void setDynamicFeatureManager(@Nullable DynamicFeatureManager dynamicFeat
@SuppressWarnings("unused")
@UiThread
public void requestDartDeferredLibrary(int loadingUnitId) {
if (dynamicFeatureManager != null) {
dynamicFeatureManager.installDynamicFeature(loadingUnitId, null);
if (deferredComponentManager != null) {
deferredComponentManager.installDeferredComponent(loadingUnitId, null);
} else {
// TODO(garyq): Add link to setup/instructions guide wiki.
Log.e(
TAG,
"No DynamicFeatureManager found. Android setup must be completed before using split AOT dynamic features.");
"No DeferredComponentManager found. Android setup must be completed before using split AOT deferred components.");
}
}

Expand Down Expand Up @@ -1048,8 +1049,8 @@ private native void nativeLoadDartDeferredLibrary(
/**
* Adds the specified AssetManager as an APKAssetResolver in the Flutter Engine's AssetManager.
*
* <p>This may be used to update the engine AssetManager when a new dynamic feature is installed
* and a new Android AssetManager is created with access to new assets.
* <p>This may be used to update the engine AssetManager when a new deferred component is
* installed and a new Android AssetManager is created with access to new assets.
*
* @param assetManager An android AssetManager that is able to access the newly downloaded assets.
* @param assetBundlePath The subdirectory that the flutter assets are stored in. The typical
Expand All @@ -1071,7 +1072,7 @@ private native void nativeUpdateJavaAssetManager(
/**
* Indicates that a failure was encountered during the Android portion of downloading a dynamic
* feature module and loading a dart deferred library, which is typically done by
* DynamicFeatureManager.
* DeferredComponentManager.
*
* <p>This will inform dart that the future returned by loadLibrary() should complete with an
* error.
Expand All @@ -1084,16 +1085,16 @@ private native void nativeUpdateJavaAssetManager(
*/
@SuppressWarnings("unused")
@UiThread
public void dynamicFeatureInstallFailure(
public void deferredComponentInstallFailure(
int loadingUnitId, @NonNull String error, boolean isTransient) {
ensureRunningOnMainThread();
nativeDynamicFeatureInstallFailure(loadingUnitId, error, isTransient);
nativeDeferredComponentInstallFailure(loadingUnitId, error, isTransient);
}

private native void nativeDynamicFeatureInstallFailure(
private native void nativeDeferredComponentInstallFailure(
int loadingUnitId, @NonNull String error, boolean isTransient);

// ----- End Dynamic Features Support ----
// ----- End Deferred Components Support ----

// @SuppressWarnings("unused")
@UiThread
Expand Down
Loading

0 comments on commit 3f20060

Please sign in to comment.