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); } }