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

Commit 03e0580e authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Start using InputMethodSettingsRepository

With this CL we start taking advantage of

  InputMethodSettingsRepository,

which enables us to get a cached InputMethodSettings instead of
dynamically querying available IMEs.

To keep the CL as minimum as possible,

  InputMethodManagerService#mSettings

remains unchanged. It will be removed in a subsequent bug 329163064.

There must be no user observable behavior change.

Bug: 329163064
Fix: 309837937
Test: presubmit
Change-Id: Ie2d3b7e9b75790f64789d0c2e96ae46b1dee3a1e
parent 90622cfc
Loading
Loading
Loading
Loading
+20 −60
Original line number Diff line number Diff line
@@ -290,6 +290,10 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    final Context mContext;
    final Resources mRes;
    private final Handler mHandler;

    /**
     * TODO(b/329163064): Remove this field.
     */
    @NonNull
    @MultiUserUnawareField
    private InputMethodSettings mSettings;
@@ -1415,13 +1419,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                final boolean isCurrentUser = (userId == mSettings.getUserId());
                final AdditionalSubtypeMap additionalSubtypeMap =
                        AdditionalSubtypeMapRepository.get(userId);
                final InputMethodSettings settings;
                if (isCurrentUser) {
                    settings = mSettings;
                } else {
                    settings = queryInputMethodServicesInternal(mContext, userId,
                            additionalSubtypeMap, DirectBootAwareness.AUTO);
                }
                final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);

                InputMethodInfo curIm = null;
                String curInputMethodId = settings.getSelectedInputMethod();
@@ -2077,9 +2075,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                        && (!connectionless
                                || mBindingController.supportsConnectionlessStylusHandwriting());
            }
            //TODO(b/197848765): This can be optimized by caching multi-user methodMaps/methodList.
            //TODO(b/210039666): use cache.
            final InputMethodSettings settings = queryMethodMapForUserLocked(userId);
            final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);
            final InputMethodInfo imi = settings.getMethodMap().get(
                    settings.getSelectedInputMethod());
            return imi != null && imi.supportsStylusHandwriting()
@@ -2103,9 +2099,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    private List<InputMethodInfo> getInputMethodListLocked(@UserIdInt int userId,
            @DirectBootAwareness int directBootAwareness, int callingUid) {
        final InputMethodSettings settings;
        if (userId == mSettings.getUserId()
                && directBootAwareness == DirectBootAwareness.AUTO) {
            settings = mSettings;
        if (directBootAwareness == DirectBootAwareness.AUTO) {
            settings = InputMethodSettingsRepository.get(userId);
        } else {
            final AdditionalSubtypeMap additionalSubtypeMap =
                    AdditionalSubtypeMapRepository.get(userId);
@@ -2129,7 +2124,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            methodList = mSettings.getEnabledInputMethodList();
            settings = mSettings;
        } else {
            settings = queryMethodMapForUserLocked(userId);
            settings = InputMethodSettingsRepository.get(userId);
            methodList = settings.getEnabledInputMethodList();
        }
        // filter caller's access to input methods
@@ -2189,22 +2184,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    @GuardedBy("ImfLock.class")
    private List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(String imiId,
            boolean allowsImplicitlyEnabledSubtypes, @UserIdInt int userId, int callingUid) {
        if (userId == mSettings.getUserId()) {
            final InputMethodInfo imi;
            String selectedMethodId = getSelectedMethodIdLocked();
            if (imiId == null && selectedMethodId != null) {
                imi = mSettings.getMethodMap().get(selectedMethodId);
            } else {
                imi = mSettings.getMethodMap().get(imiId);
            }
            if (imi == null || !canCallerAccessInputMethod(
                    imi.getPackageName(), callingUid, userId, mSettings)) {
                return Collections.emptyList();
            }
            return mSettings.getEnabledInputMethodSubtypeList(
                    imi, allowsImplicitlyEnabledSubtypes);
        }
        final InputMethodSettings settings = queryMethodMapForUserLocked(userId);
        final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);
        final InputMethodInfo imi = settings.getMethodMap().get(imiId);
        if (imi == null) {
            return Collections.emptyList();
@@ -4370,8 +4350,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                return mSettings.getLastInputMethodSubtype();
            }

            final InputMethodSettings settings = queryMethodMapForUserLocked(userId);
            return settings.getLastInputMethodSubtype();
            return InputMethodSettingsRepository.get(userId).getLastInputMethodSubtype();
        }
    }

@@ -4447,8 +4426,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        try {
            synchronized (ImfLock.class) {
                final boolean currentUser = (mSettings.getUserId() == userId);
                final InputMethodSettings settings = currentUser
                        ? mSettings : queryMethodMapForUserLocked(userId);
                final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);
                if (!settings.setEnabledInputMethodSubtypes(imeId, subtypeHashCodes)) {
                    return;
                }
@@ -5627,8 +5605,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                return getCurrentInputMethodSubtypeLocked();
            }

            final InputMethodSettings settings = queryMethodMapForUserLocked(userId);
            return settings.getCurrentInputMethodSubtypeForNonCurrentUsers();
            return InputMethodSettingsRepository.get(userId)
                    .getCurrentInputMethodSubtypeForNonCurrentUsers();
        }
    }

@@ -5690,26 +5668,10 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
     */
    @GuardedBy("ImfLock.class")
    private InputMethodInfo queryDefaultInputMethodForUserIdLocked(@UserIdInt int userId) {
        final InputMethodSettings settings;
        if (userId == mSettings.getUserId()) {
            settings = mSettings;
        } else {
            final AdditionalSubtypeMap additionalSubtypeMap =
                    AdditionalSubtypeMapRepository.get(userId);
            settings = queryInputMethodServicesInternal(mContext, userId,
                    additionalSubtypeMap, DirectBootAwareness.AUTO);
        }
        final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);
        return settings.getMethodMap().get(settings.getSelectedInputMethod());
    }

    @GuardedBy("ImfLock.class")
    private InputMethodSettings queryMethodMapForUserLocked(@UserIdInt int userId) {
        final AdditionalSubtypeMap additionalSubtypeMap =
                AdditionalSubtypeMapRepository.get(userId);
        return queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap,
                DirectBootAwareness.AUTO);
    }

    @GuardedBy("ImfLock.class")
    private boolean switchToInputMethodLocked(String imeId, @UserIdInt int userId) {
        if (userId == mSettings.getUserId()) {
@@ -5721,7 +5683,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            setInputMethodLocked(imeId, NOT_A_SUBTYPE_ID);
            return true;
        }
        final InputMethodSettings settings = queryMethodMapForUserLocked(userId);
        final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);
        if (!settings.getMethodMap().containsKey(imeId)
                || !settings.getEnabledInputMethodList().contains(
                        settings.getMethodMap().get(imeId))) {
@@ -5861,7 +5823,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                    setInputMethodEnabledLocked(imeId, enabled);
                    return true;
                }
                final InputMethodSettings settings = queryMethodMapForUserLocked(userId);
                final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);
                if (!settings.getMethodMap().containsKey(imeId)) {
                    return false; // IME is not found.
                }
@@ -6615,7 +6577,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                previouslyEnabled = setInputMethodEnabledLocked(imeId, enabled);
            }
        } else {
            final InputMethodSettings settings = queryMethodMapForUserLocked(userId);
            final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);
            if (enabled) {
                if (!settings.getMethodMap().containsKey(imeId)) {
                    failedToEnableUnknownIme = true;
@@ -6749,10 +6711,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                        nextIme = mSettings.getSelectedInputMethod();
                        nextEnabledImes = mSettings.getEnabledInputMethodList();
                    } else {
                        final AdditionalSubtypeMap additionalSubtypeMap =
                                AdditionalSubtypeMapRepository.get(userId);
                        final InputMethodSettings settings = queryInputMethodServicesInternal(
                                mContext, userId, additionalSubtypeMap, DirectBootAwareness.AUTO);
                        final InputMethodSettings settings =
                                InputMethodSettingsRepository.get(userId);

                        nextEnabledImes = InputMethodInfoUtils.getDefaultEnabledImes(mContext,
                                settings.getMethodList());