From 6b8c39c4af47e23d7d95cdc8421c66487468c51a Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Tue, 19 Sep 2023 14:52:33 +0200 Subject: [PATCH 1/2] [Android] Fix enableSuggestions set to false not honored --- .../plugin/editing/TextInputPlugin.java | 6 ++- .../plugin/editing/TextInputPluginTest.java | 38 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index f337132b1c810..548a020a83e5f 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -272,7 +272,11 @@ private static int inputTypeFromTextInputType( textType |= InputType.TYPE_TEXT_VARIATION_PASSWORD; } else { if (autocorrect) textType |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT; - if (!enableSuggestions) textType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; + if (!enableSuggestions) { + // Note: both required. Some devices ignore TYPE_TEXT_FLAG_NO_SUGGESTIONS. + textType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; + textType |= InputType.TYPE_TEXT_VARIATION_PASSWORD; + } } if (textCapitalization == TextInputChannel.TextCapitalization.CHARACTERS) { 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 881dffc18882c..e4582015d86d3 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -273,7 +273,7 @@ public void textEditingDelta_TestUpdateEditingValueWithDeltasIsNotInvokedWhenDel true, false, // Delta model is disabled. TextInputChannel.TextCapitalization.NONE, - new TextInputChannel.InputType(TextInputChannel.TextInputType.TEXT, false, false), + new TextInputChannel.InputType(TextInputChannel.TextInputType.MULTILINE, false, false), null, null, null, @@ -1306,6 +1306,42 @@ public void showTextInput_textInputTypeNone() { assertEquals(testImm.isSoftInputVisible(), false); } + @Test + public void inputConnection_textInputTypeMultilineAndSuggestionsDisabled() { + // Regression test for https://github.com/flutter/flutter/issues/71679. + View testView = new View(ctx); + DartExecutor dartExecutor = mock(DartExecutor.class); + TextInputChannel textInputChannel = new TextInputChannel(dartExecutor); + TextInputPlugin textInputPlugin = + new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); + textInputPlugin.setTextInputClient( + 0, + new TextInputChannel.Configuration( + false, + false, + false, // Disable suggestions. + true, + false, + TextInputChannel.TextCapitalization.NONE, + new TextInputChannel.InputType(TextInputChannel.TextInputType.MULTILINE, false, false), + null, + null, + null, + null, + null)); + + EditorInfo editorInfo = new EditorInfo(); + InputConnection connection = + textInputPlugin.createInputConnection(testView, mock(KeyboardManager.class), editorInfo); + + assertEquals( + editorInfo.inputType, + InputType.TYPE_CLASS_TEXT + | InputType.TYPE_TEXT_FLAG_MULTI_LINE + | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS + | InputType.TYPE_TEXT_VARIATION_PASSWORD); + } + // -------- Start: Autofill Tests ------- @Test public void autofill_enabledByDefault() { From 66ba4d8e56fa54638c47a4a88bf7298c62621ed2 Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Mon, 25 Sep 2023 18:08:41 +0200 Subject: [PATCH 2/2] Address review comments --- .../android/io/flutter/plugin/editing/TextInputPlugin.java | 2 +- .../test/io/flutter/plugin/editing/TextInputPluginTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 548a020a83e5f..4897eaf2f13cd 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -275,7 +275,7 @@ private static int inputTypeFromTextInputType( if (!enableSuggestions) { // Note: both required. Some devices ignore TYPE_TEXT_FLAG_NO_SUGGESTIONS. textType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; - textType |= InputType.TYPE_TEXT_VARIATION_PASSWORD; + textType |= InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; } } 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 e4582015d86d3..c4eebd33b939d 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -273,7 +273,7 @@ public void textEditingDelta_TestUpdateEditingValueWithDeltasIsNotInvokedWhenDel true, false, // Delta model is disabled. TextInputChannel.TextCapitalization.NONE, - new TextInputChannel.InputType(TextInputChannel.TextInputType.MULTILINE, false, false), + new TextInputChannel.InputType(TextInputChannel.TextInputType.TEXT, false, false), null, null, null, @@ -1339,7 +1339,7 @@ public void inputConnection_textInputTypeMultilineAndSuggestionsDisabled() { InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS - | InputType.TYPE_TEXT_VARIATION_PASSWORD); + | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); } // -------- Start: Autofill Tests -------