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

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

Unextract getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked()

By un-extracting it, we no longer need to instantiate HashMap just to
pass data from InputMethodSettings to InputMethodAndSubtypeList.

This also helps us elimicate the use of HashMap/HashSet in
com.android.server.inputmethod (Bug 119839847).

This is a mechanical refactoring.  There should be no user-visible
behavior change.

Fix: 119837138
Test: Manually verified as follows:
  1. Open Settings.
  2. Go to System -> Languages & input -> Languages
  3. Tap "Add a language"
  4. Select "Afrikaans" -> Suid-Afrika
  5. make -j SoftKeyboard
  6. adb install -r $OUT/system/app/SoftKeyboard/SoftKeyboard.apk
  7. adb shell ime enable com.example.android.softkeyboard/.SoftKeyboard
  8. Tap the keyboard icon on the navigation bar.
  9. Make sure that items are sorted in the following order:
     * English (US) - Android Keyboard (AOSP)
     * Afrikaans - Android Keyboard (AOSP)
     * English (United States) - Sample Soft Keyboard
Change-Id: I0444b9bd82f63bbca1841144f5c02b0b34acc807
parent cf3bbffa
Loading
Loading
Loading
Loading
+8 −11
Original line number Original line Diff line number Diff line
@@ -31,7 +31,6 @@ import com.android.server.inputmethod.InputMethodUtils.InputMethodSettings;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.HashSet;
import java.util.List;
import java.util.List;
import java.util.Locale;
import java.util.Locale;
@@ -184,11 +183,8 @@ final class InputMethodSubtypeSwitchingController {


        public List<ImeSubtypeListItem> getSortedInputMethodAndSubtypeList(
        public List<ImeSubtypeListItem> getSortedInputMethodAndSubtypeList(
                boolean includeAuxiliarySubtypes, boolean isScreenLocked) {
                boolean includeAuxiliarySubtypes, boolean isScreenLocked) {
            final ArrayList<ImeSubtypeListItem> imList = new ArrayList<>();
            final ArrayList<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
            final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis =
            if (imis.isEmpty()) {
                    mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(
                            mContext);
            if (immis == null || immis.size() == 0) {
                return Collections.emptyList();
                return Collections.emptyList();
            }
            }
            if (isScreenLocked && includeAuxiliarySubtypes) {
            if (isScreenLocked && includeAuxiliarySubtypes) {
@@ -197,11 +193,12 @@ final class InputMethodSubtypeSwitchingController {
                }
                }
                includeAuxiliarySubtypes = false;
                includeAuxiliarySubtypes = false;
            }
            }
            for (InputMethodInfo imi : immis.keySet()) {
            final ArrayList<ImeSubtypeListItem> imList = new ArrayList<>();
                if (imi == null) {
            final int numImes = imis.size();
                    continue;
            for (int i = 0; i < numImes; ++i) {
                }
                final InputMethodInfo imi = imis.get(i);
                List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypeList = immis.get(imi);
                final List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypeList =
                        mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
                HashSet<String> enabledSubtypeSet = new HashSet<>();
                HashSet<String> enabledSubtypeSet = new HashSet<>();
                for (InputMethodSubtype subtype : explicitlyOrImplicitlyEnabledSubtypeList) {
                for (InputMethodSubtype subtype : explicitlyOrImplicitlyEnabledSubtypeList) {
                    enabledSubtypeSet.add(String.valueOf(subtype.hashCode()));
                    enabledSubtypeSet.add(String.valueOf(subtype.hashCode()));
+0 −11
Original line number Original line Diff line number Diff line
@@ -1277,17 +1277,6 @@ final class InputMethodUtils {
            }
            }
        }
        }


        public HashMap<InputMethodInfo, List<InputMethodSubtype>>
                getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(Context context) {
            HashMap<InputMethodInfo, List<InputMethodSubtype>> enabledInputMethodAndSubtypes =
                    new HashMap<>();
            for (InputMethodInfo imi: getEnabledInputMethodListLocked()) {
                enabledInputMethodAndSubtypes.put(
                        imi, getEnabledInputMethodSubtypeListLocked(context, imi, true));
            }
            return enabledInputMethodAndSubtypes;
        }

        public void dumpLocked(final Printer pw, final String prefix) {
        public void dumpLocked(final Printer pw, final String prefix) {
            pw.println(prefix + "mCurrentUserId=" + mCurrentUserId);
            pw.println(prefix + "mCurrentUserId=" + mCurrentUserId);
            pw.println(prefix + "mCurrentProfileIds=" + Arrays.toString(mCurrentProfileIds));
            pw.println(prefix + "mCurrentProfileIds=" + Arrays.toString(mCurrentProfileIds));