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

Commit 1b8e5f03 authored by Yohei Yukawa's avatar Yohei Yukawa Committed by Android (Google) Code Review
Browse files

Merge "Simplify findLastResortApplicableSubtypeLocked" into main

parents 1368ce4f 86eb36c9
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -4073,14 +4073,18 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
                if (enabled != null) {
                    final int enabledCount = enabled.size();
                    final String locale = mCurrentSubtype == null
                            ? mRes.getConfiguration().locale.toString()
                            : mCurrentSubtype.getLocale();
                    final String locale;
                    if (mCurrentSubtype != null
                            && !TextUtils.isEmpty(mCurrentSubtype.getLocale())) {
                        locale = mCurrentSubtype.getLocale();
                    } else {
                        locale = mRes.getConfiguration().locale.toString();
                    }
                    for (int i = 0; i < enabledCount; ++i) {
                        final InputMethodInfo imi = enabled.get(i);
                        if (imi.getSubtypeCount() > 0 && imi.isSystem()) {
                            InputMethodSubtype keyboardSubtype =
                                    SubtypeUtils.findLastResortApplicableSubtypeLocked(mRes,
                                    SubtypeUtils.findLastResortApplicableSubtypeLocked(
                                            SubtypeUtils.getSubtypes(imi),
                                            SubtypeUtils.SUBTYPE_MODE_KEYBOARD, locale, true);
                            if (keyboardSubtype != null) {
@@ -5430,12 +5434,13 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) {
                    mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0);
                } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) {
                    final String locale = mRes.getConfiguration().locale.toString();
                    mCurrentSubtype = SubtypeUtils.findLastResortApplicableSubtypeLocked(
                            mRes, explicitlyOrImplicitlyEnabledSubtypes,
                            SubtypeUtils.SUBTYPE_MODE_KEYBOARD, null, true);
                            explicitlyOrImplicitlyEnabledSubtypes,
                            SubtypeUtils.SUBTYPE_MODE_KEYBOARD, locale, true);
                    if (mCurrentSubtype == null) {
                        mCurrentSubtype = SubtypeUtils.findLastResortApplicableSubtypeLocked(
                                mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, true);
                                explicitlyOrImplicitlyEnabledSubtypes, null, locale, true);
                    }
                }
            } else {
+5 −4
Original line number Diff line number Diff line
@@ -847,14 +847,15 @@ final class InputMethodUtils {
            if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) {
                return explicitlyOrImplicitlyEnabledSubtypes.get(0);
            }
            final String locale = mRes.getConfiguration().locale.toString();
            final InputMethodSubtype subtype = SubtypeUtils.findLastResortApplicableSubtypeLocked(
                    mRes, explicitlyOrImplicitlyEnabledSubtypes, SubtypeUtils.SUBTYPE_MODE_KEYBOARD,
                    null, true);
                    explicitlyOrImplicitlyEnabledSubtypes, SubtypeUtils.SUBTYPE_MODE_KEYBOARD,
                    locale, true);
            if (subtype != null) {
                return subtype;
            }
            return SubtypeUtils.findLastResortApplicableSubtypeLocked(mRes,
                    explicitlyOrImplicitlyEnabledSubtypes, null, null, true);
            return SubtypeUtils.findLastResortApplicableSubtypeLocked(
                    explicitlyOrImplicitlyEnabledSubtypes, null, locale, true);
        }

        boolean setAdditionalInputMethodSubtypes(@NonNull String imeId,
+2 −5
Original line number Diff line number Diff line
@@ -220,7 +220,7 @@ final class SubtypeUtils {

        if (applicableSubtypes.isEmpty()) {
            InputMethodSubtype lastResortKeyboardSubtype = findLastResortApplicableSubtypeLocked(
                    res, subtypes, SUBTYPE_MODE_KEYBOARD, systemLocale, true);
                    subtypes, SUBTYPE_MODE_KEYBOARD, systemLocale, true);
            if (lastResortKeyboardSubtype != null) {
                applicableSubtypes.add(lastResortKeyboardSubtype);
            }
@@ -249,14 +249,11 @@ final class SubtypeUtils {
     * @return the most applicable subtypeId
     */
    static InputMethodSubtype findLastResortApplicableSubtypeLocked(
            Resources res, List<InputMethodSubtype> subtypes, String mode, String locale,
            List<InputMethodSubtype> subtypes, String mode, @NonNull String locale,
            boolean canIgnoreLocaleAsLastResort) {
        if (subtypes == null || subtypes.isEmpty()) {
            return null;
        }
        if (TextUtils.isEmpty(locale)) {
            locale = res.getConfiguration().locale.toString();
        }
        final String language = LocaleUtils.getLanguageFromLocaleString(locale);
        boolean partialMatchFound = false;
        InputMethodSubtype applicableSubtype = null;