Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7d6484a

Browse files
Revert "Handle SurfaceView in a VirtualDisplay (#33599)"
This reverts commit e986f43.
1 parent 0671bca commit 7d6484a

39 files changed

+246
-2300
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,8 +1481,6 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/Platfor
14811481
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java
14821482
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java
14831483
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java
1484-
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java
1485-
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java
14861484
FILE: ../../../flutter/shell/platform/android/io/flutter/util/PathUtils.java
14871485
FILE: ../../../flutter/shell/platform/android/io/flutter/util/Preconditions.java
14881486
FILE: ../../../flutter/shell/platform/android/io/flutter/util/Predicate.java

shell/platform/android/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,6 @@ android_java_sources = [
286286
"io/flutter/plugin/platform/PlatformViewWrapper.java",
287287
"io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java",
288288
"io/flutter/plugin/platform/PlatformViewsController.java",
289-
"io/flutter/plugin/platform/SingleViewPresentation.java",
290-
"io/flutter/plugin/platform/VirtualDisplayController.java",
291289
"io/flutter/util/PathUtils.java",
292290
"io/flutter/util/Preconditions.java",
293291
"io/flutter/util/Predicate.java",

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -873,21 +873,6 @@ public InputConnection onCreateInputConnection(@NonNull EditorInfo outAttrs) {
873873
return textInputPlugin.createInputConnection(this, keyboardManager, outAttrs);
874874
}
875875

876-
/**
877-
* Allows a {@code View} that is not currently the input connection target to invoke commands on
878-
* the {@link android.view.inputmethod.InputMethodManager}, which is otherwise disallowed.
879-
*
880-
* <p>Returns true to allow non-input-connection-targets to invoke methods on {@code
881-
* InputMethodManager}, or false to exclusively allow the input connection target to invoke such
882-
* methods.
883-
*/
884-
@Override
885-
public boolean checkInputConnectionProxy(View view) {
886-
return flutterEngine != null
887-
? flutterEngine.getPlatformViewsController().checkInputConnectionProxy(view)
888-
: super.checkInputConnectionProxy(view);
889-
}
890-
891876
/**
892877
* Invoked when a hardware key is pressed or released.
893878
*

shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,15 @@ private void resize(@NonNull MethodCall call, @NonNull MethodChannel.Result resu
147147
(double) resizeArgs.get("width"),
148148
(double) resizeArgs.get("height"));
149149
try {
150-
handler.resize(
151-
resizeRequest,
152-
(PlatformViewBufferSize bufferSize) -> {
153-
if (bufferSize == null) {
154-
result.error("error", "Failed to resize the platform view", null);
155-
} else {
156-
final Map<String, Object> response = new HashMap<>();
157-
response.put("width", (double) bufferSize.width);
158-
response.put("height", (double) bufferSize.height);
159-
result.success(response);
160-
}
161-
});
150+
final PlatformViewBufferSize sz = handler.resize(resizeRequest);
151+
if (sz == null) {
152+
result.error("error", "Failed to resize the platform view", null);
153+
} else {
154+
final Map<String, Object> response = new HashMap<>();
155+
response.put("width", (double) sz.width);
156+
response.put("height", (double) sz.height);
157+
result.success(response);
158+
}
162159
} catch (IllegalStateException exception) {
163160
result.error("error", detailedExceptionString(exception), null);
164161
}
@@ -301,11 +298,9 @@ public interface PlatformViewsHandler {
301298
* The Flutter application would like to resize an existing Android {@code View}.
302299
*
303300
* @param request The request to resize the platform view.
304-
* @param onComplete Once the resize is completed, this is the handler to notify the size of the
305-
* platform view buffer.
301+
* @return The buffer size where the platform view pixels are written to.
306302
*/
307-
void resize(
308-
@NonNull PlatformViewResizeRequest request, @NonNull PlatformViewBufferResized onComplete);
303+
PlatformViewBufferSize resize(@NonNull PlatformViewResizeRequest request);
309304

310305
/**
311306
* The Flutter application would like to change the offset of an existing Android {@code View}.
@@ -423,11 +418,6 @@ public PlatformViewBufferSize(int width, int height) {
423418
}
424419
}
425420

426-
/** Allows to notify when a platform view buffer has been resized. */
427-
public interface PlatformViewBufferResized {
428-
void run(@Nullable PlatformViewBufferSize bufferSize);
429-
}
430-
431421
/** The state of a touch event in Flutter within a platform view. */
432422
public static class PlatformViewTouch {
433423
/** The ID of the platform view as seen by the Flutter side. */

shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
8989
try {
9090
final JSONObject arguments = (JSONObject) args;
9191
final int platformViewId = arguments.getInt("platformViewId");
92-
final boolean usesVirtualDisplay =
93-
arguments.optBoolean("usesVirtualDisplay", false);
94-
textInputMethodHandler.setPlatformViewClient(platformViewId, usesVirtualDisplay);
92+
textInputMethodHandler.setPlatformViewClient(platformViewId);
9593
result.success(null);
9694
} catch (JSONException exception) {
9795
result.error("error", exception.getMessage(), null);
@@ -403,10 +401,8 @@ public interface TextInputMethodHandler {
403401
* different client is set.
404402
*
405403
* @param id the ID of the platform view to be set as a text input client.
406-
* @param usesVirtualDisplay True if the platform view uses a virtual display, false if it uses
407-
* hybrid composition.
408404
*/
409-
void setPlatformViewClient(int id, boolean usesVirtualDisplay);
405+
void setPlatformViewClient(int id);
410406

411407
/**
412408
* Sets the size and the transform matrix of the current text input client.

shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java

Lines changed: 11 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
5454
// Initialize the "last seen" text editing values to a non-null value.
5555
private TextEditState mLastKnownFrameworkTextEditingState;
5656

57-
// When true following calls to createInputConnection will return the cached lastInputConnection
58-
// if the input
59-
// target is a platform view. See the comments on lockPlatformViewInputConnection for more
60-
// details.
61-
private boolean isInputConnectionLocked;
62-
6357
@SuppressLint("NewApi")
6458
public TextInputPlugin(
6559
@NonNull View view,
@@ -105,7 +99,7 @@ public void show() {
10599

106100
@Override
107101
public void hide() {
108-
if (inputTarget.type == InputTarget.Type.PHYSICAL_DISPLAY_PLATFORM_VIEW) {
102+
if (inputTarget.type == InputTarget.Type.PLATFORM_VIEW) {
109103
notifyViewExited();
110104
} else {
111105
hideTextInput(mView);
@@ -136,8 +130,8 @@ public void setClient(
136130
}
137131

138132
@Override
139-
public void setPlatformViewClient(int platformViewId, boolean usesVirtualDisplay) {
140-
setPlatformViewTextInputClient(platformViewId, usesVirtualDisplay);
133+
public void setPlatformViewClient(int platformViewId) {
134+
setPlatformViewTextInputClient(platformViewId);
141135
}
142136

143137
@Override
@@ -182,36 +176,6 @@ ImeSyncDeferringInsetsCallback getImeSyncCallback() {
182176
return imeSyncCallback;
183177
}
184178

185-
/**
186-
* Use the current platform view input connection until unlockPlatformViewInputConnection is
187-
* called.
188-
*
189-
* <p>The current input connection instance is cached and any following call to @{link
190-
* createInputConnection} returns the cached connection until unlockPlatformViewInputConnection is
191-
* called.
192-
*
193-
* <p>This is a no-op if the current input target isn't a platform view.
194-
*
195-
* <p>This is used to preserve an input connection when moving a platform view from one virtual
196-
* display to another.
197-
*/
198-
public void lockPlatformViewInputConnection() {
199-
if (inputTarget.type == InputTarget.Type.VIRTUAL_DISPLAY_PLATFORM_VIEW) {
200-
isInputConnectionLocked = true;
201-
}
202-
}
203-
204-
/**
205-
* Unlocks the input connection.
206-
*
207-
* <p>See also: @{link lockPlatformViewInputConnection}.
208-
*/
209-
public void unlockPlatformViewInputConnection() {
210-
if (inputTarget.type == InputTarget.Type.VIRTUAL_DISPLAY_PLATFORM_VIEW) {
211-
isInputConnectionLocked = false;
212-
}
213-
}
214-
215179
/**
216180
* Detaches the text input plugin from the platform views controller.
217181
*
@@ -295,21 +259,10 @@ public InputConnection createInputConnection(
295259
return null;
296260
}
297261

298-
if (inputTarget.type == InputTarget.Type.PHYSICAL_DISPLAY_PLATFORM_VIEW) {
262+
if (inputTarget.type == InputTarget.Type.PLATFORM_VIEW) {
299263
return null;
300264
}
301265

302-
if (inputTarget.type == InputTarget.Type.VIRTUAL_DISPLAY_PLATFORM_VIEW) {
303-
if (isInputConnectionLocked) {
304-
return lastInputConnection;
305-
}
306-
lastInputConnection =
307-
platformViewsController
308-
.getPlatformViewById(inputTarget.id)
309-
.onCreateInputConnection(outAttrs);
310-
return lastInputConnection;
311-
}
312-
313266
outAttrs.inputType =
314267
inputTypeFromTextInputType(
315268
configuration.inputType,
@@ -364,9 +317,7 @@ public InputConnection getLastInputConnection() {
364317
* input connection.
365318
*/
366319
public void clearPlatformViewClient(int platformViewId) {
367-
if ((inputTarget.type == InputTarget.Type.VIRTUAL_DISPLAY_PLATFORM_VIEW
368-
|| inputTarget.type == InputTarget.Type.PHYSICAL_DISPLAY_PLATFORM_VIEW)
369-
&& inputTarget.id == platformViewId) {
320+
if (inputTarget.type == InputTarget.Type.PLATFORM_VIEW && inputTarget.id == platformViewId) {
370321
inputTarget = new InputTarget(InputTarget.Type.NO_TARGET, 0);
371322
notifyViewExited();
372323
mImm.hideSoftInputFromWindow(mView.getApplicationWindowToken(), 0);
@@ -427,26 +378,13 @@ void setTextInputClient(int client, TextInputChannel.Configuration configuration
427378
// setTextInputClient will be followed by a call to setTextInputEditingState.
428379
// Do a restartInput at that time.
429380
mRestartInputPending = true;
430-
unlockPlatformViewInputConnection();
431381
lastClientRect = null;
432382
mEditable.addEditingStateListener(this);
433383
}
434384

435-
private void setPlatformViewTextInputClient(int platformViewId, boolean usesVirtualDisplay) {
436-
if (usesVirtualDisplay) {
437-
// We need to make sure that the Flutter view is focused so that no imm operations get short
438-
// circuited.
439-
// Not asking for focus here specifically manifested in a bug on API 28 devices where the
440-
// platform view's request to show a keyboard was ignored.
441-
mView.requestFocus();
442-
inputTarget = new InputTarget(InputTarget.Type.VIRTUAL_DISPLAY_PLATFORM_VIEW, platformViewId);
443-
mImm.restartInput(mView);
444-
mRestartInputPending = false;
445-
} else {
446-
inputTarget =
447-
new InputTarget(InputTarget.Type.PHYSICAL_DISPLAY_PLATFORM_VIEW, platformViewId);
448-
lastInputConnection = null;
449-
}
385+
private void setPlatformViewTextInputClient(int platformViewId) {
386+
inputTarget = new InputTarget(InputTarget.Type.PLATFORM_VIEW, platformViewId);
387+
lastInputConnection = null;
450388
}
451389

452390
private static boolean composingChanged(
@@ -537,29 +475,11 @@ public void inspect(double x, double y) {
537475

538476
@VisibleForTesting
539477
void clearTextInputClient() {
540-
if (inputTarget.type == InputTarget.Type.VIRTUAL_DISPLAY_PLATFORM_VIEW) {
541-
// This only applies to platform views that use a virtual display.
542-
// Focus changes in the framework tree have no guarantees on the order focus nodes are
543-
// notified. A node that lost focus may be notified before or after a node that gained focus.
544-
// When moving the focus from a Flutter text field to an AndroidView, it is possible that the
545-
// Flutter text field's focus node will be notified that it lost focus after the AndroidView
546-
// was notified that it gained focus. When this happens the text field will send a
547-
// clearTextInput command which we ignore.
548-
// By doing this we prevent the framework from clearing a platform view input client (the only
549-
// way to do so is to set a new framework text client). I don't see an obvious use case for
550-
// "clearing" a platform view's text input client, and it may be error prone as we don't know
551-
// how the platform view manages the input connection and we probably shouldn't interfere.
552-
// If we ever want to allow the framework to clear a platform view text client we should
553-
// probably consider changing the focus manager such that focus nodes that lost focus are
554-
// notified before focus nodes that gained focus as part of the same focus event.
555-
return;
556-
}
557478
mEditable.removeEditingStateListener(this);
558479
notifyViewExited();
559480
configuration = null;
560481
updateAutofillConfigurationIfNeeded(null);
561482
inputTarget = new InputTarget(InputTarget.Type.NO_TARGET, 0);
562-
unlockPlatformViewInputConnection();
563483
lastClientRect = null;
564484
}
565485

@@ -569,12 +489,9 @@ enum Type {
569489
// InputConnection is managed by the TextInputPlugin, and events are forwarded to the Flutter
570490
// framework.
571491
FRAMEWORK_CLIENT,
572-
// InputConnection is managed by a platform view that is presented on a virtual display.
573-
VIRTUAL_DISPLAY_PLATFORM_VIEW,
574-
// InputConnection is managed by a platform view that is embedded in the activity's view
575-
// hierarchy. This view hierarchy is displayed in a physical display within the aplication
576-
// display area.
577-
PHYSICAL_DISPLAY_PLATFORM_VIEW,
492+
// InputConnection is managed by a platform view that is embeded in the Android view
493+
// hierarchy.
494+
PLATFORM_VIEW,
578495
}
579496

580497
public InputTarget(@NonNull Type type, int id) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,22 @@ default void onFlutterViewDetached() {}
6666
*
6767
* <p>This hook only exists for rare cases where the plugin relies on the state of the input
6868
* connection. This probably doesn't need to be implemented.
69+
*
70+
* <p>This method is deprecated, and will be removed in a future release.
6971
*/
7072
@SuppressLint("NewApi")
73+
@Deprecated
7174
default void onInputConnectionLocked() {}
7275

7376
/**
7477
* Callback fired when the platform input connection has been unlocked.
7578
*
7679
* <p>This hook only exists for rare cases where the plugin relies on the state of the input
7780
* connection. This probably doesn't need to be implemented.
81+
*
82+
* <p>This method is deprecated, and will be removed in a future release.
7883
*/
7984
@SuppressLint("NewApi")
85+
@Deprecated
8086
default void onInputConnectionUnlocked() {}
8187
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public PlatformViewFactory(@Nullable MessageCodec<Object> createArgsCodec) {
2828
* null, or no arguments were sent from the Flutter app.
2929
*/
3030
@NonNull
31-
public abstract PlatformView create(Context context, int viewId, @Nullable Object args);
31+
public abstract PlatformView create(@Nullable Context context, int viewId, @Nullable Object args);
3232

3333
/** Returns the codec to be used for decoding the args parameter of {@link #create}. */
3434
@Nullable

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ public interface PlatformViewsAccessibilityDelegate {
1818
@Nullable
1919
View getPlatformViewById(int viewId);
2020

21-
/** Returns true if the platform view uses virtual displays. */
22-
boolean usesVirtualDisplay(int id);
23-
2421
/**
2522
* Attaches an accessibility bridge for this platform views accessibility delegate.
2623
*

0 commit comments

Comments
 (0)