From ab187daf71ba5b59e626b1af05ce2310025664f3 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 2 Jun 2021 22:37:08 -0700 Subject: [PATCH] Teach IMMS#shouldShowImeSwitcherLocked() about shouldShowInInputMethodPicker attr This is a follow up CL to our previous CL [1], which introduced shouldShowInInputMethodPicker attribute then made IME picker UI be aware of it. There was a method we forgot to update in that CL: InputMethodManagerService#shouldShowImeSwitcherLocked(), which determines when the IME switcher icon is shown on the navigation bar. It should just ignore IMEs that have shouldShowInInputMethodPicker=false because those IMEs are actually not shown on the IME switcher dialog. [1]: I18dda0525168f9195606840239507b9daba65be7 43dbb54918415d219074f9017ab070bdfe95da8a Fix: 175480153 Fix: 186150194 Test: Manually tested as follows: 1. Build aosp_coral-userdebug and flash it. 2. Open the dialar app and focus in any input field. 3. Make sure that AOSP Keyboard shows up and the IME swicher icon is not shown on the navigation bar. 4. adb install -r \ $ANDROID_HOST_OUT/cts/android-cts/testcases/CtsHiddenFromPickerIme.apk 5. adb shell ime enable \ com.android.cts.hiddenfrompickerime/.HiddenFromPickerIme 6. Hide and show the AOSP keyboard. 7. Make sure that the IME swicher icon is still not shown. 8. adb install -r \ $ANDROID_PRODUCT_OUT/system/app/SoftKeyboard/SoftKeyboard.apk 9. adb shell ime \ enable com.example.android.softkeyboard/.SoftKeyboard 10. Hide and show the AOSP keyboard. 11. Make sure that the IME swicher icon becomes visible. Change-Id: Id4b4c208e11d574d6118c8cd2b5aa79dd5486c14 --- .../inputmethod/InputMethodManagerService.java | 3 ++- .../server/inputmethod/InputMethodUtils.java | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index a0004a075cb78..3c0dae52e71cc 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -2762,7 +2762,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return false; } - List imis = mSettings.getEnabledInputMethodListLocked(); + List imis = mSettings.getEnabledInputMethodListWithFilterLocked( + InputMethodInfo::shouldShowInInputMethodPicker); final int N = imis.size(); if (N > 2) return true; if (N < 1) return false; diff --git a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java index ac3c31d5cca46..e619fff24d228 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java @@ -54,6 +54,7 @@ import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; +import java.util.function.Predicate; /** * This class provides random static utility methods for {@link InputMethodManagerService} and its @@ -946,8 +947,14 @@ final class InputMethodUtils { } ArrayList getEnabledInputMethodListLocked() { + return getEnabledInputMethodListWithFilterLocked(null /* matchingCondition */); + } + + @NonNull + ArrayList getEnabledInputMethodListWithFilterLocked( + @Nullable Predicate matchingCondition) { return createEnabledInputMethodListLocked( - getEnabledInputMethodsAndSubtypeListLocked()); + getEnabledInputMethodsAndSubtypeListLocked(), matchingCondition); } List getEnabledInputMethodSubtypeListLocked( @@ -1036,11 +1043,13 @@ final class InputMethodUtils { } private ArrayList createEnabledInputMethodListLocked( - List>> imsList) { + List>> imsList, + Predicate matchingCondition) { final ArrayList res = new ArrayList<>(); for (Pair> ims: imsList) { InputMethodInfo info = mMethodMap.get(ims.first); - if (info != null && !info.isVrOnly()) { + if (info != null && !info.isVrOnly() + && (matchingCondition == null || matchingCondition.test(info))) { res.add(info); } }