|
18 | 18 |
|
19 | 19 | import android.annotation.TargetApi; |
20 | 20 | import android.content.Context; |
| 21 | +import android.content.pm.PackageInfo; |
21 | 22 | import android.content.res.AssetManager; |
22 | 23 | import android.graphics.Insets; |
23 | 24 | import android.graphics.Rect; |
|
64 | 65 | import org.mockito.Mock; |
65 | 66 | import org.robolectric.RobolectricTestRunner; |
66 | 67 | import org.robolectric.RuntimeEnvironment; |
| 68 | +import org.robolectric.Shadows; |
67 | 69 | import org.robolectric.annotation.Config; |
68 | 70 | import org.robolectric.annotation.Implementation; |
69 | 71 | import org.robolectric.annotation.Implements; |
70 | 72 | import org.robolectric.shadow.api.Shadow; |
71 | 73 | import org.robolectric.shadows.ShadowAutofillManager; |
72 | 74 | import org.robolectric.shadows.ShadowBuild; |
73 | 75 | import org.robolectric.shadows.ShadowInputMethodManager; |
| 76 | +import org.robolectric.shadows.ShadowPackageManager; |
74 | 77 |
|
75 | 78 | @Config( |
76 | 79 | manifest = Config.NONE, |
@@ -339,14 +342,21 @@ public void setTextInputEditingState_alwaysSetEditableWhenDifferent() { |
339 | 342 | assertTrue(textInputPlugin.getEditable().toString().equals("Shibuyawoo")); |
340 | 343 | } |
341 | 344 |
|
342 | | - // See https://github.com/flutter/flutter/issues/29341 and |
343 | | - // https://github.com/flutter/flutter/issues/31512 |
344 | | - // All modern Samsung keybords are affected including non-korean languages and thus |
345 | | - // need the restart. |
| 345 | + // See also: https://github.com/flutter/flutter/issues/29341 and |
| 346 | + // https://github.com/flutter/flutter/issues/31512. |
| 347 | + // Some recent versions of Samsung keybords are affected including non-korean |
| 348 | + // languages and thus needed the restart. |
346 | 349 | @Test |
347 | | - public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() { |
348 | | - // Initialize a TextInputPlugin that needs to be always restarted. |
| 350 | + public void setTextInputEditingState_alwaysRestartsOnAffectedDevices() { |
| 351 | + // Initialize a TextInputPlugin with a Samsung keypad. |
349 | 352 | ShadowBuild.setManufacturer("samsung"); |
| 353 | + final ShadowPackageManager packageManager = |
| 354 | + Shadows.shadowOf( |
| 355 | + RuntimeEnvironment.application.getApplicationContext().getPackageManager()); |
| 356 | + final PackageInfo info = new PackageInfo(); |
| 357 | + info.packageName = "com.sec.android.inputmethod"; |
| 358 | + info.versionCode = 200000000; |
| 359 | + packageManager.addPackage(info); |
350 | 360 | InputMethodSubtype inputMethodSubtype = |
351 | 361 | new InputMethodSubtype(0, 0, /*locale=*/ "en", "", "", false, false); |
352 | 362 | Settings.Secure.putString( |
@@ -386,6 +396,59 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() { |
386 | 396 | assertEquals(2, testImm.getRestartCount(testView)); |
387 | 397 | } |
388 | 398 |
|
| 399 | + // Regression test for https://github.com/flutter/flutter/issues/73433. |
| 400 | + // The restart workaround seems to have caused #73433 and it's no longer |
| 401 | + // needed on newer versions of Samsung keyboard. |
| 402 | + @Test |
| 403 | + public void setTextInputEditingState_DontForceRestartOnNewSamsungKeyboard() { |
| 404 | + // Initialize a TextInputPlugin with a Samsung keypad. |
| 405 | + ShadowBuild.setManufacturer("samsung"); |
| 406 | + final ShadowPackageManager packageManager = |
| 407 | + Shadows.shadowOf( |
| 408 | + RuntimeEnvironment.application.getApplicationContext().getPackageManager()); |
| 409 | + final PackageInfo info = new PackageInfo(); |
| 410 | + info.packageName = "com.sec.android.inputmethod"; |
| 411 | + info.versionCode = 333183070; |
| 412 | + packageManager.addPackage(info); |
| 413 | + InputMethodSubtype inputMethodSubtype = |
| 414 | + new InputMethodSubtype(0, 0, /*locale=*/ "en", "", "", false, false); |
| 415 | + Settings.Secure.putString( |
| 416 | + RuntimeEnvironment.application.getContentResolver(), |
| 417 | + Settings.Secure.DEFAULT_INPUT_METHOD, |
| 418 | + "com.sec.android.inputmethod/.SamsungKeypad"); |
| 419 | + TestImm testImm = |
| 420 | + Shadow.extract( |
| 421 | + RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); |
| 422 | + testImm.setCurrentInputMethodSubtype(inputMethodSubtype); |
| 423 | + View testView = new View(RuntimeEnvironment.application); |
| 424 | + TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); |
| 425 | + TextInputPlugin textInputPlugin = |
| 426 | + new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); |
| 427 | + textInputPlugin.setTextInputClient( |
| 428 | + 0, |
| 429 | + new TextInputChannel.Configuration( |
| 430 | + false, |
| 431 | + false, |
| 432 | + true, |
| 433 | + TextInputChannel.TextCapitalization.NONE, |
| 434 | + null, |
| 435 | + null, |
| 436 | + null, |
| 437 | + null, |
| 438 | + null)); |
| 439 | + // There's a pending restart since we initialized the text input client. Flush that now. |
| 440 | + textInputPlugin.setTextInputEditingState( |
| 441 | + testView, new TextInputChannel.TextEditState("", 0, 0, -1, -1)); |
| 442 | + |
| 443 | + // Move the cursor. |
| 444 | + assertEquals(1, testImm.getRestartCount(testView)); |
| 445 | + textInputPlugin.setTextInputEditingState( |
| 446 | + testView, new TextInputChannel.TextEditState("", 0, 0, -1, -1)); |
| 447 | + |
| 448 | + // Verify that we've NOT restarted the input. |
| 449 | + assertEquals(1, testImm.getRestartCount(testView)); |
| 450 | + } |
| 451 | + |
389 | 452 | @Test |
390 | 453 | public void setTextInputEditingState_doesNotRestartOnUnaffectedDevices() { |
391 | 454 | // Initialize a TextInputPlugin that needs to be always restarted. |
@@ -425,7 +488,7 @@ public void setTextInputEditingState_doesNotRestartOnUnaffectedDevices() { |
425 | 488 | textInputPlugin.setTextInputEditingState( |
426 | 489 | testView, new TextInputChannel.TextEditState("", 0, 0, -1, -1)); |
427 | 490 |
|
428 | | - // Verify that we've restarted the input. |
| 491 | + // Verify that we've NOT restarted the input. |
429 | 492 | assertEquals(1, testImm.getRestartCount(testView)); |
430 | 493 | } |
431 | 494 |
|
|
0 commit comments