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

Commit 8696b0b7 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Move getCurrentInputMethodSubtype() to InputMethodBindingController

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

Bug: 325515685
Test: presubmit
Flag: EXEMPT refactor
Change-Id: I96a44772ff96ea0fbf3277c244e59487eff2e463
parent 0c32789b
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -664,6 +664,36 @@ final class InputMethodBindingController {
        }
    }

    /**
     * Returns the current {@link InputMethodSubtype}.
     *
     * <p>Also this method has had questionable behaviors:</p>
     * <ul>
     *     <li>Calling this method can update {@link #mCurrentSubtype}.</li>
     *     <li>This method may return {@link #mCurrentSubtype} as-is, even if it does not belong to
     *     the current IME.</li>
     * </ul>
     * <p>TODO(b/347083680): Address above issues.</p>
     */
    @GuardedBy("ImfLock.class")
    @Nullable
    InputMethodSubtype getCurrentInputMethodSubtype() {
        final var selectedMethodId = getSelectedMethodId();
        if (selectedMethodId == null) {
            return null;
        }
        final InputMethodSettings settings = InputMethodSettingsRepository.get(mUserId);
        final InputMethodInfo imi = settings.getMethodMap().get(selectedMethodId);
        if (imi == null || imi.getSubtypeCount() == 0) {
            return null;
        }
        final var subtype = SubtypeUtils.getCurrentInputMethodSubtype(imi, settings,
                mCurrentSubtype);
        mCurrentSubtype = subtype;
        return subtype;
    }


    @GuardedBy("ImfLock.class")
    void setDisplayIdToShowIme(int displayId) {
        mDisplayIdToShowIme = displayId;
+4 −33
Original line number Diff line number Diff line
@@ -3038,7 +3038,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                // getCurrentInputMethodSubtype.
                subtypeId = NOT_A_SUBTYPE_ID;
                // TODO(b/347083680): The method below has questionable behaviors.
                newSubtype = getCurrentInputMethodSubtypeLocked(userId);
                newSubtype = bindingController.getCurrentInputMethodSubtype();
                if (newSubtype != null) {
                    for (int i = 0; i < subtypeCount; ++i) {
                        if (Objects.equals(newSubtype, info.getSubtypeAt(i))) {
@@ -5486,7 +5486,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                newSubtypeHashcode = INVALID_SUBTYPE_HASHCODE;
                // If the subtype is not specified, choose the most applicable one
                // TODO(b/347083680): The method below has questionable behaviors.
                newSubtype = getCurrentInputMethodSubtypeLocked(userId);
                newSubtype = bindingController.getCurrentInputMethodSubtype();
            }
        }
        settings.putSelectedSubtype(newSubtypeHashcode);
@@ -5541,39 +5541,10 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    Manifest.permission.INTERACT_ACROSS_USERS_FULL, null);
        }
        synchronized (ImfLock.class) {
            final var bindingController = getInputMethodBindingController(userId);
            // TODO(b/347083680): The method below has questionable behaviors.
            return getCurrentInputMethodSubtypeLocked(userId);
        }
    }

    /**
     * Returns the current {@link InputMethodSubtype} for the current user.
     *
     * <p>Also this method has had questionable behaviors:</p>
     * <ul>
     *     <li>Calling this method can update {@link InputMethodBindingController#mCurrentSubtype}.
     *     </li>
     *     <li>This method may return {@link InputMethodBindingController#mCurrentSubtype} as-is,
     *     even if it does not belong to the current IME.</li>
     * </ul>
     * <p>TODO(b/347083680): Address above issues.</p>
     */
    @GuardedBy("ImfLock.class")
    InputMethodSubtype getCurrentInputMethodSubtypeLocked(@UserIdInt int userId) {
        final var selectedMethodId = getInputMethodBindingController(userId).getSelectedMethodId();
        if (selectedMethodId == null) {
            return null;
            return bindingController.getCurrentInputMethodSubtype();
        }
        final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);
        final InputMethodInfo imi = settings.getMethodMap().get(selectedMethodId);
        if (imi == null || imi.getSubtypeCount() == 0) {
            return null;
        }
        final var bindingController = getInputMethodBindingController(userId);
        final var subtype = SubtypeUtils.getCurrentInputMethodSubtype(imi, settings,
                bindingController.getCurrentSubtype());
        bindingController.setCurrentSubtype(subtype);
        return subtype;
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ final class InputMethodMenuController {

        if (preferredInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
            final InputMethodSubtype currentSubtype =
                    mService.getCurrentInputMethodSubtypeLocked(userId);
                    bindingController.getCurrentInputMethodSubtype();
            if (currentSubtype != null) {
                final String curMethodId = bindingController.getSelectedMethodId();
                final InputMethodInfo currentImi =