From a081806ce3dcdef4e98c125c6ad20bde5548b0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Wed, 8 Feb 2023 11:03:11 +0800 Subject: [PATCH] [Android] Convert `int` in Dart to `long` instead of `int` in java. --- .../android/android_context_gl_unittests.cc | 2 +- .../android/android_shell_holder_unittests.cc | 2 +- .../flutter/embedding/engine/FlutterJNI.java | 2 +- .../systemchannels/PlatformViewsChannel.java | 38 +++++----- .../plugin/editing/TextInputPlugin.java | 2 +- .../plugin/platform/PlatformViewFactory.java | 2 +- .../PlatformViewsAccessibilityDelegate.java | 4 +- .../platform/PlatformViewsController.java | 47 ++++++------- .../platform/SingleViewPresentation.java | 4 +- .../platform/VirtualDisplayController.java | 4 +- shell/platform/android/jni/jni_mock.h | 2 +- .../android/jni/platform_view_android_jni.h | 2 +- .../android/platform_view_android_jni_impl.cc | 4 +- .../android/platform_view_android_jni_impl.h | 2 +- .../embedding/engine/FlutterJNITest.java | 4 +- .../platform/PlatformViewsControllerTest.java | 69 ++++++++++--------- .../scenarios/SurfacePlatformViewFactory.java | 2 +- .../scenarios/TextPlatformViewFactory.java | 4 +- .../scenarios/TexturePlatformViewFactory.java | 2 +- 19 files changed, 100 insertions(+), 98 deletions(-) diff --git a/shell/platform/android/android_context_gl_unittests.cc b/shell/platform/android/android_context_gl_unittests.cc index bf1c7a78407ec..b129ce01fcde3 100644 --- a/shell/platform/android/android_context_gl_unittests.cc +++ b/shell/platform/android/android_context_gl_unittests.cc @@ -39,7 +39,7 @@ class MockPlatformViewAndroidJNI : public PlatformViewAndroidJNI { MOCK_METHOD1(SurfaceTextureDetachFromGLContext, void(JavaLocalRef surface_texture)); MOCK_METHOD8(FlutterViewOnDisplayPlatformView, - void(int view_id, + void(int64_t view_id, int x, int y, int width, diff --git a/shell/platform/android/android_shell_holder_unittests.cc b/shell/platform/android/android_shell_holder_unittests.cc index 85cb352e005f9..a87626a5f6fbb 100644 --- a/shell/platform/android/android_shell_holder_unittests.cc +++ b/shell/platform/android/android_shell_holder_unittests.cc @@ -31,7 +31,7 @@ class MockPlatformViewAndroidJNI : public PlatformViewAndroidJNI { MOCK_METHOD1(SurfaceTextureDetachFromGLContext, void(JavaLocalRef surface_texture)); MOCK_METHOD8(FlutterViewOnDisplayPlatformView, - void(int view_id, + void(int64_t view_id, int x, int y, int width, diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 3a20807bdf1f0..6449fefd21695 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -1382,7 +1382,7 @@ private native void nativeDeferredComponentInstallFailure( // @SuppressWarnings("unused") @UiThread public void onDisplayPlatformView( - int viewId, + long viewId, int x, int y, int width, diff --git a/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java b/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java index df58b0badfdc5..36b67a1607cf9 100644 --- a/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java +++ b/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java @@ -28,7 +28,7 @@ public class PlatformViewsChannel { private final MethodChannel channel; private PlatformViewsHandler handler; - public void invokeViewFocused(int viewId) { + public void invokeViewFocused(long viewId) { if (channel == null) { return; } @@ -93,7 +93,7 @@ private void create(@NonNull MethodCall call, @NonNull MethodChannel.Result resu if (usesPlatformViewLayer) { final PlatformViewCreationRequest request = new PlatformViewCreationRequest( - (int) createArgs.get("id"), + ((Number) createArgs.get("id")).longValue(), (String) createArgs.get("viewType"), 0, 0, @@ -116,7 +116,7 @@ private void create(@NonNull MethodCall call, @NonNull MethodChannel.Result resu .TEXTURE_WITH_VIRTUAL_FALLBACK; final PlatformViewCreationRequest request = new PlatformViewCreationRequest( - (int) createArgs.get("id"), + ((Number) createArgs.get("id")).longValue(), (String) createArgs.get("viewType"), createArgs.containsKey("top") ? (double) createArgs.get("top") : 0.0, createArgs.containsKey("left") ? (double) createArgs.get("left") : 0.0, @@ -144,7 +144,7 @@ private void create(@NonNull MethodCall call, @NonNull MethodChannel.Result resu private void dispose(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { Map disposeArgs = call.arguments(); - int viewId = (int) disposeArgs.get("id"); + long viewId = ((Number) disposeArgs.get("id")).longValue(); try { handler.dispose(viewId); @@ -158,7 +158,7 @@ private void resize(@NonNull MethodCall call, @NonNull MethodChannel.Result resu Map resizeArgs = call.arguments(); PlatformViewResizeRequest resizeRequest = new PlatformViewResizeRequest( - (int) resizeArgs.get("id"), + ((Number) resizeArgs.get("id")).longValue(), (double) resizeArgs.get("width"), (double) resizeArgs.get("height")); try { @@ -183,7 +183,7 @@ private void offset(@NonNull MethodCall call, @NonNull MethodChannel.Result resu Map offsetArgs = call.arguments(); try { handler.offset( - (int) offsetArgs.get("id"), + ((Number) offsetArgs.get("id")).longValue(), (double) offsetArgs.get("top"), (double) offsetArgs.get("left")); result.success(null); @@ -223,7 +223,7 @@ private void touch(@NonNull MethodCall call, @NonNull MethodChannel.Result resul private void setDirection(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { Map setDirectionArgs = call.arguments(); - int newDirectionViewId = (int) setDirectionArgs.get("id"); + long newDirectionViewId = ((Number) setDirectionArgs.get("id")).longValue(); int direction = (int) setDirectionArgs.get("direction"); try { @@ -235,7 +235,7 @@ private void setDirection(@NonNull MethodCall call, @NonNull MethodChannel.Resul } private void clearFocus(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { - int viewId = call.arguments(); + long viewId = call.arguments(); try { handler.clearFocus(viewId); result.success(null); @@ -319,7 +319,7 @@ public interface PlatformViewsHandler { long createForTextureLayer(@NonNull PlatformViewCreationRequest request); /** The Flutter application would like to dispose of an existing Android {@code View}. */ - void dispose(int viewId); + void dispose(long viewId); /** * The Flutter application would like to resize an existing Android {@code View}. @@ -334,7 +334,7 @@ void resize( /** * The Flutter application would like to change the offset of an existing Android {@code View}. */ - void offset(int viewId, double top, double left); + void offset(long viewId, double top, double left); /** * The user touched a platform view within Flutter. @@ -348,10 +348,10 @@ void resize( * {@code View}, i.e., platform view. */ // TODO(mattcarroll): Introduce an annotation for @TextureId - void setDirection(int viewId, int direction); + void setDirection(long viewId, int direction); /** Clears the focus from the platform view with a give id if it is currently focused. */ - void clearFocus(int viewId); + void clearFocus(long viewId); /** * Whether the render surface of {@code FlutterView} should be converted to a {@code @@ -376,7 +376,7 @@ public enum RequestedDisplayMode { } /** The ID of the platform view as seen by the Flutter side. */ - public final int viewId; + public final long viewId; /** The type of Android {@code View} to create for this platform view. */ @NonNull public final String viewType; @@ -408,7 +408,7 @@ public enum RequestedDisplayMode { /** Creates a request to construct a platform view. */ public PlatformViewCreationRequest( - int viewId, + long viewId, @NonNull String viewType, double logicalTop, double logicalLeft, @@ -430,7 +430,7 @@ public PlatformViewCreationRequest( /** Creates a request to construct a platform view with the given display mode. */ public PlatformViewCreationRequest( - int viewId, + long viewId, @NonNull String viewType, double logicalTop, double logicalLeft, @@ -454,7 +454,7 @@ public PlatformViewCreationRequest( /** Request sent from Flutter to resize a platform view. */ public static class PlatformViewResizeRequest { /** The ID of the platform view as seen by the Flutter side. */ - public final int viewId; + public final long viewId; /** The new density independent width to display the platform view. */ public final double newLogicalWidth; @@ -462,7 +462,7 @@ public static class PlatformViewResizeRequest { /** The new density independent height to display the platform view. */ public final double newLogicalHeight; - public PlatformViewResizeRequest(int viewId, double newLogicalWidth, double newLogicalHeight) { + public PlatformViewResizeRequest(long viewId, double newLogicalWidth, double newLogicalHeight) { this.viewId = viewId; this.newLogicalWidth = newLogicalWidth; this.newLogicalHeight = newLogicalHeight; @@ -491,7 +491,7 @@ public interface PlatformViewBufferResized { /** The state of a touch event in Flutter within a platform view. */ public static class PlatformViewTouch { /** The ID of the platform view as seen by the Flutter side. */ - public final int viewId; + public final long viewId; /** The amount of time that the touch has been pressed. */ @NonNull public final Number downTime; @@ -525,7 +525,7 @@ public static class PlatformViewTouch { public final long motionEventId; public PlatformViewTouch( - int viewId, + long viewId, @NonNull Number downTime, @NonNull Number eventTime, int action, diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 10cbc1b65cb61..69b63d0e80d85 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -369,7 +369,7 @@ public InputConnection getLastInputConnection() { *

This is called when a platform view is disposed to make sure we're not hanging to a stale * input connection. */ - public void clearPlatformViewClient(int platformViewId) { + public void clearPlatformViewClient(long platformViewId) { if ((inputTarget.type == InputTarget.Type.VIRTUAL_DISPLAY_PLATFORM_VIEW || inputTarget.type == InputTarget.Type.PHYSICAL_DISPLAY_PLATFORM_VIEW) && inputTarget.id == platformViewId) { diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewFactory.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewFactory.java index e21ee3897f555..3f1be9ff8497b 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewFactory.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewFactory.java @@ -28,7 +28,7 @@ public PlatformViewFactory(@Nullable MessageCodec createArgsCodec) { * null, or no arguments were sent from the Flutter app. */ @NonNull - public abstract PlatformView create(Context context, int viewId, @Nullable Object args); + public abstract PlatformView create(Context context, long viewId, @Nullable Object args); /** Returns the codec to be used for decoding the args parameter of {@link #create}. */ @Nullable diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java index f1f91ddaa3055..39164bec36bb3 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java @@ -16,10 +16,10 @@ public interface PlatformViewsAccessibilityDelegate { * there is no corresponding view. */ @Nullable - View getPlatformViewById(int viewId); + View getPlatformViewById(long viewId); /** Returns true if the platform view uses virtual displays. */ - boolean usesVirtualDisplay(int id); + boolean usesVirtualDisplay(long viewId); /** * Attaches an accessibility bridge for this platform views accessibility delegate. diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 4b61cdc10d8d8..a2f0f7a08da9b 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -11,6 +11,7 @@ import android.content.Context; import android.content.MutableContextWrapper; import android.os.Build; +import android.util.LongSparseArray; import android.util.SparseArray; import android.view.MotionEvent; import android.view.SurfaceView; @@ -87,7 +88,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega // TODO(mattcarroll): Refactor overall platform views to facilitate testing and then make // this private. This is visible as a hack to facilitate testing. This was deemed the least // bad option at the time of writing. - @VisibleForTesting /* package */ final HashMap vdControllers; + @VisibleForTesting /* package */ final LongSparseArray vdControllers; // Maps a virtual display's context to the embedded view hosted in this virtual display. // Since each virtual display has it's unique context this allows associating any view with the @@ -96,7 +97,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega @VisibleForTesting /* package */ final HashMap contextToEmbeddedView; // The platform views. - private final SparseArray platformViews; + private final LongSparseArray platformViews; // The platform view wrappers that are appended to FlutterView. // @@ -111,7 +112,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega // // This view provides a wrapper that applies scene builder operations to the platform view. // For example, a transform matrix, or setting opacity on the platform view layer. - private final SparseArray platformViewParent; + private final LongSparseArray platformViewParent; // Map of unique IDs to views that render overlay layers. private final SparseArray overlayLayerViews; @@ -122,7 +123,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega // the platform views that use a PlatformViewLayer. // // This is the default mode, and recommended for better performance. - private final SparseArray viewWrappers; + private final LongSparseArray viewWrappers; // Next available unique ID for use in overlayLayerViews. private int nextOverlayLayerId = 0; @@ -139,7 +140,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega private final HashSet currentFrameUsedOverlayLayerIds; // Platform view IDs that were displayed since the start of the current frame. - private final HashSet currentFrameUsedPlatformViewIds; + private final HashSet currentFrameUsedPlatformViewIds; // Used to acquire the original motion events using the motionEventIds. private final MotionEventTracker motionEventTracker; @@ -172,7 +173,7 @@ public void createForPlatformViewLayer( public long createForTextureLayer( @NonNull PlatformViewsChannel.PlatformViewCreationRequest request) { ensureValidRequest(request); - final int viewId = request.viewId; + final long viewId = request.viewId; if (viewWrappers.get(viewId) != null) { throw new IllegalStateException( "Trying to create an already created platform view, view id: " + viewId); @@ -226,7 +227,7 @@ public long createForTextureLayer( } @Override - public void dispose(int viewId) { + public void dispose(long viewId) { final PlatformView platformView = platformViews.get(viewId); if (platformView == null) { Log.e(TAG, "Disposing unknown platform view with id: " + viewId); @@ -279,7 +280,7 @@ public void dispose(int viewId) { } @Override - public void offset(int viewId, double top, double left) { + public void offset(long viewId, double top, double left) { if (usesVirtualDisplay(viewId)) { // Virtual displays don't need an accessibility offset. return; @@ -311,7 +312,7 @@ public void resize( @NonNull PlatformViewsChannel.PlatformViewBufferResized onComplete) { final int physicalWidth = toPhysicalPixels(request.newLogicalWidth); final int physicalHeight = toPhysicalPixels(request.newLogicalHeight); - final int viewId = request.viewId; + final long viewId = request.viewId; if (usesVirtualDisplay(viewId)) { final float originalDisplayDensity = getDisplayDensity(); @@ -378,7 +379,7 @@ public void resize( @Override public void onTouch(@NonNull PlatformViewsChannel.PlatformViewTouch touch) { - final int viewId = touch.viewId; + final long viewId = touch.viewId; final float density = context.getResources().getDisplayMetrics().density; if (usesVirtualDisplay(viewId)) { @@ -404,7 +405,7 @@ public void onTouch(@NonNull PlatformViewsChannel.PlatformViewTouch touch) { @TargetApi(17) @Override - public void setDirection(int viewId, int direction) { + public void setDirection(long viewId, int direction) { if (!validateDirection(direction)) { throw new IllegalStateException( "Trying to set unknown direction value: " @@ -435,7 +436,7 @@ public void setDirection(int viewId, int direction) { } @Override - public void clearFocus(int viewId) { + public void clearFocus(long viewId) { View embeddedView; if (usesVirtualDisplay(viewId)) { @@ -712,15 +713,15 @@ public MotionEvent toMotionEvent( public PlatformViewsController() { registry = new PlatformViewRegistryImpl(); - vdControllers = new HashMap<>(); + vdControllers = new LongSparseArray<>(); accessibilityEventsDelegate = new AccessibilityEventsDelegate(); contextToEmbeddedView = new HashMap<>(); overlayLayerViews = new SparseArray<>(); currentFrameUsedOverlayLayerIds = new HashSet<>(); currentFrameUsedPlatformViewIds = new HashSet<>(); - viewWrappers = new SparseArray<>(); - platformViews = new SparseArray<>(); - platformViewParent = new SparseArray<>(); + viewWrappers = new LongSparseArray<>(); + platformViews = new LongSparseArray<>(); + platformViewParent = new LongSparseArray<>(); motionEventTracker = MotionEventTracker.getInstance(); } @@ -917,7 +918,7 @@ public void onPreEngineRestart() { @Override @Nullable - public View getPlatformViewById(int viewId) { + public View getPlatformViewById(long viewId) { if (usesVirtualDisplay(viewId)) { final VirtualDisplayController controller = vdControllers.get(viewId); return controller.getView(); @@ -931,8 +932,8 @@ public View getPlatformViewById(int viewId) { } @Override - public boolean usesVirtualDisplay(int id) { - return vdControllers.containsKey(id); + public boolean usesVirtualDisplay(long viewId) { + return vdControllers.get(viewId) != null; } private void lockInputConnection(@NonNull VirtualDisplayController controller) { @@ -1018,7 +1019,7 @@ private int toLogicalPixels(double physicalPixels) { private void diposeAllViews() { while (platformViews.size() > 0) { - final int viewId = platformViews.keyAt(0); + final long viewId = platformViews.keyAt(0); // Dispose deletes the entry from platformViews and clears associated resources. channelHandler.dispose(viewId); } @@ -1039,7 +1040,7 @@ private void initializeRootImageViewIfNeeded() { */ @VisibleForTesting @TargetApi(Build.VERSION_CODES.KITKAT) - void initializePlatformViewIfNeeded(int viewId) { + void initializePlatformViewIfNeeded(long viewId) { final PlatformView platformView = platformViews.get(viewId); if (platformView == null) { throw new IllegalStateException( @@ -1103,7 +1104,7 @@ public void attachToFlutterRenderer(@NonNull FlutterRenderer flutterRenderer) { * visible for testing. */ public void onDisplayPlatformView( - int viewId, + long viewId, int x, int y, int width, @@ -1220,7 +1221,7 @@ private void finishFrame(boolean isFrameRenderedUsingImageReaders) { } for (int i = 0; i < platformViewParent.size(); i++) { - final int viewId = platformViewParent.keyAt(i); + final long viewId = platformViewParent.keyAt(i); final View parentView = platformViewParent.get(viewId); // This should only show platform views that are rendered in this frame and either: diff --git a/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java b/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java index 7841452321878..a12864f203272 100644 --- a/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java +++ b/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java @@ -82,7 +82,7 @@ static class PresentationState { // This is the view id assigned by the Flutter framework to the embedded view, we keep it here // so when we create the platform view we can tell it its view id. - private int viewId; + private long viewId; // The root view for the presentation, it has 2 childs: container which contains the embedded // view, and @@ -110,7 +110,7 @@ public SingleViewPresentation( Display display, PlatformView view, AccessibilityEventsDelegate accessibilityEventsDelegate, - int viewId, + long viewId, OnFocusChangeListener focusChangeListener) { super(new ImmContext(outerContext), display); this.accessibilityEventsDelegate = accessibilityEventsDelegate; diff --git a/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java b/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java index 3438db5dd648c..258c3a3d43bfe 100644 --- a/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java +++ b/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java @@ -30,7 +30,7 @@ public static VirtualDisplayController create( TextureRegistry.SurfaceTextureEntry textureEntry, int width, int height, - int viewId, + long viewId, Object createParams, OnFocusChangeListener focusChangeListener) { @@ -98,7 +98,7 @@ private VirtualDisplayController( Surface surface, TextureRegistry.SurfaceTextureEntry textureEntry, OnFocusChangeListener focusChangeListener, - int viewId, + long viewId, Object createParams) { this.context = context; this.accessibilityEventsDelegate = accessibilityEventsDelegate; diff --git a/shell/platform/android/jni/jni_mock.h b/shell/platform/android/jni/jni_mock.h index aaa52b80d7bd4..a22974fa59e62 100644 --- a/shell/platform/android/jni/jni_mock.h +++ b/shell/platform/android/jni/jni_mock.h @@ -66,7 +66,7 @@ class JNIMock final : public PlatformViewAndroidJNI { MOCK_METHOD(void, FlutterViewOnDisplayPlatformView, - (int view_id, + (int64_t view_id, int x, int y, int width, diff --git a/shell/platform/android/jni/platform_view_android_jni.h b/shell/platform/android/jni/platform_view_android_jni.h index 8e38a385fe771..9328a31d4a738 100644 --- a/shell/platform/android/jni/platform_view_android_jni.h +++ b/shell/platform/android/jni/platform_view_android_jni.h @@ -116,7 +116,7 @@ class PlatformViewAndroidJNI { /// @note Must be called from the platform thread. /// virtual void FlutterViewOnDisplayPlatformView( - int view_id, + int64_t view_id, int x, int y, int width, diff --git a/shell/platform/android/platform_view_android_jni_impl.cc b/shell/platform/android/platform_view_android_jni_impl.cc index 031ec1057eb22..cb21dbc887ecc 100644 --- a/shell/platform/android/platform_view_android_jni_impl.cc +++ b/shell/platform/android/platform_view_android_jni_impl.cc @@ -1026,7 +1026,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { g_on_display_platform_view_method = env->GetMethodID(g_flutter_jni_class->obj(), "onDisplayPlatformView", - "(IIIIIIILio/flutter/embedding/engine/mutatorsstack/" + "(JIIIIIILio/flutter/embedding/engine/mutatorsstack/" "FlutterMutatorsStack;)V"); if (g_on_display_platform_view_method == nullptr) { @@ -1406,7 +1406,7 @@ void PlatformViewAndroidJNIImpl::SurfaceTextureDetachFromGLContext( } void PlatformViewAndroidJNIImpl::FlutterViewOnDisplayPlatformView( - int view_id, + int64_t view_id, int x, int y, int width, diff --git a/shell/platform/android/platform_view_android_jni_impl.h b/shell/platform/android/platform_view_android_jni_impl.h index b3df5358291fa..364b43807e74c 100644 --- a/shell/platform/android/platform_view_android_jni_impl.h +++ b/shell/platform/android/platform_view_android_jni_impl.h @@ -52,7 +52,7 @@ class PlatformViewAndroidJNIImpl final : public PlatformViewAndroidJNI { void SurfaceTextureDetachFromGLContext(JavaLocalRef surface_texture) override; - void FlutterViewOnDisplayPlatformView(int view_id, + void FlutterViewOnDisplayPlatformView(int64_t view_id, int x, int y, int width, diff --git a/shell/platform/android/test/io/flutter/embedding/engine/FlutterJNITest.java b/shell/platform/android/test/io/flutter/embedding/engine/FlutterJNITest.java index e40096e7b01c6..927cba933c014 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/FlutterJNITest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/FlutterJNITest.java @@ -158,7 +158,7 @@ public void onDisplayPlatformView_callsPlatformViewsController() { FlutterMutatorsStack stack = new FlutterMutatorsStack(); // --- Execute Test --- flutterJNI.onDisplayPlatformView( - /*viewId=*/ 1, + /*viewId=*/ 1L, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, @@ -170,7 +170,7 @@ public void onDisplayPlatformView_callsPlatformViewsController() { // --- Verify Results --- verify(platformViewsController, times(1)) .onDisplayPlatformView( - /*viewId=*/ 1, + /*viewId=*/ 1L, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java index b3f22dc485c1a..1979cfff09426 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java @@ -129,7 +129,7 @@ public void itCancelsOldPresentationOnResize() { @Test @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void virtualDisplay_handlesResizeResponseWithoutContext() { - final int platformViewId = 0; + final long platformViewId = 0L; FlutterView fakeFlutterView = new FlutterView(ApplicationProvider.getApplicationContext()); VirtualDisplayController fakeVdController = mock(VirtualDisplayController.class); PlatformViewsController platformViewsController = new PlatformViewsController(); @@ -295,7 +295,7 @@ public void itUsesActionEventTypeFromMotionEventForHybridPlatformViews() { public void getPlatformViewById_hybridComposition() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -323,7 +323,7 @@ public void getPlatformViewById_hybridComposition() { public void createPlatformViewMessage_initializesAndroidView() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -345,7 +345,7 @@ public void createPlatformViewMessage_initializesAndroidView() { public void createPlatformViewMessage_wrapsContextForVirtualDisplay() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -370,7 +370,7 @@ public void createPlatformViewMessage_wrapsContextForVirtualDisplay() { public void createPlatformViewMessage_doesNotWrapContextForHybrid() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -395,7 +395,7 @@ public void createPlatformViewMessage_setsAndroidViewLayoutDirection() { PlatformViewsController platformViewsController = new PlatformViewsController(); platformViewsController.setSoftwareRendering(true); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -421,7 +421,7 @@ public void createPlatformViewMessage_setsAndroidViewSize() { PlatformViewsController platformViewsController = new PlatformViewsController(); platformViewsController.setSoftwareRendering(true); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -454,7 +454,7 @@ public void createPlatformViewMessage_disablesAccessibility() { PlatformViewsController platformViewsController = new PlatformViewsController(); platformViewsController.setSoftwareRendering(true); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -480,7 +480,7 @@ public void createPlatformViewMessage_disablesAccessibility() { public void createPlatformViewMessage_throwsIfViewIsNull() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -509,7 +509,7 @@ public void createPlatformViewMessage_throwsIfViewIsNull() { public void createHybridPlatformViewMessage_throwsIfViewIsNull() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -537,7 +537,7 @@ public void createHybridPlatformViewMessage_throwsIfViewIsNull() { public void onDetachedFromJNI_clearsPlatformViewContext() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -568,7 +568,7 @@ public void onDetachedFromJNI_clearsPlatformViewContext() { public void onPreEngineRestart_clearsPlatformViewContext() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -599,7 +599,7 @@ public void onPreEngineRestart_clearsPlatformViewContext() { public void createPlatformViewMessage_throwsIfViewHasParent() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -630,7 +630,7 @@ public void createPlatformViewMessage_throwsIfViewHasParent() { public void createHybridPlatformViewMessage_throwsIfViewHasParent() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -660,7 +660,7 @@ public void createHybridPlatformViewMessage_throwsIfViewHasParent() { public void setPlatformViewDirection_throwIfPlatformViewNotFound() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -695,7 +695,7 @@ public void resizeAndroidView() { PlatformViewsController platformViewsController = new PlatformViewsController(); platformViewsController.setSoftwareRendering(true); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -731,7 +731,7 @@ public void resizeAndroidView() { public void disposeAndroidView_hybridComposition() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -772,7 +772,7 @@ public void disposeAndroidView_hybridComposition() { public void disposeNullAndroidView() { PlatformViewsController platformViewsController = new PlatformViewsController(); - int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -809,7 +809,7 @@ public void disposeNullAndroidView() { public void onEndFrame_destroysOverlaySurfaceAfterFrameOnFlutterSurfaceView() { final PlatformViewsController platformViewsController = new PlatformViewsController(); - final int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -868,7 +868,7 @@ public void onEndFrame_destroysOverlaySurfaceAfterFrameOnFlutterSurfaceView() { public void onEndFrame_removesPlatformView() { final PlatformViewsController platformViewsController = new PlatformViewsController(); - final int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -909,7 +909,7 @@ public void onEndFrame_removesPlatformView() { public void onEndFrame_removesPlatformViewParent() { final PlatformViewsController platformViewsController = new PlatformViewsController(); - final int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -952,7 +952,7 @@ public void onEndFrame_removesPlatformViewParent() { public void detach_destroysOverlaySurfaces() { final PlatformViewsController platformViewsController = new PlatformViewsController(); - final int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -1003,7 +1003,7 @@ public void detach_destroysOverlaySurfaces() { public void detachFromView_removesAndDestroysOverlayViews() { final PlatformViewsController platformViewsController = new PlatformViewsController(); - final int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -1041,7 +1041,7 @@ public void detachFromView_removesAndDestroysOverlayViews() { public void destroyOverlaySurfaces_doesNotThrowIfFlutterViewIsDetached() { final PlatformViewsController platformViewsController = new PlatformViewsController(); - final int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -1079,7 +1079,7 @@ public void destroyOverlaySurfaces_doesNotThrowIfFlutterViewIsDetached() { public void destroyOverlaySurfaces_doesNotRemoveOverlayView() { final PlatformViewsController platformViewsController = new PlatformViewsController(); - final int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -1121,7 +1121,7 @@ public void checkInputConnectionProxy_falseIfViewIsNull() { public void convertPlatformViewRenderSurfaceAsDefault() { final PlatformViewsController platformViewsController = new PlatformViewsController(); - final int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -1167,7 +1167,7 @@ public void convertPlatformViewRenderSurfaceAsDefault() { public void dontConverRenderSurfaceWhenFlagIsTrue() { final PlatformViewsController platformViewsController = new PlatformViewsController(); - final int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -1216,7 +1216,7 @@ public void reattachToFlutterView() { PlatformViewsController platformViewsController = new PlatformViewsController(); platformViewsController.setSoftwareRendering(true); - int platformViewId = 100; + final long platformViewId = 0x80000000L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -1251,7 +1251,7 @@ public void reattachToFlutterView() { public void revertImageViewAndRemoveImageView() { final PlatformViewsController platformViewsController = new PlatformViewsController(); - final int platformViewId = 0; + final long platformViewId = 0L; assertNull(platformViewsController.getPlatformViewById(platformViewId)); final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); @@ -1274,8 +1274,9 @@ public void revertImageViewAndRemoveImageView() { // The simulation creates an Overlay on top of the PlatformView // This is going to be called `flutterView.convertToImageView` + final int overlaySurfaceId = 0; platformViewsController.createOverlaySurface(); - platformViewsController.onDisplayOverlaySurface(platformViewId, 0, 0, 10, 10); + platformViewsController.onDisplayOverlaySurface(overlaySurfaceId, 0, 0, 10, 10); // This will contain three views: Background ImageView、PlatformView、Overlay ImageView assertEquals(flutterView.getChildCount(), 3); @@ -1319,7 +1320,7 @@ private static ByteBuffer encodeMethodCall(MethodCall call) { private static void createPlatformView( FlutterJNI jni, PlatformViewsController platformViewsController, - int platformViewId, + long platformViewId, String viewType, boolean hybrid) { final Map args = new HashMap<>(); @@ -1342,7 +1343,7 @@ private static void createPlatformView( private static void setLayoutDirection( FlutterJNI jni, PlatformViewsController platformViewsController, - int platformViewId, + long platformViewId, int direction) { final Map args = new HashMap<>(); args.put("id", platformViewId); @@ -1360,7 +1361,7 @@ private static void setLayoutDirection( private static void resize( FlutterJNI jni, PlatformViewsController platformViewsController, - int platformViewId, + long platformViewId, double width, double height) { final Map args = new HashMap<>(); @@ -1378,7 +1379,7 @@ private static void resize( } private static void disposePlatformView( - FlutterJNI jni, PlatformViewsController platformViewsController, int platformViewId) { + FlutterJNI jni, PlatformViewsController platformViewsController, long platformViewId) { final Map args = new HashMap<>(); args.put("hybrid", true); diff --git a/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/SurfacePlatformViewFactory.java b/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/SurfacePlatformViewFactory.java index 399afdf1be6b9..04e77582ae0f4 100644 --- a/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/SurfacePlatformViewFactory.java +++ b/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/SurfacePlatformViewFactory.java @@ -51,7 +51,7 @@ public Object decodeMessage(@Nullable ByteBuffer byteBuffer) { @SuppressWarnings("unchecked") @Override @NonNull - public PlatformView create(@NonNull Context context, int id, @Nullable Object args) { + public PlatformView create(@NonNull Context context, long id, @Nullable Object args) { if (preserveContext) { return new SurfacePlatformView(context); } else { diff --git a/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TextPlatformViewFactory.java b/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TextPlatformViewFactory.java index 93806dea105f5..316d66a96cfb5 100644 --- a/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TextPlatformViewFactory.java +++ b/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TextPlatformViewFactory.java @@ -41,7 +41,7 @@ public Object decodeMessage(@Nullable ByteBuffer byteBuffer) { @SuppressWarnings("unchecked") @Override @NonNull - public PlatformView create(@NonNull Context context, int id, @Nullable Object args) { + public PlatformView create(@NonNull Context context, long id, @Nullable Object args) { String params = (String) args; return new TextPlatformView(context, id, params); } @@ -50,7 +50,7 @@ private static class TextPlatformView implements PlatformView { final TextView textView; @SuppressWarnings("unchecked") - TextPlatformView(@NonNull final Context context, int id, @Nullable String params) { + TextPlatformView(@NonNull final Context context, long id, @Nullable String params) { textView = new TextView(context); textView.setTextSize(72); textView.setBackgroundColor(Color.WHITE); diff --git a/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TexturePlatformViewFactory.java b/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TexturePlatformViewFactory.java index e79dd16ccb4c5..cd33d1ffc37fa 100644 --- a/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TexturePlatformViewFactory.java +++ b/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TexturePlatformViewFactory.java @@ -47,7 +47,7 @@ public Object decodeMessage(@Nullable ByteBuffer byteBuffer) { @SuppressWarnings("unchecked") @Override @NonNull - public PlatformView create(@NonNull Context context, int id, @Nullable Object args) { + public PlatformView create(@NonNull Context context, long id, @Nullable Object args) { return new TexturePlatformView(context); }