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

Commit 90bc0740 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ia52b556f,I83844835 into main

* changes:
  Remove getCurrentInputMethodSubtypeForNonCurrentUsers()
  Make IMMS#getCurrentInputMethodSubtypeLocked() multi-user aware
parents 77a06f43 0c32789b
Loading
Loading
Loading
Loading
+9 −21
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();
                newSubtype = getCurrentInputMethodSubtypeLocked(userId);
                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();
                newSubtype = getCurrentInputMethodSubtypeLocked(userId);
            }
        }
        settings.putSelectedSubtype(newSubtypeHashcode);
@@ -5541,37 +5541,25 @@ 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();
            }

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

    /**
     * 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 #mCurrentSubtype}.</li>
     *     <li>This method may return {@link #mCurrentSubtype} as-is, even if it does not belong
     *         to the current IME.</li>
     *     <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() {
        final int userId = mCurrentUserId;
    InputMethodSubtype getCurrentInputMethodSubtypeLocked(@UserIdInt int userId) {
        final var selectedMethodId = getInputMethodBindingController(userId).getSelectedMethodId();
        if (selectedMethodId == null) {
            return null;
+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();
                    mService.getCurrentInputMethodSubtypeLocked(userId);
            if (currentSubtype != null) {
                final String curMethodId = bindingController.getSelectedMethodId();
                final InputMethodInfo currentImi =
+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,