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

Commit 23d665cf authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Simplify InputMethodUtils a bit

This is a follow up to our previous CL [1], which introduced

  InputMethodManager#getCurrentInputMethodInfo().

As a preparatoin to start maintaining multiple instances of
InputMethodSettings at the same time, this CL simplifies
InputMethodUtils a bit without changing the behavior.

 [1]: I60a0f67bf7d261d3a4a733adcb8a022ceac6e1db
      2422bcff

Bug: 255799034
Bug: 309837937
Test: atest CtsInputMethodServiceHostTestCases:MultiUserTest
Change-Id: I1a9a09655bd63fc5d8cd1811f82c04001d21c22d
parent 6c984cca
Loading
Loading
Loading
Loading
+10 −36
Original line number Diff line number Diff line
@@ -5442,47 +5442,21 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
     */
    @GuardedBy("ImfLock.class")
    private InputMethodInfo queryDefaultInputMethodForUserIdLocked(@UserIdInt int userId) {
        final String imeId = mSettings.getSelectedInputMethodForUser(userId);
        if (TextUtils.isEmpty(imeId)) {
            Slog.e(TAG, "No default input method found for userId " + userId);
            return null;
        }

        InputMethodInfo curInputMethodInfo;
        if (userId == mSettings.getCurrentUserId()
                && (curInputMethodInfo = mMethodMap.get(imeId)) != null) {
            // clone the InputMethodInfo before returning.
            return new InputMethodInfo(curInputMethodInfo);
        if (userId == mSettings.getCurrentUserId()) {
            return mMethodMap.get(mSettings.getSelectedInputMethod());
        }

        final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>();
        final ArrayList<InputMethodInfo> methodList = new ArrayList<>();
        final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = new ArrayMap<>();
        AdditionalSubtypeUtils.load(additionalSubtypeMap, userId);
        Context userAwareContext =
                mContext.createContextAsUser(UserHandle.of(userId), 0 /* flags */);

        final int flags = PackageManager.GET_META_DATA
                | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
                | PackageManager.MATCH_DIRECT_BOOT_AUTO;
        final List<ResolveInfo> services =
                userAwareContext.getPackageManager().queryIntentServicesAsUser(
                        new Intent(InputMethod.SERVICE_INTERFACE),
                        PackageManager.ResolveInfoFlags.of(flags),
                        userId);
        for (ResolveInfo ri : services) {
            final String imeIdResolved = InputMethodInfo.computeId(ri);
            if (imeId.equals(imeIdResolved)) {
                try {
                    return new InputMethodInfo(
                            userAwareContext, ri, additionalSubtypeMap.get(imeId));
                } catch (Exception e) {
                    Slog.wtf(TAG, "Unable to load input method " + imeId, e);
                }
            }
        }
        // we didn't find the InputMethodInfo for imeId. This shouldn't happen.
        Slog.e(TAG, "Error while locating input method info for imeId: " + imeId);
        return null;
        queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap,
                methodList, DirectBootAwareness.AUTO);
        InputMethodSettings settings = new InputMethodSettings(mContext, methodMap, userId,
                true /* copyOnWrite */);
        return methodMap.get(settings.getSelectedInputMethod());
    }

    private ArrayMap<String, InputMethodInfo> queryMethodMapForUser(@UserIdInt int userId) {
        final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>();
        final ArrayList<InputMethodInfo> methodList = new ArrayList<>();
+0 −10
Original line number Diff line number Diff line
@@ -756,16 +756,6 @@ final class InputMethodUtils {
            return imi;
        }

        @Nullable
        String getSelectedInputMethodForUser(@UserIdInt int userId) {
            final String imi =
                    getStringForUser(Settings.Secure.DEFAULT_INPUT_METHOD, null, userId);
            if (DEBUG) {
                Slog.d(TAG, "getSelectedInputMethodForUserStr: " + imi);
            }
            return imi;
        }

        void putDefaultVoiceInputMethod(String imeId) {
            if (DEBUG) {
                Slog.d(TAG, "putDefaultVoiceInputMethodStr: " + imeId + ", " + mCurrentUserId);