From 665d969facafba051999884a3228048821bcbd89 Mon Sep 17 00:00:00 2001 From: GaryQian Date: Thu, 3 Oct 2019 15:20:04 -0700 Subject: [PATCH 01/10] Restart all modern samsung keyboard IMM --- .../plugin/editing/TextInputPlugin.java | 5 ++-- .../plugin/editing/TextInputPluginTest.java | 24 +++++++++++++++++++ 2 files changed, 27 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 9da7c58768bd8..0e57fbdd903d2 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -324,13 +324,14 @@ private void applyStateToSelection(TextInputChannel.TextEditState state) { @SuppressWarnings("deprecation") private boolean isRestartAlwaysRequired() { InputMethodSubtype subtype = mImm.getCurrentInputMethodSubtype(); - if (subtype == null) { + // Impacted devices all shipped with Android Lollipop or newer. + if (subtype == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.L) { return false; } String language = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) ? subtype.getLanguageTag() : subtype.getLocale(); - return Build.MANUFACTURER.equals("samsung") && language.equals("ko"); + return Build.MANUFACTURER.equals("samsung"); } private void clearTextInputClient() { 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 a0598380b70f6..4c950d31c9f58 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -69,6 +69,30 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices() { assertEquals(2, testImm.getRestartCount(testView)); } + // See https://github.com/flutter/flutter/issues/31512 + // All modern Samsung keybords are affected including non-korean languages and thus + // need the restart. + @Test + public void setTextInputEditingState_alwaysRestartsOnAffectedDevices() { + // Initialize a TextInputPlugin that needs to be always restarted. + ShadowBuild.setManufacturer("samsung"); + InputMethodSubtype inputMethodSubtype = new InputMethodSubtype(0, 0, /*locale=*/"en", "", "", false, false); + TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); + testImm.setCurrentInputMethodSubtype(inputMethodSubtype); + View testView = new View(RuntimeEnvironment.application); + TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); + textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, 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)); + + // Move the cursor. + assertEquals(1, testImm.getRestartCount(testView)); + textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0)); + + // Verify that we've restarted the input. + assertEquals(2, testImm.getRestartCount(testView)); + } + @Test public void setTextInputEditingState_nullInputMethodSubtype() { TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); From fc1e16474cfb63855bd8e6613b6d06dda5748b79 Mon Sep 17 00:00:00 2001 From: GaryQian Date: Thu, 3 Oct 2019 16:52:35 -0700 Subject: [PATCH 02/10] Check default keyboard to determine if fix should be applied. --- .../flutter/plugin/editing/TextInputPlugin.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 0e57fbdd903d2..404c0505a460c 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -7,6 +7,7 @@ import android.annotation.SuppressLint; import android.content.Context; import android.os.Build; +import android.provider.Settings; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; @@ -315,7 +316,9 @@ private void applyStateToSelection(TextInputChannel.TextEditState state) { } // Samsung's Korean keyboard has a bug where it always attempts to combine characters based on - // its internal state, ignoring if and when the cursor is moved programmatically. + // its internal state, ignoring if and when the cursor is moved programmatically. The same bug + // also causes non-korean keyboards to occasionally duplicate text when tapping in the middle + // of existing text to edit it. // // Fully restarting the IMM works around this because it flushes the keyboard's internal state // and stops it from trying to incorrectly combine characters. However this also has some @@ -325,13 +328,13 @@ private void applyStateToSelection(TextInputChannel.TextEditState state) { private boolean isRestartAlwaysRequired() { InputMethodSubtype subtype = mImm.getCurrentInputMethodSubtype(); // Impacted devices all shipped with Android Lollipop or newer. - if (subtype == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.L) { + if (subtype == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return false; } - String language = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - ? subtype.getLanguageTag() - : subtype.getLocale(); - return Build.MANUFACTURER.equals("samsung"); + String keyboardName = Settings.Secure.getString(mView.getContext().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); + // The Samsung keyboard is called "com.sec.android.inputmethod/.SamsungKeypad" but look + // for "Samsung" just in case Samsung changes the name of the keyboard. + return Build.MANUFACTURER.equals("samsung") && keyboardName.contains("Samsung"); } private void clearTextInputClient() { From 8f9fc096f7ff99189bf5906e7a6f2eb288dd07f8 Mon Sep 17 00:00:00 2001 From: GaryQian Date: Thu, 3 Oct 2019 17:03:45 -0700 Subject: [PATCH 03/10] Change test name --- .../android/io/flutter/plugin/editing/TextInputPlugin.java | 2 +- .../test/io/flutter/plugin/editing/TextInputPluginTest.java | 2 +- 2 files changed, 2 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 404c0505a460c..6d3146b9ead38 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -334,7 +334,7 @@ private boolean isRestartAlwaysRequired() { String keyboardName = Settings.Secure.getString(mView.getContext().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); // The Samsung keyboard is called "com.sec.android.inputmethod/.SamsungKeypad" but look // for "Samsung" just in case Samsung changes the name of the keyboard. - return Build.MANUFACTURER.equals("samsung") && keyboardName.contains("Samsung"); + return Build.MANUFACTURER.equals("samsung") && keyboardName.toLowerCase().contains("samsung"); } private void clearTextInputClient() { 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 4c950d31c9f58..6cdf9f2e5e2fb 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -73,7 +73,7 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices() { // All modern Samsung keybords are affected including non-korean languages and thus // need the restart. @Test - public void setTextInputEditingState_alwaysRestartsOnAffectedDevices() { + public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() { // Initialize a TextInputPlugin that needs to be always restarted. ShadowBuild.setManufacturer("samsung"); InputMethodSubtype inputMethodSubtype = new InputMethodSubtype(0, 0, /*locale=*/"en", "", "", false, false); From a8008d61db270a0a0fbc1e4255a7a830899f6008 Mon Sep 17 00:00:00 2001 From: GaryQian Date: Thu, 3 Oct 2019 17:12:12 -0700 Subject: [PATCH 04/10] VTOL --- .../android/io/flutter/plugin/editing/TextInputPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 6d3146b9ead38..404c0505a460c 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -334,7 +334,7 @@ private boolean isRestartAlwaysRequired() { String keyboardName = Settings.Secure.getString(mView.getContext().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); // The Samsung keyboard is called "com.sec.android.inputmethod/.SamsungKeypad" but look // for "Samsung" just in case Samsung changes the name of the keyboard. - return Build.MANUFACTURER.equals("samsung") && keyboardName.toLowerCase().contains("samsung"); + return Build.MANUFACTURER.equals("samsung") && keyboardName.contains("Samsung"); } private void clearTextInputClient() { From 5a695e1f3cef93d9fe914e975914c1ae0539ac05 Mon Sep 17 00:00:00 2001 From: GaryQian Date: Thu, 3 Oct 2019 17:28:35 -0700 Subject: [PATCH 05/10] Fix tests --- .../plugin/editing/TextInputPluginTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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 6cdf9f2e5e2fb..945d15ecd2bc4 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -55,6 +55,7 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices() { InputMethodSubtype inputMethodSubtype = new InputMethodSubtype(0, 0, /*locale=*/"ko", "", "", false, false); TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); testImm.setCurrentInputMethodSubtype(inputMethodSubtype); + Settings.Secure.getString(RuntimeEnvironment.application.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, "com.sec.android.inputmethod/.SamsungKeypad"); View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); @@ -79,6 +80,7 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() { InputMethodSubtype inputMethodSubtype = new InputMethodSubtype(0, 0, /*locale=*/"en", "", "", false, false); TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); testImm.setCurrentInputMethodSubtype(inputMethodSubtype); + Settings.Secure.getString(RuntimeEnvironment.application.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, "com.sec.android.inputmethod/.SamsungKeypad"); View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); @@ -93,6 +95,27 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() { assertEquals(2, testImm.getRestartCount(testView)); } + @Test + public void setTextInputEditingState_doesNotRestartsOnUnaffectedDevices() { + // Initialize a TextInputPlugin that needs to be always restarted. + ShadowBuild.setManufacturer("samsung"); + InputMethodSubtype inputMethodSubtype = new InputMethodSubtype(0, 0, /*locale=*/"en", "", "", false, false); + TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); + testImm.setCurrentInputMethodSubtype(inputMethodSubtype); + View testView = new View(RuntimeEnvironment.application); + TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); + textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, 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)); + + // Move the cursor. + assertEquals(1, testImm.getRestartCount(testView)); + textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0)); + + // Verify that we've restarted the input. + assertEquals(1, testImm.getRestartCount(testView)); + } + @Test public void setTextInputEditingState_nullInputMethodSubtype() { TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); From f186de1aaced086ba46cffb634f8325fe3d6c1ee Mon Sep 17 00:00:00 2001 From: GaryQian Date: Thu, 3 Oct 2019 17:39:08 -0700 Subject: [PATCH 06/10] Imports --- .../test/io/flutter/plugin/editing/TextInputPluginTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 945d15ecd2bc4..12e6115d724a1 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -1,6 +1,7 @@ package io.flutter.plugin.editing; import android.content.Context; +import android.provider.Settings; import android.util.SparseIntArray; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -96,7 +97,7 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() { } @Test - public void setTextInputEditingState_doesNotRestartsOnUnaffectedDevices() { + public void setTextInputEditingState_doesNotRestartOnUnaffectedDevices() { // Initialize a TextInputPlugin that needs to be always restarted. ShadowBuild.setManufacturer("samsung"); InputMethodSubtype inputMethodSubtype = new InputMethodSubtype(0, 0, /*locale=*/"en", "", "", false, false); From 582bfc9df5783a07873ec484b1b31a96eefed381 Mon Sep 17 00:00:00 2001 From: GaryQian Date: Thu, 3 Oct 2019 17:54:18 -0700 Subject: [PATCH 07/10] putString --- .../test/io/flutter/plugin/editing/TextInputPluginTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 12e6115d724a1..6193998b5e0cc 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -56,7 +56,7 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices() { InputMethodSubtype inputMethodSubtype = new InputMethodSubtype(0, 0, /*locale=*/"ko", "", "", false, false); TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); testImm.setCurrentInputMethodSubtype(inputMethodSubtype); - Settings.Secure.getString(RuntimeEnvironment.application.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, "com.sec.android.inputmethod/.SamsungKeypad"); + Settings.Secure.putString(RuntimeEnvironment.application.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, "com.sec.android.inputmethod/.SamsungKeypad"); View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); @@ -81,7 +81,7 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() { InputMethodSubtype inputMethodSubtype = new InputMethodSubtype(0, 0, /*locale=*/"en", "", "", false, false); TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); testImm.setCurrentInputMethodSubtype(inputMethodSubtype); - Settings.Secure.getString(RuntimeEnvironment.application.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, "com.sec.android.inputmethod/.SamsungKeypad"); + Settings.Secure.putString(RuntimeEnvironment.application.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, "com.sec.android.inputmethod/.SamsungKeypad"); View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); From 2ce3a6994812a4cb9715e53d4404d73ef683b0a7 Mon Sep 17 00:00:00 2001 From: GaryQian Date: Thu, 3 Oct 2019 18:04:34 -0700 Subject: [PATCH 08/10] Short circuit to skip keyboard lookup on non-samsung devices --- .../android/io/flutter/plugin/editing/TextInputPlugin.java | 5 +++-- 1 file changed, 3 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 404c0505a460c..f76ccad792cc9 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -328,13 +328,14 @@ private void applyStateToSelection(TextInputChannel.TextEditState state) { private boolean isRestartAlwaysRequired() { InputMethodSubtype subtype = mImm.getCurrentInputMethodSubtype(); // Impacted devices all shipped with Android Lollipop or newer. - if (subtype == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + if (subtype == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || !Build.MANUFACTURER.equals("samsung")) { return false; } String keyboardName = Settings.Secure.getString(mView.getContext().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); // The Samsung keyboard is called "com.sec.android.inputmethod/.SamsungKeypad" but look // for "Samsung" just in case Samsung changes the name of the keyboard. - return Build.MANUFACTURER.equals("samsung") && keyboardName.contains("Samsung"); + System.err.println("KEYBOARD::::: " + keyboardName); + return keyboardName.contains("Samsung"); } private void clearTextInputClient() { From ff6ba8945f625801394626bdf6165932b214a0f4 Mon Sep 17 00:00:00 2001 From: GaryQian Date: Fri, 4 Oct 2019 10:48:42 -0700 Subject: [PATCH 09/10] Remove redundant test, add sdk=27 --- .../plugin/editing/TextInputPluginTest.java | 27 ++----------------- 1 file changed, 2 insertions(+), 25 deletions(-) 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 6193998b5e0cc..8c4f056857ac1 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -25,7 +25,7 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; -@Config(manifest = Config.NONE, shadows = TextInputPluginTest.TestImm.class) +@Config(manifest = Config.NONE, shadows = TextInputPluginTest.TestImm.class, sdk = 27) @RunWith(RobolectricTestRunner.class) public class TextInputPluginTest { @Test @@ -48,30 +48,7 @@ public void setTextInputEditingState_doesNotRestartWhenTextIsIdentical() { assertEquals(1, testImm.getRestartCount(testView)); } - // See https://github.com/flutter/flutter/issues/29341 - @Test - public void setTextInputEditingState_alwaysRestartsOnAffectedDevices() { - // Initialize a TextInputPlugin that needs to be always restarted. - ShadowBuild.setManufacturer("samsung"); - InputMethodSubtype inputMethodSubtype = new InputMethodSubtype(0, 0, /*locale=*/"ko", "", "", false, false); - TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); - testImm.setCurrentInputMethodSubtype(inputMethodSubtype); - Settings.Secure.putString(RuntimeEnvironment.application.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, "com.sec.android.inputmethod/.SamsungKeypad"); - View testView = new View(RuntimeEnvironment.application); - TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, 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)); - - // Move the cursor. - assertEquals(1, testImm.getRestartCount(testView)); - textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0)); - - // Verify that we've restarted the input. - assertEquals(2, testImm.getRestartCount(testView)); - } - - // See https://github.com/flutter/flutter/issues/31512 + // See https://github.com/flutter/flutter/issues/29341 and https://github.com/flutter/flutter/issues/31512 // All modern Samsung keybords are affected including non-korean languages and thus // need the restart. @Test From bf11a2a8a51117dcd0e238787440494553844acb Mon Sep 17 00:00:00 2001 From: GaryQian Date: Fri, 4 Oct 2019 11:05:25 -0700 Subject: [PATCH 10/10] Fix test --- .../android/io/flutter/plugin/editing/TextInputPlugin.java | 1 - .../test/io/flutter/plugin/editing/TextInputPluginTest.java | 3 ++- 2 files changed, 2 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 f76ccad792cc9..5c23ea40beca9 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -334,7 +334,6 @@ private boolean isRestartAlwaysRequired() { String keyboardName = Settings.Secure.getString(mView.getContext().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); // The Samsung keyboard is called "com.sec.android.inputmethod/.SamsungKeypad" but look // for "Samsung" just in case Samsung changes the name of the keyboard. - System.err.println("KEYBOARD::::: " + keyboardName); return keyboardName.contains("Samsung"); } 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 8c4f056857ac1..cd5eb377861dc 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -56,9 +56,9 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() { // Initialize a TextInputPlugin that needs to be always restarted. ShadowBuild.setManufacturer("samsung"); InputMethodSubtype inputMethodSubtype = new InputMethodSubtype(0, 0, /*locale=*/"en", "", "", false, false); + Settings.Secure.putString(RuntimeEnvironment.application.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, "com.sec.android.inputmethod/.SamsungKeypad"); TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); testImm.setCurrentInputMethodSubtype(inputMethodSubtype); - Settings.Secure.putString(RuntimeEnvironment.application.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, "com.sec.android.inputmethod/.SamsungKeypad"); View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); @@ -78,6 +78,7 @@ public void setTextInputEditingState_doesNotRestartOnUnaffectedDevices() { // Initialize a TextInputPlugin that needs to be always restarted. ShadowBuild.setManufacturer("samsung"); InputMethodSubtype inputMethodSubtype = new InputMethodSubtype(0, 0, /*locale=*/"en", "", "", false, false); + Settings.Secure.putString(RuntimeEnvironment.application.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, "com.fake.test.blah/.NotTheRightKeyboard"); TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); testImm.setCurrentInputMethodSubtype(inputMethodSubtype); View testView = new View(RuntimeEnvironment.application);