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

Commit 4d88d1b1 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Clarify when IMMS#mSettings gets updated

As a preparation to introduce per-user InputMethodSettings cache, this
CL aims to clarify when

  InputMethodManagerService#mSettings

gets updated and how, by extracting its update logic out of

  InputMethodManagerService#buildInputMethodListLocked

and renaming that method to

  IMMS#postInputMethodSettingUpdatedLocked.

This is still a mechanical code change. There must be no observable
behavior change.

Bug: 309837937
Test: presubmit
Change-Id: Ie37cd8043f15f2a820205542b4d9d67f1933ca82
parent ed1a8280
Loading
Loading
Loading
Loading
+33 −17
Original line number Diff line number Diff line
@@ -1208,7 +1208,10 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            if (!mSystemReady) {
                return;
            }
            buildInputMethodListLocked(true);
            mSettings = queryInputMethodServicesInternal(mContext, mSettings.getUserId(),
                    AdditionalSubtypeMapRepository.get(mSettings.getUserId()),
                    DirectBootAwareness.AUTO);
            postInputMethodSettingUpdatedLocked(true /* resetDefaultEnabledIme */);
            // If the locale is changed, needs to reset the default ime
            resetDefaultImeLocked(mContext);
            updateFromSettingsLocked(true);
@@ -1455,12 +1458,16 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                            settings.getMethodMap());
                }

                if (!isCurrentUser
                        || !(additionalSubtypeChanged || shouldRebuildInputMethodListLocked())) {
                if (!isCurrentUser) {
                    return;
                }

                buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
                if (!(additionalSubtypeChanged || shouldRebuildInputMethodListLocked())) {
                    return;
                }
                mSettings = queryInputMethodServicesInternal(mContext, userId,
                        newAdditionalSubtypeMap, DirectBootAwareness.AUTO);
                postInputMethodSettingUpdatedLocked(false /* resetDefaultEnabledIme */);

                boolean changed = false;

@@ -1619,14 +1626,16 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            if (userId != currentUserId) {
                return;
            }
            mSettings = InputMethodSettings.createEmptyMap(userId);
            if (mSystemReady) {
            if (!mSystemReady) {
                return;
            }
            mSettings = queryInputMethodServicesInternal(mContext, userId,
                    AdditionalSubtypeMapRepository.get(userId), DirectBootAwareness.AUTO);
            // We need to rebuild IMEs.
                buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
            postInputMethodSettingUpdatedLocked(false /* resetDefaultEnabledIme */);
            updateInputMethodsFromSettingsLocked(true /* enabledChanged */);
        }
    }
    }

    @GuardedBy("ImfLock.class")
    void scheduleSwitchUserTaskLocked(@UserIdInt int userId,
@@ -1856,7 +1865,10 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        // The mSystemReady flag is set during boot phase,
        // and user switch would not happen at that time.
        resetCurrentMethodAndClientLocked(UnbindReason.SWITCH_USER);
        buildInputMethodListLocked(initialUserSwitch);

        mSettings = queryInputMethodServicesInternal(mContext, newUserId,
                AdditionalSubtypeMapRepository.get(newUserId), DirectBootAwareness.AUTO);
        postInputMethodSettingUpdatedLocked(initialUserSwitch /* resetDefaultEnabledIme */);
        if (TextUtils.isEmpty(mSettings.getSelectedInputMethod())) {
            // This is the first time of the user switch and
            // set the current ime to the proper one.
@@ -1937,7 +1949,11 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub

                final String defaultImiId = mSettings.getSelectedInputMethod();
                final boolean imeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId);
                buildInputMethodListLocked(!imeSelectedOnBoot /* resetDefaultEnabledIme */);
                mSettings = queryInputMethodServicesInternal(mContext, currentUserId,
                        AdditionalSubtypeMapRepository.get(mSettings.getUserId()),
                        DirectBootAwareness.AUTO);
                postInputMethodSettingUpdatedLocked(
                        !imeSelectedOnBoot /* resetDefaultEnabledIme */);
                updateFromSettingsLocked(true);
                InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(
                        getPackageManagerForUser(mContext, currentUserId),
@@ -4382,7 +4398,11 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                if (isCurrentUser) {
                    final long ident = Binder.clearCallingIdentity();
                    try {
                        buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
                        mSettings = queryInputMethodServicesInternal(mContext,
                                mSettings.getUserId(),
                                AdditionalSubtypeMapRepository.get(mSettings.getUserId()),
                                DirectBootAwareness.AUTO);
                        postInputMethodSettingUpdatedLocked(false /* resetDefaultEnabledIme */);
                    } finally {
                        Binder.restoreCallingIdentity(ident);
                    }
@@ -5310,7 +5330,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    }

    @GuardedBy("ImfLock.class")
    void buildInputMethodListLocked(boolean resetDefaultEnabledIme) {
    void postInputMethodSettingUpdatedLocked(boolean resetDefaultEnabledIme) {
        if (DEBUG) {
            Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme
                    + " \n ------ caller=" + Debug.getCallers(10));
@@ -5322,10 +5342,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        mMethodMapUpdateCount++;
        mMyPackageMonitor.clearKnownImePackageNamesLocked();

        mSettings = queryInputMethodServicesInternal(mContext, mSettings.getUserId(),
                AdditionalSubtypeMapRepository.get(mSettings.getUserId()),
                DirectBootAwareness.AUTO);

        // Construct the set of possible IME packages for onPackageChanged() to avoid false
        // negatives when the package state remains to be the same but only the component state is
        // changed.