From 110c63afafac49d5c4737bfaa5e257dda79afcdd Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Mon, 24 Jun 2019 13:13:00 -0700 Subject: [PATCH] Don't hang to a platform view's input connection after it's disposed (flutter/engine#9423) Addresses the crash reported in https://github.com/flutter/flutter/issues/19718#issuecomment-504174596 --- .../flutter/plugin/editing/TextInputPlugin.java | 15 +++++++++++++++ .../plugin/platform/PlatformViewsController.java | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 72b1f56167d..9a72419016b 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -237,6 +237,21 @@ public class TextInputPlugin { return lastInputConnection; } + /** + * Clears a platform view text input client if it is the current input target. + * + * 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) { + if (inputTarget.type == InputTarget.Type.PLATFORM_VIEW && inputTarget.id == platformViewId) { + inputTarget = new InputTarget(InputTarget.Type.NO_TARGET, 0); + hideTextInput(mView); + mImm.restartInput(mView); + mRestartInputPending = false; + } + } + private void showTextInput(View view) { view.requestFocus(); mImm.showSoftInput(view, 0); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 334d2d18dcf..8ea704b39c7 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -135,8 +135,11 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega + viewId); } - contextToPlatformView.remove(vdController.getView().getContext()); + if (textInputPlugin != null) { + textInputPlugin.clearPlatformViewClient(viewId); + } + contextToPlatformView.remove(vdController.getView().getContext()); vdController.dispose(); vdControllers.remove(viewId); }