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

Commit 931b02f0 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Remove UMS#mUserStates lock from IMM#getInputMethodList()

With this CL the following methods

 * InputMethodManager#getInputMethodList()
 * InputMethodManager#getInputMethodListAsUser()
 * InputMethodManagerInternal#getInputMethodListAsUser()

stop acquiring

  synchronized (UserManagerService#mUserStates)

internally.

The idea is that we already have all the relevant user lifecycle
events. Thus it would make more sense to have our own canonical user
storage lock/unlock state in UserData rather than always calling into

  UserManagerInternal#isUserUnlockingOrUnlocked(userId),

which internally acquires mUserStates lock in UserManagerService.

This CL should generally make IMMS operations more predictable
regarding whether a user storage is considered to be still locked or
already unlocked. Other than that, the semantics should remain
unchanged.

Bug: 329703038
Bug: 343601565
Bug: 354323416
Test: presubmit
Flag: EXEMPT refactor
Change-Id: I8a83910d770754eef4b81a542d4f21ffc8efe296
parent 9f94e49d
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -718,7 +718,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    userData.mRawInputMethodMap.set(rawMethodMap);
                    final var methodMap = rawMethodMap.toInputMethodMap(additionalSubtypeMap,
                            DirectBootAwareness.AUTO,
                            mUserManagerInternal.isUserUnlockingOrUnlocked(userId));
                            userData.mIsUnlockingOrUnlocked.get());
                    final var settings = InputMethodSettings.create(methodMap, userId);
                    InputMethodSettingsRepository.put(userId, settings);
                }
@@ -842,7 +842,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            final var newMethodMap = userData.mRawInputMethodMap.get().toInputMethodMap(
                    newAdditionalSubtypeMap,
                    DirectBootAwareness.AUTO,
                    mUserManagerInternal.isUserUnlockingOrUnlocked(userId));
                    userData.mIsUnlockingOrUnlocked.get());

            final boolean noUpdate = InputMethodMap.areSame(settings.getMethodMap(), newMethodMap);
            if (noUpdate && imesToBeDisabled.isEmpty()) {
@@ -1072,6 +1072,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            final int userId = user.getUserIdentifier();
            final var userData = mService.getUserData(userId);
            final boolean userUnlocked = true;
            userData.mIsUnlockingOrUnlocked.set(userUnlocked);
            SecureSettingsWrapper.onUserUnlocking(userId);
            final var methodMap = userData.mRawInputMethodMap.get().toInputMethodMap(
                    AdditionalSubtypeMapRepository.get(userId), DirectBootAwareness.AUTO,
@@ -1122,9 +1123,12 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    final var additionalSubtypeMap = AdditionalSubtypeMapRepository.get(userId);
                    final var rawMethodMap = queryRawInputMethodServiceMap(context, userId);
                    userData.mRawInputMethodMap.set(rawMethodMap);

                    final boolean unlocked = userManagerInternal.isUserUnlockingOrUnlocked(userId);
                    userData.mIsUnlockingOrUnlocked.set(unlocked);
                    final var methodMap = rawMethodMap.toInputMethodMap(additionalSubtypeMap,
                            DirectBootAwareness.AUTO,
                            userManagerInternal.isUserUnlockingOrUnlocked(userId));
                            DirectBootAwareness.AUTO, unlocked);

                    final var settings = InputMethodSettings.create(methodMap, userId);
                    InputMethodSettingsRepository.put(userId, settings);

@@ -1152,6 +1156,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            final var additionalSubtypeMap = AdditionalSubtypeMapRepository.get(userId);
            final var rawMethodMap = userData.mRawInputMethodMap.get();
            final boolean userUnlocked = false;  // Stopping a user also locks their storage.
            userData.mIsUnlockingOrUnlocked.set(userUnlocked);
            final var methodMap = rawMethodMap.toInputMethodMap(additionalSubtypeMap,
                    DirectBootAwareness.AUTO, userUnlocked);
            InputMethodSettingsRepository.put(userId,
@@ -1656,7 +1661,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        final var userData = getUserData(userId);
        final var methodMap = userData.mRawInputMethodMap.get().toInputMethodMap(
                AdditionalSubtypeMapRepository.get(userId), directBootAwareness,
                mUserManagerInternal.isUserUnlockingOrUnlocked(userId));
                userData.mIsUnlockingOrUnlocked.get());
        final var settings = InputMethodSettings.create(methodMap, userId);
        // Create a copy.
        final ArrayList<InputMethodInfo> methodList = new ArrayList<>(settings.getMethodList());
@@ -4394,7 +4399,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                try {
                    final var methodMap = userData.mRawInputMethodMap.get().toInputMethodMap(
                            AdditionalSubtypeMapRepository.get(userId), DirectBootAwareness.AUTO,
                            mUserManagerInternal.isUserUnlockingOrUnlocked(userId));
                            userData.mIsUnlockingOrUnlocked.get());
                    final var newSettings = InputMethodSettings.create(methodMap, userId);
                    InputMethodSettingsRepository.put(userId, newSettings);
                    postInputMethodSettingUpdatedLocked(false /* resetDefaultEnabledIme */, userId);
@@ -6296,6 +6301,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            @SuppressWarnings("GuardedBy") Consumer<UserData> userDataDump =
                    u -> {
                        p.println("    mUserId=" + u.mUserId);
                        p.println("      unlocked=" + u.mIsUnlockingOrUnlocked.get());
                        p.println("      hasMainConnection="
                                + u.mBindingController.hasMainConnection());
                        p.println("      isVisibleBound=" + u.mBindingController.isVisibleBound());
+9 −0
Original line number Diff line number Diff line
@@ -154,6 +154,15 @@ final class UserData {
    @NonNull
    final AtomicBoolean mImeDrawsNavBar = new AtomicBoolean();


    /**
     * {@code true} if the user storage is considered to be unlocked.
     *
     * @see com.android.server.pm.UserManagerInternal#isUserUnlockingOrUnlocked(int)
     */
    @NonNull
    final AtomicBoolean mIsUnlockingOrUnlocked = new AtomicBoolean(false);

    /**
     * Intended to be instantiated only from this file.
     */