Add new IME attr

This new attr will allow IME to specify whether they support inline suggestion with touch exploration

Fixes: 207007377
Test: atest android.view.inputmethod.InputMethodInfoTest
Change-Id: I1fa36d7fd57a9b25838d4dd48243c19630495648
This commit is contained in:
skxu
2021-12-01 17:44:45 +00:00
parent ea836e826c
commit 06a8880edf
6 changed files with 89 additions and 5 deletions

View File

@@ -1453,6 +1453,7 @@ package android {
field public static final int supportsAssist = 16844016; // 0x10104f0
field public static final int supportsBatteryGameMode;
field public static final int supportsInlineSuggestions = 16844301; // 0x101060d
field public static final int supportsInlineSuggestionsWithTouchExploration;
field public static final int supportsLaunchVoiceAssistFromKeyguard = 16844017; // 0x10104f1
field public static final int supportsLocalInteraction = 16844047; // 0x101050f
field public static final int supportsMultipleDisplays = 16844182; // 0x1010596

View File

@@ -64,6 +64,7 @@ import java.util.List;
* @attr ref android.R.styleable#InputMethod_isDefault
* @attr ref android.R.styleable#InputMethod_supportsSwitchingToNextInputMethod
* @attr ref android.R.styleable#InputMethod_supportsInlineSuggestions
* @attr ref android.R.styleable#InputMethod_supportsInlineSuggestionsWithTouchExploration
* @attr ref android.R.styleable#InputMethod_suppressesSpellChecker
* @attr ref android.R.styleable#InputMethod_showInInputMethodPicker
* @attr ref android.R.styleable#InputMethod_configChanges
@@ -124,6 +125,11 @@ public final class InputMethodInfo implements Parcelable {
*/
private final boolean mInlineSuggestionsEnabled;
/**
* The flag whether this IME supports inline suggestions when touch exploration is enabled.
*/
private final boolean mSupportsInlineSuggestionsWithTouchExploration;
/**
* The flag whether this IME suppresses spell checker.
*/
@@ -189,6 +195,7 @@ public final class InputMethodInfo implements Parcelable {
boolean isAuxIme = true;
boolean supportsSwitchingToNextInputMethod = false; // false as default
boolean inlineSuggestionsEnabled = false; // false as default
boolean supportsInlineSuggestionsWithTouchExploration = false; // false as default
boolean suppressesSpellChecker = false; // false as default
boolean showInInputMethodPicker = true; // true as default
mForceDefault = false;
@@ -234,6 +241,9 @@ public final class InputMethodInfo implements Parcelable {
false);
inlineSuggestionsEnabled = sa.getBoolean(
com.android.internal.R.styleable.InputMethod_supportsInlineSuggestions, false);
supportsInlineSuggestionsWithTouchExploration = sa.getBoolean(
com.android.internal.R.styleable
.InputMethod_supportsInlineSuggestionsWithTouchExploration, false);
suppressesSpellChecker = sa.getBoolean(
com.android.internal.R.styleable.InputMethod_suppressesSpellChecker, false);
showInInputMethodPicker = sa.getBoolean(
@@ -314,6 +324,8 @@ public final class InputMethodInfo implements Parcelable {
mIsAuxIme = isAuxIme;
mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod;
mInlineSuggestionsEnabled = inlineSuggestionsEnabled;
mSupportsInlineSuggestionsWithTouchExploration =
supportsInlineSuggestionsWithTouchExploration;
mSuppressesSpellChecker = suppressesSpellChecker;
mShowInInputMethodPicker = showInInputMethodPicker;
mIsVrOnly = isVrOnly;
@@ -326,6 +338,7 @@ public final class InputMethodInfo implements Parcelable {
mIsAuxIme = source.readInt() == 1;
mSupportsSwitchingToNextInputMethod = source.readInt() == 1;
mInlineSuggestionsEnabled = source.readInt() == 1;
mSupportsInlineSuggestionsWithTouchExploration = source.readInt() == 1;
mSuppressesSpellChecker = source.readBoolean();
mShowInInputMethodPicker = source.readBoolean();
mIsVrOnly = source.readBoolean();
@@ -345,7 +358,8 @@ public final class InputMethodInfo implements Parcelable {
settingsActivity, null /* subtypes */, 0 /* isDefaultResId */,
false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */,
false /* inlineSuggestionsEnabled */, false /* isVrOnly */,
0 /* handledConfigChanges */, false /* supportsStylusHandwriting */);
0 /* handledConfigChanges */, false /* supportsStylusHandwriting */,
false /* inlineSuggestionsEnabled */);
}
/**
@@ -360,7 +374,8 @@ public final class InputMethodInfo implements Parcelable {
settingsActivity, null /* subtypes */, 0 /* isDefaultResId */,
false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */,
false /* inlineSuggestionsEnabled */, false /* isVrOnly */, handledConfigChanges,
false /* supportsStylusHandwriting */);
false /* supportsStylusHandwriting */,
false /* inlineSuggestionsEnabled */);
}
/**
@@ -373,7 +388,8 @@ public final class InputMethodInfo implements Parcelable {
this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId, forceDefault,
true /* supportsSwitchingToNextInputMethod */, false /* inlineSuggestionsEnabled */,
false /* isVrOnly */, 0 /* handledconfigChanges */,
false /* supportsStylusHandwriting */);
false /* supportsStylusHandwriting */,
false /* inlineSuggestionsEnabled */);
}
/**
@@ -385,7 +401,8 @@ public final class InputMethodInfo implements Parcelable {
boolean supportsSwitchingToNextInputMethod, boolean isVrOnly) {
this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId, forceDefault,
supportsSwitchingToNextInputMethod, false /* inlineSuggestionsEnabled */, isVrOnly,
0 /* handledConfigChanges */, false /* supportsStylusHandwriting */);
0 /* handledConfigChanges */, false /* supportsStylusHandwriting */,
false /* inlineSuggestionsEnabled */);
}
/**
@@ -395,7 +412,8 @@ public final class InputMethodInfo implements Parcelable {
public InputMethodInfo(ResolveInfo ri, boolean isAuxIme, String settingsActivity,
List<InputMethodSubtype> subtypes, int isDefaultResId, boolean forceDefault,
boolean supportsSwitchingToNextInputMethod, boolean inlineSuggestionsEnabled,
boolean isVrOnly, int handledConfigChanges, boolean supportsStylusHandwriting) {
boolean isVrOnly, int handledConfigChanges, boolean supportsStylusHandwriting,
boolean supportsInlineSuggestionsWithTouchExploration) {
final ServiceInfo si = ri.serviceInfo;
mService = ri;
mId = new ComponentName(si.packageName, si.name).flattenToShortString();
@@ -406,6 +424,8 @@ public final class InputMethodInfo implements Parcelable {
mForceDefault = forceDefault;
mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod;
mInlineSuggestionsEnabled = inlineSuggestionsEnabled;
mSupportsInlineSuggestionsWithTouchExploration =
supportsInlineSuggestionsWithTouchExploration;
mSuppressesSpellChecker = false;
mShowInInputMethodPicker = true;
mIsVrOnly = isVrOnly;
@@ -583,6 +603,8 @@ public final class InputMethodInfo implements Parcelable {
+ " mIsVrOnly=" + mIsVrOnly
+ " mSupportsSwitchingToNextInputMethod=" + mSupportsSwitchingToNextInputMethod
+ " mInlineSuggestionsEnabled=" + mInlineSuggestionsEnabled
+ " mSupportsInlineSuggestionsWithTouchExploration="
+ mSupportsInlineSuggestionsWithTouchExploration
+ " mSuppressesSpellChecker=" + mSuppressesSpellChecker
+ " mShowInInputMethodPicker=" + mShowInInputMethodPicker
+ " mSupportsStylusHandwriting=" + mSupportsStylusHandwriting);
@@ -653,6 +675,15 @@ public final class InputMethodInfo implements Parcelable {
return mInlineSuggestionsEnabled;
}
/**
* Returns {@code true} if this input method supports inline suggestions when touch exploration
* is enabled.
* @hide
*/
public boolean supportsInlineSuggestionsWithTouchExploration() {
return mSupportsInlineSuggestionsWithTouchExploration;
}
/**
* Return {@code true} if this input method suppresses spell checker.
*/
@@ -683,6 +714,7 @@ public final class InputMethodInfo implements Parcelable {
dest.writeInt(mIsAuxIme ? 1 : 0);
dest.writeInt(mSupportsSwitchingToNextInputMethod ? 1 : 0);
dest.writeInt(mInlineSuggestionsEnabled ? 1 : 0);
dest.writeInt(mSupportsInlineSuggestionsWithTouchExploration ? 1 : 0);
dest.writeBoolean(mSuppressesSpellChecker);
dest.writeBoolean(mShowInInputMethodPicker);
dest.writeBoolean(mIsVrOnly);

View File

@@ -3644,6 +3644,14 @@
<attr name="__removed2" format="boolean" />
<!-- Specifies whether the IME supports showing inline suggestions. -->
<attr name="supportsInlineSuggestions" format="boolean" />
<!-- Specifies whether the IME supports showing inline suggestions when touch
exploration is enabled. This does nothing if supportsInlineSuggestions is false.
The default value is false and most IMEs should not set this
to true since the older menu-style Autofill works better with touch exploration.
This attribute should be set to true in special situations, such as if this is an
accessibility-focused IME which blocks user interaction with the app window while the
IME is displayed. -->
<attr name="supportsInlineSuggestionsWithTouchExploration" format="boolean" />
<!-- Specifies whether the IME suppresses system spell checker.
The default value is false. If an IME sets this attribute to true,
the system spell checker will be disabled while the IME has an

View File

@@ -3280,6 +3280,7 @@
<public name="knownActivityEmbeddingCerts" />
<public name="intro" />
<public name="enableOnBackInvokedCallback" />
<public name="supportsInlineSuggestionsWithTouchExploration" />
</staging-public-group>
<staging-public-group type="id" first-id="0x01de0000">

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2022 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<input-method
xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.android.inputmethod.latin.settings.SettingsActivity"
android:supportsInlineSuggestionsWithTouchExploration="true"
>
<subtype
android:label="subtype1"
android:imeSubtypeLocale="en_US"
android:imeSubtypeMode="keyboard" />
</input-method>

View File

@@ -55,11 +55,13 @@ public class InputMethodInfoTest {
assertThat(imi.supportsSwitchingToNextInputMethod(), is(false));
assertThat(imi.isInlineSuggestionsEnabled(), is(false));
assertThat(imi.supportsInlineSuggestionsWithTouchExploration(), is(false));
final InputMethodInfo clone = cloneViaParcel(imi);
assertThat(clone.supportsSwitchingToNextInputMethod(), is(false));
assertThat(imi.isInlineSuggestionsEnabled(), is(false));
assertThat(imi.supportsInlineSuggestionsWithTouchExploration(), is(false));
}
@Test
@@ -84,6 +86,18 @@ public class InputMethodInfoTest {
assertThat(clone.isInlineSuggestionsEnabled(), is(true));
}
@Test
public void testInlineSuggestionsEnabledWithTouchExploration() throws Exception {
final InputMethodInfo imi =
buildInputMethodForTest(R.xml.ime_meta_inline_suggestions_with_touch_exploration);
assertThat(imi.supportsInlineSuggestionsWithTouchExploration(), is(true));
final InputMethodInfo clone = cloneViaParcel(imi);
assertThat(clone.supportsInlineSuggestionsWithTouchExploration(), is(true));
}
@Test
public void testIsVrOnly() throws Exception {
final InputMethodInfo imi = buildInputMethodForTest(R.xml.ime_meta_vr_only);