From 475ce46d3bb6b6b8186c8eb70d30054be86d6956 Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Thu, 1 Aug 2024 13:04:44 +0200 Subject: [PATCH 1/2] Revert "[Android] Call restartInput selectively on clear (#53662)" This reverts commit 766f7bed7185832d960eafd35be5ab285b822bd2. --- .../plugin/editing/TextInputPlugin.java | 13 +- .../plugin/editing/TextInputPluginTest.java | 111 +----------------- 2 files changed, 4 insertions(+), 120 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index a021214164ede..d6c3c6f90d483 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -546,22 +546,15 @@ void clearTextInputClient() { } mEditable.removeEditingStateListener(this); notifyViewExited(); - - boolean needsRestart = - configuration.inputAction == null - || configuration.inputAction == EditorInfo.IME_ACTION_DONE - || configuration.inputAction == EditorInfo.IME_ACTION_NONE; configuration = null; updateAutofillConfigurationIfNeeded(null); inputTarget = new InputTarget(InputTarget.Type.NO_TARGET, 0); unlockPlatformViewInputConnection(); lastClientRect = null; - if (needsRestart) { - // Call restartInput to reset IME internal states. Otherwise some IMEs (Gboard for instance) - // keep reacting based on the previous input configuration until a new configuration is set. - mImm.restartInput(mView); - } + // Call restartInput to reset IME internal states. Otherwise some IMEs (Gboard for instance) + // keep reacting based on the previous input configuration until a new configuration is set. + mImm.restartInput(mView); } private static class InputTarget { diff --git a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index 1c8b0517e818d..cc04befc45d9e 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -1131,7 +1131,7 @@ public void setTextInputEditingState_nullInputMethodSubtype() { } @Test - public void clearTextInputClient_restartsImmWhenInputActionIsNull() { + public void clearTextInputClient_alwaysRestartsImm() { // Initialize a general TextInputPlugin. InputMethodSubtype inputMethodSubtype = mock(InputMethodSubtype.class); TestImm testImm = Shadow.extract(ctx.getSystemService(Context.INPUT_METHOD_SERVICE)); @@ -1165,115 +1165,6 @@ public void clearTextInputClient_restartsImmWhenInputActionIsNull() { assertEquals(2, testImm.getRestartCount(testView)); } - @Test - public void clearTextInputClient_restartsImmWhenInputActionIsDone() { - // Initialize a general TextInputPlugin. - InputMethodSubtype inputMethodSubtype = mock(InputMethodSubtype.class); - TestImm testImm = Shadow.extract(ctx.getSystemService(Context.INPUT_METHOD_SERVICE)); - testImm.setCurrentInputMethodSubtype(inputMethodSubtype); - View testView = new View(ctx); - TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); - TextInputPlugin textInputPlugin = - new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient( - 0, - new TextInputChannel.Configuration( - false, - false, - true, - true, - false, - TextInputChannel.TextCapitalization.NONE, - null, - EditorInfo.IME_ACTION_DONE, - null, - null, - null, - null)); - // There's a pending restart since we initialized the text input client. Flush that now. - textInputPlugin.setTextInputEditingState( - testView, new TextInputChannel.TextEditState("", 0, 0, -1, -1)); - assertEquals(1, testImm.getRestartCount(testView)); - - // A restart should be forced when calling clearTextInputClient() and input action is - // EditorInfo.IME_ACTION_DONE. - textInputPlugin.clearTextInputClient(); - assertEquals(2, testImm.getRestartCount(testView)); - } - - @Test - public void clearTextInputClient_restartsImmWhenInputActionIsNone() { - // Initialize a general TextInputPlugin. - InputMethodSubtype inputMethodSubtype = mock(InputMethodSubtype.class); - TestImm testImm = Shadow.extract(ctx.getSystemService(Context.INPUT_METHOD_SERVICE)); - testImm.setCurrentInputMethodSubtype(inputMethodSubtype); - View testView = new View(ctx); - TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); - TextInputPlugin textInputPlugin = - new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient( - 0, - new TextInputChannel.Configuration( - false, - false, - true, - true, - false, - TextInputChannel.TextCapitalization.NONE, - null, - EditorInfo.IME_ACTION_NONE, - null, - null, - null, - null)); - // There's a pending restart since we initialized the text input client. Flush that now. - textInputPlugin.setTextInputEditingState( - testView, new TextInputChannel.TextEditState("", 0, 0, -1, -1)); - assertEquals(1, testImm.getRestartCount(testView)); - - // A restart should be forced when calling clearTextInputClient() and input action is - // EditorInfo.IME_ACTION_NONE. - textInputPlugin.clearTextInputClient(); - assertEquals(2, testImm.getRestartCount(testView)); - } - - @Test - public void clearTextInputClient_doesNotRestartImmWhenInputActionIsNext() { - // Regression test for https://github.com/flutter/flutter/issues/148673. - // Initialize a general TextInputPlugin. - InputMethodSubtype inputMethodSubtype = mock(InputMethodSubtype.class); - TestImm testImm = Shadow.extract(ctx.getSystemService(Context.INPUT_METHOD_SERVICE)); - testImm.setCurrentInputMethodSubtype(inputMethodSubtype); - View testView = new View(ctx); - TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); - TextInputPlugin textInputPlugin = - new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient( - 0, - new TextInputChannel.Configuration( - false, - false, - true, - true, - false, - TextInputChannel.TextCapitalization.NONE, - null, - EditorInfo.IME_ACTION_NEXT, - null, - null, - null, - null)); - // There's a pending restart since we initialized the text input client. Flush that now. - textInputPlugin.setTextInputEditingState( - testView, new TextInputChannel.TextEditState("", 0, 0, -1, -1)); - assertEquals(1, testImm.getRestartCount(testView)); - - // No restart is forced when calling clearTextInputClient() and input action is - // EditorInfo.IME_ACTION_NEXT. - textInputPlugin.clearTextInputClient(); - assertEquals(1, testImm.getRestartCount(testView)); - } - @Test public void destroy_clearTextInputMethodHandler() { View testView = new View(ctx); From ebd64c9b31cde22b1de6eb885fc5a43da6cb5c1b Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Thu, 1 Aug 2024 13:08:20 +0200 Subject: [PATCH 2/2] Revert "[Android] Reset IME state in TextInputPlugin.clearTextInputClient (#49829)" This reverts commit 873449c27d5a04a066a1854bddf044e1edd07b23. --- .../plugin/editing/TextInputPlugin.java | 4 --- .../plugin/editing/TextInputPluginTest.java | 35 ------------------- 2 files changed, 39 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index d6c3c6f90d483..beae70837e3c3 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -551,10 +551,6 @@ void clearTextInputClient() { inputTarget = new InputTarget(InputTarget.Type.NO_TARGET, 0); unlockPlatformViewInputConnection(); lastClientRect = null; - - // Call restartInput to reset IME internal states. Otherwise some IMEs (Gboard for instance) - // keep reacting based on the previous input configuration until a new configuration is set. - mImm.restartInput(mView); } private static class InputTarget { diff --git a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index cc04befc45d9e..2656902b52543 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -1130,41 +1130,6 @@ public void setTextInputEditingState_nullInputMethodSubtype() { assertEquals(1, testImm.getRestartCount(testView)); } - @Test - public void clearTextInputClient_alwaysRestartsImm() { - // Initialize a general TextInputPlugin. - InputMethodSubtype inputMethodSubtype = mock(InputMethodSubtype.class); - TestImm testImm = Shadow.extract(ctx.getSystemService(Context.INPUT_METHOD_SERVICE)); - testImm.setCurrentInputMethodSubtype(inputMethodSubtype); - View testView = new View(ctx); - TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); - TextInputPlugin textInputPlugin = - new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient( - 0, - new TextInputChannel.Configuration( - false, - false, - true, - true, - false, - TextInputChannel.TextCapitalization.NONE, - null, - null, - null, - null, - null, - null)); - // There's a pending restart since we initialized the text input client. Flush that now. - textInputPlugin.setTextInputEditingState( - testView, new TextInputChannel.TextEditState("", 0, 0, -1, -1)); - assertEquals(1, testImm.getRestartCount(testView)); - - // A restart is always forced when calling clearTextInputClient(). - textInputPlugin.clearTextInputClient(); - assertEquals(2, testImm.getRestartCount(testView)); - } - @Test public void destroy_clearTextInputMethodHandler() { View testView = new View(ctx);