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

Commit 1cd00f3c authored by android-build-team Robot's avatar android-build-team Robot Committed by Android (Google) Code Review
Browse files

Merge changes I5ed0feb5,I33faa3c8,Id2ee2e55,Iad0d4e94,I3ae5e544

* changes:
  Revert "Rotate IMEs (subtypes) by Meta+Space."
  Revert "Show toast when subtype is rotated by Meta-Space."
  Revert "Shift+Meta+Space should reverse-rotate subtypes."
  Revert "Shift+Meta+Space should reverse-rotate subtypes part 2."
  Revert "Make sure that Toast is always shown by Meta-Space."
parents df487d3b fec8cef7
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -30,11 +30,6 @@ public interface InputMethodManagerInternal {
     */
    void setInteractive(boolean interactive);

    /**
     * Called by the window manager to let the input method manager rotate the input method.
     */
    void switchInputMethod(boolean forwardDirection);

    /**
     * Hides the current input method, if visible.
     */
+10 −54
Original line number Diff line number Diff line
@@ -291,22 +291,8 @@ public class InputMethodSubtypeSwitchingController {
            return -1;
        }

        /**
         * Provides the basic operation to implement bi-directional IME rotation.
         * @param onlyCurrentIme {@code true} to limit the search space to IME subtypes that belong
         * to {@code imi}.
         * @param imi {@link InputMethodInfo} that will be used in conjunction with {@code subtype}
         * from which we find the adjacent IME subtype.
         * @param subtype {@link InputMethodSubtype} that will be used in conjunction with
         * {@code imi} from which we find the next IME subtype.  {@code null} if the input method
         * does not have a subtype.
         * @param forward {@code true} to do forward search the next IME subtype. Specify
         * {@code false} to do backward search.
         * @return The IME subtype found. {@code null} if no IME subtype is found.
         */
        @Nullable
        public ImeSubtypeListItem getNextInputMethodLocked(boolean onlyCurrentIme,
                InputMethodInfo imi, @Nullable InputMethodSubtype subtype, boolean forward) {
                InputMethodInfo imi, InputMethodSubtype subtype) {
            if (imi == null) {
                return null;
            }
@@ -318,9 +304,8 @@ public class InputMethodSubtypeSwitchingController {
                return null;
            }
            final int N = mImeSubtypeList.size();
            for (int i = 1; i < N; ++i) {
                // Start searching the next IME/subtype from +/- 1 indices.
                final int offset = forward ? i : N - i;
            for (int offset = 1; offset < N; ++offset) {
                // Start searching the next IME/subtype from the next of the current index.
                final int candidateIndex = (currentIndex + offset) % N;
                final ImeSubtypeListItem candidate = mImeSubtypeList.get(candidateIndex);
                // Skip if searching inside the current IME only, but the candidate is not
@@ -392,22 +377,8 @@ public class InputMethodSubtypeSwitchingController {
            mUsageHistoryOfSubtypeListItemIndex[0] = currentItemIndex;
        }

        /**
         * Provides the basic operation to implement bi-directional IME rotation.
         * @param onlyCurrentIme {@code true} to limit the search space to IME subtypes that belong
         * to {@code imi}.
         * @param imi {@link InputMethodInfo} that will be used in conjunction with {@code subtype}
         * from which we find the adjacent IME subtype.
         * @param subtype {@link InputMethodSubtype} that will be used in conjunction with
         * {@code imi} from which we find the next IME subtype.  {@code null} if the input method
         * does not have a subtype.
         * @param forward {@code true} to do forward search the next IME subtype. Specify
         * {@code false} to do backward search.
         * @return The IME subtype found. {@code null} if no IME subtype is found.
         */
        @Nullable
        public ImeSubtypeListItem getNextInputMethodLocked(boolean onlyCurrentIme,
                InputMethodInfo imi, @Nullable InputMethodSubtype subtype, boolean forward) {
                InputMethodInfo imi, InputMethodSubtype subtype) {
            int currentUsageRank = getUsageRank(imi, subtype);
            if (currentUsageRank < 0) {
                if (DEBUG) {
@@ -417,8 +388,7 @@ public class InputMethodSubtypeSwitchingController {
            }
            final int N = mUsageHistoryOfSubtypeListItemIndex.length;
            for (int i = 1; i < N; i++) {
                final int offset = forward ? i : N - i;
                final int subtypeListItemRank = (currentUsageRank + offset) % N;
                final int subtypeListItemRank = (currentUsageRank + i) % N;
                final int subtypeListItemIndex =
                        mUsageHistoryOfSubtypeListItemIndex[subtypeListItemRank];
                final ImeSubtypeListItem subtypeListItem =
@@ -491,31 +461,17 @@ public class InputMethodSubtypeSwitchingController {
            mSwitchingUnawareRotationList = switchingUnawareRotationList;
        }

        /**
         * Provides the basic operation to implement bi-directional IME rotation.
         * @param onlyCurrentIme {@code true} to limit the search space to IME subtypes that belong
         * to {@code imi}.
         * @param imi {@link InputMethodInfo} that will be used in conjunction with {@code subtype}
         * from which we find the adjacent IME subtype.
         * @param subtype {@link InputMethodSubtype} that will be used in conjunction with
         * {@code imi} from which we find the next IME subtype.  {@code null} if the input method
         * does not have a subtype.
         * @param forward {@code true} to do forward search the next IME subtype. Specify
         * {@code false} to do backward search.
         * @return The IME subtype found. {@code null} if no IME subtype is found.
         */
        @Nullable
        public ImeSubtypeListItem getNextInputMethod(boolean onlyCurrentIme, InputMethodInfo imi,
                @Nullable InputMethodSubtype subtype, boolean forward) {
                InputMethodSubtype subtype) {
            if (imi == null) {
                return null;
            }
            if (imi.supportsSwitchingToNextInputMethod()) {
                return mSwitchingAwareRotationList.getNextInputMethodLocked(onlyCurrentIme, imi,
                        subtype, forward);
                        subtype);
            } else {
                return mSwitchingUnawareRotationList.getNextInputMethodLocked(onlyCurrentIme, imi,
                        subtype, forward);
                        subtype);
            }
        }

@@ -583,14 +539,14 @@ public class InputMethodSubtypeSwitchingController {
    }

    public ImeSubtypeListItem getNextInputMethodLocked(boolean onlyCurrentIme, InputMethodInfo imi,
            InputMethodSubtype subtype, boolean forward) {
            InputMethodSubtype subtype) {
        if (mController == null) {
            if (DEBUG) {
                Log.e(TAG, "mController shouldn't be null.");
            }
            return null;
        }
        return mController.getNextInputMethod(onlyCurrentIme, imi, subtype, forward);
        return mController.getNextInputMethod(onlyCurrentIme, imi, subtype);
    }

    public List<ImeSubtypeListItem> getSortedInputMethodAndSubtypeListLocked(
+23 −27
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;

import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ControllerImpl;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
import com.android.internal.inputmethod.InputMethodUtils;

import org.junit.Test;
import org.junit.runner.RunWith;
@@ -78,7 +79,7 @@ public class InputMethodSubtypeSwitchingControllerTest {
        ri.serviceInfo = si;
        List<InputMethodSubtype> subtypes = null;
        if (subtypeLocales != null) {
            subtypes = new ArrayList<>();
            subtypes = new ArrayList<InputMethodSubtype>();
            for (String subtypeLocale : subtypeLocales) {
                subtypes.add(createDummySubtype(subtypeLocale));
            }
@@ -128,7 +129,7 @@ public class InputMethodSubtypeSwitchingControllerTest {
    }

    private static List<ImeSubtypeListItem> createEnabledImeSubtypes() {
        final List<ImeSubtypeListItem> items = new ArrayList<>();
        final List<ImeSubtypeListItem> items = new ArrayList<ImeSubtypeListItem>();
        addDummyImeSubtypeListItems(items, "LatinIme", "LatinIme", Arrays.asList("en_US", "fr"),
                true /* supportsSwitchingToNextInputMethod*/);
        addDummyImeSubtypeListItems(items, "switchUnawareLatinIme", "switchUnawareLatinIme",
@@ -144,7 +145,7 @@ public class InputMethodSubtypeSwitchingControllerTest {
    }

    private static List<ImeSubtypeListItem> createDisabledImeSubtypes() {
        final List<ImeSubtypeListItem> items = new ArrayList<>();
        final List<ImeSubtypeListItem> items = new ArrayList<ImeSubtypeListItem>();
        addDummyImeSubtypeListItems(items,
                "UnknownIme", "UnknownIme",
                Arrays.asList("en_US", "hi"),
@@ -160,18 +161,15 @@ public class InputMethodSubtypeSwitchingControllerTest {
    }

    private void assertNextInputMethod(final ControllerImpl controller,
            final boolean onlyCurrentIme, final ImeSubtypeListItem currentItem,
            final ImeSubtypeListItem nextItem, final ImeSubtypeListItem prevItem) {
            final boolean onlyCurrentIme,
            final ImeSubtypeListItem currentItem, final ImeSubtypeListItem nextItem) {
        InputMethodSubtype subtype = null;
        if (currentItem.mSubtypeName != null) {
            subtype = createDummySubtype(currentItem.mSubtypeName.toString());
        }
        final ImeSubtypeListItem nextIme = controller.getNextInputMethod(onlyCurrentIme,
                currentItem.mImi, subtype, true /* forward */);
                currentItem.mImi, subtype);
        assertEquals(nextItem, nextIme);
        final ImeSubtypeListItem prevIme = controller.getNextInputMethod(onlyCurrentIme,
                currentItem.mImi, subtype, false /* forward */);
        assertEquals(prevItem, prevIme);
    }

    private void assertRotationOrder(final ControllerImpl controller,
@@ -180,13 +178,11 @@ public class InputMethodSubtypeSwitchingControllerTest {
        final int N = expectedRotationOrderOfImeSubtypeList.length;
        for (int i = 0; i < N; i++) {
            final int currentIndex = i;
            final int prevIndex = (currentIndex + N - 1) % N;
            final int nextIndex = (currentIndex + 1) % N;
            final ImeSubtypeListItem currentItem =
                    expectedRotationOrderOfImeSubtypeList[currentIndex];
            final ImeSubtypeListItem nextItem = expectedRotationOrderOfImeSubtypeList[nextIndex];
            final ImeSubtypeListItem prevItem = expectedRotationOrderOfImeSubtypeList[prevIndex];
            assertNextInputMethod(controller, onlyCurrentIme, currentItem, nextItem, prevItem);
            assertNextInputMethod(controller, onlyCurrentIme, currentItem, nextItem);
        }
    }

@@ -234,29 +230,29 @@ public class InputMethodSubtypeSwitchingControllerTest {
        assertRotationOrder(controller, true /* onlyCurrentIme */,
                switchingUnawarelatinIme_en_UK, switchingUnawarelatinIme_hi);
        assertNextInputMethod(controller, true /* onlyCurrentIme */,
                subtypeUnawareIme, null, null);
                subtypeUnawareIme, null);
        assertNextInputMethod(controller, true /* onlyCurrentIme */,
                japaneseIme_ja_JP, null, null);
                japaneseIme_ja_JP, null);
        assertNextInputMethod(controller, true /* onlyCurrentIme */,
                switchUnawareJapaneseIme_ja_JP, null, null);
                switchUnawareJapaneseIme_ja_JP, null);

        // Make sure that disabled IMEs are not accepted.
        assertNextInputMethod(controller, false /* onlyCurrentIme */,
                disabledIme_en_US, null, null);
                disabledIme_en_US, null);
        assertNextInputMethod(controller, false /* onlyCurrentIme */,
                disabledIme_hi, null, null);
                disabledIme_hi, null);
        assertNextInputMethod(controller, false /* onlyCurrentIme */,
                disabledSwitchingUnawareIme, null, null);
                disabledSwitchingUnawareIme, null);
        assertNextInputMethod(controller, false /* onlyCurrentIme */,
                disabledSubtypeUnawareIme, null, null);
                disabledSubtypeUnawareIme, null);
        assertNextInputMethod(controller, true /* onlyCurrentIme */,
                disabledIme_en_US, null, null);
                disabledIme_en_US, null);
        assertNextInputMethod(controller, true /* onlyCurrentIme */,
                disabledIme_hi, null, null);
                disabledIme_hi, null);
        assertNextInputMethod(controller, true /* onlyCurrentIme */,
                disabledSwitchingUnawareIme, null, null);
                disabledSwitchingUnawareIme, null);
        assertNextInputMethod(controller, true /* onlyCurrentIme */,
                disabledSubtypeUnawareIme, null, null);
                disabledSubtypeUnawareIme, null);
    }

    @Test
@@ -290,7 +286,7 @@ public class InputMethodSubtypeSwitchingControllerTest {
                japaneseIme_ja_JP, latinIme_fr, latinIme_en_US);
        // Check onlyCurrentIme == true.
        assertNextInputMethod(controller, true /* onlyCurrentIme */,
                japaneseIme_ja_JP, null, null);
                japaneseIme_ja_JP, null);
        assertRotationOrder(controller, true /* onlyCurrentIme */,
                latinIme_fr, latinIme_en_US);
        assertRotationOrder(controller, true /* onlyCurrentIme */,
@@ -314,9 +310,9 @@ public class InputMethodSubtypeSwitchingControllerTest {
        assertRotationOrder(controller, true /* onlyCurrentIme */,
                switchingUnawarelatinIme_en_UK, switchingUnawarelatinIme_hi);
        assertNextInputMethod(controller, true /* onlyCurrentIme */,
                subtypeUnawareIme, null, null);
                subtypeUnawareIme, null);
        assertNextInputMethod(controller, true /* onlyCurrentIme */,
                switchUnawareJapaneseIme_ja_JP, null, null);
                switchUnawareJapaneseIme_ja_JP, null);

        // Rotation order should be preserved when created with the same subtype list.
        final List<ImeSubtypeListItem> sameEnabledItems = createEnabledImeSubtypes();
@@ -342,7 +338,7 @@ public class InputMethodSubtypeSwitchingControllerTest {

    @Test
    public void testImeSubtypeListItem() throws Exception {
        final List<ImeSubtypeListItem> items = new ArrayList<>();
        final List<ImeSubtypeListItem> items = new ArrayList<ImeSubtypeListItem>();
        addDummyImeSubtypeListItems(items, "LatinIme", "LatinIme",
                Arrays.asList("en_US", "fr", "en", "en_uk", "enn", "e", "EN_US"),
                true /* supportsSwitchingToNextInputMethod*/);
+2 −60
Original line number Diff line number Diff line
@@ -152,7 +152,6 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.android.server.wm.WindowManagerInternal;

@@ -211,7 +210,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    static final int MSG_SET_INTERACTIVE = 3030;
    static final int MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER = 3040;
    static final int MSG_REPORT_FULLSCREEN_MODE = 3045;
    static final int MSG_SWITCH_IME = 3050;

    static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000;

@@ -608,7 +606,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private AlertDialog mSwitchingDialog;
    private IBinder mSwitchingDialogToken = new Binder();
    private View mSwitchingDialogTitleView;
    private Toast mSubtypeSwitchedByShortCutToast;
    private InputMethodInfo[] mIms;
    private int[] mSubtypeIds;
    private LocaleList mLastSystemLocales;
@@ -3108,8 +3105,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                return false;
            }
            final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
                    onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype,
                    true /* forward */);
                    onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype);
            if (nextSubtype == null) {
                return false;
            }
@@ -3129,8 +3125,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                return false;
            }
            final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
                    false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype,
                    true /* forward */);
                    false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype);
            if (nextSubtype == null) {
                return false;
            }
@@ -3493,9 +3488,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            case MSG_START_VR_INPUT:
                startVrInputMethodNoCheck((ComponentName) msg.obj);
                return true;
            case MSG_SWITCH_IME:
                handleSwitchInputMethod(msg.arg1 != 0);
                return true;
            case MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER: {
                final int sequenceNumber = msg.arg1;
                final ClientState clientState = (ClientState)msg.obj;
@@ -3549,32 +3541,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        }
    }

    private void handleSwitchInputMethod(final boolean forwardDirection) {
        synchronized (mMethodMap) {
            final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
                    false, mMethodMap.get(mCurMethodId), mCurrentSubtype, forwardDirection);
            if (nextSubtype == null) {
                return;
            }
            setInputMethodLocked(nextSubtype.mImi.getId(), nextSubtype.mSubtypeId);
            final InputMethodInfo newInputMethodInfo = mMethodMap.get(mCurMethodId);
            if (newInputMethodInfo == null) {
                return;
            }
            final CharSequence toastText = InputMethodUtils.getImeAndSubtypeDisplayName(mContext,
                    newInputMethodInfo, mCurrentSubtype);
            if (!TextUtils.isEmpty(toastText)) {
                if (mSubtypeSwitchedByShortCutToast == null) {
                    mSubtypeSwitchedByShortCutToast = Toast.makeText(mContext, toastText,
                            Toast.LENGTH_SHORT);
                } else {
                    mSubtypeSwitchedByShortCutToast.setText(toastText);
                }
                mSubtypeSwitchedByShortCutToast.show();
            }
        }
    }

    private boolean chooseNewDefaultIMELocked() {
        final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME(
                mSettings.getEnabledInputMethodListLocked());
@@ -4474,13 +4440,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    interactive ? 1 : 0, 0));
        }

        @Override
        public void switchInputMethod(boolean forwardDirection) {
            // Do everything in handler so as not to block the caller.
            mHandler.sendMessage(mHandler.obtainMessage(MSG_SWITCH_IME,
                    forwardDirection ? 1 : 0, 0));
        }

        @Override
        public void hideCurrentInputMethod() {
            mHandler.removeMessages(MSG_HIDE_CURRENT_INPUT_METHOD);
@@ -4493,22 +4452,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        }
    }

    private static String imeWindowStatusToString(final int imeWindowVis) {
        final StringBuilder sb = new StringBuilder();
        boolean first = true;
        if ((imeWindowVis & InputMethodService.IME_ACTIVE) != 0) {
            sb.append("Active");
            first = false;
        }
        if ((imeWindowVis & InputMethodService.IME_VISIBLE) != 0) {
            if (!first) {
                sb.append("|");
            }
            sb.append("Visible");
        }
        return sb.toString();
    }

    @Override
    public IInputContentUriToken createInputContentUriToken(@Nullable IBinder token,
            @Nullable Uri contentUri, @Nullable String packageName) {
@@ -4626,7 +4569,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            method = mCurMethod;
            p.println("  mCurMethod=" + mCurMethod);
            p.println("  mEnabledSession=" + mEnabledSession);
            p.println("  mImeWindowVis=" + imeWindowStatusToString(mImeWindowVis));
            p.println("  mShowRequested=" + mShowRequested
                    + " mShowExplicitlyRequested=" + mShowExplicitlyRequested
                    + " mShowForced=" + mShowForced
+4 −13
Original line number Diff line number Diff line
@@ -3985,22 +3985,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            hideRecentApps(true, false);
        }

        // Handle keyboard layout switching.
        // TODO: Deprecate this behavior when we fully migrate to IME subtype-based layout rotation.
        if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_SPACE
                && ((metaState & KeyEvent.META_CTRL_MASK) != 0)) {
            int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
            mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
            return -1;
        }

        // Handle input method switching.
        // Handle keyboard language switching.
        if (down && repeatCount == 0
                && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
                        || (keyCode == KeyEvent.KEYCODE_SPACE
                                && (metaState & KeyEvent.META_META_MASK) != 0))) {
            final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
            mWindowManagerFuncs.switchInputMethod(forwardDirection);
                                && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
            int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
            mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
            return -1;
        }
        if (mLanguageSwitchKeyPressed && !down
Loading