From 1093787d587cedb8488f548d263ba9cc502266c1 Mon Sep 17 00:00:00 2001 From: Casey Hillers Date: Fri, 14 Apr 2023 12:22:36 -0700 Subject: [PATCH] Revert "[Android] Send connectionClosed message when keyboard becomes invisible to ensure framework focus state is correct." (flutter/engine#41211) Reverts flutter/engine#40746 Googler bug: b/278174021 Failing on ``` shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java:239: Error: This method should only be accessed from tests or within private scope [VisibleForTests] imeSyncCallback.remove(); ``` --- .../systemchannels/TextInputChannel.java | 8 ----- .../ImeSyncDeferringInsetsCallback.java | 32 ------------------- .../plugin/editing/TextInputPlugin.java | 15 --------- .../plugin/editing/TextInputPluginTest.java | 13 -------- 4 files changed, 68 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java index 687d1f29a2..e0f95681f3 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java @@ -367,14 +367,6 @@ public class TextInputChannel { "TextInputClient.performPrivateCommand", Arrays.asList(inputClientId, json)); } - /** Instructs Flutter to execute a "onConnectionClosed" action. */ - public void onConnectionClosed(int inputClientId) { - Log.v(TAG, "Sending 'onConnectionClosed' message."); - channel.invokeMethod( - "TextInputClient.onConnectionClosed", - Arrays.asList(inputClientId, "TextInputClient.onConnectionClosed")); - } - /** * Sets the {@link TextInputMethodHandler} which receives all events and requests that are parsed * from the underlying platform channel. diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/ImeSyncDeferringInsetsCallback.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/ImeSyncDeferringInsetsCallback.java index e33aed5d41..0a6f0ef3f6 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/ImeSyncDeferringInsetsCallback.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/ImeSyncDeferringInsetsCallback.java @@ -14,8 +14,6 @@ import androidx.annotation.Keep; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.annotation.VisibleForTesting; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; import java.util.List; // Loosely based off of @@ -56,7 +54,6 @@ class ImeSyncDeferringInsetsCallback { private WindowInsets lastWindowInsets; private AnimationCallback animationCallback; private InsetsListener insetsListener; - private ImeVisibleListener imeVisibleListener; // True when an animation that matches deferredInsetTypes is active. // @@ -91,11 +88,6 @@ class ImeSyncDeferringInsetsCallback { view.setOnApplyWindowInsetsListener(null); } - // Set a listener to be notified when the IME visibility changes. - void setImeVisibleListener(ImeVisibleListener imeVisibleListener) { - this.imeVisibleListener = imeVisibleListener; - } - @VisibleForTesting View.OnApplyWindowInsetsListener getInsetsListener() { return insetsListener; @@ -106,11 +98,6 @@ class ImeSyncDeferringInsetsCallback { return animationCallback; } - @VisibleForTesting - ImeVisibleListener getImeVisibleListener() { - return imeVisibleListener; - } - // WindowInsetsAnimation.Callback was introduced in API level 30. The callback // subclass is separated into an inner class in order to avoid warnings from // the Android class loader on older platforms. @@ -128,20 +115,6 @@ class ImeSyncDeferringInsetsCallback { } } - @NonNull - @Override - public WindowInsetsAnimation.Bounds onStart( - @NonNull WindowInsetsAnimation animation, @NonNull WindowInsetsAnimation.Bounds bounds) { - // Observe changes to software keyboard visibility and notify listener when animation start. - // See https://developer.android.com/develop/ui/views/layout/sw-keyboard. - WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(view); - if (insets != null && imeVisibleListener != null) { - boolean imeVisible = insets.isVisible(WindowInsetsCompat.Type.ime()); - imeVisibleListener.onImeVisibleChanged(imeVisible); - } - return super.onStart(animation, bounds); - } - @Override public WindowInsets onProgress( WindowInsets insets, List runningAnimations) { @@ -226,9 +199,4 @@ class ImeSyncDeferringInsetsCallback { return view.onApplyWindowInsets(windowInsets); } } - - // Listener for IME visibility changes. - public interface ImeVisibleListener { - void onImeVisibleChanged(boolean visible); - } } 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 042d3d2070..10cbc1b65c 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 @@ -94,17 +94,6 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch WindowInsets.Type.ime() // Deferred, insets that will animate ); imeSyncCallback.install(); - - // When the IME is hidden, we need to notify the framework that close connection. - imeSyncCallback.setImeVisibleListener( - new ImeSyncDeferringInsetsCallback.ImeVisibleListener() { - @Override - public void onImeVisibleChanged(boolean visible) { - if (!visible) { - onConnectionClosed(); - } - } - }); } this.textInputChannel = textInputChannel; @@ -849,8 +838,4 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch textInputChannel.updateEditingStateWithTag(inputTarget.id, editingValues); } // -------- End: Autofill ------- - - public void onConnectionClosed() { - textInputChannel.onConnectionClosed(inputTarget.id); - } } diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index 9459a5701f..462b6ec2ff 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -2118,19 +2118,6 @@ public class TextInputPluginTest { assertEquals(0, viewportMetricsCaptor.getValue().viewInsetTop); } - @Test - @TargetApi(30) - @Config(sdk = 30) - public void onConnectionClosed_imeInvisible() { - View testView = new View(ctx); - TextInputChannel textInputChannel = spy(new TextInputChannel(mock(DartExecutor.class))); - TextInputPlugin textInputPlugin = - new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); - ImeSyncDeferringInsetsCallback imeSyncCallback = textInputPlugin.getImeSyncCallback(); - imeSyncCallback.getImeVisibleListener().onImeVisibleChanged(false); - verify(textInputChannel, times(1)).onConnectionClosed(anyInt()); - } - interface EventHandler { void sendAppPrivateCommand(View view, String action, Bundle data); }