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

Commit 68c860bb authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Minimize the number of default enabled IMEs part 2

Previously the system tried to enable at least one auxiliary IME
even when the system is not ready.  However, this doesn't make
much sense because the user should be able to set up their phone
without auxiliary IMEs. Also, IMEs enabled before the system
becomes ready are kept to be enabled after the system becomes
ready. Thus, we should minimize the number of enabled IMEs
until the system becomes ready.

BUG: 17347871
Change-Id: Ife93d909fb8a24471c425c903e2b7048826e17a3
parent c0b8cb89
Loading
Loading
Loading
Loading
+23 −8
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import java.util.Locale;
public class InputMethodUtils {
    public static final boolean DEBUG = false;
    public static final int NOT_A_SUBTYPE_ID = -1;
    public static final String SUBTYPE_MODE_ANY = null;
    public static final String SUBTYPE_MODE_KEYBOARD = "keyboard";
    public static final String SUBTYPE_MODE_VOICE = "voice";
    private static final String TAG = "InputMethodUtils";
@@ -127,10 +128,23 @@ public class InputMethodUtils {

    public static ArrayList<InputMethodInfo> getDefaultEnabledImes(
            Context context, boolean isSystemReady, ArrayList<InputMethodInfo> imis) {
        final ArrayList<InputMethodInfo> retval = new ArrayList<InputMethodInfo>();
        if (!isSystemReady) {
            final ArrayList<InputMethodInfo> retval = new ArrayList<>();
            for (int i = 0; i < imis.size(); ++i) {
                final InputMethodInfo imi = imis.get(i);
                if (isSystemImeThatHasEnglishKeyboardSubtype(imi)) {
                    retval.add(imi);
                }
            }
            return retval;
        }

        final ArrayList<InputMethodInfo> retval = new ArrayList<>();
        boolean auxilialyImeAdded = false;
        for (int i = 0; i < imis.size(); ++i) {
            final InputMethodInfo imi = imis.get(i);
            // TODO: We should check isAsciiCapable instead of relying on
            // isSystemImeThatHasEnglishKeyboardSubtype().
            if (isValidSystemDefaultIme(isSystemReady, imi, context)
                    || isSystemImeThatHasEnglishKeyboardSubtype(imi)) {
                retval.add(imi);
@@ -139,6 +153,7 @@ public class InputMethodUtils {
                }
            }
        }
        // If one or more auxiliary input methods are available, OK to stop populating the list.
        if (auxilialyImeAdded) {
            return retval;
        }
@@ -164,7 +179,7 @@ public class InputMethodUtils {
            try {
                if (imi.isDefault(context) && containsSubtypeOf(
                        imi, context.getResources().getConfiguration().locale.getLanguage(),
                        null /* mode */)) {
                        SUBTYPE_MODE_ANY)) {
                    return true;
                }
            } catch (Resources.NotFoundException ex) {
@@ -179,14 +194,15 @@ public class InputMethodUtils {
    public static boolean containsSubtypeOf(InputMethodInfo imi, String language, String mode) {
        final int N = imi.getSubtypeCount();
        for (int i = 0; i < N; ++i) {
            if (!imi.getSubtypeAt(i).getLocale().startsWith(language)) {
                continue;
            }
            if(!TextUtils.isEmpty(mode) && !imi.getSubtypeAt(i).getMode().equalsIgnoreCase(mode)) {
            final InputMethodSubtype subtype = imi.getSubtypeAt(i);
            if (!subtype.getLocale().startsWith(language)) {
                continue;
            }
            if (mode == SUBTYPE_MODE_ANY || TextUtils.isEmpty(mode) ||
                    mode.equalsIgnoreCase(subtype.getMode())) {
                return true;
            }
        }
        return false;
    }

@@ -212,8 +228,7 @@ public class InputMethodUtils {
        return subtypes;
    }

    public static InputMethodInfo getMostApplicableDefaultIME(
            List<InputMethodInfo> enabledImes) {
    public static InputMethodInfo getMostApplicableDefaultIME(List<InputMethodInfo> enabledImes) {
        if (enabledImes == null || enabledImes.isEmpty()) {
            return null;
        }
+8 −19
Original line number Diff line number Diff line
@@ -53,10 +53,8 @@ public class InputMethodTest extends InstrumentationTestCase {
    public void testVoiceImes() throws Exception {
        // locale: en_US
        assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY,
                "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
                "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
                "DummyDefaultEnKeyboardIme");
        assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY,
                "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
                "DummyDefaultEnKeyboardIme");
        assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, IS_SYSTEM_READY,
                "DummyDefaultAutoVoiceIme", "DummyDefaultEnKeyboardIme");
@@ -66,10 +64,8 @@ public class InputMethodTest extends InstrumentationTestCase {

        // locale: en_GB
        assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY,
                "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
                "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
                "DummyDefaultEnKeyboardIme");
        assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY,
                "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
                "DummyDefaultEnKeyboardIme");
        assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, IS_SYSTEM_READY,
                "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
@@ -79,10 +75,8 @@ public class InputMethodTest extends InstrumentationTestCase {

        // locale: ja_JP
        assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY,
                "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
                "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
                "DummyDefaultEnKeyboardIme");
        assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY,
                "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
                "DummyDefaultEnKeyboardIme");
        assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, IS_SYSTEM_READY,
                "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
@@ -96,40 +90,35 @@ public class InputMethodTest extends InstrumentationTestCase {
    public void testKeyboardImes() throws Exception {
        // locale: en_US
        assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, !IS_SYSTEM_READY,
                "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
                "com.android.apps.inputmethod.hindi");
                "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi");
        assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, IS_SYSTEM_READY,
                "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
                "com.android.apps.inputmethod.hindi");

        // locale: en_GB
        assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, !IS_SYSTEM_READY,
                "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
                "com.android.apps.inputmethod.hindi");
                "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi");
        assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, IS_SYSTEM_READY,
                "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
                "com.android.apps.inputmethod.hindi");

        // locale: en_IN
        assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, !IS_SYSTEM_READY,
                "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
                "com.android.apps.inputmethod.hindi");
                "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi");
        assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, IS_SYSTEM_READY,
                "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
                "com.android.apps.inputmethod.hindi");

        // locale: hi
        assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, !IS_SYSTEM_READY,
                "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
                "com.android.apps.inputmethod.hindi");
                "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi");
        assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, IS_SYSTEM_READY,
                "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
                "com.android.apps.inputmethod.hindi");

        // locale: ja_JP
        assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, !IS_SYSTEM_READY,
                "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
                "com.android.apps.inputmethod.hindi");
                "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi");
        assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, IS_SYSTEM_READY,
                "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
                "com.android.apps.inputmethod.hindi", "com.android.apps.inputmethod.japanese");