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
      43dbb54918

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
This commit is contained in:
Yohei Yukawa
2021-06-02 22:37:08 -07:00
parent 03b86cd11f
commit ab187daf71
2 changed files with 14 additions and 4 deletions

View File

@@ -2762,7 +2762,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
return false;
}
List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListWithFilterLocked(
InputMethodInfo::shouldShowInInputMethodPicker);
final int N = imis.size();
if (N > 2) return true;
if (N < 1) return false;

View File

@@ -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<InputMethodInfo> getEnabledInputMethodListLocked() {
return getEnabledInputMethodListWithFilterLocked(null /* matchingCondition */);
}
@NonNull
ArrayList<InputMethodInfo> getEnabledInputMethodListWithFilterLocked(
@Nullable Predicate<InputMethodInfo> matchingCondition) {
return createEnabledInputMethodListLocked(
getEnabledInputMethodsAndSubtypeListLocked());
getEnabledInputMethodsAndSubtypeListLocked(), matchingCondition);
}
List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(
@@ -1036,11 +1043,13 @@ final class InputMethodUtils {
}
private ArrayList<InputMethodInfo> createEnabledInputMethodListLocked(
List<Pair<String, ArrayList<String>>> imsList) {
List<Pair<String, ArrayList<String>>> imsList,
Predicate<InputMethodInfo> matchingCondition) {
final ArrayList<InputMethodInfo> res = new ArrayList<>();
for (Pair<String, ArrayList<String>> 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);
}
}