diff options
3 files changed, 10 insertions, 73 deletions
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 5228be48371c..07a7c5536352 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -3038,7 +3038,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. // getCurrentInputMethodSubtype. subtypeId = NOT_A_SUBTYPE_ID; // TODO(b/347083680): The method below has questionable behaviors. - newSubtype = getCurrentInputMethodSubtypeLocked(); + newSubtype = getCurrentInputMethodSubtypeLocked(userId); if (newSubtype != null) { for (int i = 0; i < subtypeCount; ++i) { if (Objects.equals(newSubtype, info.getSubtypeAt(i))) { @@ -5486,7 +5486,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. newSubtypeHashcode = INVALID_SUBTYPE_HASHCODE; // If the subtype is not specified, choose the most applicable one // TODO(b/347083680): The method below has questionable behaviors. - newSubtype = getCurrentInputMethodSubtypeLocked(); + newSubtype = getCurrentInputMethodSubtypeLocked(userId); } } settings.putSelectedSubtype(newSubtypeHashcode); @@ -5541,37 +5541,25 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); } synchronized (ImfLock.class) { - if (mCurrentUserId == userId) { - // TODO(b/347083680): The method below has questionable behaviors. - return getCurrentInputMethodSubtypeLocked(); - } - - return InputMethodSettingsRepository.get(userId) - .getCurrentInputMethodSubtypeForNonCurrentUsers(); + // TODO(b/347083680): The method below has questionable behaviors. + return getCurrentInputMethodSubtypeLocked(userId); } } /** * Returns the current {@link InputMethodSubtype} for the current user. * - * <p>CAVEATS: You must also update - * {@link InputMethodSettings#getCurrentInputMethodSubtypeForNonCurrentUsers()} - * when you update the algorithm of this method.</p> - * - * <p>TODO: Address code duplication between this and - * {@link InputMethodSettings#getCurrentInputMethodSubtypeForNonCurrentUsers()}.</p> - * * <p>Also this method has had questionable behaviors:</p> * <ul> - * <li>Calling this method can update {@link #mCurrentSubtype}.</li> - * <li>This method may return {@link #mCurrentSubtype} as-is, even if it does not belong - * to the current IME.</li> + * <li>Calling this method can update {@link InputMethodBindingController#mCurrentSubtype}. + * </li> + * <li>This method may return {@link InputMethodBindingController#mCurrentSubtype} as-is, + * even if it does not belong to the current IME.</li> * </ul> * <p>TODO(b/347083680): Address above issues.</p> */ @GuardedBy("ImfLock.class") - InputMethodSubtype getCurrentInputMethodSubtypeLocked() { - final int userId = mCurrentUserId; + InputMethodSubtype getCurrentInputMethodSubtypeLocked(@UserIdInt int userId) { final var selectedMethodId = getInputMethodBindingController(userId).getSelectedMethodId(); if (selectedMethodId == null) { return null; diff --git a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java index 154ee1d9fde8..a5d963bd5be3 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java @@ -85,7 +85,7 @@ final class InputMethodMenuController { if (preferredInputMethodSubtypeId == NOT_A_SUBTYPE_ID) { final InputMethodSubtype currentSubtype = - mService.getCurrentInputMethodSubtypeLocked(); + mService.getCurrentInputMethodSubtypeLocked(userId); if (currentSubtype != null) { final String curMethodId = bindingController.getSelectedMethodId(); final InputMethodInfo currentImi = diff --git a/services/core/java/com/android/server/inputmethod/InputMethodSettings.java b/services/core/java/com/android/server/inputmethod/InputMethodSettings.java index 5569e1e5211e..0152158cbb7a 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodSettings.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodSettings.java @@ -571,57 +571,6 @@ final class InputMethodSettings { } } - /** - * A variant of {@link InputMethodManagerService#getCurrentInputMethodSubtypeLocked()} for - * non-current users. - * - * <p>TODO: Address code duplication between this and - * {@link InputMethodManagerService#getCurrentInputMethodSubtypeLocked()}.</p> - * - * @return {@link InputMethodSubtype} if exists. {@code null} otherwise. - */ - @Nullable - InputMethodSubtype getCurrentInputMethodSubtypeForNonCurrentUsers() { - final String selectedMethodId = getSelectedInputMethod(); - if (selectedMethodId == null) { - return null; - } - final InputMethodInfo imi = mMethodMap.get(selectedMethodId); - if (imi == null || imi.getSubtypeCount() == 0) { - return null; - } - - final int subtypeHashCode = getSelectedInputMethodSubtypeHashCode(); - if (subtypeHashCode != INVALID_SUBTYPE_HASHCODE) { - final int subtypeIndex = SubtypeUtils.getSubtypeIdFromHashCode(imi, - subtypeHashCode); - if (subtypeIndex >= 0) { - return imi.getSubtypeAt(subtypeIndex); - } - } - - // If there are no selected subtypes, the framework will try to find the most applicable - // subtype from explicitly or implicitly enabled subtypes. - final List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = - getEnabledInputMethodSubtypeList(imi, true); - // If there is only one explicitly or implicitly enabled subtype, just returns it. - if (explicitlyOrImplicitlyEnabledSubtypes.isEmpty()) { - return null; - } - if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) { - return explicitlyOrImplicitlyEnabledSubtypes.get(0); - } - final String locale = SystemLocaleWrapper.get(mUserId).get(0).toString(); - final InputMethodSubtype subtype = SubtypeUtils.findLastResortApplicableSubtype( - explicitlyOrImplicitlyEnabledSubtypes, SubtypeUtils.SUBTYPE_MODE_KEYBOARD, - locale, true); - if (subtype != null) { - return subtype; - } - return SubtypeUtils.findLastResortApplicableSubtype( - explicitlyOrImplicitlyEnabledSubtypes, null, locale, true); - } - @NonNull AdditionalSubtypeMap getNewAdditionalSubtypeMap(@NonNull String imeId, @NonNull ArrayList<InputMethodSubtype> subtypes, |