Always propagate userId to InputMethodMenuController
This is a mechanical change to get rid of
InputMethodManagerService#getCurrentImeUserIdLocked()
by always propagating userId from
InputMethodManagerService
to
InputMethodMenuController.
There must be no observable behavior change.
Bug: 350386877
Test: manually tested with IME switcher
Flag: EXEMPT refactor
Change-Id: I158f39edf0b8bc50824fd4c1440bf20db6f698e7
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 730077c..0a60faa 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -619,7 +619,7 @@
case Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD: {
if (!mNewInputMethodSwitcherMenuEnabled) {
if (userId == mCurrentUserId) {
- mMenuController.updateKeyboardFromSettingsLocked();
+ mMenuController.updateKeyboardFromSettingsLocked(userId);
}
}
break;
@@ -693,7 +693,7 @@
senderUserId);
}
} else {
- mMenuController.hideInputMethodMenu();
+ mMenuController.hideInputMethodMenu(senderUserId);
}
} else {
Slog.w(TAG, "Unexpected intent " + intent);
@@ -1222,12 +1222,6 @@
}
}
- @GuardedBy("ImfLock.class")
- @UserIdInt
- int getCurrentImeUserIdLocked() {
- return mCurrentUserId;
- }
-
private final class InkWindowInitializer implements Runnable {
public void run() {
synchronized (ImfLock.class) {
@@ -1826,7 +1820,7 @@
if (mNewInputMethodSwitcherMenuEnabled) {
mMenuControllerNew.hide(bindingController.getCurTokenDisplayId(), userId);
} else {
- mMenuController.hideInputMethodMenuLocked();
+ mMenuController.hideInputMethodMenuLocked(userId);
}
}
}
@@ -2860,7 +2854,7 @@
void updateFromSettingsLocked(boolean enabledMayChange, @UserIdInt int userId) {
updateInputMethodsFromSettingsLocked(enabledMayChange, userId);
if (!mNewInputMethodSwitcherMenuEnabled) {
- mMenuController.updateKeyboardFromSettingsLocked();
+ mMenuController.updateKeyboardFromSettingsLocked(userId);
}
}
@@ -5071,7 +5065,7 @@
mMenuControllerNew.show(menuItems, selectedIndex, displayId, userId);
} else {
mMenuController.showInputMethodMenuLocked(showAuxSubtypes, displayId,
- lastInputMethodId, lastInputMethodSubtypeId, imList);
+ lastInputMethodId, lastInputMethodSubtypeId, imList, userId);
}
}
@@ -5948,7 +5942,7 @@
final var bindingController = getInputMethodBindingController(userId);
mMenuControllerNew.hide(bindingController.getCurTokenDisplayId(), userId);
} else {
- mMenuController.hideInputMethodMenuLocked();
+ mMenuController.hideInputMethodMenuLocked(userId);
}
}
}
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java
index ba5c13e..f16a5a0 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java
@@ -21,6 +21,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.UserIdInt;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
@@ -77,13 +78,12 @@
@GuardedBy("ImfLock.class")
void showInputMethodMenuLocked(boolean showAuxSubtypes, int displayId,
String preferredInputMethodId, int preferredInputMethodSubtypeId,
- @NonNull List<ImeSubtypeListItem> imList) {
+ @NonNull List<ImeSubtypeListItem> imList, @UserIdInt int userId) {
if (DEBUG) Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);
- final int userId = mService.getCurrentImeUserIdLocked();
final var bindingController = mService.getInputMethodBindingController(userId);
- hideInputMethodMenuLocked();
+ hideInputMethodMenuLocked(userId);
if (preferredInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
final InputMethodSubtype currentSubtype =
@@ -131,7 +131,7 @@
}
final Context dialogWindowContext = mDialogWindowContext.get(displayId);
mDialogBuilder = new AlertDialog.Builder(dialogWindowContext);
- mDialogBuilder.setOnCancelListener(dialog -> hideInputMethodMenu());
+ mDialogBuilder.setOnCancelListener(dialog -> hideInputMethodMenu(userId));
final Context dialogContext = mDialogBuilder.getContext();
final TypedArray a = dialogContext.obtainStyledAttributes(null,
@@ -162,7 +162,7 @@
isChecked, userId);
// Ensure that the input method dialog is dismissed when changing
// the hardware keyboard state.
- hideInputMethodMenu();
+ hideInputMethodMenu(userId);
});
// Fill the list items with onClick listener, which takes care of IME (and subtype)
@@ -185,7 +185,7 @@
}
mService.setInputMethodLocked(im.getId(), subtypeId, userId);
}
- hideInputMethodMenuLocked();
+ hideInputMethodMenuLocked(userId);
}
};
mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
@@ -209,10 +209,10 @@
mSwitchingDialog.show();
}
- void updateKeyboardFromSettingsLocked() {
+ void updateKeyboardFromSettingsLocked(@UserIdInt int userId) {
mShowImeWithHardKeyboard =
SecureSettingsWrapper.getBoolean(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD,
- false, mService.getCurrentImeUserIdLocked());
+ false, userId);
if (mSwitchingDialog != null && mSwitchingDialogTitleView != null
&& mSwitchingDialog.isShowing()) {
final Switch hardKeySwitch = mSwitchingDialogTitleView.findViewById(
@@ -223,18 +223,22 @@
/**
* Hides the input method switcher menu.
+ *
+ * @param userId user ID for this operation
*/
- void hideInputMethodMenu() {
+ void hideInputMethodMenu(@UserIdInt int userId) {
synchronized (ImfLock.class) {
- hideInputMethodMenuLocked();
+ hideInputMethodMenuLocked(userId);
}
}
/**
* Hides the input method switcher menu, synchronised version of {@link #hideInputMethodMenu}.
+ *
+ * @param userId user ID for this operation
*/
@GuardedBy("ImfLock.class")
- void hideInputMethodMenuLocked() {
+ void hideInputMethodMenuLocked(@UserIdInt int userId) {
if (DEBUG) Slog.v(TAG, "Hide switching menu");
if (mSwitchingDialog != null) {
@@ -242,8 +246,6 @@
mSwitchingDialog = null;
mSwitchingDialogTitleView = null;
- // TODO(b/305849394): Make InputMethodMenuController multi-user aware
- final int userId = mService.getCurrentImeUserIdLocked();
mService.updateSystemUiLocked(userId);
mService.sendOnNavButtonFlagsChangedToAllImesLocked();
mDialogBuilder = null;