Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5aef342a authored by Satoshi Kataoka's avatar Satoshi Kataoka
Browse files

Use isAsciiCapable when disabling system ime

Bug: 8364845
Change-Id: I2bb02b0c57b65ac3496b92d379e6d4ff21f338b1
parent 7f34fab6
Loading
Loading
Loading
Loading
+31 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.view.inputmethod.InputMethodSubtype;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;

@@ -48,6 +49,8 @@ public class InputMethodSettingValuesWrapper {
            new HashMap<String, InputMethodInfo>();
    private final InputMethodSettings mSettings;
    private final InputMethodManager mImm;
    private final HashSet<InputMethodInfo> mAsciiCapableEnabledImis =
            new HashSet<InputMethodInfo>();

    public static InputMethodSettingValuesWrapper getInstance(Context context) {
        if (sInstance == null) {
@@ -87,6 +90,26 @@ public class InputMethodSettingValuesWrapper {
            for (InputMethodInfo imi : imms) {
                mMethodMap.put(imi.getId(), imi);
            }
            updateAsciiCapableEnabledImis();
        }
    }

    // TODO: Add a cts to ensure at least one AsciiCapableSubtypeEnabledImis exist
    private void updateAsciiCapableEnabledImis() {
        synchronized (mMethodMap) {
            mAsciiCapableEnabledImis.clear();
            final List<InputMethodInfo> enabledImis = mSettings.getEnabledInputMethodListLocked();
            for (final InputMethodInfo imi : enabledImis) {
                final int subtypeCount = imi.getSubtypeCount();
                for (int i = 0; i < subtypeCount; ++i) {
                    final InputMethodSubtype subtype = imi.getSubtypeAt(i);
                    if (InputMethodUtils.SUBTYPE_MODE_KEYBOARD.equalsIgnoreCase(subtype.getMode())
                            && subtype.isAsciiCapable()) {
                        mAsciiCapableEnabledImis.add(imi);
                        break;
                    }
                }
            }
        }
    }

@@ -162,7 +185,7 @@ public class InputMethodSettingValuesWrapper {
        return false;
    }

    public static boolean isValidSystemNonAuxAsciiCapableIme(InputMethodInfo imi,
    public boolean isValidSystemNonAuxAsciiCapableIme(InputMethodInfo imi,
            Context context) {
        if (imi.isAuxiliaryIme()) {
            return false;
@@ -170,7 +193,12 @@ public class InputMethodSettingValuesWrapper {
        if (InputMethodUtils.isValidSystemDefaultIme(true /* isSystemReady */, imi, context)) {
            return true;
        }
        if (mAsciiCapableEnabledImis.isEmpty()) {
            Log.w(TAG, "ascii capable subtype enabled imi not found. Fall back to English"
                    + " Keyboard subtype.");
            return InputMethodUtils.containsSubtypeOf(imi, ENGLISH_LOCALE.getLanguage(),
                    InputMethodUtils.SUBTYPE_MODE_KEYBOARD);
        }
        return mAsciiCapableEnabledImis.contains(imi);
    }
}