diff options
| author | Adam He <adamhe@google.com> | 2019-12-12 17:00:34 -0800 |
|---|---|---|
| committer | Adam He <adamhe@google.com> | 2020-01-03 14:14:17 -0800 |
| commit | 7bc8f60377e6fef99f9fdb2ac5cd70716abe9526 (patch) | |
| tree | 38c4baf6a32423fd59985104ac9f2a6e2ffba4a5 /core/java/android | |
| parent | de12cc1af014597da075d7582989fe928a0de666 (diff) | |
Added attributes for IME and AutofillService to indicate they support
inline suggestions.
Fixes: 146452946
Test: atest FrameworksCoreTests:android.view.inputmethod.InputMethodInfoTest
Change-Id: I709b16d3f12c693bc670600bdcb9125630eb9b8e
Diffstat (limited to 'core/java/android')
3 files changed, 55 insertions, 24 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index a45f70316953..fe4f860484cf 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -722,15 +722,6 @@ public class InputMethodService extends AbstractInputMethodService { } /** - * Returns whether inline suggestions are enabled on this service. - * - * TODO(b/137800469): check XML for value. - */ - private boolean isInlineSuggestionsEnabled() { - return true; - } - - /** * Sends an {@link InlineSuggestionsRequest} obtained from * {@link #onCreateInlineSuggestionsRequest()} to the current Autofill Session through * {@link IInlineSuggestionsRequestCallback#onInlineSuggestionsRequest}. @@ -763,23 +754,14 @@ public class InputMethodService extends AbstractInputMethodService { private void handleOnCreateInlineSuggestionsRequest(@NonNull ComponentName componentName, @NonNull AutofillId autofillId, @NonNull IInlineSuggestionsRequestCallback callback) { - mInlineSuggestionsRequestInfo = new InlineSuggestionsRequestInfo(componentName, autofillId, - callback); - - if (!isInlineSuggestionsEnabled()) { - try { - callback.onInlineSuggestionsUnsupported(); - } catch (RemoteException e) { - Log.w(TAG, "handleMakeInlineSuggestionsRequest() RemoteException:" + e); - } - return; - } - if (!mInputStarted) { Log.w(TAG, "onStartInput() not called yet"); return; } + mInlineSuggestionsRequestInfo = new InlineSuggestionsRequestInfo(componentName, autofillId, + callback); + makeInlineSuggestionsRequest(); } diff --git a/core/java/android/service/autofill/AutofillServiceInfo.java b/core/java/android/service/autofill/AutofillServiceInfo.java index b7ec281993df..fbc25a6aaf74 100644 --- a/core/java/android/service/autofill/AutofillServiceInfo.java +++ b/core/java/android/service/autofill/AutofillServiceInfo.java @@ -80,6 +80,8 @@ public final class AutofillServiceInfo { @Nullable private final ArrayMap<String, Long> mCompatibilityPackages; + private final boolean mInlineSuggestionsEnabled; + public AutofillServiceInfo(Context context, ComponentName comp, int userHandle) throws PackageManager.NameNotFoundException { this(context, getServiceInfoOrThrow(comp, userHandle)); @@ -112,11 +114,13 @@ public final class AutofillServiceInfo { if (parser == null) { mSettingsActivity = null; mCompatibilityPackages = null; + mInlineSuggestionsEnabled = false; return; } String settingsActivity = null; ArrayMap<String, Long> compatibilityPackages = null; + boolean inlineSuggestionsEnabled = false; // false by default. try { final Resources resources = context.getPackageManager().getResourcesForApplication( @@ -135,6 +139,8 @@ public final class AutofillServiceInfo { com.android.internal.R.styleable.AutofillService); settingsActivity = afsAttributes.getString( R.styleable.AutofillService_settingsActivity); + inlineSuggestionsEnabled = afsAttributes.getBoolean( + R.styleable.AutofillService_supportsInlineSuggestions, false); } finally { if (afsAttributes != null) { afsAttributes.recycle(); @@ -150,6 +156,7 @@ public final class AutofillServiceInfo { mSettingsActivity = settingsActivity; mCompatibilityPackages = compatibilityPackages; + mInlineSuggestionsEnabled = inlineSuggestionsEnabled; } private ArrayMap<String, Long> parseCompatibilityPackages(XmlPullParser parser, @@ -227,6 +234,10 @@ public final class AutofillServiceInfo { return mCompatibilityPackages; } + public boolean isInlineSuggestionsEnabled() { + return mInlineSuggestionsEnabled; + } + @Override public String toString() { final StringBuilder builder = new StringBuilder(); @@ -235,6 +246,7 @@ public final class AutofillServiceInfo { builder.append(", settings:").append(mSettingsActivity); builder.append(", hasCompatPckgs:").append(mCompatibilityPackages != null && !mCompatibilityPackages.isEmpty()).append("]"); + builder.append(", inline suggestions enabled:").append(mInlineSuggestionsEnabled); return builder.toString(); } @@ -245,5 +257,7 @@ public final class AutofillServiceInfo { pw.print(prefix); pw.print("Component: "); pw.println(getServiceInfo().getComponentName()); pw.print(prefix); pw.print("Settings: "); pw.println(mSettingsActivity); pw.print(prefix); pw.print("Compat packages: "); pw.println(mCompatibilityPackages); + pw.print(prefix); pw.print("Inline Suggestions Enabled: "); + pw.println(mInlineSuggestionsEnabled); } } diff --git a/core/java/android/view/inputmethod/InputMethodInfo.java b/core/java/android/view/inputmethod/InputMethodInfo.java index 34005ac02735..28644858377a 100644 --- a/core/java/android/view/inputmethod/InputMethodInfo.java +++ b/core/java/android/view/inputmethod/InputMethodInfo.java @@ -58,6 +58,7 @@ import java.util.List; * @attr ref android.R.styleable#InputMethod_settingsActivity * @attr ref android.R.styleable#InputMethod_isDefault * @attr ref android.R.styleable#InputMethod_supportsSwitchingToNextInputMethod + * @attr ref android.R.styleable#InputMethod_supportsInlineSuggestions */ public final class InputMethodInfo implements Parcelable { static final String TAG = "InputMethodInfo"; @@ -111,6 +112,11 @@ public final class InputMethodInfo implements Parcelable { private final boolean mSupportsSwitchingToNextInputMethod; /** + * The flag whether this IME supports inline suggestions. + */ + private final boolean mInlineSuggestionsEnabled; + + /** * @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 * {@link ComponentName#flattenToShortString()} for this purpose (and it is already @@ -152,6 +158,7 @@ public final class InputMethodInfo implements Parcelable { mId = computeId(service); boolean isAuxIme = true; boolean supportsSwitchingToNextInputMethod = false; // false as default + boolean inlineSuggestionsEnabled = false; // false as default mForceDefault = false; PackageManager pm = context.getPackageManager(); @@ -193,6 +200,8 @@ public final class InputMethodInfo implements Parcelable { supportsSwitchingToNextInputMethod = sa.getBoolean( com.android.internal.R.styleable.InputMethod_supportsSwitchingToNextInputMethod, false); + inlineSuggestionsEnabled = sa.getBoolean( + com.android.internal.R.styleable.InputMethod_supportsInlineSuggestions, false); sa.recycle(); final int depth = parser.getDepth(); @@ -263,6 +272,7 @@ public final class InputMethodInfo implements Parcelable { mIsDefaultResId = isDefaultResId; mIsAuxIme = isAuxIme; mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod; + mInlineSuggestionsEnabled = inlineSuggestionsEnabled; mIsVrOnly = isVrOnly; } @@ -272,6 +282,7 @@ public final class InputMethodInfo implements Parcelable { mIsDefaultResId = source.readInt(); mIsAuxIme = source.readInt() == 1; mSupportsSwitchingToNextInputMethod = source.readInt() == 1; + mInlineSuggestionsEnabled = source.readInt() == 1; mIsVrOnly = source.readBoolean(); mService = ResolveInfo.CREATOR.createFromParcel(source); mSubtypes = new InputMethodSubtypeArray(source); @@ -286,7 +297,7 @@ public final class InputMethodInfo implements Parcelable { this(buildDummyResolveInfo(packageName, className, label), false /* isAuxIme */, settingsActivity, null /* subtypes */, 0 /* isDefaultResId */, false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */, - false /* isVrOnly */); + false /* inlineSuggestionsEnabled */, false /* isVrOnly */); } /** @@ -297,7 +308,8 @@ public final class InputMethodInfo implements Parcelable { String settingsActivity, List<InputMethodSubtype> subtypes, int isDefaultResId, boolean forceDefault) { this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId, forceDefault, - true /* supportsSwitchingToNextInputMethod */, false /* isVrOnly */); + true /* supportsSwitchingToNextInputMethod */, false /* inlineSuggestionsEnabled */, + false /* isVrOnly */); } /** @@ -307,6 +319,18 @@ public final class InputMethodInfo implements Parcelable { public InputMethodInfo(ResolveInfo ri, boolean isAuxIme, String settingsActivity, List<InputMethodSubtype> subtypes, int isDefaultResId, boolean forceDefault, boolean supportsSwitchingToNextInputMethod, boolean isVrOnly) { + this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId, forceDefault, + supportsSwitchingToNextInputMethod, false /* inlineSuggestionsEnabled */, isVrOnly); + } + + /** + * Temporary API for creating a built-in input method for test. + * @hide + */ + public InputMethodInfo(ResolveInfo ri, boolean isAuxIme, String settingsActivity, + List<InputMethodSubtype> subtypes, int isDefaultResId, boolean forceDefault, + boolean supportsSwitchingToNextInputMethod, boolean inlineSuggestionsEnabled, + boolean isVrOnly) { final ServiceInfo si = ri.serviceInfo; mService = ri; mId = new ComponentName(si.packageName, si.name).flattenToShortString(); @@ -316,6 +340,7 @@ public final class InputMethodInfo implements Parcelable { mSubtypes = new InputMethodSubtypeArray(subtypes); mForceDefault = forceDefault; mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod; + mInlineSuggestionsEnabled = inlineSuggestionsEnabled; mIsVrOnly = isVrOnly; } @@ -467,7 +492,8 @@ public final class InputMethodInfo implements Parcelable { pw.println(prefix + "mId=" + mId + " mSettingsActivityName=" + mSettingsActivityName + " mIsVrOnly=" + mIsVrOnly - + " mSupportsSwitchingToNextInputMethod=" + mSupportsSwitchingToNextInputMethod); + + " mSupportsSwitchingToNextInputMethod=" + mSupportsSwitchingToNextInputMethod + + " mInlineSuggestionsEnabled=" + mInlineSuggestionsEnabled); pw.println(prefix + "mIsDefaultResId=0x" + Integer.toHexString(mIsDefaultResId)); pw.println(prefix + "Service:"); @@ -528,6 +554,14 @@ public final class InputMethodInfo implements Parcelable { } /** + * @return true if this input method supports inline suggestions. + * @hide + */ + public boolean isInlineSuggestionsEnabled() { + return mInlineSuggestionsEnabled; + } + + /** * Used to package this object into a {@link Parcel}. * * @param dest The {@link Parcel} to be written. @@ -540,6 +574,7 @@ public final class InputMethodInfo implements Parcelable { dest.writeInt(mIsDefaultResId); dest.writeInt(mIsAuxIme ? 1 : 0); dest.writeInt(mSupportsSwitchingToNextInputMethod ? 1 : 0); + dest.writeInt(mInlineSuggestionsEnabled ? 1 : 0); dest.writeBoolean(mIsVrOnly); mService.writeToParcel(dest, flags); mSubtypes.writeToParcel(dest); |
