diff options
author | 2024-01-03 22:27:55 +0900 | |
---|---|---|
committer | 2024-01-03 22:27:55 +0900 | |
commit | 22b9aa5b474761b64ba78455860e376b80477a3a (patch) | |
tree | 1d09a80d48fa110b99c86dc8eadca21f5e720d80 | |
parent | 46e75da5a1a2f9d53d8a504861436e35849e5c58 (diff) |
Prepare to make HardwareKeyboardShortcutController per-user
Previously we have reused the same instance of
InputMethodManagerService#mHardwareKeyboardShortcutController
across users, which needs to be updated before supporting concurrent
multiple users in InputMethodManagerService.
With this CL a new instance of HardwareKeyboardShortcutController will
be recreated every time the current IME user is switching. This is an
important milestone to keep maintaining multiple instances of
HardwareKeyboardShortcutController for each user.
There must be no observable behavior change in this CL.
Bug: 309868254
Bug: 309837937
Test: presubmit
Change-Id: I679cbe81a475566d9f9651c9977023025bcae3a6
-rw-r--r-- | services/core/java/com/android/server/inputmethod/HardwareKeyboardShortcutController.java | 21 | ||||
-rw-r--r-- | services/core/java/com/android/server/inputmethod/InputMethodManagerService.java | 25 |
2 files changed, 39 insertions, 7 deletions
diff --git a/services/core/java/com/android/server/inputmethod/HardwareKeyboardShortcutController.java b/services/core/java/com/android/server/inputmethod/HardwareKeyboardShortcutController.java index f0e4b0f59b06..898d5a5e0644 100644 --- a/services/core/java/com/android/server/inputmethod/HardwareKeyboardShortcutController.java +++ b/services/core/java/com/android/server/inputmethod/HardwareKeyboardShortcutController.java @@ -19,6 +19,8 @@ package com.android.server.inputmethod; import android.annotation.AnyThread; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.UserIdInt; +import android.util.ArrayMap; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodSubtype; @@ -33,9 +35,26 @@ final class HardwareKeyboardShortcutController { @GuardedBy("ImfLock.class") private final ArrayList<InputMethodSubtypeHandle> mSubtypeHandles = new ArrayList<>(); + @UserIdInt + private final int mUserId; + + @AnyThread + @UserIdInt + int getUserId() { + return mUserId; + } + + HardwareKeyboardShortcutController( + @NonNull ArrayMap<String, InputMethodInfo> methodMap, @UserIdInt int userId) { + mUserId = userId; + reset(methodMap); + } + @GuardedBy("ImfLock.class") - void reset(@NonNull InputMethodUtils.InputMethodSettings settings) { + void reset(@NonNull ArrayMap<String, InputMethodInfo> methodMap) { mSubtypeHandles.clear(); + final InputMethodUtils.InputMethodSettings settings = + new InputMethodUtils.InputMethodSettings(methodMap, mUserId); for (final InputMethodInfo imi : settings.getEnabledInputMethodListLocked()) { if (!imi.shouldShowInInputMethodPicker()) { continue; diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index bcb21dda604c..94811585dc56 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -319,8 +319,9 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub // TODO: Instantiate mSwitchingController for each user. @NonNull private InputMethodSubtypeSwitchingController mSwitchingController; - final HardwareKeyboardShortcutController mHardwareKeyboardShortcutController = - new HardwareKeyboardShortcutController(); + // TODO: Instantiate mHardwareKeyboardShortcutController for each user. + @NonNull + private HardwareKeyboardShortcutController mHardwareKeyboardShortcutController; /** * Tracks how many times {@link #mMethodMap} was updated. @@ -1701,7 +1702,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked(context, mMethodMap, userId); - mHardwareKeyboardShortcutController.reset(mSettings); + mHardwareKeyboardShortcutController = + new HardwareKeyboardShortcutController(mMethodMap, userId); mMenuController = new InputMethodMenuController(this); mBindingController = bindingControllerForTesting != null @@ -3215,8 +3217,13 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked( mContext, mMethodMap, mSettings.getCurrentUserId()); } - - mHardwareKeyboardShortcutController.reset(mSettings); + // TODO: Instantiate mHardwareKeyboardShortcutController for each user. + if (mSettings.getCurrentUserId() == mHardwareKeyboardShortcutController.getUserId()) { + mHardwareKeyboardShortcutController.reset(mMethodMap); + } else { + mHardwareKeyboardShortcutController = new HardwareKeyboardShortcutController( + mMethodMap, mSettings.getCurrentUserId()); + } sendOnNavButtonFlagsChangedLocked(); } @@ -5224,7 +5231,13 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked( mContext, mMethodMap, mSettings.getCurrentUserId()); } - mHardwareKeyboardShortcutController.reset(mSettings); + // TODO: Instantiate mHardwareKeyboardShortcutController for each user. + if (mSettings.getCurrentUserId() == mHardwareKeyboardShortcutController.getUserId()) { + mHardwareKeyboardShortcutController.reset(mMethodMap); + } else { + mHardwareKeyboardShortcutController = new HardwareKeyboardShortcutController( + mMethodMap, mSettings.getCurrentUserId()); + } sendOnNavButtonFlagsChangedLocked(); |