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

Commit c84144bb authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Eagaly update data in onUserUnlocking() and onUserStopped()

User unlocking scenario (the first user unlock that triggers storage
unlocking) remains to be a tricky corner case in IMMS (Bug 315382143
and Bug 356116143 for examples).

For better predictability, with this CL we start updating

  InputMethodSettingsRepository

with the updated InputMethodSettings before returning from
onUserUnlocking() and onUserStopped() with an assumption that such
operations are fast enough and will not be caught in our existing
benchmarks around user switching.

There should be no semantic change in this CL.

Bug: 329703038
Test: presubmit
Flag: EXEMPT refactor
Change-Id: I814958f1f5ac5b451627eea640a96328892862ec
parent c39c6979
Loading
Loading
Loading
Loading
+18 −14
Original line number Diff line number Diff line
@@ -1070,13 +1070,15 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        public void onUserUnlocking(@NonNull TargetUser user) {
            // Called on ActivityManager thread. Do not block the calling thread.
            final int userId = user.getUserIdentifier();
            SecureSettingsWrapper.onUserUnlocking(userId);
            mService.mIoHandler.post(() -> {
            final var userData = mService.getUserData(userId);
            final boolean userUnlocked = true;
            SecureSettingsWrapper.onUserUnlocking(userId);
            final var methodMap = userData.mRawInputMethodMap.get().toInputMethodMap(
                        AdditionalSubtypeMapRepository.get(userId), DirectBootAwareness.AUTO, true);
                    AdditionalSubtypeMapRepository.get(userId), DirectBootAwareness.AUTO,
                    userUnlocked);
            final var newSettings = InputMethodSettings.create(methodMap, userId);
            InputMethodSettingsRepository.put(userId, newSettings);
            mService.mIoHandler.post(() -> {
                synchronized (ImfLock.class) {
                    if (!mService.mSystemReady) {
                        return;
@@ -1142,16 +1144,18 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        public void onUserStopped(@NonNull TargetUser user) {
            final int userId = user.getUserIdentifier();
            // Called on ActivityManager thread.

            // Following operations should be trivial and fast enough, so do not dispatch them to
            // the IO thread.
            SecureSettingsWrapper.onUserStopped(userId);
            mService.mIoHandler.post(() -> {
            final var userData = mService.getUserData(userId);
            final var additionalSubtypeMap = AdditionalSubtypeMapRepository.get(userId);
            final var rawMethodMap = userData.mRawInputMethodMap.get();
            final boolean userUnlocked = false;  // Stopping a user also locks their storage.
            final var methodMap = rawMethodMap.toInputMethodMap(additionalSubtypeMap,
                        DirectBootAwareness.AUTO, false /* userUnlocked */);
                    DirectBootAwareness.AUTO, userUnlocked);
            InputMethodSettingsRepository.put(userId,
                    InputMethodSettings.create(methodMap, userId));
            });
        }
    }