Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 0ea829a

Browse files
Revert "[Android Text Input] Remove Samsung restart input workaround for newer Samsung keyboards (#24288)"
This reverts commit 1687040.
1 parent 8c81ce6 commit 0ea829a

File tree

2 files changed

+8
-92
lines changed

2 files changed

+8
-92
lines changed

shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import android.annotation.SuppressLint;
88
import android.content.Context;
9-
import android.content.pm.PackageManager;
109
import android.graphics.Rect;
1110
import android.os.Build;
1211
import android.os.Bundle;
@@ -500,27 +499,7 @@ private boolean isRestartAlwaysRequired() {
500499
mView.getContext().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
501500
// The Samsung keyboard is called "com.sec.android.inputmethod/.SamsungKeypad" but look
502501
// for "Samsung" just in case Samsung changes the name of the keyboard.
503-
if (!keyboardName.contains("Samsung")) {
504-
return false;
505-
}
506-
507-
final long versionCode;
508-
try {
509-
versionCode =
510-
mView
511-
.getContext()
512-
.getPackageManager()
513-
.getPackageInfo("com.sec.android.inputmethod", 0)
514-
.getLongVersionCode();
515-
} catch (PackageManager.NameNotFoundException e) {
516-
Log.w(TAG, "com.sec.android.inputmethod is not installed.");
517-
return false;
518-
}
519-
520-
// 3.3.23.33 is a known version that's free of the aforementioned bug.
521-
// 3.0.24.96 still has this bug.
522-
// TODO(LongCatIsLooong): Find the minimum version that has the fix.
523-
return versionCode < 332333999;
502+
return keyboardName.contains("Samsung");
524503
}
525504

526505
@VisibleForTesting

shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import android.annotation.TargetApi;
2020
import android.content.Context;
21-
import android.content.pm.PackageInfo;
2221
import android.content.res.AssetManager;
2322
import android.graphics.Insets;
2423
import android.graphics.Rect;
@@ -67,15 +66,13 @@
6766
import org.mockito.Mock;
6867
import org.robolectric.RobolectricTestRunner;
6968
import org.robolectric.RuntimeEnvironment;
70-
import org.robolectric.Shadows;
7169
import org.robolectric.annotation.Config;
7270
import org.robolectric.annotation.Implementation;
7371
import org.robolectric.annotation.Implements;
7472
import org.robolectric.shadow.api.Shadow;
7573
import org.robolectric.shadows.ShadowAutofillManager;
7674
import org.robolectric.shadows.ShadowBuild;
7775
import org.robolectric.shadows.ShadowInputMethodManager;
78-
import org.robolectric.shadows.ShadowPackageManager;
7976

8077
@Config(
8178
manifest = Config.NONE,
@@ -344,21 +341,14 @@ public void setTextInputEditingState_alwaysSetEditableWhenDifferent() {
344341
assertTrue(textInputPlugin.getEditable().toString().equals("Shibuyawoo"));
345342
}
346343

347-
// See also: https://github.com/flutter/flutter/issues/29341 and
348-
// https://github.com/flutter/flutter/issues/31512.
349-
// Some recent versions of Samsung keybords are affected including non-korean
350-
// languages and thus needed the restart.
344+
// See https://github.com/flutter/flutter/issues/29341 and
345+
// https://github.com/flutter/flutter/issues/31512
346+
// All modern Samsung keybords are affected including non-korean languages and thus
347+
// need the restart.
351348
@Test
352-
public void setTextInputEditingState_alwaysRestartsOnAffectedDevices() {
353-
// Initialize a TextInputPlugin with a Samsung keypad.
349+
public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() {
350+
// Initialize a TextInputPlugin that needs to be always restarted.
354351
ShadowBuild.setManufacturer("samsung");
355-
final ShadowPackageManager packageManager =
356-
Shadows.shadowOf(
357-
RuntimeEnvironment.application.getApplicationContext().getPackageManager());
358-
final PackageInfo info = new PackageInfo();
359-
info.packageName = "com.sec.android.inputmethod";
360-
info.versionCode = 200000000;
361-
packageManager.addPackage(info);
362352
InputMethodSubtype inputMethodSubtype =
363353
new InputMethodSubtype(0, 0, /*locale=*/ "en", "", "", false, false);
364354
Settings.Secure.putString(
@@ -398,59 +388,6 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices() {
398388
assertEquals(2, testImm.getRestartCount(testView));
399389
}
400390

401-
// Regression test for https://github.com/flutter/flutter/issues/73433.
402-
// The restart workaround seems to have caused #73433 and it's no longer
403-
// needed on newer versions of Samsung keyboard.
404-
@Test
405-
public void setTextInputEditingState_DontForceRestartOnNewSamsungKeyboard() {
406-
// Initialize a TextInputPlugin with a Samsung keypad.
407-
ShadowBuild.setManufacturer("samsung");
408-
final ShadowPackageManager packageManager =
409-
Shadows.shadowOf(
410-
RuntimeEnvironment.application.getApplicationContext().getPackageManager());
411-
final PackageInfo info = new PackageInfo();
412-
info.packageName = "com.sec.android.inputmethod";
413-
info.versionCode = 333183070;
414-
packageManager.addPackage(info);
415-
InputMethodSubtype inputMethodSubtype =
416-
new InputMethodSubtype(0, 0, /*locale=*/ "en", "", "", false, false);
417-
Settings.Secure.putString(
418-
RuntimeEnvironment.application.getContentResolver(),
419-
Settings.Secure.DEFAULT_INPUT_METHOD,
420-
"com.sec.android.inputmethod/.SamsungKeypad");
421-
TestImm testImm =
422-
Shadow.extract(
423-
RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE));
424-
testImm.setCurrentInputMethodSubtype(inputMethodSubtype);
425-
View testView = new View(RuntimeEnvironment.application);
426-
TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class));
427-
TextInputPlugin textInputPlugin =
428-
new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class));
429-
textInputPlugin.setTextInputClient(
430-
0,
431-
new TextInputChannel.Configuration(
432-
false,
433-
false,
434-
true,
435-
TextInputChannel.TextCapitalization.NONE,
436-
null,
437-
null,
438-
null,
439-
null,
440-
null));
441-
// There's a pending restart since we initialized the text input client. Flush that now.
442-
textInputPlugin.setTextInputEditingState(
443-
testView, new TextInputChannel.TextEditState("", 0, 0, -1, -1));
444-
445-
// Move the cursor.
446-
assertEquals(1, testImm.getRestartCount(testView));
447-
textInputPlugin.setTextInputEditingState(
448-
testView, new TextInputChannel.TextEditState("", 0, 0, -1, -1));
449-
450-
// Verify that we've NOT restarted the input.
451-
assertEquals(1, testImm.getRestartCount(testView));
452-
}
453-
454391
@Test
455392
public void setTextInputEditingState_doesNotRestartOnUnaffectedDevices() {
456393
// Initialize a TextInputPlugin that needs to be always restarted.
@@ -490,7 +427,7 @@ public void setTextInputEditingState_doesNotRestartOnUnaffectedDevices() {
490427
textInputPlugin.setTextInputEditingState(
491428
testView, new TextInputChannel.TextEditState("", 0, 0, -1, -1));
492429

493-
// Verify that we've NOT restarted the input.
430+
// Verify that we've restarted the input.
494431
assertEquals(1, testImm.getRestartCount(testView));
495432
}
496433

0 commit comments

Comments
 (0)