diff options
5 files changed, 17 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java b/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java index 0749edce97a1..aeace7ac9aee 100644 --- a/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java +++ b/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java @@ -103,8 +103,8 @@ final class AutofillSuggestionsController { // Note that current user ID is guaranteed to be userId. final var imeId = mBindingController.getSelectedMethodId(); - final InputMethodInfo imi = InputMethodSettingsRepository.get(mBindingController.mUserId) - .getMethodMap().get(imeId); + final InputMethodInfo imi = InputMethodSettingsRepository.get( + mBindingController.getUserId()).getMethodMap().get(imeId); if (imi == null || !isInlineSuggestionsEnabled(imi, touchExplorationEnabled)) { callback.onInlineSuggestionsUnsupported(); return; diff --git a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java index afc10290ee02..e1aa3a2ee177 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java @@ -70,7 +70,7 @@ final class InputMethodBindingController { /** Time in milliseconds that the IME service has to bind before it is reconnected. */ static final long TIME_TO_RECONNECT = 3 * 1000; - @UserIdInt final int mUserId; + @UserIdInt private final int mUserId; @NonNull private final InputMethodManagerService mService; @NonNull private final Context mContext; @NonNull private final AutofillSuggestionsController mAutofillController; @@ -657,4 +657,9 @@ final class InputMethodBindingController { int getDeviceIdToShowIme() { return mDeviceIdToShowIme; } + + @UserIdInt + int getUserId() { + return mUserId; + } } diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 3c74b23fc8c2..0b61b0186cb7 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -2051,7 +2051,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. @NonNull ImeOnBackInvokedDispatcher imeDispatcher, @NonNull InputMethodBindingController bindingController) { - final int userId = bindingController.mUserId; + final int userId = bindingController.getUserId(); final var userData = getUserData(userId); // Compute the final shown display ID with validated cs.selfReportedDisplayId for this @@ -2068,8 +2068,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. // Potentially override the selected input method if the new display belongs to a virtual // device with a custom IME. String selectedMethodId = bindingController.getSelectedMethodId(); - final String deviceMethodId = computeCurrentDeviceMethodIdLocked(bindingController.mUserId, - selectedMethodId); + final String deviceMethodId = computeCurrentDeviceMethodIdLocked( + bindingController.getUserId(), selectedMethodId); if (deviceMethodId == null) { mVisibilityStateComputer.getImePolicy().setImeHiddenByDisplayPolicy(true); } else if (!Objects.equals(deviceMethodId, selectedMethodId)) { @@ -2567,7 +2567,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. @GuardedBy("ImfLock.class") void clearClientSessionsLocked(@NonNull InputMethodBindingController bindingController) { - final int userId = bindingController.mUserId; + final int userId = bindingController.getUserId(); final var userData = getUserData(userId); if (bindingController.getCurMethod() != null) { // TODO(b/324907325): Remove the suppress warnings once b/324907325 is fixed. @@ -3856,7 +3856,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. + " cs=" + cs); } - final int userId = bindingController.mUserId; + final int userId = bindingController.getUserId(); final var userData = getUserData(userId); final boolean sameWindowFocused = userData.mImeBindingState.mFocusedWindow == windowToken; final boolean isTextEditor = (startInputFlags & StartInputFlags.IS_TEXT_EDITOR) != 0; @@ -3890,7 +3890,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. null, null, null, null, -1, false); } - userData.mImeBindingState = new ImeBindingState(bindingController.mUserId, windowToken, + userData.mImeBindingState = new ImeBindingState(bindingController.getUserId(), windowToken, softInputMode, cs, editorInfo); mFocusedWindowPerceptible.put(windowToken, true); diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java index 42bd75a7a67e..80eab112d814 100644 --- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java +++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java @@ -189,6 +189,7 @@ public class InputMethodManagerServiceTestBase { // Injecting and mocked InputMethodBindingController and InputMethod. mMockInputMethodInvoker = IInputMethodInvoker.create(mMockInputMethod); mInputManagerGlobalSession = InputManagerGlobal.createTestSession(mMockIInputManager); + when(mMockInputMethodBindingController.getUserId()).thenReturn(mCallingUserId); synchronized (ImfLock.class) { when(mMockInputMethodBindingController.getCurMethod()) .thenReturn(mMockInputMethodInvoker); diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/UserDataRepositoryTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/UserDataRepositoryTest.java index f9f45057f57f..e2f3eec1a20b 100644 --- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/UserDataRepositoryTest.java +++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/UserDataRepositoryTest.java @@ -106,7 +106,7 @@ public final class UserDataRepositoryTest { // Assert UserDataRepository called the InputMethodBindingController creator function. verify(bindingControllerFactorySpy).apply(ANY_USER_ID); - assertThat(allUserData.get(0).mBindingController.mUserId).isEqualTo(ANY_USER_ID); + assertThat(allUserData.get(0).mBindingController.getUserId()).isEqualTo(ANY_USER_ID); } @Test @@ -149,7 +149,7 @@ public final class UserDataRepositoryTest { assertThat(allUserData.get(0).mUserId).isEqualTo(ANY_USER_ID); // Assert UserDataRepository called the InputMethodBindingController creator function. - assertThat(allUserData.get(0).mBindingController.mUserId).isEqualTo(ANY_USER_ID); + assertThat(allUserData.get(0).mBindingController.getUserId()).isEqualTo(ANY_USER_ID); } private List<UserDataRepository.UserData> collectUserData(UserDataRepository repository) { |