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

Commit 7a1b3dca authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Add InputMethodBindingController#getSelectedMethod()

This is a preparation before making

  InputMethodManagerService#mSwitchingController

per-user.

The following code is often used in InputMethodManagerService.

  final var settings =
     InputMethodSettingsRepository.get(userId);
  final var imi =
     settings.getMethodMap().get(getSelectedMethodIdLocked());

Let's add a utility method to InputMethodBindingController so that we
can avoid the above common code.

This is a mechanical refactoring CL. There must be no observable
behavior change.

Bug: 305849394
Test: presubmit
Flag: EXEMPT refactor
Change-Id: I0eda340a55141617a7a5c2642e7bebbfe71e71f9
parent 25baebe5
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -194,6 +194,18 @@ final class InputMethodBindingController {
        mSelectedMethodId = selectedMethodId;
    }

    /**
     * Returns {@link InputMethodInfo} that is queried from {@link #getSelectedMethodId()}.
     *
     * @return {@link InputMethodInfo} whose IME ID is the same as {@link #getSelectedMethodId()}.
     *         {@code null} otherwise
     */
    @GuardedBy("ImfLock.class")
    @Nullable
    InputMethodInfo getSelectedMethod() {
        return InputMethodSettingsRepository.get(mUserId).getMethodMap().get(mSelectedMethodId);
    }

    /**
     * The token we have made for the currently active input method, to
     * identify it in the future.
+7 −8
Original line number Diff line number Diff line
@@ -4186,10 +4186,10 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.

    @GuardedBy("ImfLock.class")
    private boolean switchToNextInputMethodLocked(@Nullable IBinder token, boolean onlyCurrentIme) {
        final InputMethodSettings settings = InputMethodSettingsRepository.get(mCurrentUserId);
        final int userId = mCurrentUserId;
        final var currentImi = getInputMethodBindingController(userId).getSelectedMethod();
        final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
                onlyCurrentIme, settings.getMethodMap().get(getSelectedMethodIdLocked()),
                mCurrentSubtype);
                onlyCurrentIme, currentImi, mCurrentSubtype);
        if (nextSubtype == null) {
            return false;
        }
@@ -4204,10 +4204,10 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            if (!calledWithValidTokenLocked(token)) {
                return false;
            }
            final InputMethodSettings settings = InputMethodSettingsRepository.get(mCurrentUserId);
            final int userId = mCurrentUserId;
            final var currentImi = getInputMethodBindingController(userId).getSelectedMethod();
            final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
                    false /* onlyCurrentIme */,
                    settings.getMethodMap().get(getSelectedMethodIdLocked()), mCurrentSubtype);
                    false /* onlyCurrentIme */, currentImi, mCurrentSubtype);
            return nextSubtype != null;
        }
    }
@@ -4642,8 +4642,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            if (mCurrentUserId != mSwitchingController.getUserId()) {
                return;
            }
            final InputMethodInfo imi = InputMethodSettingsRepository.get(mCurrentUserId)
                    .getMethodMap().get(getSelectedMethodIdLocked());
            final var imi = getInputMethodBindingController(mCurrentUserId).getSelectedMethod();
            if (imi != null) {
                mSwitchingController.onUserActionLocked(imi, mCurrentSubtype);
            }