Merge "Add new SystemApi InputMethod attr isVrOnly."

This commit is contained in:
TreeHugger Robot
2017-12-05 23:51:48 +00:00
committed by Android (Google) Code Review
8 changed files with 71 additions and 7 deletions

View File

@@ -184,6 +184,7 @@ package android {
}
public static final class R.attr {
field public static final int isVrOnly = 16844152; // 0x1010578
field public static final int requiredSystemPropertyName = 16844133; // 0x1010565
field public static final int requiredSystemPropertyValue = 16844134; // 0x1010566
field public static final int searchKeyphrase = 16843871; // 0x101045f

View File

@@ -66,6 +66,11 @@ public final class InputMethodInfo implements Parcelable {
*/
final ResolveInfo mService;
/**
* IME only supports VR mode.
*/
final boolean mIsVrOnly;
/**
* The unique string Id to identify the input method. This is generated
* from the input method component.
@@ -149,6 +154,7 @@ public final class InputMethodInfo implements Parcelable {
PackageManager pm = context.getPackageManager();
String settingsActivityComponent = null;
boolean isVrOnly;
int isDefaultResId = 0;
XmlResourceParser parser = null;
@@ -179,6 +185,7 @@ public final class InputMethodInfo implements Parcelable {
com.android.internal.R.styleable.InputMethod);
settingsActivityComponent = sa.getString(
com.android.internal.R.styleable.InputMethod_settingsActivity);
isVrOnly = sa.getBoolean(com.android.internal.R.styleable.InputMethod_isVrOnly, false);
isDefaultResId = sa.getResourceId(
com.android.internal.R.styleable.InputMethod_isDefault, 0);
supportsSwitchingToNextInputMethod = sa.getBoolean(
@@ -254,6 +261,8 @@ public final class InputMethodInfo implements Parcelable {
mIsDefaultResId = isDefaultResId;
mIsAuxIme = isAuxIme;
mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod;
// TODO(b/68948291): remove this meta-data before release.
mIsVrOnly = isVrOnly || service.serviceInfo.metaData.getBoolean("isVrOnly", false);
}
InputMethodInfo(Parcel source) {
@@ -262,6 +271,7 @@ public final class InputMethodInfo implements Parcelable {
mIsDefaultResId = source.readInt();
mIsAuxIme = source.readInt() == 1;
mSupportsSwitchingToNextInputMethod = source.readInt() == 1;
mIsVrOnly = source.readBoolean();
mService = ResolveInfo.CREATOR.createFromParcel(source);
mSubtypes = new InputMethodSubtypeArray(source);
mForceDefault = false;
@@ -274,7 +284,8 @@ public final class InputMethodInfo implements Parcelable {
CharSequence label, String settingsActivity) {
this(buildDummyResolveInfo(packageName, className, label), false /* isAuxIme */,
settingsActivity, null /* subtypes */, 0 /* isDefaultResId */,
false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */);
false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */,
false /* isVrOnly */);
}
/**
@@ -285,7 +296,7 @@ public final class InputMethodInfo implements Parcelable {
String settingsActivity, List<InputMethodSubtype> subtypes, int isDefaultResId,
boolean forceDefault) {
this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId, forceDefault,
true /* supportsSwitchingToNextInputMethod */);
true /* supportsSwitchingToNextInputMethod */, false /* isVrOnly */);
}
/**
@@ -294,7 +305,7 @@ public final class InputMethodInfo implements Parcelable {
*/
public InputMethodInfo(ResolveInfo ri, boolean isAuxIme, String settingsActivity,
List<InputMethodSubtype> subtypes, int isDefaultResId, boolean forceDefault,
boolean supportsSwitchingToNextInputMethod) {
boolean supportsSwitchingToNextInputMethod, boolean isVrOnly) {
final ServiceInfo si = ri.serviceInfo;
mService = ri;
mId = new ComponentName(si.packageName, si.name).flattenToShortString();
@@ -304,6 +315,7 @@ public final class InputMethodInfo implements Parcelable {
mSubtypes = new InputMethodSubtypeArray(subtypes);
mForceDefault = forceDefault;
mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod;
mIsVrOnly = isVrOnly;
}
private static ResolveInfo buildDummyResolveInfo(String packageName, String className,
@@ -397,6 +409,14 @@ public final class InputMethodInfo implements Parcelable {
return mSettingsActivityName;
}
/**
* Returns true if IME supports VR mode only.
* @hide
*/
public boolean isVrOnly() {
return mIsVrOnly;
}
/**
* Return the count of the subtypes of Input Method.
*/
@@ -444,6 +464,7 @@ public final class InputMethodInfo implements Parcelable {
public void dump(Printer pw, String prefix) {
pw.println(prefix + "mId=" + mId
+ " mSettingsActivityName=" + mSettingsActivityName
+ " mIsVrOnly=" + mIsVrOnly
+ " mSupportsSwitchingToNextInputMethod=" + mSupportsSwitchingToNextInputMethod);
pw.println(prefix + "mIsDefaultResId=0x"
+ Integer.toHexString(mIsDefaultResId));
@@ -509,6 +530,7 @@ public final class InputMethodInfo implements Parcelable {
dest.writeInt(mIsDefaultResId);
dest.writeInt(mIsAuxIme ? 1 : 0);
dest.writeInt(mSupportsSwitchingToNextInputMethod ? 1 : 0);
dest.writeBoolean(mIsVrOnly);
mService.writeToParcel(dest, flags);
mSubtypes.writeToParcel(dest);
}

View File

@@ -3294,6 +3294,9 @@
and subtype in order to provide the consistent user experience in switching
between IMEs and subtypes. -->
<attr name="supportsSwitchingToNextInputMethod" format="boolean" />
<!-- Specifies if an IME can only be used while a device is in VR mode or on a dedicated
device -->
<attr name="isVrOnly" format="boolean"/>
<attr name="__removed2" format="boolean" />
</declare-styleable>

View File

@@ -2856,6 +2856,8 @@
<public name="buttonCornerRadius" />
<public name="versionCodeMajor" />
<public name="versionMajor" />
<!-- @hide @SystemApi -->
<public name="isVrOnly"/>
</public-group>
<public-group type="style" first-id="0x010302e0">

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2017 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:isVrOnly="true">
</input-method>

View File

@@ -68,6 +68,17 @@ public class InputMethodInfoTest {
assertThat(clone.supportsSwitchingToNextInputMethod(), is(true));
}
@Test
public void testIsVrOnly() throws Exception {
final InputMethodInfo imi = buildInputMethodForTest(R.xml.ime_meta_vr_only);
assertThat(imi.isVrOnly(), is(true));
final InputMethodInfo clone = cloneViaParcel(imi);
assertThat(clone.isVrOnly(), is(true));
}
private InputMethodInfo buildInputMethodForTest(final @XmlRes int metaDataRes)
throws Exception {
final Context context = InstrumentationRegistry.getContext();

View File

@@ -38,6 +38,7 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe
private static final String DUMMY_SETTING_ACTIVITY_NAME = "";
private static final boolean DUMMY_IS_AUX_IME = false;
private static final boolean DUMMY_FORCE_DEFAULT = false;
private static final boolean DUMMY_IS_VR_IME = false;
private static final int DUMMY_IS_DEFAULT_RES_ID = 0;
private static final String SYSTEM_LOCALE = "en_US";
private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
@@ -75,7 +76,7 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe
}
final InputMethodInfo imi = new InputMethodInfo(ri, DUMMY_IS_AUX_IME,
DUMMY_SETTING_ACTIVITY_NAME, subtypes, DUMMY_IS_DEFAULT_RES_ID,
DUMMY_FORCE_DEFAULT, supportsSwitchingToNextInputMethod);
DUMMY_FORCE_DEFAULT, supportsSwitchingToNextInputMethod, DUMMY_IS_VR_IME);
if (subtypes == null) {
items.add(new ImeSubtypeListItem(imeName, null /* variableName */, imi,
NOT_A_SUBTYPE_ID, null, SYSTEM_LOCALE));
@@ -111,7 +112,8 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe
.build());
final InputMethodInfo imi = new InputMethodInfo(ri, DUMMY_IS_AUX_IME,
DUMMY_SETTING_ACTIVITY_NAME, subtypes, DUMMY_IS_DEFAULT_RES_ID,
DUMMY_FORCE_DEFAULT, true /* supportsSwitchingToNextInputMethod */);
DUMMY_FORCE_DEFAULT, true /* supportsSwitchingToNextInputMethod */,
DUMMY_IS_VR_IME);
return new ImeSubtypeListItem(imeName, subtypeName, imi, subtypeIndex, subtypeLocale,
systemLocale);
}

View File

@@ -159,14 +159,14 @@ public class AppRestrictionsHelperTest extends BaseTest {
for (String pkg : defaultImes) {
final ResolveInfo ri = createResolveInfoForSystemApp(pkg);
final InputMethodInfo inputMethodInfo = new InputMethodInfo(
ri, false, null, null, 0, true, true);
ri, false, null, null, 0, true, true, false);
inputMethods.add(inputMethodInfo);
addInstalledApp(ri);
}
for (String pkg : otherImes) {
final ResolveInfo ri = createResolveInfoForSystemApp(pkg);
final InputMethodInfo inputMethodInfo = new InputMethodInfo(
ri, false, null, null, 0, false, true);
ri, false, null, null, 0, false, true, false);
inputMethods.add(inputMethodInfo);
addInstalledApp(ri);
}