From 43dbb54918415d219074f9017ab070bdfe95da8a Mon Sep 17 00:00:00 2001 From: Ahaan Ugale Date: Thu, 25 Mar 2021 12:57:08 -0700 Subject: [PATCH] Add a showInInputMethodPicker attr. An app that provided an IME and is deprecating that functionality may want to still keep it's IME around temporarily, to prevent breaking clients that hardcode the component name when switching to the IME. Such an IME may want to not be presented as an option in the Input Method picker. They can now set showInInputMethodPicker=false for this. Fix: 175480153 Test: manual - Test IME with showInInputMethodPicker=false isn't shown in the IME picker. Test: [new tests] atest android.view.inputmethod.cts.InputMethodManagerTest Test: atest CtsInputMethodTestCases Change-Id: I18dda0525168f9195606840239507b9daba65be7 --- core/api/current.txt | 1 + .../view/inputmethod/InputMethodInfo.java | 24 ++++++++++++++++++- core/res/res/values/attrs.xml | 6 +++++ core/res/res/values/public.xml | 1 + .../InputMethodMenuController.java | 3 ++- ...InputMethodSubtypeSwitchingController.java | 12 ++++++---- 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index f86544784dc4d..5622f4b14d94d 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -1296,6 +1296,7 @@ package android { field public static final int showDefault = 16843258; // 0x10101fa field public static final int showDividers = 16843561; // 0x1010329 field public static final int showForAllUsers = 16844015; // 0x10104ef + field public static final int showInInputMethodPicker = 16844361; // 0x1010649 field public static final int showMetadataInPreview = 16844079; // 0x101052f field @Deprecated public static final int showOnLockScreen = 16843721; // 0x10103c9 field public static final int showSilent = 16843259; // 0x10101fb diff --git a/core/java/android/view/inputmethod/InputMethodInfo.java b/core/java/android/view/inputmethod/InputMethodInfo.java index cc533eb3b5d73..6ba3b37ce2140 100644 --- a/core/java/android/view/inputmethod/InputMethodInfo.java +++ b/core/java/android/view/inputmethod/InputMethodInfo.java @@ -61,6 +61,7 @@ import java.util.List; * @attr ref android.R.styleable#InputMethod_supportsSwitchingToNextInputMethod * @attr ref android.R.styleable#InputMethod_supportsInlineSuggestions * @attr ref android.R.styleable#InputMethod_suppressesSpellChecker + * @attr ref android.R.styleable#InputMethod_showInInputMethodPicker */ public final class InputMethodInfo implements Parcelable { static final String TAG = "InputMethodInfo"; @@ -123,6 +124,11 @@ public final class InputMethodInfo implements Parcelable { */ private final boolean mSuppressesSpellChecker; + /** + * The flag whether this IME should be shown as an option in the IME picker. + */ + private final boolean mShowInInputMethodPicker; + /** * @param service the {@link ResolveInfo} corresponds in which the IME is implemented. * @return a unique ID to be returned by {@link #getId()}. We have used @@ -167,6 +173,7 @@ public final class InputMethodInfo implements Parcelable { boolean supportsSwitchingToNextInputMethod = false; // false as default boolean inlineSuggestionsEnabled = false; // false as default boolean suppressesSpellChecker = false; // false as default + boolean showInInputMethodPicker = true; // true as default mForceDefault = false; PackageManager pm = context.getPackageManager(); @@ -212,6 +219,8 @@ public final class InputMethodInfo implements Parcelable { com.android.internal.R.styleable.InputMethod_supportsInlineSuggestions, false); suppressesSpellChecker = sa.getBoolean( com.android.internal.R.styleable.InputMethod_suppressesSpellChecker, false); + showInInputMethodPicker = sa.getBoolean( + com.android.internal.R.styleable.InputMethod_showInInputMethodPicker, true); sa.recycle(); final int depth = parser.getDepth(); @@ -284,6 +293,7 @@ public final class InputMethodInfo implements Parcelable { mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod; mInlineSuggestionsEnabled = inlineSuggestionsEnabled; mSuppressesSpellChecker = suppressesSpellChecker; + mShowInInputMethodPicker = showInInputMethodPicker; mIsVrOnly = isVrOnly; } @@ -295,6 +305,7 @@ public final class InputMethodInfo implements Parcelable { mSupportsSwitchingToNextInputMethod = source.readInt() == 1; mInlineSuggestionsEnabled = source.readInt() == 1; mSuppressesSpellChecker = source.readBoolean(); + mShowInInputMethodPicker = source.readBoolean(); mIsVrOnly = source.readBoolean(); mService = ResolveInfo.CREATOR.createFromParcel(source); mSubtypes = new InputMethodSubtypeArray(source); @@ -354,6 +365,7 @@ public final class InputMethodInfo implements Parcelable { mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod; mInlineSuggestionsEnabled = inlineSuggestionsEnabled; mSuppressesSpellChecker = false; + mShowInInputMethodPicker = true; mIsVrOnly = isVrOnly; } @@ -507,7 +519,8 @@ public final class InputMethodInfo implements Parcelable { + " mIsVrOnly=" + mIsVrOnly + " mSupportsSwitchingToNextInputMethod=" + mSupportsSwitchingToNextInputMethod + " mInlineSuggestionsEnabled=" + mInlineSuggestionsEnabled - + " mSuppressesSpellChecker=" + mSuppressesSpellChecker); + + " mSuppressesSpellChecker=" + mSuppressesSpellChecker + + " mShowInInputMethodPicker=" + mShowInInputMethodPicker); pw.println(prefix + "mIsDefaultResId=0x" + Integer.toHexString(mIsDefaultResId)); pw.println(prefix + "Service:"); @@ -582,6 +595,14 @@ public final class InputMethodInfo implements Parcelable { return mSuppressesSpellChecker; } + /** + * Return {@code true} if this input method should be shown in the IME picker. + * @hide + */ + public boolean showInInputMethodPicker() { + return mShowInInputMethodPicker; + } + /** * Used to package this object into a {@link Parcel}. * @@ -597,6 +618,7 @@ public final class InputMethodInfo implements Parcelable { dest.writeInt(mSupportsSwitchingToNextInputMethod ? 1 : 0); dest.writeInt(mInlineSuggestionsEnabled ? 1 : 0); dest.writeBoolean(mSuppressesSpellChecker); + dest.writeBoolean(mShowInInputMethodPicker); dest.writeBoolean(mIsVrOnly); mService.writeToParcel(dest, flags); mSubtypes.writeToParcel(dest); diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index eea379944a217..3940dc556d41c 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -3579,6 +3579,12 @@ + + + diff --git a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java index f646d5d22263c..e25b034819347 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java @@ -100,7 +100,8 @@ public class InputMethodMenuController { synchronized (mMethodMap) { final List imList = mSwitchingController - .getSortedInputMethodAndSubtypeListLocked(showAuxSubtypes, isScreenLocked); + .getSortedInputMethodAndSubtypeListForImeMenuLocked( + showAuxSubtypes, isScreenLocked); if (imList.isEmpty()) { return; } diff --git a/services/core/java/com/android/server/inputmethod/InputMethodSubtypeSwitchingController.java b/services/core/java/com/android/server/inputmethod/InputMethodSubtypeSwitchingController.java index 8e84002dc6554..2969e53f2ba67 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodSubtypeSwitchingController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodSubtypeSwitchingController.java @@ -181,7 +181,7 @@ final class InputMethodSubtypeSwitchingController { } public List getSortedInputMethodAndSubtypeList( - boolean includeAuxiliarySubtypes, boolean isScreenLocked) { + boolean includeAuxiliarySubtypes, boolean isScreenLocked, boolean forImeMenu) { final ArrayList imis = mSettings.getEnabledInputMethodListLocked(); if (imis.isEmpty()) { return Collections.emptyList(); @@ -196,6 +196,9 @@ final class InputMethodSubtypeSwitchingController { final int numImes = imis.size(); for (int i = 0; i < numImes; ++i) { final InputMethodInfo imi = imis.get(i); + if (forImeMenu && !imi.showInInputMethodPicker()) { + continue; + } final List explicitlyOrImplicitlyEnabledSubtypeList = mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); final ArraySet enabledSubtypeSet = new ArraySet<>(); @@ -513,7 +516,8 @@ final class InputMethodSubtypeSwitchingController { mSubtypeList = new InputMethodAndSubtypeList(context, mSettings); mController = ControllerImpl.createFrom(mController, mSubtypeList.getSortedInputMethodAndSubtypeList( - false /* includeAuxiliarySubtypes */, false /* isScreenLocked */)); + false /* includeAuxiliarySubtypes */, false /* isScreenLocked */, + false /* forImeMenu */)); } public ImeSubtypeListItem getNextInputMethodLocked(boolean onlyCurrentIme, InputMethodInfo imi, @@ -527,10 +531,10 @@ final class InputMethodSubtypeSwitchingController { return mController.getNextInputMethod(onlyCurrentIme, imi, subtype); } - public List getSortedInputMethodAndSubtypeListLocked( + public List getSortedInputMethodAndSubtypeListForImeMenuLocked( boolean includingAuxiliarySubtypes, boolean isScreenLocked) { return mSubtypeList.getSortedInputMethodAndSubtypeList( - includingAuxiliarySubtypes, isScreenLocked); + includingAuxiliarySubtypes, isScreenLocked, true /* forImeMenu */); } public void dump(final Printer pw) {