Check for a null input method subtype (flutter/engine#12706)

Fixes https://github.com/flutter/flutter/issues/41557
This commit is contained in:
Jason Simmons
2019-10-01 09:03:47 -07:00
committed by Michael Klimushyn
parent c31a9759d7
commit e023418f3f
2 changed files with 21 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.systemchannels.TextInputChannel;
@@ -320,10 +321,15 @@ public class TextInputPlugin {
// and stops it from trying to incorrectly combine characters. However this also has some
// negative performance implications, so we don't want to apply this workaround in every case.
@SuppressLint("NewApi") // New API guard is inline, the linter can't see it.
@SuppressWarnings("deprecation")
private boolean isRestartAlwaysRequired() {
InputMethodSubtype subtype = mImm.getCurrentInputMethodSubtype();
if (subtype == null) {
return false;
}
String language = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
? mImm.getCurrentInputMethodSubtype().getLanguageTag()
: mImm.getCurrentInputMethodSubtype().getLocale();
? subtype.getLanguageTag()
: subtype.getLocale();
return Build.MANUFACTURER.equals("samsung") && language.equals("ko");
}

View File

@@ -69,6 +69,19 @@ public class TextInputPluginTest {
assertEquals(2, testImm.getRestartCount(testView));
}
@Test
public void setTextInputEditingState_nullInputMethodSubtype() {
TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE));
testImm.setCurrentInputMethodSubtype(null);
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));
assertEquals(1, testImm.getRestartCount(testView));
}
@Implements(InputMethodManager.class)
public static class TestImm extends ShadowInputMethodManager {
private InputMethodSubtype currentInputMethodSubtype;
@@ -97,4 +110,3 @@ public class TextInputPluginTest {
}
}
}