diff --git a/dev/integration_tests/android_engine_test/android/app/src/main/kotlin/com/example/native_driver_test/MainActivity.kt b/dev/integration_tests/android_engine_test/android/app/src/main/kotlin/com/example/native_driver_test/MainActivity.kt index 389deaa422..dae1f3c4ed 100644 --- a/dev/integration_tests/android_engine_test/android/app/src/main/kotlin/com/example/native_driver_test/MainActivity.kt +++ b/dev/integration_tests/android_engine_test/android/app/src/main/kotlin/com/example/native_driver_test/MainActivity.kt @@ -32,17 +32,6 @@ class MainActivity : FlutterActivity() { add(NativeDriverSupportPlugin()) } - // TODO(jonahwilliams): make platform view controllers share platform view registry. - flutterEngine - .platformViewsController2 - .registry - .apply { - registerViewFactory("blue_orange_gradient_platform_view", BlueOrangeGradientPlatformViewFactory()) - registerViewFactory("blue_orange_gradient_surface_view_platform_view", BlueOrangeGradientSurfaceViewPlatformViewFactory()) - registerViewFactory("changing_color_button_platform_view", ChangingColorButtonPlatformViewFactory()) - registerViewFactory("box_platform_view", BoxPlatformViewFactory()) - } - flutterEngine .platformViewsController .registry diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java index 2957c9a355..9e46ada709 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java @@ -364,6 +364,7 @@ public class FlutterEngine implements ViewUtils.DisplayUpdater { } PlatformViewsController2 platformViewsController2 = new PlatformViewsController2(); + platformViewsController2.setRegistry(platformViewsController.getRegistry()); flutterJNI.addEngineLifecycleListener(engineLifecycleListener); flutterJNI.setPlatformViewsController(platformViewsController); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java index 10fa4cf4d8..f42b7949bd 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java @@ -46,7 +46,7 @@ import java.util.List; public class PlatformViewsController2 implements PlatformViewsAccessibilityDelegate { private static final String TAG = "PlatformViewsController2"; - private final PlatformViewRegistryImpl registry; + private PlatformViewRegistryImpl registry; private AndroidTouchProcessor androidTouchProcessor; private Context context; private FlutterView flutterView; @@ -65,7 +65,6 @@ public class PlatformViewsController2 implements PlatformViewsAccessibilityDeleg private Surface overlayerSurface = null; public PlatformViewsController2() { - registry = new PlatformViewRegistryImpl(); accessibilityEventsDelegate = new AccessibilityEventsDelegate(); platformViews = new SparseArray<>(); platformViewParent = new SparseArray<>(); @@ -74,6 +73,10 @@ public class PlatformViewsController2 implements PlatformViewsAccessibilityDeleg motionEventTracker = MotionEventTracker.getInstance(); } + public void setRegistry(@NonNull PlatformViewRegistry registry) { + this.registry = (PlatformViewRegistryImpl) registry; + } + @Override public boolean usesVirtualDisplay(int id) { return false; diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsController2Test.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsController2Test.java index eeab758349..9efe663813 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsController2Test.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsController2Test.java @@ -95,7 +95,9 @@ public class PlatformViewsController2Test { @Test @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void itRemovesPlatformViewBeforeDiposeIsCalled() { + PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl(); PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2(); + PlatformViewsController2.setRegistry(registryImpl); FlutterJNI jni = new FlutterJNI(); attach(jni, PlatformViewsController2); // Get the platform view registry. @@ -127,7 +129,9 @@ public class PlatformViewsController2Test { @Test @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void itNotifiesPlatformViewsOfEngineAttachmentAndDetachment() { + PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl(); PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2(); + PlatformViewsController2.setRegistry(registryImpl); FlutterJNI jni = new FlutterJNI(); attach(jni, PlatformViewsController2); // Get the platform view registry. @@ -165,7 +169,9 @@ public class PlatformViewsController2Test { @Test public void itUsesActionEventTypeFromFrameworkEventAsActionChanged() { MotionEventTracker motionEventTracker = MotionEventTracker.getInstance(); + PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl(); PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2(); + PlatformViewsController2.setRegistry(registryImpl); MotionEvent original = MotionEvent.obtain( @@ -257,7 +263,9 @@ public class PlatformViewsController2Test { @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void getPlatformViewById() { + PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl(); PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2(); + PlatformViewsController2.setRegistry(registryImpl); int platformViewId = 0; assertNull(PlatformViewsController2.getPlatformViewById(platformViewId)); @@ -285,7 +293,9 @@ public class PlatformViewsController2Test { @Test @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void createPlatformViewMessage_initializesAndroidView() { + PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl(); PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2(); + PlatformViewsController2.setRegistry(registryImpl); int platformViewId = 0; assertNull(PlatformViewsController2.getPlatformViewById(platformViewId)); @@ -307,7 +317,9 @@ public class PlatformViewsController2Test { @Test @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void createPlatformViewMessage_setsAndroidViewLayoutDirection() { + PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl(); PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2(); + PlatformViewsController2.setRegistry(registryImpl); int platformViewId = 0; assertNull(PlatformViewsController2.getPlatformViewById(platformViewId)); @@ -331,7 +343,9 @@ public class PlatformViewsController2Test { @Test @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void createPlatformViewMessage_throwsIfViewIsNull() { + PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl(); PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2(); + PlatformViewsController2.setRegistry(registryImpl); int platformViewId = 0; assertNull(PlatformViewsController2.getPlatformViewById(platformViewId)); @@ -355,7 +369,9 @@ public class PlatformViewsController2Test { @Test @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void createHybridPlatformViewMessage_throwsIfViewIsNull() { + PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl(); PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2(); + PlatformViewsController2.setRegistry(registryImpl); int platformViewId = 0; assertNull(PlatformViewsController2.getPlatformViewById(platformViewId)); @@ -379,7 +395,9 @@ public class PlatformViewsController2Test { @Test @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void setPlatformViewDirection_throwIfPlatformViewNotFound() { + PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl(); PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2(); + PlatformViewsController2.setRegistry(registryImpl); int platformViewId = 0; assertNull(PlatformViewsController2.getPlatformViewById(platformViewId)); @@ -413,7 +431,9 @@ public class PlatformViewsController2Test { @Test @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void disposeAndroidView() { + PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl(); PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2(); + PlatformViewsController2.setRegistry(registryImpl); int platformViewId = 0; assertNull(PlatformViewsController2.getPlatformViewById(platformViewId)); @@ -454,7 +474,9 @@ public class PlatformViewsController2Test { @Test @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void disposeNullAndroidView() { + PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl(); PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2(); + PlatformViewsController2.setRegistry(registryImpl); int platformViewId = 0; assertNull(PlatformViewsController2.getPlatformViewById(platformViewId)); 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 0b3e3aaa0a..3c3a33cd76 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 @@ -1665,6 +1665,7 @@ public class PlatformViewsControllerTest { platformViewsController.attach(context, registry, executor); PlatformViewsController2 secondController = new PlatformViewsController2(); + secondController.setRegistry(new PlatformViewRegistryImpl()); final FlutterEngine engine = mock(FlutterEngine.class); when(engine.getRenderer()).thenReturn(new FlutterRenderer(jni));