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

Commit bc3dba45 authored by satok's avatar satok
Browse files

A fix for handling dummy voice subtypes

Change-Id: I75d4d1625e0925d01ae84c9577e15087d83e4191
parent 458807e8
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ public class InputMethodManagerCompatWrapper {

    // For the compatibility, IMM will create dummy subtypes if subtypes are not found.
    // This is required to be false if the current behavior is broken. For now, it's ok to be true.
    private static final boolean ALLOW_DUMMY_SUBTYPE = true;
    private static final boolean HAS_VOICE_FUNCTION = true;
    private static final String VOICE_MODE = "voice";
    private static final String KEYBOARD_MODE = "keyboard";
@@ -119,11 +118,13 @@ public class InputMethodManagerCompatWrapper {
        Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList,
                (imi != null ? imi.getInputMethodInfo() : null), allowsImplicitlySelectedSubtypes);
        if (retval == null || !(retval instanceof List) || ((List<?>)retval).isEmpty()) {
            if (!ALLOW_DUMMY_SUBTYPE) {
            if (InputMethodServiceCompatWrapper.
                    CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
                // Returns an empty list
                return Collections.emptyList();
            }
            // Creates dummy subtypes
            @SuppressWarnings("unused")
            List<InputMethodSubtypeCompatWrapper> subtypeList =
                    new ArrayList<InputMethodSubtypeCompatWrapper>();
            InputMethodSubtypeCompatWrapper keyboardSubtype = getLastResortSubtype(KEYBOARD_MODE);
@@ -159,11 +160,13 @@ public class InputMethodManagerCompatWrapper {
            getShortcutInputMethodsAndSubtypes() {
        Object retval = CompatUtils.invoke(mImm, null, METHOD_getShortcutInputMethodsAndSubtypes);
        if (retval == null || !(retval instanceof Map) || ((Map<?, ?>)retval).isEmpty()) {
            if (!ALLOW_DUMMY_SUBTYPE) {
            if (InputMethodServiceCompatWrapper.
                    CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
                // Returns an empty map
                return Collections.emptyMap();
            }
            // Creates dummy subtypes
            @SuppressWarnings("unused")
            InputMethodInfoCompatWrapper imi = getLatinImeInputMethodInfo();
            InputMethodSubtypeCompatWrapper voiceSubtype = getLastResortSubtype(VOICE_MODE);
            if (imi != null && voiceSubtype != null) {
@@ -196,9 +199,11 @@ public class InputMethodManagerCompatWrapper {

    public void setInputMethodAndSubtype(
            IBinder token, String id, InputMethodSubtypeCompatWrapper subtype) {
        if (subtype != null && subtype.hasOriginalObject()) {
            CompatUtils.invoke(mImm, null, METHOD_setInputMethodAndSubtype,
                    token, id, subtype.getOriginalObject());
        }
    }

    public boolean switchToLastInputMethod(IBinder token) {
        if (SubtypeSwitcher.getInstance().isDummyVoiceMode()) {
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ public class InputMethodServiceCompatWrapper extends InputMethodService {
    // For the API level 11 or later, LatinIME should override onCurrentInputMethodSubtypeChanged().
    // For the API level 10 or previous, we handle the "subtype changed" events by ourselves
    // without having support from framework -- onCurrentInputMethodSubtypeChanged().
    private static final boolean CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED = true;
    public static final boolean CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED = true;

    private InputMethodManagerCompatWrapper mImm;

+5 −1
Original line number Diff line number Diff line
@@ -382,13 +382,17 @@ public class SubtypeSwitcher {
            return false;
        if (mShortcutSubtype == null)
            return true;
        // For compatibility, if the shortcut subtype is dummy, we assume the shortcut IME
        // (built-in voice dummy subtype) is available.
        if (!mShortcutSubtype.hasOriginalObject()) return true;
        final boolean allowsImplicitlySelectedSubtypes = true;
        for (final InputMethodSubtypeCompatWrapper enabledSubtype :
                mImm.getEnabledInputMethodSubtypeList(
                        mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
            if (enabledSubtype.equals(mShortcutSubtype))
            if (enabledSubtype.equals(mShortcutSubtype)) {
                return true;
            }
        }
        return false;
    }