Remove some deprecated APIs from the Android embedding (flutter/engine#28977)

This commit is contained in:
Emmanuel Garcia
2021-10-06 15:38:02 -07:00
committed by GitHub
parent 60d358d6a8
commit c47526067a
9 changed files with 21 additions and 185 deletions

View File

@@ -1283,81 +1283,6 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC
textInputPlugin.autofill(values);
}
/**
* Render modes for a {@link FlutterView}.
*
* <p>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}.
*
* <p>Deprecated - please use {@link io.flutter.embedding.android.TransparencyMode} instead.
*
* <p>{@code TransparencyMode} impacts the visual behavior and performance of a {@link
* FlutterSurfaceView}, which is displayed when a {@code FlutterView} uses {@link
* RenderMode#surface}.
*
* <p>{@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.
*
* <p>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.
*
* <p>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}.

View File

@@ -65,8 +65,6 @@ import java.util.Set;
private final Map<Class<? extends FlutterPlugin>, 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<Activity> 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;
}

View File

@@ -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

View File

@@ -54,25 +54,6 @@ public class FlutterLoader {
private static FlutterLoader instance;
/**
* Returns a singleton {@code FlutterLoader} instance.
*
* <p>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}.

View File

@@ -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}.
*
* <p>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}.
*
* <p>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<Activity> exclusiveActivity, @NonNull Lifecycle lifecycle);

View File

@@ -347,27 +347,6 @@ public class FlutterView extends SurfaceView
mFirstFrameListeners.remove(listener);
}
/**
* Updates this to support rendering as a transparent {@link SurfaceView}.
*
* <p>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.
*/

View File

@@ -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();
}

View File

@@ -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 =

View File

@@ -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);