fix spellchecker crash when keyboard has never been initialized, fixes #684

This commit is contained in:
Helium314 2024-04-15 22:59:33 +02:00
parent 87f1092eac
commit 382bdb6ff6
2 changed files with 9 additions and 5 deletions

View file

@ -100,6 +100,7 @@ public final class InputAttributes {
final boolean noMicrophone = mIsPasswordField
|| InputTypeUtils.isEmailVariation(variation)
|| hasNoMicrophoneKeyOption()
|| !RichInputMethodManager.isInitialized() // avoid crash when only using spell checker
|| !RichInputMethodManager.getInstance().hasShortcutIme();
mShouldShowVoiceInputKey = !noMicrophone;

View file

@ -69,24 +69,27 @@ public class RichInputMethodManager {
sInstance.initInternal(context);
}
private boolean isInitialized() {
private boolean isInitializedInternal() {
return mImm != null;
}
public static boolean isInitialized() {
return sInstance.isInitializedInternal();
}
private void checkInitialized() {
if (!isInitialized()) {
if (!isInitializedInternal()) {
throw new RuntimeException(TAG + " is used before initialization");
}
}
private void initInternal(final Context context) {
if (isInitialized()) {
if (isInitializedInternal()) {
return;
}
mImm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
mContext = context;
mInputMethodInfoCache = new InputMethodInfoCache(
mImm, context.getPackageName());
mInputMethodInfoCache = new InputMethodInfoCache(mImm, context.getPackageName());
// Initialize subtype utils.
SubtypeLocaleUtils.init(context);