5package io.flutter.plugin.platform;
7import static android.os.Looper.getMainLooper;
8import static io.flutter.embedding.engine.systemchannels.PlatformViewsChannel.PlatformViewTouch;
9import static org.junit.Assert.*;
10import static org.mockito.ArgumentMatchers.*;
11import static org.mockito.Mockito.*;
12import static org.robolectric.Shadows.shadowOf;
16import android.content.MutableContextWrapper;
17import android.content.res.AssetManager;
18import android.graphics.SurfaceTexture;
23import android.view.SurfaceHolder;
27import android.widget.FrameLayout;
28import android.widget.FrameLayout.LayoutParams;
29import androidx.annotation.NonNull;
30import androidx.test.core.app.ApplicationProvider;
31import androidx.test.ext.junit.runners.AndroidJUnit4;
32import io.flutter.embedding.android.FlutterImageView;
33import io.flutter.embedding.android.FlutterSurfaceView;
34import io.flutter.embedding.android.FlutterView;
35import io.flutter.embedding.android.MotionEventTracker;
36import io.flutter.embedding.engine.FlutterEngine;
37import io.flutter.embedding.engine.FlutterJNI;
38import io.flutter.embedding.engine.FlutterOverlaySurface;
39import io.flutter.embedding.engine.dart.DartExecutor;
40import io.flutter.embedding.engine.mutatorsstack.FlutterMutatorView;
41import io.flutter.embedding.engine.mutatorsstack.FlutterMutatorsStack;
42import io.flutter.embedding.engine.renderer.FlutterRenderer;
43import io.flutter.embedding.engine.systemchannels.AccessibilityChannel;
44import io.flutter.embedding.engine.systemchannels.MouseCursorChannel;
45import io.flutter.embedding.engine.systemchannels.PlatformViewsChannel;
46import io.flutter.embedding.engine.systemchannels.PlatformViewsChannel.PlatformViewTouch;
47import io.flutter.embedding.engine.systemchannels.SettingsChannel;
48import io.flutter.embedding.engine.systemchannels.TextInputChannel;
49import io.flutter.plugin.common.MethodCall;
50import io.flutter.plugin.common.StandardMessageCodec;
51import io.flutter.plugin.common.StandardMethodCodec;
52import io.flutter.plugin.localization.LocalizationPlugin;
53import io.flutter.view.TextureRegistry;
54import java.nio.ByteBuffer;
55import java.util.Arrays;
56import java.util.HashMap;
59import org.junit.Ignore;
61import org.junit.runner.RunWith;
62import org.mockito.ArgumentCaptor;
63import org.robolectric.annotation.Config;
64import org.robolectric.annotation.Implementation;
65import org.robolectric.annotation.Implements;
66import org.robolectric.shadows.ShadowDialog;
67import org.robolectric.shadows.ShadowSurfaceView;
70@RunWith(AndroidJUnit4.class)
74 static final String VIEW_TYPE_ID =
"CountingPlatformView";
78 view =
new SurfaceView(context);
81 public int disposeCalls = 0;
82 public int attachCalls = 0;
83 public int detachCalls = 0;
88 assertNull(view.getParent());
109 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
112 FlutterJNI jni =
new FlutterJNI();
113 attach(jni, platformViewsController);
122 public PlatformView create(Context context, int viewId, Object args) {
123 return new CountingPlatformView(context);
129 final PlatformViewsChannel.PlatformViewCreationRequest request =
130 new PlatformViewsChannel.PlatformViewCreationRequest(
132 CountingPlatformView.VIEW_TYPE_ID,
137 View.LAYOUT_DIRECTION_LTR,
139 PlatformView pView = platformViewsController.createPlatformView(request,
true);
140 assertTrue(pView instanceof CountingPlatformView);
141 CountingPlatformView cpv = (CountingPlatformView) pView;
142 platformViewsController.configureForTextureLayerComposition(pView, request);
143 assertEquals(0, cpv.disposeCalls);
144 platformViewsController.disposePlatformView(viewId);
145 assertEquals(1, cpv.disposeCalls);
149 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
152 FlutterJNI jni =
new FlutterJNI();
153 attach(jni, platformViewsController);
162 public PlatformView create(Context context, int viewId, Object args) {
163 return new CountingPlatformView(context);
169 final PlatformViewsChannel.PlatformViewCreationRequest request =
170 new PlatformViewsChannel.PlatformViewCreationRequest(
172 CountingPlatformView.VIEW_TYPE_ID,
177 View.LAYOUT_DIRECTION_LTR,
179 PlatformView pView = platformViewsController.createPlatformView(request,
true);
180 assertTrue(pView instanceof CountingPlatformView);
181 CountingPlatformView cpv = (CountingPlatformView) pView;
182 assertEquals(1, cpv.attachCalls);
183 assertEquals(0, cpv.detachCalls);
184 assertEquals(0, cpv.disposeCalls);
185 platformViewsController.detachFromView();
186 assertEquals(1, cpv.attachCalls);
187 assertEquals(1, cpv.detachCalls);
188 assertEquals(0, cpv.disposeCalls);
189 platformViewsController.disposePlatformView(viewId);
197 View fakeFlutterView =
new View(ApplicationProvider.getApplicationContext());
209 fakeVdController1.
resize(10, 10,
null);
211 assertEquals(fakeVdController1.
presentation != presentation,
true);
212 assertEquals(presentation.isShowing(),
false);
216 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
218 final int platformViewId = 0;
222 platformViewsController.
vdControllers.put(platformViewId, fakeVdController);
226 FlutterJNI jni =
new FlutterJNI();
227 attach(jni, platformViewsController);
229 resize(jni, platformViewsController, platformViewId, 10.0, 20.0);
231 ArgumentCaptor<Runnable> resizeCallbackCaptor = ArgumentCaptor.forClass(Runnable.class);
232 verify(fakeVdController,
times(1)).resize(anyInt(), anyInt(), resizeCallbackCaptor.capture());
235 platformViewsController.
detach();
238 resizeCallbackCaptor.getValue().run();
242 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
244 final int platformViewId = 0;
248 FlutterJNI jni =
new FlutterJNI();
249 attach(jni, platformViewsController);
254 Context context = ApplicationProvider.getApplicationContext();
255 View androidView =
new View(context);
256 when(platformView.
getView()).thenReturn(androidView);
257 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
260 jni, platformViewsController, platformViewId,
"testType",
false);
262 platformViewsController.
vdControllers.put(platformViewId, fakeVdController);
265 disposePlatformView(jni, platformViewsController, platformViewId);
268 verify(fakeVdController,
times(1)).dispose();
273 MotionEventTracker motionEventTracker = MotionEventTracker.getInstance();
276 MotionEvent original =
287 MotionEventTracker.MotionEventId motionEventId = motionEventTracker.track(original);
289 PlatformViewTouch frameWorkTouch =
290 new PlatformViewTouch(
292 original.getDownTime(),
293 original.getEventTime(),
296 Arrays.asList(Arrays.asList(0, 0)),
297 Arrays.asList(Arrays.asList(0., 1., 2., 3., 4., 5., 6., 7., 8.)),
298 original.getMetaState(),
299 original.getButtonState(),
300 original.getXPrecision(),
301 original.getYPrecision(),
302 original.getDeviceId(),
303 original.getEdgeFlags(),
304 original.getSource(),
306 motionEventId.getId());
308 MotionEvent resolvedEvent =
315 assertEquals(resolvedEvent.getAction(), frameWorkTouch.action);
316 assertNotEquals(resolvedEvent.getAction(), original.getAction());
321 MotionEventTracker motionEventTracker = MotionEventTracker.getInstance();
324 MotionEvent original =
334 MotionEventTracker.MotionEventId motionEventId = motionEventTracker.track(original);
336 PlatformViewTouch frameWorkTouch =
337 new PlatformViewTouch(
339 original.getDownTime(),
340 original.getEventTime(),
343 Arrays.asList(Arrays.asList(0, 0)),
344 Arrays.asList(Arrays.asList(0., 1., 2., 3., 4., 5., 6., 7., 8.)),
345 original.getMetaState(),
346 original.getButtonState(),
347 original.getXPrecision(),
348 original.getYPrecision(),
349 original.getDeviceId(),
350 original.getEdgeFlags(),
351 original.getSource(),
353 motionEventId.getId());
354 MotionEvent resolvedEvent =
360 assertEquals(resolvedEvent.getAction(), original.getAction());
361 assertNotEquals(resolvedEvent.getAction(), frameWorkTouch.action);
367 MotionEventTracker motionEventTracker = MotionEventTracker.getInstance();
370 MotionEvent original =
381 MotionEventTracker.MotionEventId motionEventId = motionEventTracker.track(original);
383 PlatformViewTouch frameWorkTouch =
384 new PlatformViewTouch(
386 original.getDownTime(),
387 original.getEventTime(),
390 Arrays.asList(Arrays.asList(0, 0)),
391 Arrays.asList(Arrays.asList(0., 1., 2., 3., 4., 5., 6., 7., 8.)),
392 original.getMetaState(),
393 original.getButtonState(),
394 original.getXPrecision(),
395 original.getYPrecision(),
396 original.getDeviceId(),
397 original.getEdgeFlags(),
398 original.getSource(),
400 motionEventId.getId());
402 MotionEvent resolvedEvent =
404 1, frameWorkTouch,
false);
406 assertEquals(resolvedEvent.getAction(), frameWorkTouch.action);
410 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
414 int platformViewId = 0;
419 View androidView = mock(View.class);
420 when(platformView.
getView()).thenReturn(androidView);
421 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
424 FlutterJNI jni =
new FlutterJNI();
425 attach(jni, platformViewsController);
428 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
433 assertNotNull(resultAndroidView);
434 assertEquals(resultAndroidView, androidView);
438 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
442 int platformViewId = 0;
447 when(platformView.
getView()).thenReturn(mock(View.class));
448 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
451 FlutterJNI jni =
new FlutterJNI();
452 attach(jni, platformViewsController);
455 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
456 verify(viewFactory,
times(1)).create(any(),
eq(platformViewId), any());
460 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
464 int platformViewId = 0;
469 when(platformView.
getView()).thenReturn(mock(View.class));
470 ArgumentCaptor<Context> passedContext = ArgumentCaptor.forClass(
Context.class);
471 when(viewFactory.
create(passedContext.capture(),
eq(platformViewId), any()))
472 .thenReturn(platformView);
475 FlutterJNI jni =
new FlutterJNI();
476 attach(jni, platformViewsController);
480 jni, platformViewsController, platformViewId,
"testType",
false);
481 assertTrue(passedContext.getValue() instanceof MutableContextWrapper);
485 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
489 int platformViewId = 0;
494 when(platformView.
getView()).thenReturn(mock(View.class));
495 ArgumentCaptor<Context> passedContext = ArgumentCaptor.forClass(
Context.class);
496 when(viewFactory.
create(passedContext.capture(),
eq(platformViewId), any()))
497 .thenReturn(platformView);
500 FlutterJNI jni =
new FlutterJNI();
501 attach(jni, platformViewsController);
504 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
505 assertFalse(passedContext.getValue() instanceof MutableContextWrapper);
509 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
514 int platformViewId = 0;
520 View androidView = mock(View.class);
521 when(platformView.
getView()).thenReturn(androidView);
522 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
525 FlutterJNI jni =
new FlutterJNI();
526 attach(jni, platformViewsController);
530 jni, platformViewsController, platformViewId,
"testType",
false);
531 verify(androidView,
times(1)).setLayoutDirection(0);
535 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
540 int platformViewId = 0;
546 View androidView = mock(View.class);
547 when(platformView.
getView()).thenReturn(androidView);
548 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
551 FlutterJNI jni =
new FlutterJNI();
552 attach(jni, platformViewsController);
556 jni, platformViewsController, platformViewId,
"testType",
false);
558 ArgumentCaptor<FrameLayout.LayoutParams> layoutParamsCaptor =
559 ArgumentCaptor.forClass(FrameLayout.LayoutParams.class);
560 verify(androidView,
times(2)).setLayoutParams(layoutParamsCaptor.capture());
562 List<FrameLayout.LayoutParams> capturedLayoutParams = layoutParamsCaptor.getAllValues();
563 assertEquals(capturedLayoutParams.get(0).width, 1);
564 assertEquals(capturedLayoutParams.get(0).height, 1);
568 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
573 int platformViewId = 0;
579 View androidView = mock(View.class);
580 when(platformView.
getView()).thenReturn(androidView);
581 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
584 FlutterJNI jni =
new FlutterJNI();
585 attach(jni, platformViewsController);
589 jni, platformViewsController, platformViewId,
"testType",
false);
590 verify(androidView,
times(1))
591 .setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
595 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
599 int platformViewId = 0;
604 when(platformView.
getView()).thenReturn(
null);
605 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
608 FlutterJNI jni =
new FlutterJNI();
609 attach(jni, platformViewsController);
613 jni, platformViewsController, platformViewId,
"testType",
false);
617 IllegalStateException.class,
619 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
624 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
628 int platformViewId = 0;
633 when(platformView.
getView()).thenReturn(
null);
634 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
637 FlutterJNI jni =
new FlutterJNI();
638 attach(jni, platformViewsController);
641 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
645 IllegalStateException.class,
647 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
653 shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class, ShadowPresentation.class})
657 int platformViewId = 0;
663 SurfaceView pv = mock(SurfaceView.class);
664 when(pv.getContext()).thenReturn(mock(MutableContextWrapper.class));
665 when(pv.getLayoutParams()).thenReturn(
new LayoutParams(1, 1));
667 when(platformView.
getView()).thenReturn(pv);
668 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
671 FlutterJNI jni =
new FlutterJNI();
672 attach(jni, platformViewsController);
676 jni, platformViewsController, platformViewId,
"testType",
false);
685 shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class, ShadowPresentation.class})
689 int platformViewId = 0;
695 SurfaceView pv = mock(SurfaceView.class);
696 when(pv.getContext()).thenReturn(mock(MutableContextWrapper.class));
697 when(pv.getLayoutParams()).thenReturn(
new LayoutParams(1, 1));
699 when(platformView.
getView()).thenReturn(pv);
700 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
703 FlutterJNI jni =
new FlutterJNI();
704 attach(jni, platformViewsController);
708 jni, platformViewsController, platformViewId,
"testType",
false);
716 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
720 int platformViewId = 0;
725 View androidView = mock(View.class);
726 when(androidView.getParent()).thenReturn(mock(ViewParent.class));
727 when(platformView.
getView()).thenReturn(androidView);
728 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
731 FlutterJNI jni =
new FlutterJNI();
732 attach(jni, platformViewsController);
736 jni, platformViewsController, platformViewId,
"testType",
false);
740 IllegalStateException.class,
742 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
747 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
751 int platformViewId = 0;
756 View androidView = mock(View.class);
757 when(androidView.getParent()).thenReturn(mock(ViewParent.class));
758 when(platformView.
getView()).thenReturn(androidView);
759 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
762 FlutterJNI jni =
new FlutterJNI();
763 attach(jni, platformViewsController);
766 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
770 IllegalStateException.class,
772 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
777 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
781 int platformViewId = 0;
786 final View androidView = mock(View.class);
787 when(platformView.
getView()).thenReturn(androidView);
788 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
791 FlutterJNI jni =
new FlutterJNI();
792 attach(jni, platformViewsController);
794 verify(androidView, never()).setLayoutDirection(anyInt());
797 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
801 setLayoutDirection(jni, platformViewsController, platformViewId, 1);
802 verify(androidView,
times(1)).setLayoutDirection(1);
811 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
816 int platformViewId = 0;
821 final View androidView = mock(View.class);
822 when(platformView.
getView()).thenReturn(androidView);
823 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
826 FlutterJNI jni =
new FlutterJNI();
827 attach(jni, platformViewsController);
831 jni, platformViewsController, platformViewId,
"testType",
false);
834 when(androidView.getLayoutParams()).thenReturn(
new FrameLayout.LayoutParams(0, 0));
837 resize(jni, platformViewsController, platformViewId, 10.0, 20.0);
839 ArgumentCaptor<FrameLayout.LayoutParams> layoutParamsCaptor =
840 ArgumentCaptor.forClass(FrameLayout.LayoutParams.class);
841 verify(androidView,
times(1)).setLayoutParams(layoutParamsCaptor.capture());
843 assertEquals(layoutParamsCaptor.getValue().width, 10);
844 assertEquals(layoutParamsCaptor.getValue().height, 20);
848 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
852 int platformViewId = 0;
858 Context context = ApplicationProvider.getApplicationContext();
859 View androidView =
new View(context);
861 when(platformView.
getView()).thenReturn(androidView);
862 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
865 FlutterJNI jni =
new FlutterJNI();
866 attach(jni, platformViewsController);
869 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
872 assertNotNull(androidView.getParent());
876 disposePlatformView(jni, platformViewsController, platformViewId);
877 assertNull(androidView.getParent());
880 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
883 assertNotNull(androidView.getParent());
885 verify(platformView,
times(1)).dispose();
889 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
893 int platformViewId = 0;
899 View androidView = mock(View.class);
900 when(platformView.
getView()).thenReturn(androidView);
901 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
904 FlutterJNI jni =
new FlutterJNI();
905 attach(jni, platformViewsController);
909 jni, platformViewsController, platformViewId,
"testType",
false);
912 when(platformView.
getView()).thenReturn(
null);
915 disposePlatformView(jni, platformViewsController, platformViewId);
916 verify(platformView,
times(1)).dispose();
922 ShadowFlutterSurfaceView.class,
923 ShadowFlutterJNI.class,
924 ShadowPlatformTaskQueue.class
929 final int platformViewId = 0;
934 when(platformView.
getView()).thenReturn(mock(View.class));
935 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
939 final FlutterJNI jni =
new FlutterJNI();
940 jni.attachToNative();
941 attach(jni, platformViewsController);
946 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
958 new FlutterMutatorsStack());
961 when(overlayImageView.acquireLatestImage()).thenReturn(
true);
963 final FlutterOverlaySurface overlaySurface =
966 overlaySurface.getId(), 0, 0, 10, 10);
973 verify(overlayImageView, never()).detachFromRenderer();
979 shadowOf(getMainLooper()).idle();
980 verify(overlayImageView,
times(1)).detachFromRenderer();
984 @Config(shadows = {ShadowFlutterSurfaceView.class, ShadowFlutterJNI.class})
988 final int platformViewId = 0;
993 final View androidView = mock(View.class);
994 when(platformView.
getView()).thenReturn(androidView);
995 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
999 final FlutterJNI jni =
new FlutterJNI();
1000 jni.attachToNative();
1001 attach(jni, platformViewsController);
1006 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1013 verify(androidView, never()).setVisibility(View.GONE);
1015 final ViewParent parentView = mock(ViewParent.class);
1016 when(androidView.getParent()).thenReturn(parentView);
1022 ShadowFlutterSurfaceView.class,
1023 ShadowFlutterJNI.class,
1024 ShadowPlatformTaskQueue.class
1029 final int platformViewId = 0;
1034 final View androidView = mock(View.class);
1035 when(platformView.
getView()).thenReturn(androidView);
1036 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
1040 final FlutterJNI jni =
new FlutterJNI();
1041 jni.attachToNative();
1043 final FlutterView flutterView = attach(jni, platformViewsController);
1048 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1050 assertEquals(flutterView.getChildCount(), 2);
1058 disposePlatformView(jni, platformViewsController, platformViewId);
1059 assertEquals(flutterView.getChildCount(), 1);
1065 ShadowFlutterSurfaceView.class,
1066 ShadowFlutterJNI.class,
1067 ShadowPlatformTaskQueue.class
1072 final int platformViewId = 0;
1077 when(platformView.
getView()).thenReturn(mock(View.class));
1078 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
1082 final FlutterJNI jni =
new FlutterJNI();
1083 jni.attachToNative();
1084 attach(jni, platformViewsController);
1089 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1101 new FlutterMutatorsStack());
1104 when(overlayImageView.acquireLatestImage()).thenReturn(
true);
1106 final FlutterOverlaySurface overlaySurface =
1110 overlaySurface.getId(), 0, 0, 10, 10);
1112 platformViewsController.
detach();
1114 verify(overlayImageView,
times(1)).closeImageReader();
1115 verify(overlayImageView,
times(1)).detachFromRenderer();
1119 @Config(shadows = {ShadowFlutterSurfaceView.class, ShadowFlutterJNI.class})
1123 final int platformViewId = 0;
1128 when(platformView.
getView()).thenReturn(mock(View.class));
1129 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
1133 final FlutterJNI jni =
new FlutterJNI();
1134 jni.attachToNative();
1135 attach(jni, platformViewsController);
1141 when(overlayImageView.acquireLatestImage()).thenReturn(
true);
1143 final FlutterOverlaySurface overlaySurface =
1147 overlaySurface.getId(), 0, 0, 10, 10);
1151 verify(overlayImageView,
times(1)).closeImageReader();
1152 verify(overlayImageView,
times(1)).detachFromRenderer();
1153 verify(flutterView,
times(1)).removeView(overlayImageView);
1157 @Config(shadows = {ShadowFlutterSurfaceView.class, ShadowFlutterJNI.class})
1161 final int platformViewId = 0;
1166 when(platformView.
getView()).thenReturn(mock(View.class));
1167 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
1171 final FlutterJNI jni =
new FlutterJNI();
1172 jni.attachToNative();
1173 attach(jni, platformViewsController);
1179 when(overlayImageView.acquireLatestImage()).thenReturn(
true);
1181 final FlutterOverlaySurface overlaySurface =
1185 overlaySurface.getId(), 0, 0, 10, 10);
1190 verify(overlayImageView,
times(1)).closeImageReader();
1191 verify(overlayImageView,
times(1)).detachFromRenderer();
1195 @Config(shadows = {ShadowFlutterSurfaceView.class, ShadowFlutterJNI.class})
1199 final int platformViewId = 0;
1204 when(platformView.
getView()).thenReturn(mock(View.class));
1205 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
1209 final FlutterJNI jni =
new FlutterJNI();
1210 jni.attachToNative();
1211 attach(jni, platformViewsController);
1217 when(overlayImageView.acquireLatestImage()).thenReturn(
true);
1219 final FlutterOverlaySurface overlaySurface =
1223 overlaySurface.getId(), 0, 0, 10, 10);
1226 verify(flutterView, never()).removeView(overlayImageView);
1233 assertFalse(shouldProxying);
1237 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
1241 final int platformViewId = 0;
1246 final View androidView = mock(View.class);
1247 when(platformView.
getView()).thenReturn(androidView);
1248 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
1252 final FlutterJNI jni =
new FlutterJNI();
1253 jni.attachToNative();
1254 final FlutterView flutterView = attach(jni, platformViewsController);
1259 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1271 new FlutterMutatorsStack());
1273 assertEquals(flutterView.getChildCount(), 3);
1275 final View view = flutterView.getChildAt(1);
1276 assertTrue(view instanceof FlutterImageView);
1279 disposePlatformView(jni, platformViewsController, platformViewId);
1283 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
1287 final int platformViewId = 0;
1292 final View androidView = mock(View.class);
1293 when(platformView.
getView()).thenReturn(androidView);
1294 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
1298 final FlutterJNI jni =
new FlutterJNI();
1299 jni.attachToNative();
1300 final FlutterView flutterView = attach(jni, platformViewsController);
1305 synchronizeToNativeViewHierarchy(jni, platformViewsController,
false);
1308 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1320 new FlutterMutatorsStack());
1322 assertEquals(flutterView.getChildCount(), 2);
1327 disposePlatformView(jni, platformViewsController, platformViewId);
1331 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
1336 int platformViewId = 100;
1341 View androidView = mock(View.class);
1342 when(platformView.
getView()).thenReturn(androidView);
1343 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
1346 FlutterJNI jni =
new FlutterJNI();
1348 attachToFlutterView(jni, platformViewsController, initFlutterView);
1351 jni, platformViewsController, platformViewId,
"testType",
false);
1364 ShadowFlutterSurfaceView.class,
1365 ShadowFlutterJNI.class,
1366 ShadowPlatformTaskQueue.class
1371 final int platformViewId = 0;
1376 final View androidView = mock(View.class);
1377 when(platformView.
getView()).thenReturn(androidView);
1378 when(viewFactory.
create(any(),
eq(platformViewId), any())).thenReturn(platformView);
1382 final FlutterJNI jni =
new FlutterJNI();
1383 jni.attachToNative();
1385 final FlutterView flutterView = attach(jni, platformViewsController);
1390 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1398 assertEquals(flutterView.getChildCount(), 3);
1400 FlutterImageView imageView = flutterView.getCurrentImageSurface();
1403 assertTrue(imageView !=
null);
1404 assertTrue(flutterView.indexOfChild(imageView) != -1);
1409 assertTrue(overlayView !=
null);
1410 assertTrue(flutterView.indexOfChild(overlayView) != -1);
1421 assertEquals(
null, flutterView.getCurrentImageSurface());
1424 assertTrue(flutterView.indexOfChild(imageView) == -1);
1427 assertTrue(flutterView.indexOfChild(overlayView) == -1);
1430 private static ByteBuffer encodeMethodCall(
MethodCall call) {
1431 final ByteBuffer
buffer = StandardMethodCodec.INSTANCE.encodeMethodCall(call);
1436 private static void createPlatformView(
1438 PlatformViewsController platformViewsController,
1442 final Map<String, Object>
args =
new HashMap<>();
1443 args.put(
"hybrid", hybrid);
1444 args.put(
"id", platformViewId);
1445 args.put(
"viewType", viewType);
1446 args.put(
"direction", 0);
1447 args.put(
"width", 1.0);
1448 args.put(
"height", 1.0);
1452 jni.handlePlatformMessage(
1453 "flutter/platform_views",
1454 encodeMethodCall(platformCreateMethodCall),
1459 private static void setLayoutDirection(
1461 PlatformViewsController platformViewsController,
1464 final Map<String, Object>
args =
new HashMap<>();
1465 args.put(
"id", platformViewId);
1466 args.put(
"direction", direction);
1470 jni.handlePlatformMessage(
1471 "flutter/platform_views",
1472 encodeMethodCall(platformSetDirectionMethodCall),
1477 private static void resize(
1479 PlatformViewsController platformViewsController,
1483 final Map<String, Object>
args =
new HashMap<>();
1484 args.put(
"id", platformViewId);
1490 jni.handlePlatformMessage(
1491 "flutter/platform_views",
1492 encodeMethodCall(platformResizeMethodCall),
1497 private static void disposePlatformView(
1498 FlutterJNI jni, PlatformViewsController platformViewsController,
int platformViewId) {
1500 final Map<String, Object>
args =
new HashMap<>();
1501 args.put(
"hybrid",
true);
1502 args.put(
"id", platformViewId);
1506 jni.handlePlatformMessage(
1507 "flutter/platform_views",
1508 encodeMethodCall(platformDisposeMethodCall),
1513 private static void synchronizeToNativeViewHierarchy(
1514 FlutterJNI jni, PlatformViewsController platformViewsController,
boolean yes) {
1518 jni.handlePlatformMessage(
1519 "flutter/platform_views",
1520 encodeMethodCall(convertMethodCall),
1526 FlutterJNI jni, PlatformViewsController platformViewsController) {
1527 final Context context = ApplicationProvider.getApplicationContext();
1529 new FlutterView(context,
new FlutterSurfaceView(context)) {
1531 public FlutterImageView createImageView() {
1532 final FlutterImageView view = mock(FlutterImageView.class);
1533 when(view.acquireLatestImage()).thenReturn(
true);
1534 return mock(FlutterImageView.class);
1537 attachToFlutterView(jni, platformViewsController, flutterView);
1541 private static void attachToFlutterView(
1542 FlutterJNI jni, PlatformViewsController platformViewsController,
FlutterView flutterView) {
1543 final DartExecutor executor =
new DartExecutor(jni, mock(AssetManager.class));
1544 executor.onAttachedToJNI();
1546 final Context context = ApplicationProvider.getApplicationContext();
1547 final TextureRegistry registry =
1548 new TextureRegistry() {
1549 public void TextureRegistry() {}
1552 public SurfaceTextureEntry createSurfaceTexture() {
1553 return registerSurfaceTexture(mock(SurfaceTexture.class));
1557 public SurfaceTextureEntry registerSurfaceTexture(SurfaceTexture surfaceTexture) {
1558 return new SurfaceTextureEntry() {
1561 public SurfaceTexture surfaceTexture() {
1562 return mock(SurfaceTexture.class);
1571 public void release() {}
1576 public ImageTextureEntry createImageTexture() {
1577 return new ImageTextureEntry() {
1584 public void release() {}
1587 public void pushImage(Image
image) {}
1592 public SurfaceProducer createSurfaceProducer() {
1593 return new SurfaceProducer() {
1600 public void release() {}
1603 public int getWidth() {
1608 public int getHeight() {
1620 public void scheduleFrame() {}
1625 platformViewsController.attach(context, registry, executor);
1629 when(
engine.getMouseCursorChannel()).thenReturn(mock(MouseCursorChannel.class));
1630 when(
engine.getTextInputChannel()).thenReturn(mock(TextInputChannel.class));
1631 when(
engine.getSettingsChannel()).thenReturn(
new SettingsChannel(executor));
1632 when(
engine.getPlatformViewsController()).thenReturn(platformViewsController);
1633 when(
engine.getLocalizationPlugin()).thenReturn(mock(LocalizationPlugin.class));
1634 when(
engine.getAccessibilityChannel()).thenReturn(mock(AccessibilityChannel.class));
1635 when(
engine.getDartExecutor()).thenReturn(executor);
1637 flutterView.attachToFlutterEngine(
engine);
1638 platformViewsController.attachToView(flutterView);
1647 @Implements(io.flutter.embedding.engine.dart.PlatformTaskQueue.class)
1661 @Implements(Presentation.class)
1663 private boolean isShowing =
false;
1683 @Implements(FlutterJNI.class)
1685 private static SparseArray<ByteBuffer> replies =
new SparseArray<>();
1701 String channel, ByteBuffer
message,
int position,
int responseId) {}
1714 float devicePixelRatio,
1717 int physicalPaddingTop,
1718 int physicalPaddingRight,
1719 int physicalPaddingBottom,
1720 int physicalPaddingLeft,
1721 int physicalViewInsetTop,
1722 int physicalViewInsetRight,
1723 int physicalViewInsetBottom,
1724 int physicalViewInsetLeft,
1725 int systemGestureInsetTop,
1726 int systemGestureInsetRight,
1727 int systemGestureInsetBottom,
1728 int systemGestureInsetLeft,
1729 int physicalTouchSlop,
1730 int[] displayFeaturesBounds,
1731 int[] displayFeaturesType,
1732 int[] displayFeaturesState) {}
1736 int responseId, ByteBuffer
message,
int position) {
1737 replies.put(responseId,
message);
1745 @Implements(SurfaceView.class)
static SkISize times(const SkISize &size, float factor)
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static const uint8_t buffer[]