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

Commit 0c32789b authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Remove getCurrentInputMethodSubtypeForNonCurrentUsers()

This is a follow up CL to my previous CL [1], which enabled background
users to call

  InputMethodManager#getCurrentInputMethodSubtype()

by introducing

  #getCurrentInputMethodSubtypeForNonCurrentUsers().

The reason why we could not simply reuse the same implementation for

  InputMethodManagerService#getCurrentInputMethodSubtypeLocked()

was due to the fact that IMMS#mCurrentSubtype was not per-user.

Now that #mCurrentSubtype is fully per-user [2], we should be able to
unify the code.

 [1]: Icb09f9cb1a4147884faa9952b2e03ec4afa9f0b1
      a6a20724
 [2]: Ibcc39212ead12c2897f8f52cb9f15b1d39959f71
      769e7472

Bug: 325515685
Bug: 350386877
Test: presubmit
Flag: EXEMPT refactor
Change-Id: Ia52b556ff3df3d2b50b9d62198455e5ce6ebe659
parent 6a6bc9e4
Loading
Loading
Loading
Loading
+2 −14
Original line number Diff line number Diff line
@@ -5541,26 +5541,14 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    Manifest.permission.INTERACT_ACROSS_USERS_FULL, null);
        }
        synchronized (ImfLock.class) {
            if (mCurrentUserId == userId) {
            // TODO(b/347083680): The method below has questionable behaviors.
            return getCurrentInputMethodSubtypeLocked(userId);
        }

            return InputMethodSettingsRepository.get(userId)
                    .getCurrentInputMethodSubtypeForNonCurrentUsers();
        }
    }

    /**
     * Returns the current {@link InputMethodSubtype} for the current user.
     *
     * <p>CAVEATS: You must also update
     * {@link InputMethodSettings#getCurrentInputMethodSubtypeForNonCurrentUsers()}
     * when you update the algorithm of this method.</p>
     *
     * <p>TODO: Address code duplication between this and
     * {@link InputMethodSettings#getCurrentInputMethodSubtypeForNonCurrentUsers()}.</p>
     *
     * <p>Also this method has had questionable behaviors:</p>
     * <ul>
     *     <li>Calling this method can update {@link InputMethodBindingController#mCurrentSubtype}.
+0 −51
Original line number Diff line number Diff line
@@ -571,57 +571,6 @@ final class InputMethodSettings {
        }
    }

    /**
     * A variant of {@link InputMethodManagerService#getCurrentInputMethodSubtypeLocked()} for
     * non-current users.
     *
     * <p>TODO: Address code duplication between this and
     * {@link InputMethodManagerService#getCurrentInputMethodSubtypeLocked()}.</p>
     *
     * @return {@link InputMethodSubtype} if exists. {@code null} otherwise.
     */
    @Nullable
    InputMethodSubtype getCurrentInputMethodSubtypeForNonCurrentUsers() {
        final String selectedMethodId = getSelectedInputMethod();
        if (selectedMethodId == null) {
            return null;
        }
        final InputMethodInfo imi = mMethodMap.get(selectedMethodId);
        if (imi == null || imi.getSubtypeCount() == 0) {
            return null;
        }

        final int subtypeHashCode = getSelectedInputMethodSubtypeHashCode();
        if (subtypeHashCode != INVALID_SUBTYPE_HASHCODE) {
            final int subtypeIndex = SubtypeUtils.getSubtypeIdFromHashCode(imi,
                    subtypeHashCode);
            if (subtypeIndex >= 0) {
                return imi.getSubtypeAt(subtypeIndex);
            }
        }

        // If there are no selected subtypes, the framework will try to find the most applicable
        // subtype from explicitly or implicitly enabled subtypes.
        final List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes =
                getEnabledInputMethodSubtypeList(imi, true);
        // If there is only one explicitly or implicitly enabled subtype, just returns it.
        if (explicitlyOrImplicitlyEnabledSubtypes.isEmpty()) {
            return null;
        }
        if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) {
            return explicitlyOrImplicitlyEnabledSubtypes.get(0);
        }
        final String locale = SystemLocaleWrapper.get(mUserId).get(0).toString();
        final InputMethodSubtype subtype = SubtypeUtils.findLastResortApplicableSubtype(
                explicitlyOrImplicitlyEnabledSubtypes, SubtypeUtils.SUBTYPE_MODE_KEYBOARD,
                locale, true);
        if (subtype != null) {
            return subtype;
        }
        return SubtypeUtils.findLastResortApplicableSubtype(
                explicitlyOrImplicitlyEnabledSubtypes, null, locale, true);
    }

    @NonNull
    AdditionalSubtypeMap getNewAdditionalSubtypeMap(@NonNull String imeId,
            @NonNull ArrayList<InputMethodSubtype> subtypes,