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
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 7992190..2f1fe8a 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -1070,13 +1070,15 @@
public void onUserUnlocking(@NonNull TargetUser user) {
// Called on ActivityManager thread. Do not block the calling thread.
final int userId = user.getUserIdentifier();
+ 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,
+ userUnlocked);
+ final var newSettings = InputMethodSettings.create(methodMap, userId);
+ InputMethodSettingsRepository.put(userId, newSettings);
mService.mIoHandler.post(() -> {
- final var userData = mService.getUserData(userId);
- final var methodMap = userData.mRawInputMethodMap.get().toInputMethodMap(
- AdditionalSubtypeMapRepository.get(userId), DirectBootAwareness.AUTO, true);
- final var newSettings = InputMethodSettings.create(methodMap, userId);
- InputMethodSettingsRepository.put(userId, newSettings);
synchronized (ImfLock.class) {
if (!mService.mSystemReady) {
return;
@@ -1142,16 +1144,18 @@
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 var methodMap = rawMethodMap.toInputMethodMap(additionalSubtypeMap,
- DirectBootAwareness.AUTO, false /* userUnlocked */);
- InputMethodSettingsRepository.put(userId,
- InputMethodSettings.create(methodMap, userId));
- });
+ 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, userUnlocked);
+ InputMethodSettingsRepository.put(userId,
+ InputMethodSettings.create(methodMap, userId));
}
}