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})
113 attach(jni, platformViewsController);
122 public PlatformView create(Context context, int viewId, Object args) {
123 return new CountingPlatformView(context);
129 final PlatformViewsChannel.PlatformViewCreationRequest request =
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})
153 attach(jni, platformViewsController);
162 public PlatformView create(Context context, int viewId, Object args) {
163 return new CountingPlatformView(context);
169 final PlatformViewsChannel.PlatformViewCreationRequest request =
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);
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;
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();
276 MotionEvent original =
287 MotionEventTracker.MotionEventId motionEventId = motionEventTracker.
track(original);
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());
324 MotionEvent original =
334 MotionEventTracker.MotionEventId motionEventId = motionEventTracker.
track(original);
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);
364 private MotionEvent makePlatformViewTouchAndInvokeToMotionEvent(
367 MotionEvent original,
368 boolean usingVirtualDisplays) {
369 MotionEventTracker.MotionEventId motionEventId = motionEventTracker.
track(original);
373 List<List<Integer>> pointerProperties =
374 Arrays.asList(Arrays.asList(original.getPointerId(0), original.getToolType(0)));
377 List<List<Double>> pointerCoordinates =
380 (
double) original.getOrientation(),
381 (
double) original.getPressure(),
382 (
double) original.getSize(),
383 (
double) original.getToolMajor(),
384 (
double) original.getToolMinor(),
385 (
double) original.getTouchMajor(),
386 (
double) original.getTouchMinor(),
387 (
double) original.getX(),
388 (
double) original.getY()));
393 original.getDownTime(),
394 original.getEventTime(),
395 original.getAction(),
399 original.getMetaState(),
400 original.getButtonState(),
401 original.getXPrecision(),
402 original.getYPrecision(),
403 original.getDeviceId(),
404 original.getEdgeFlags(),
405 original.getSource(),
407 motionEventId.getId());
412 usingVirtualDisplays);
420 MotionEvent original =
430 MotionEvent resolvedNonVdEvent =
431 makePlatformViewTouchAndInvokeToMotionEvent(
432 platformViewsController, motionEventTracker, original,
false);
434 MotionEvent resolvedVdEvent =
435 makePlatformViewTouchAndInvokeToMotionEvent(
436 platformViewsController, motionEventTracker, original,
true);
438 assertEquals(resolvedVdEvent.getEventTime(), resolvedNonVdEvent.getEventTime());
439 assertEquals(resolvedVdEvent.getX(), resolvedNonVdEvent.getX(), 0.001f);
440 assertEquals(resolvedVdEvent.getY(), resolvedNonVdEvent.getY(), 0.001f);
444 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
448 int platformViewId = 0;
453 View androidView = mock(View.class);
454 when(platformView.
getView()).thenReturn(androidView);
455 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
459 attach(jni, platformViewsController);
462 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
467 assertNotNull(resultAndroidView);
468 assertEquals(resultAndroidView, androidView);
472 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
476 int platformViewId = 0;
481 when(platformView.
getView()).thenReturn(mock(View.class));
482 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
486 attach(jni, platformViewsController);
489 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
490 verify(viewFactory,
times(1)).create(
any(),
eq(platformViewId),
any());
494 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
498 int platformViewId = 0;
503 when(platformView.
getView()).thenReturn(mock(View.class));
504 ArgumentCaptor<Context> passedContext = ArgumentCaptor.forClass(Context.class);
505 when(viewFactory.
create(passedContext.capture(),
eq(platformViewId),
any()))
506 .thenReturn(platformView);
510 attach(jni, platformViewsController);
514 jni, platformViewsController, platformViewId,
"testType",
false);
515 assertTrue(passedContext.getValue() instanceof MutableContextWrapper);
519 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
523 int platformViewId = 0;
528 when(platformView.
getView()).thenReturn(mock(View.class));
529 ArgumentCaptor<Context> passedContext = ArgumentCaptor.forClass(Context.class);
530 when(viewFactory.
create(passedContext.capture(),
eq(platformViewId),
any()))
531 .thenReturn(platformView);
535 attach(jni, platformViewsController);
538 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
539 assertFalse(passedContext.getValue() instanceof MutableContextWrapper);
543 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
548 int platformViewId = 0;
554 View androidView = mock(View.class);
555 when(platformView.
getView()).thenReturn(androidView);
556 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
560 attach(jni, platformViewsController);
564 jni, platformViewsController, platformViewId,
"testType",
false);
565 verify(androidView,
times(1)).setLayoutDirection(0);
569 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
574 int platformViewId = 0;
580 View androidView = mock(View.class);
581 when(platformView.
getView()).thenReturn(androidView);
582 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
586 attach(jni, platformViewsController);
590 jni, platformViewsController, platformViewId,
"testType",
false);
592 ArgumentCaptor<FrameLayout.LayoutParams> layoutParamsCaptor =
593 ArgumentCaptor.forClass(FrameLayout.LayoutParams.class);
594 verify(androidView,
times(2)).setLayoutParams(layoutParamsCaptor.capture());
596 List<FrameLayout.LayoutParams> capturedLayoutParams = layoutParamsCaptor.getAllValues();
597 assertEquals(capturedLayoutParams.get(0).width, 1);
598 assertEquals(capturedLayoutParams.get(0).height, 1);
602 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
607 int platformViewId = 0;
613 View androidView = mock(View.class);
614 when(platformView.
getView()).thenReturn(androidView);
615 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
619 attach(jni, platformViewsController);
623 jni, platformViewsController, platformViewId,
"testType",
false);
624 verify(androidView,
times(1))
625 .setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
629 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
633 int platformViewId = 0;
638 when(platformView.
getView()).thenReturn(
null);
639 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
643 attach(jni, platformViewsController);
647 jni, platformViewsController, platformViewId,
"testType",
false);
651 IllegalStateException.class,
653 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
658 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
662 int platformViewId = 0;
667 when(platformView.
getView()).thenReturn(
null);
668 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
672 attach(jni, platformViewsController);
675 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
679 IllegalStateException.class,
681 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
687 shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class, ShadowPresentation.class})
691 int platformViewId = 0;
697 SurfaceView pv = mock(SurfaceView.class);
698 when(pv.getContext()).thenReturn(mock(MutableContextWrapper.class));
699 when(pv.getLayoutParams()).thenReturn(
new LayoutParams(1, 1));
701 when(platformView.
getView()).thenReturn(pv);
702 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
706 attach(jni, platformViewsController);
710 jni, platformViewsController, platformViewId,
"testType",
false);
719 shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class, ShadowPresentation.class})
723 int platformViewId = 0;
729 SurfaceView pv = mock(SurfaceView.class);
730 when(pv.getContext()).thenReturn(mock(MutableContextWrapper.class));
731 when(pv.getLayoutParams()).thenReturn(
new LayoutParams(1, 1));
733 when(platformView.
getView()).thenReturn(pv);
734 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
738 attach(jni, platformViewsController);
742 jni, platformViewsController, platformViewId,
"testType",
false);
750 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
754 int platformViewId = 0;
759 View androidView = mock(View.class);
760 when(androidView.getParent()).thenReturn(mock(ViewParent.class));
761 when(platformView.
getView()).thenReturn(androidView);
762 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
766 attach(jni, platformViewsController);
770 jni, platformViewsController, platformViewId,
"testType",
false);
774 IllegalStateException.class,
776 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
781 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
785 int platformViewId = 0;
790 View androidView = mock(View.class);
791 when(androidView.getParent()).thenReturn(mock(ViewParent.class));
792 when(platformView.
getView()).thenReturn(androidView);
793 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
797 attach(jni, platformViewsController);
800 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
804 IllegalStateException.class,
806 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
811 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
815 int platformViewId = 0;
820 final View androidView = mock(View.class);
821 when(platformView.
getView()).thenReturn(androidView);
822 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
826 attach(jni, platformViewsController);
828 verify(androidView, never()).setLayoutDirection(anyInt());
831 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
835 setLayoutDirection(jni, platformViewsController, platformViewId, 1);
836 verify(androidView,
times(1)).setLayoutDirection(1);
845 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
850 int platformViewId = 0;
855 final View androidView = mock(View.class);
856 when(platformView.
getView()).thenReturn(androidView);
857 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
861 attach(jni, platformViewsController);
865 jni, platformViewsController, platformViewId,
"testType",
false);
868 when(androidView.getLayoutParams()).thenReturn(
new FrameLayout.LayoutParams(0, 0));
871 resize(jni, platformViewsController, platformViewId, 10.0, 20.0);
873 ArgumentCaptor<FrameLayout.LayoutParams> layoutParamsCaptor =
874 ArgumentCaptor.forClass(FrameLayout.LayoutParams.class);
875 verify(androidView,
times(1)).setLayoutParams(layoutParamsCaptor.capture());
877 assertEquals(layoutParamsCaptor.getValue().width, 10);
878 assertEquals(layoutParamsCaptor.getValue().height, 20);
882 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
886 int platformViewId = 0;
892 Context context = ApplicationProvider.getApplicationContext();
893 View androidView =
new View(context);
895 when(platformView.
getView()).thenReturn(androidView);
896 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
900 attach(jni, platformViewsController);
903 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
906 assertNotNull(androidView.getParent());
910 disposePlatformView(jni, platformViewsController, platformViewId);
911 assertNull(androidView.getParent());
914 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
917 assertNotNull(androidView.getParent());
919 verify(platformView,
times(1)).dispose();
923 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
927 int platformViewId = 0;
933 View androidView = mock(View.class);
934 when(platformView.
getView()).thenReturn(androidView);
935 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
939 attach(jni, platformViewsController);
943 jni, platformViewsController, platformViewId,
"testType",
false);
946 when(platformView.
getView()).thenReturn(
null);
949 disposePlatformView(jni, platformViewsController, platformViewId);
950 verify(platformView,
times(1)).dispose();
956 ShadowFlutterSurfaceView.class,
957 ShadowFlutterJNI.class,
958 ShadowPlatformTaskQueue.class
963 final int platformViewId = 0;
968 when(platformView.
getView()).thenReturn(mock(View.class));
969 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
975 attach(jni, platformViewsController);
980 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1000 overlaySurface.
getId(), 0, 0, 10, 10);
1007 verify(overlayImageView, never()).detachFromRenderer();
1013 shadowOf(getMainLooper()).idle();
1014 verify(overlayImageView,
times(1)).detachFromRenderer();
1018 @Config(shadows = {ShadowFlutterSurfaceView.class, ShadowFlutterJNI.class})
1022 final int platformViewId = 0;
1027 final View androidView = mock(View.class);
1028 when(platformView.
getView()).thenReturn(androidView);
1029 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
1035 attach(jni, platformViewsController);
1040 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1047 verify(androidView, never()).setVisibility(View.GONE);
1049 final ViewParent parentView = mock(ViewParent.class);
1050 when(androidView.getParent()).thenReturn(parentView);
1056 ShadowFlutterSurfaceView.class,
1057 ShadowFlutterJNI.class,
1058 ShadowPlatformTaskQueue.class
1063 final int platformViewId = 0;
1068 final View androidView = mock(View.class);
1069 when(platformView.
getView()).thenReturn(androidView);
1070 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
1077 final FlutterView flutterView = attach(jni, platformViewsController);
1082 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1084 assertEquals(flutterView.getChildCount(), 2);
1092 disposePlatformView(jni, platformViewsController, platformViewId);
1093 assertEquals(flutterView.getChildCount(), 1);
1099 ShadowFlutterSurfaceView.class,
1100 ShadowFlutterJNI.class,
1101 ShadowPlatformTaskQueue.class
1106 final int platformViewId = 0;
1111 when(platformView.
getView()).thenReturn(mock(View.class));
1112 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
1118 attach(jni, platformViewsController);
1123 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1144 overlaySurface.
getId(), 0, 0, 10, 10);
1146 platformViewsController.
detach();
1148 verify(overlayImageView,
times(1)).closeImageReader();
1149 verify(overlayImageView,
times(1)).detachFromRenderer();
1153 @Config(shadows = {ShadowFlutterSurfaceView.class, ShadowFlutterJNI.class})
1157 final int platformViewId = 0;
1162 when(platformView.
getView()).thenReturn(mock(View.class));
1163 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
1169 attach(jni, platformViewsController);
1181 overlaySurface.
getId(), 0, 0, 10, 10);
1185 verify(overlayImageView,
times(1)).closeImageReader();
1186 verify(overlayImageView,
times(1)).detachFromRenderer();
1187 verify(flutterView,
times(1)).removeView(overlayImageView);
1191 @Config(shadows = {ShadowFlutterSurfaceView.class, ShadowFlutterJNI.class})
1195 final int platformViewId = 0;
1200 when(platformView.
getView()).thenReturn(mock(View.class));
1201 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
1207 attach(jni, platformViewsController);
1219 overlaySurface.
getId(), 0, 0, 10, 10);
1224 verify(overlayImageView,
times(1)).closeImageReader();
1225 verify(overlayImageView,
times(1)).detachFromRenderer();
1229 @Config(shadows = {ShadowFlutterSurfaceView.class, ShadowFlutterJNI.class})
1233 final int platformViewId = 0;
1238 when(platformView.
getView()).thenReturn(mock(View.class));
1239 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
1245 attach(jni, platformViewsController);
1257 overlaySurface.
getId(), 0, 0, 10, 10);
1260 verify(flutterView, never()).removeView(overlayImageView);
1267 assertFalse(shouldProxying);
1271 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
1275 final int platformViewId = 0;
1280 final View androidView = mock(View.class);
1281 when(platformView.
getView()).thenReturn(androidView);
1282 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
1288 final FlutterView flutterView = attach(jni, platformViewsController);
1293 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1307 assertEquals(flutterView.getChildCount(), 3);
1309 final View view = flutterView.getChildAt(1);
1313 disposePlatformView(jni, platformViewsController, platformViewId);
1317 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
1321 final int platformViewId = 0;
1326 final View androidView = mock(View.class);
1327 when(platformView.
getView()).thenReturn(androidView);
1328 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
1334 final FlutterView flutterView = attach(jni, platformViewsController);
1339 synchronizeToNativeViewHierarchy(jni, platformViewsController,
false);
1342 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1356 assertEquals(flutterView.getChildCount(), 2);
1361 disposePlatformView(jni, platformViewsController, platformViewId);
1365 @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
1370 int platformViewId = 100;
1375 View androidView = mock(View.class);
1376 when(platformView.
getView()).thenReturn(androidView);
1377 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
1382 attachToFlutterView(jni, platformViewsController, initFlutterView);
1385 jni, platformViewsController, platformViewId,
"testType",
false);
1398 ShadowFlutterSurfaceView.class,
1399 ShadowFlutterJNI.class,
1400 ShadowPlatformTaskQueue.class
1405 final int platformViewId = 0;
1410 final View androidView = mock(View.class);
1411 when(platformView.
getView()).thenReturn(androidView);
1412 when(viewFactory.
create(
any(),
eq(platformViewId),
any())).thenReturn(platformView);
1419 final FlutterView flutterView = attach(jni, platformViewsController);
1424 createPlatformView(jni, platformViewsController, platformViewId,
"testType",
true);
1432 assertEquals(flutterView.getChildCount(), 3);
1437 assertTrue(imageView !=
null);
1438 assertTrue(flutterView.indexOfChild(imageView) != -1);
1443 assertTrue(overlayView !=
null);
1444 assertTrue(flutterView.indexOfChild(overlayView) != -1);
1458 assertTrue(flutterView.indexOfChild(imageView) == -1);
1461 assertTrue(flutterView.indexOfChild(overlayView) == -1);
1470 private static void createPlatformView(
1472 PlatformViewsController platformViewsController,
1476 final Map<String, Object>
args =
new HashMap<>();
1477 args.put(
"hybrid", hybrid);
1478 args.put(
"id", platformViewId);
1479 args.put(
"viewType", viewType);
1480 args.put(
"direction", 0);
1481 args.put(
"width", 1.0);
1482 args.put(
"height", 1.0);
1487 "flutter/platform_views",
1488 encodeMethodCall(platformCreateMethodCall),
1493 private static void setLayoutDirection(
1495 PlatformViewsController platformViewsController,
1498 final Map<String, Object>
args =
new HashMap<>();
1499 args.put(
"id", platformViewId);
1500 args.put(
"direction", direction);
1505 "flutter/platform_views",
1506 encodeMethodCall(platformSetDirectionMethodCall),
1511 private static void resize(
1513 PlatformViewsController platformViewsController,
1517 final Map<String, Object>
args =
new HashMap<>();
1518 args.put(
"id", platformViewId);
1524 jni.handlePlatformMessage(
1525 "flutter/platform_views",
1526 encodeMethodCall(platformResizeMethodCall),
1531 private static void disposePlatformView(
1532 FlutterJNI jni, PlatformViewsController platformViewsController,
int platformViewId) {
1534 final Map<String, Object>
args =
new HashMap<>();
1535 args.put(
"hybrid",
true);
1536 args.put(
"id", platformViewId);
1540 jni.handlePlatformMessage(
1541 "flutter/platform_views",
1542 encodeMethodCall(platformDisposeMethodCall),
1547 private static void synchronizeToNativeViewHierarchy(
1548 FlutterJNI jni, PlatformViewsController platformViewsController,
boolean yes) {
1552 jni.handlePlatformMessage(
1553 "flutter/platform_views",
1554 encodeMethodCall(convertMethodCall),
1560 FlutterJNI jni, PlatformViewsController platformViewsController) {
1561 final Context context = ApplicationProvider.getApplicationContext();
1563 new FlutterView(context,
new FlutterSurfaceView(context)) {
1565 public FlutterImageView createImageView() {
1566 final FlutterImageView view = mock(FlutterImageView.class);
1567 when(view.acquireLatestImage()).thenReturn(
true);
1568 return mock(FlutterImageView.class);
1571 attachToFlutterView(jni, platformViewsController, flutterView);
1575 private static void attachToFlutterView(
1576 FlutterJNI jni, PlatformViewsController platformViewsController,
FlutterView flutterView) {
1577 final DartExecutor executor =
new DartExecutor(jni, mock(AssetManager.class));
1578 executor.onAttachedToJNI();
1580 final Context context = ApplicationProvider.getApplicationContext();
1581 final TextureRegistry registry =
1582 new TextureRegistry() {
1583 public void TextureRegistry() {}
1586 public SurfaceTextureEntry createSurfaceTexture() {
1587 return registerSurfaceTexture(mock(SurfaceTexture.class));
1591 public SurfaceTextureEntry registerSurfaceTexture(SurfaceTexture surfaceTexture) {
1592 return new SurfaceTextureEntry() {
1595 public SurfaceTexture surfaceTexture() {
1596 return mock(SurfaceTexture.class);
1605 public void release() {}
1610 public ImageTextureEntry createImageTexture() {
1611 return new ImageTextureEntry() {
1618 public void release() {}
1626 public SurfaceProducer createSurfaceProducer() {
1627 return new SurfaceProducer() {
1634 public void release() {}
1637 public int getWidth() {
1642 public int getHeight() {
1650 public Surface getSurface() {
1654 public void scheduleFrame() {}
1659 platformViewsController.attach(context, registry, executor);
1663 when(
engine.getMouseCursorChannel()).thenReturn(mock(MouseCursorChannel.class));
1664 when(
engine.getTextInputChannel()).thenReturn(mock(TextInputChannel.class));
1665 when(
engine.getSettingsChannel()).thenReturn(
new SettingsChannel(executor));
1666 when(
engine.getPlatformViewsController()).thenReturn(platformViewsController);
1667 when(
engine.getLocalizationPlugin()).thenReturn(mock(LocalizationPlugin.class));
1668 when(
engine.getAccessibilityChannel()).thenReturn(mock(AccessibilityChannel.class));
1669 when(
engine.getDartExecutor()).thenReturn(executor);
1671 flutterView.attachToFlutterEngine(
engine);
1672 platformViewsController.attachToView(flutterView);
1681 @Implements(io.flutter.embedding.engine.dart.PlatformTaskQueue.class)
1695 @Implements(Presentation.class)
1697 private boolean isShowing =
false;
1719 private static SparseArray<ByteBuffer> replies =
new SparseArray<>();
1735 String channel, ByteBuffer
message,
int position,
int responseId) {}
1748 float devicePixelRatio,
1751 int physicalPaddingTop,
1752 int physicalPaddingRight,
1753 int physicalPaddingBottom,
1754 int physicalPaddingLeft,
1755 int physicalViewInsetTop,
1756 int physicalViewInsetRight,
1757 int physicalViewInsetBottom,
1758 int physicalViewInsetLeft,
1759 int systemGestureInsetTop,
1760 int systemGestureInsetRight,
1761 int systemGestureInsetBottom,
1762 int systemGestureInsetLeft,
1763 int physicalTouchSlop,
1764 int[] displayFeaturesBounds,
1765 int[] displayFeaturesType,
1766 int[] displayFeaturesState) {}
1770 int responseId, ByteBuffer
message,
int position) {
1771 replies.put(responseId,
message);
1779 @Implements(SurfaceView.class)
1784 private final Surface
surface = mock(Surface.class);
static SkISize times(const SkISize &size, float factor)
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
boolean acquireLatestImage()
FlutterImageView getCurrentImageSurface()
MotionEventId track(@NonNull MotionEvent event)
static MotionEventTracker getInstance()
void handlePlatformMessage( @NonNull final String channel, ByteBuffer message, final int replyId, final long messageData)
static final StandardMessageCodec INSTANCE
ByteBuffer encodeMethodCall(@NonNull MethodCall methodCall)
static final StandardMethodCodec INSTANCE
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
sk_sp< const SkImage > image
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
SIT bool any(const Vec< 1, T > &x)