diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java index 47eedb6860..07d5f500f2 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java @@ -1283,81 +1283,6 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC textInputPlugin.autofill(values); } - /** - * Render modes for a {@link FlutterView}. - * - *

Deprecated - please use {@link io.flutter.embedding.android.RenderMode} instead. - */ - @Deprecated() - public enum RenderMode { - /** - * {@code RenderMode}, which paints a Flutter UI to a {@link android.view.SurfaceView}. This - * mode has the best performance, but a {@code FlutterView} in this mode cannot be positioned - * between 2 other Android {@code View}s in the z-index, nor can it be animated/transformed. - * Unless the special capabilities of a {@link android.graphics.SurfaceTexture} are required, - * developers should strongly prefer this render mode. - */ - surface, - /** - * {@code RenderMode}, which paints a Flutter UI to a {@link android.graphics.SurfaceTexture}. - * This mode is not as performant as {@link RenderMode#surface}, but a {@code FlutterView} in - * this mode can be animated and transformed, as well as positioned in the z-index between 2+ - * other Android {@code Views}. Unless the special capabilities of a {@link - * android.graphics.SurfaceTexture} are required, developers should strongly prefer the {@link - * RenderMode#surface} render mode. - */ - texture, - /** - * {@code RenderMode}, which paints Paints a Flutter UI provided by an {@link - * android.media.ImageReader} onto a {@link android.graphics.Canvas}. This mode is not as - * performant as {@link RenderMode#surface}, but a {@code FlutterView} in this mode can handle - * full interactivity with a {@link io.flutter.plugin.platform.PlatformView}. Unless {@link - * io.flutter.plugin.platform.PlatformView}s are required developers should strongly prefer the - * {@link RenderMode#surface} render mode. - */ - image - } - - /** - * Transparency mode for a {@code FlutterView}. - * - *

Deprecated - please use {@link io.flutter.embedding.android.TransparencyMode} instead. - * - *

{@code TransparencyMode} impacts the visual behavior and performance of a {@link - * FlutterSurfaceView}, which is displayed when a {@code FlutterView} uses {@link - * RenderMode#surface}. - * - *

{@code TransparencyMode} does not impact {@link FlutterTextureView}, which is displayed when - * a {@code FlutterView} uses {@link RenderMode#texture}, because a {@link FlutterTextureView} - * automatically comes with transparency. - */ - @Deprecated - public enum TransparencyMode { - /** - * Renders a {@code FlutterView} without any transparency. This affects {@code FlutterView}s in - * {@link io.flutter.embedding.android.RenderMode#surface} by introducing a base color of black, - * and places the {@link FlutterSurfaceView}'s {@code Window} behind all other content. - * - *

In {@link io.flutter.embedding.android.RenderMode#surface}, this mode is the most - * performant and is a good choice for fullscreen Flutter UIs that will not undergo {@code - * Fragment} transactions. If this mode is used within a {@code Fragment}, and that {@code - * Fragment} is replaced by another one, a brief black flicker may be visible during the switch. - */ - opaque, - /** - * Renders a {@code FlutterView} with transparency. This affects {@code FlutterView}s in {@link - * io.flutter.embedding.android.RenderMode#surface} by allowing background transparency, and - * places the {@link FlutterSurfaceView}'s {@code Window} on top of all other content. - * - *

In {@link io.flutter.embedding.android.RenderMode#surface}, this mode is less performant - * than {@link #opaque}, but this mode avoids the black flicker problem that {@link #opaque} has - * when going through {@code Fragment} transactions. Consider using this {@code - * TransparencyMode} if you intend to switch {@code Fragment}s at runtime that contain a Flutter - * UI. - */ - transparent - } - /** * Listener that is notified when a {@link io.flutter.embedding.engine.FlutterEngine} is attached * to/detached from a given {@code FlutterView}. diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngineConnectionRegistry.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngineConnectionRegistry.java index 9f23b2e732..98d0047162 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngineConnectionRegistry.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngineConnectionRegistry.java @@ -65,8 +65,6 @@ import java.util.Set; private final Map, ActivityAware> activityAwarePlugins = new HashMap<>(); - // TODO(xster): remove activity after 2021/03/01 since exclusiveActivity should be the API to use. - @Deprecated @Nullable private Activity activity; @Nullable private ExclusiveAppComponent exclusiveActivity; @Nullable private FlutterEngineActivityPluginBinding activityPluginBinding; private boolean isWaitingForActivityReattachment = false; @@ -293,32 +291,11 @@ import java.util.Set; // -------- Start ActivityControlSurface ------- private boolean isAttachedToActivity() { - return activity != null || exclusiveActivity != null; + return exclusiveActivity != null; } private Activity attachedActivity() { - return exclusiveActivity != null ? exclusiveActivity.getAppComponent() : activity; - } - - @Override - public void attachToActivity(@NonNull Activity activity, @NonNull Lifecycle lifecycle) { - Log.v( - TAG, - "Attaching to an Activity: " - + activity - + "." - + (isWaitingForActivityReattachment ? " This is after a config change." : "")); - if (this.exclusiveActivity != null) { - this.exclusiveActivity.detachFromFlutterEngine(); - } - // If we were already attached to an app component, detach from it. - detachFromAppComponent(); - - if (this.exclusiveActivity != null) { - throw new AssertionError("Only activity or exclusiveActivity should be set"); - } - this.activity = activity; - attachToActivityInternal(activity, lifecycle); + return exclusiveActivity != null ? exclusiveActivity.getAppComponent() : null; } @Override @@ -336,10 +313,6 @@ import java.util.Set; } // If we were already attached to an app component, detach from it. detachFromAppComponent(); - - if (this.activity != null) { - throw new AssertionError("Only activity or exclusiveActivity should be set"); - } this.exclusiveActivity = exclusiveActivity; attachToActivityInternal(exclusiveActivity.getAppComponent(), lifecycle); } @@ -400,7 +373,6 @@ import java.util.Set; flutterEngine.getPlatformViewsController().detach(); exclusiveActivity = null; - activity = null; activityPluginBinding = null; } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 5da49e8915..b06487d614 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -135,6 +135,8 @@ public class FlutterJNI { FlutterJNI.prefetchDefaultFontManagerCalled = true; } + private static native void nativePrefetchDefaultFontManager(); + private static boolean prefetchDefaultFontManagerCalled = false; /** @@ -165,6 +167,14 @@ public class FlutterJNI { FlutterJNI.initCalled = true; } + private static native void nativeInit( + @NonNull Context context, + @NonNull String[] args, + @Nullable String bundlePath, + @NonNull String appStoragePath, + @NonNull String engineCachesPath, + long initTimeMillis); + private static boolean initCalled = false; // END methods related to FlutterLoader @@ -176,20 +186,6 @@ public class FlutterJNI { // This is set from native code via JNI. @Nullable private static String observatoryUri; - /** @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); - - /** @deprecated Use {@link #prefetchDefaultFontManager()} instead. */ - @Deprecated - public static native void nativePrefetchDefaultFontManager(); - private native boolean nativeGetIsSoftwareRenderingEnabled(); @UiThread diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java index 7f3a2797e5..190324abc9 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java @@ -54,25 +54,6 @@ public class FlutterLoader { private static FlutterLoader instance; - /** - * Returns a singleton {@code FlutterLoader} instance. - * - *

The returned instance loads Flutter native libraries in the standard way. A singleton object - * is used instead of static methods to facilitate testing without actually running native library - * linking. - * - * @return The Flutter loader. - * @deprecated Use the {@link io.flutter.FlutterInjector} instead. - */ - @Deprecated - @NonNull - public static FlutterLoader getInstance() { - if (instance == null) { - instance = new FlutterLoader(); - } - return instance; - } - /** * Creates a {@code FlutterLoader} that uses a default constructed {@link FlutterJNI} and {@link * ExecutorService}. diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/plugins/activity/ActivityControlSurface.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/plugins/activity/ActivityControlSurface.java index 7e1e8812f9..5ceab71ef4 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/plugins/activity/ActivityControlSurface.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/plugins/activity/ActivityControlSurface.java @@ -50,25 +50,6 @@ import io.flutter.embedding.android.ExclusiveAppComponent; * io.flutter.embedding.engine.FlutterEngine}. */ public interface ActivityControlSurface { - /** - * Call this method from the {@link android.app.Activity} that is displaying the visual content of - * the {@link io.flutter.embedding.engine.FlutterEngine} that is associated with this {@code - * ActivityControlSurface}. - * - *

Once an {@link android.app.Activity} is created, and its associated {@link - * io.flutter.embedding.engine.FlutterEngine} is executing Dart code, the {@link - * android.app.Activity} should invoke this method. At that point the {@link - * io.flutter.embedding.engine.FlutterEngine} is considered "attached" to the {@link - * android.app.Activity} and all {@link ActivityAware} plugins are given access to the {@link - * android.app.Activity}. - * - * @deprecated Prefer using the {@link #attachToActivity(ExclusiveAppComponent, Lifecycle)} API to - * avoid situations where multiple activities are driving the FlutterEngine simultaneously. - * See https://github.com/flutter/flutter/issues/66192. - */ - @Deprecated - void attachToActivity(@NonNull Activity activity, @NonNull Lifecycle lifecycle); - /** * Call this method from the {@link ExclusiveAppComponent} that is displaying the visual content * of the {@link io.flutter.embedding.engine.FlutterEngine} that is associated with this {@code @@ -80,10 +61,6 @@ public interface ActivityControlSurface { * io.flutter.embedding.engine.FlutterEngine} is considered "attached" to the {@link * ExclusiveAppComponent} and all {@link ActivityAware} plugins are given access to the {@link * ExclusiveAppComponent}'s {@link android.app.Activity}. - * - *

This method differs from {@link #attachToActivity(Activity, Lifecycle)} in that it calls - * back the existing {@link ExclusiveAppComponent} to give it a chance to cleanly detach before a - * new {@link ExclusiveAppComponent} is attached. */ void attachToActivity( @NonNull ExclusiveAppComponent exclusiveActivity, @NonNull Lifecycle lifecycle); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java index 4ed83c0d55..4876f1b67c 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java @@ -347,27 +347,6 @@ public class FlutterView extends SurfaceView mFirstFrameListeners.remove(listener); } - /** - * Updates this to support rendering as a transparent {@link SurfaceView}. - * - *

Sets it on top of its window. The background color still needs to be controlled from within - * the Flutter UI itself. - * - * @deprecated FlutterView in the v1 embedding is always a SurfaceView and will cover - * accessibility highlights when transparent. Consider migrating to the v2 Android embedding, - * using {@link io.flutter.embedding.android.FlutterView.RenderMode#texture}, and setting - * {@link io.flutter.embedding.android.FlutterView.TransparencyMode#transparent}. See also - * https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects. - */ - @Deprecated - public void enableTransparentBackground() { - Log.w( - TAG, - "FlutterView in the v1 embedding is always a SurfaceView and will cover accessibility highlights when transparent. Consider migrating to the v2 Android embedding. https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects"); - setZOrderOnTop(true); - getHolder().setFormat(PixelFormat.TRANSPARENT); - } - /** * Reverts this back to the {@link SurfaceView} defaults, at the back of its window and opaque. */ diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java index 869dabc6ab..17607e1c32 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java @@ -409,7 +409,7 @@ public class FlutterActivityAndFragmentDelegateTest { // Verify that the ActivityControlSurface was NOT told to attach or detach to an Activity. verify(mockFlutterEngine.getActivityControlSurface(), never()) - .attachToActivity(any(Activity.class), any(Lifecycle.class)); + .attachToActivity(any(ExclusiveAppComponent.class), any(Lifecycle.class)); verify(mockFlutterEngine.getActivityControlSurface(), never()).detachFromActivity(); } diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineConnectionRegistryTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineConnectionRegistryTest.java index 957b73969f..33f2cc66b7 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineConnectionRegistryTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineConnectionRegistryTest.java @@ -11,6 +11,7 @@ import android.content.Context; import android.content.Intent; import androidx.annotation.NonNull; import androidx.lifecycle.Lifecycle; +import io.flutter.embedding.android.ExclusiveAppComponent; import io.flutter.embedding.engine.loader.FlutterLoader; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.embedding.engine.plugins.activity.ActivityAware; @@ -74,7 +75,11 @@ public class FlutterEngineConnectionRegistryTest { when(flutterEngine.getPlatformViewsController()).thenReturn(platformViewsController); FlutterLoader flutterLoader = mock(FlutterLoader.class); + + ExclusiveAppComponent appComponent = mock(ExclusiveAppComponent.class); Activity activity = mock(Activity.class); + when(appComponent.getAppComponent()).thenReturn(activity); + Lifecycle lifecycle = mock(Lifecycle.class); Intent intent = mock(Intent.class); AtomicBoolean isFirstCall = new AtomicBoolean(true); @@ -84,7 +89,7 @@ public class FlutterEngineConnectionRegistryTest { new FlutterEngineConnectionRegistry(context, flutterEngine, flutterLoader); FakeActivityAwareFlutterPlugin fakePlugin = new FakeActivityAwareFlutterPlugin(); registry.add(fakePlugin); - registry.attachToActivity(activity, lifecycle); + registry.attachToActivity(appComponent, lifecycle); // The binding is now available via `fakePlugin.binding`: Create and add the listeners FakeActivityResultListener listener1 = diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java index 87d5e7a021..21c392879d 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java @@ -19,6 +19,7 @@ import android.widget.FrameLayout.LayoutParams; import io.flutter.embedding.android.FlutterImageView; import io.flutter.embedding.android.FlutterView; import io.flutter.embedding.android.MotionEventTracker; +import io.flutter.embedding.android.RenderMode; import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterJNI; import io.flutter.embedding.engine.FlutterOverlaySurface; @@ -874,7 +875,7 @@ public class PlatformViewsControllerTest { platformViewsController.attach(context, registry, executor); final FlutterView view = - new FlutterView(context, FlutterView.RenderMode.surface) { + new FlutterView(context, RenderMode.surface) { @Override public FlutterImageView createImageView() { final FlutterImageView view = mock(FlutterImageView.class);