Skip to content

Commit 3757f19

Browse files
authored
delegate checkInputConnectionProxy to the relevant platform view (flutter#9426)
The previous logic allowed proxying for any view that belonged to one of the platform views' virtual displays which may lead to us allowing proxying for a view that the platform view isn't allowing proxying for, previous logic also didn't account for unattached views. This change instead delegates the decision to the platform view. We use the fact that each virtual display has its unique context to associate any view with its relevant virtual display. A nice side effect of calling the platform view's checkInputConnectionProxy for webviews is that the plugin now has a way to get a handle to the ThreadedInputConnectionProxyView, which may be useful for getting keyboard working on webview's prior to Android N.
1 parent d9dfad3 commit 3757f19

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java

+22-20
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,12 @@
1919

2020
import io.flutter.embedding.engine.dart.DartExecutor;
2121
import io.flutter.embedding.engine.systemchannels.PlatformViewsChannel;
22-
import io.flutter.plugin.common.BinaryMessenger;
23-
import io.flutter.plugin.common.MethodCall;
24-
import io.flutter.plugin.common.MethodChannel;
25-
import io.flutter.plugin.common.StandardMethodCodec;
2622
import io.flutter.plugin.editing.TextInputPlugin;
2723
import io.flutter.view.AccessibilityBridge;
2824
import io.flutter.view.TextureRegistry;
2925

30-
import java.lang.reflect.Method;
31-
import java.nio.ByteBuffer;
3226
import java.util.ArrayList;
3327
import java.util.HashMap;
34-
import java.util.HashSet;
3528
import java.util.List;
3629

3730
/**
@@ -64,10 +57,10 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
6457

6558
private final HashMap<Integer, VirtualDisplayController> vdControllers;
6659

67-
// The set of root views for all active virtual displays managed by this controller.
68-
// This allows an O(1) check whether a view is managed by this controller(by checking if it's root view is in this
69-
// set). This is used by isPlatformView.
70-
private final HashSet<View> vdRootViews;
60+
// Maps a virtual display's context to the platform view hosted in this virtual display.
61+
// Since each virtual display has it's unique context this allows associating any view with the platform view that
62+
// it is associated with(e.g if a platform view creates other views in the same virtual display.
63+
private final HashMap<Context, View> contextToPlatformView;
7164

7265
private final PlatformViewsChannel.PlatformViewsHandler channelHandler = new PlatformViewsChannel.PlatformViewsHandler() {
7366
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@@ -125,7 +118,7 @@ public long createPlatformView(@NonNull PlatformViewsChannel.PlatformViewCreatio
125118
vdControllers.put(request.viewId, vdController);
126119
View platformView = vdController.getView();
127120
platformView.setLayoutDirection(request.direction);
128-
vdRootViews.add(platformView.getRootView());
121+
contextToPlatformView.put(platformView.getContext(), platformView);
129122

130123
// TODO(amirh): copy accessibility nodes to the FlutterView's accessibility tree.
131124

@@ -142,8 +135,7 @@ public void disposePlatformView(int viewId) {
142135
+ viewId);
143136
}
144137

145-
View rootView = vdController.getView().getRootView();
146-
vdRootViews.remove(rootView);
138+
contextToPlatformView.remove(vdController.getView().getContext());
147139

148140
vdController.dispose();
149141
vdControllers.remove(viewId);
@@ -170,7 +162,6 @@ public void resizePlatformView(@NonNull PlatformViewsChannel.PlatformViewResizeR
170162
// and unlock after the resize is complete.
171163
textInputPlugin.lockPlatformViewInputConnection();
172164
}
173-
vdRootViews.remove(vdController.getView().getRootView());
174165
vdController.resize(
175166
physicalWidth,
176167
physicalHeight,
@@ -184,7 +175,6 @@ public void run() {
184175
}
185176
}
186177
);
187-
vdRootViews.add(vdController.getView().getRootView());
188178
}
189179

190180
@Override
@@ -264,7 +254,7 @@ public PlatformViewsController() {
264254
registry = new PlatformViewRegistryImpl();
265255
vdControllers = new HashMap<>();
266256
accessibilityEventsDelegate = new AccessibilityEventsDelegate();
267-
vdRootViews = new HashSet<>();
257+
contextToPlatformView = new HashMap<>();
268258
}
269259

270260
/**
@@ -335,10 +325,22 @@ public void detachTextInputPlugin() {
335325
}
336326

337327
/**
338-
* Returns true if the view is a platform view managed by this controller.
328+
* Returns true if Flutter should perform input connection proxying for the view.
329+
*
330+
* If the view is a platform view managed by this platform views controller returns true.
331+
* Else if the view was created in a platform view's VD, delegates the decision to the platform view's
332+
* {@link View#checkInputConnectionProxy(View)} method.
333+
* Else returns false.
339334
*/
340-
public boolean isPlatformView(View view) {
341-
return vdRootViews.contains(view.getRootView());
335+
public boolean checkInputConnectionProxy(View view) {
336+
if(!contextToPlatformView.containsKey(view.getContext())) {
337+
return false;
338+
}
339+
View platformView = contextToPlatformView.get(view.getContext());
340+
if (platformView == view) {
341+
return true;
342+
}
343+
return platformView.checkInputConnectionProxy(view);
342344
}
343345

344346
public PlatformViewRegistry getRegistry() {

shell/platform/android/io/flutter/view/FlutterView.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
399399

400400
@Override
401401
public boolean checkInputConnectionProxy(View view) {
402-
PlatformViewsController platformViewsController = mNativeView.getPluginRegistry().getPlatformViewsController();
403-
return platformViewsController.isPlatformView(view);
402+
return mNativeView.getPluginRegistry().getPlatformViewsController().checkInputConnectionProxy(view);
404403
}
405404

406405
@Override

0 commit comments

Comments
 (0)