Merge "Update language to comply with Android's inclusive language guidance"

This commit is contained in:
Edgar Wang
2020-08-06 06:31:49 +00:00
committed by Android (Google) Code Review
11 changed files with 142 additions and 116 deletions

View File

@@ -19,9 +19,9 @@ package com.android.settingslib.drawer;
import android.os.Bundle;
/**
* A controller that manages event for master switch.
* A controller that manages event for Primary switch.
*/
public abstract class MasterSwitchController extends SwitchController {
public abstract class PrimarySwitchController extends SwitchController {
@Override
protected final MetaData getMetaData() {

View File

@@ -88,7 +88,7 @@ public abstract class SwitchesProvider extends ContentProvider {
controller.setAuthority(mAuthority);
mControllerMap.put(key, controller);
if (!(controller instanceof MasterSwitchController)) {
if (!(controller instanceof PrimarySwitchController)) {
mSwitchDataList.add(controller.getBundle());
}
});
@@ -116,7 +116,7 @@ public abstract class SwitchesProvider extends ContentProvider {
switch (method) {
case METHOD_GET_SWITCH_DATA:
if (!(controller instanceof MasterSwitchController)) {
if (!(controller instanceof PrimarySwitchController)) {
return controller.getBundle();
}
break;

View File

@@ -24,7 +24,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settingslib.core.AbstractPreferenceController;
/**
* This controller is used handle changes for the master switch in the developer options page.
* This controller is used handle changes for the primary switch in the developer options page.
*
* All Preference Controllers that are a part of the developer options page should inherit this
* class.

View File

@@ -34,44 +34,50 @@ import com.android.internal.telephony.SmsApplication;
import com.android.internal.util.ArrayUtils;
/**
* Handles getting/changing the whitelist for the exceptions to battery saving features.
* Handles getting/changing the allowlist for the exceptions to battery saving features.
*/
public class PowerWhitelistBackend {
public class PowerAllowlistBackend {
private static final String TAG = "PowerWhitelistBackend";
private static final String TAG = "PowerAllowlistBackend";
private static final String DEVICE_IDLE_SERVICE = "deviceidle";
private static PowerWhitelistBackend sInstance;
private static PowerAllowlistBackend sInstance;
private final Context mAppContext;
private final IDeviceIdleController mDeviceIdleService;
private final ArraySet<String> mWhitelistedApps = new ArraySet<>();
private final ArraySet<String> mSysWhitelistedApps = new ArraySet<>();
private final ArraySet<String> mAllowlistedApps = new ArraySet<>();
private final ArraySet<String> mSysAllowlistedApps = new ArraySet<>();
private final ArraySet<String> mDefaultActiveApps = new ArraySet<>();
public PowerWhitelistBackend(Context context) {
public PowerAllowlistBackend(Context context) {
this(context, IDeviceIdleController.Stub.asInterface(
ServiceManager.getService(DEVICE_IDLE_SERVICE)));
}
@VisibleForTesting
PowerWhitelistBackend(Context context, IDeviceIdleController deviceIdleService) {
PowerAllowlistBackend(Context context, IDeviceIdleController deviceIdleService) {
mAppContext = context.getApplicationContext();
mDeviceIdleService = deviceIdleService;
refreshList();
}
public int getWhitelistSize() {
return mWhitelistedApps.size();
public int getAllowlistSize() {
return mAllowlistedApps.size();
}
public boolean isSysWhitelisted(String pkg) {
return mSysWhitelistedApps.contains(pkg);
/**
* Check if target package is in System allow list
*/
public boolean isSysAllowlisted(String pkg) {
return mSysAllowlistedApps.contains(pkg);
}
public boolean isWhitelisted(String pkg) {
if (mWhitelistedApps.contains(pkg)) {
/**
* Check if target package is in allow list
*/
public boolean isAllowlisted(String pkg) {
if (mAllowlistedApps.contains(pkg)) {
return true;
}
@@ -87,7 +93,7 @@ public class PowerWhitelistBackend {
*/
public boolean isDefaultActiveApp(String pkg) {
// Additionally, check if pkg is default dialer/sms. They are considered essential apps and
// should be automatically whitelisted (otherwise user may be able to set restriction on
// should be automatically allowlisted (otherwise user may be able to set restriction on
// them, leading to bad device behavior.)
if (mDefaultActiveApps.contains(pkg)) {
@@ -103,12 +109,17 @@ public class PowerWhitelistBackend {
return false;
}
public boolean isWhitelisted(String[] pkgs) {
/**
*
* @param pkgs a list of packageName
* @return true when one of package is in allow list
*/
public boolean isAllowlisted(String[] pkgs) {
if (ArrayUtils.isEmpty(pkgs)) {
return false;
}
for (String pkg : pkgs) {
if (isWhitelisted(pkg)) {
if (isAllowlisted(pkg)) {
return true;
}
}
@@ -116,40 +127,51 @@ public class PowerWhitelistBackend {
return false;
}
/**
* Add app into power save allow list.
* @param pkg packageName
*/
public void addApp(String pkg) {
try {
mDeviceIdleService.addPowerSaveWhitelistApp(pkg);
mWhitelistedApps.add(pkg);
mAllowlistedApps.add(pkg);
} catch (RemoteException e) {
Log.w(TAG, "Unable to reach IDeviceIdleController", e);
}
}
/**
* Remove package from power save allow list.
* @param pkg
*/
public void removeApp(String pkg) {
try {
mDeviceIdleService.removePowerSaveWhitelistApp(pkg);
mWhitelistedApps.remove(pkg);
mAllowlistedApps.remove(pkg);
} catch (RemoteException e) {
Log.w(TAG, "Unable to reach IDeviceIdleController", e);
}
}
/**
* Refresh all of lists
*/
@VisibleForTesting
public void refreshList() {
mSysWhitelistedApps.clear();
mWhitelistedApps.clear();
mSysAllowlistedApps.clear();
mAllowlistedApps.clear();
mDefaultActiveApps.clear();
if (mDeviceIdleService == null) {
return;
}
try {
final String[] whitelistedApps = mDeviceIdleService.getFullPowerWhitelist();
for (String app : whitelistedApps) {
mWhitelistedApps.add(app);
final String[] allowlistedApps = mDeviceIdleService.getFullPowerWhitelist();
for (String app : allowlistedApps) {
mAllowlistedApps.add(app);
}
final String[] sysWhitelistedApps = mDeviceIdleService.getSystemPowerWhitelist();
for (String app : sysWhitelistedApps) {
mSysWhitelistedApps.add(app);
final String[] sysAllowlistedApps = mDeviceIdleService.getSystemPowerWhitelist();
for (String app : sysAllowlistedApps) {
mSysAllowlistedApps.add(app);
}
final boolean hasTelephony = mAppContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_TELEPHONY);
@@ -171,9 +193,13 @@ public class PowerWhitelistBackend {
}
}
public static PowerWhitelistBackend getInstance(Context context) {
/**
* @param context
* @return a PowerAllowlistBackend object
*/
public static PowerAllowlistBackend getInstance(Context context) {
if (sInstance == null) {
sInstance = new PowerWhitelistBackend(context);
sInstance = new PowerAllowlistBackend(context);
}
return sInstance;
}

View File

@@ -135,7 +135,7 @@ public class AppRestrictionsHelper {
// Ignore
}
} else {
// Blacklist all other apps, system or downloaded
// Denylist all other apps, system or downloaded
try {
ApplicationInfo info = mIPm.getApplicationInfo(packageName, 0, userId);
if (info != null) {
@@ -258,11 +258,11 @@ public class AppRestrictionsHelper {
}
}
// Establish master/slave relationship for entries that share a package name
// Establish primary/secondary relationship for entries that share a package name
HashMap<String,SelectableAppInfo> packageMap = new HashMap<String,SelectableAppInfo>();
for (SelectableAppInfo info : mVisibleApps) {
if (packageMap.containsKey(info.packageName)) {
info.masterEntry = packageMap.get(info.packageName);
info.primaryEntry = packageMap.get(info.packageName);
} else {
packageMap.put(info.packageName, info);
}
@@ -366,12 +366,12 @@ public class AppRestrictionsHelper {
public CharSequence appName;
public CharSequence activityName;
public Drawable icon;
public SelectableAppInfo masterEntry;
public SelectableAppInfo primaryEntry;
@Override
public String toString() {
return packageName + ": appName=" + appName + "; activityName=" + activityName
+ "; icon=" + icon + "; masterEntry=" + masterEntry;
+ "; icon=" + icon + "; primaryEntry=" + primaryEntry;
}
}

View File

@@ -290,12 +290,12 @@ public class RestrictedLockUtilsTest {
@Test
public void sendShowAdminSupportDetailsIntent_extraRestrictionProvided() {
EnforcedAdmin enforcedAdmin = new EnforcedAdmin();
enforcedAdmin.enforcedRestriction = "Dummy";
enforcedAdmin.enforcedRestriction = "Fake";
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, enforcedAdmin);
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mContext).startActivityAsUser(intentCaptor.capture(), any());
assertThat(intentCaptor.getValue().getExtra(EXTRA_RESTRICTION)).isEqualTo("Dummy");
assertThat(intentCaptor.getValue().getExtra(EXTRA_RESTRICTION)).isEqualTo("Fake");
}
@Test

View File

@@ -23,16 +23,16 @@ import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class MasterSwitchControllerTest {
public class PrimarySwitchControllerTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private MasterSwitchController mController;
private PrimarySwitchController mController;
@Before
public void setUp() {
mController = new TestMasterSwitchController("123");
mController = new TestPrimarySwitchController("123");
}
@Test
@@ -49,11 +49,11 @@ public class MasterSwitchControllerTest {
mController.getBundle();
}
static class TestMasterSwitchController extends MasterSwitchController {
static class TestPrimarySwitchController extends PrimarySwitchController {
private String mKey;
TestMasterSwitchController(String key) {
TestPrimarySwitchController(String key) {
mKey = key;
}

View File

@@ -35,7 +35,7 @@ import android.content.Context;
import android.content.pm.ProviderInfo;
import android.os.Bundle;
import com.android.settingslib.drawer.MasterSwitchControllerTest.TestMasterSwitchController;
import com.android.settingslib.drawer.PrimarySwitchControllerTest.TestPrimarySwitchController;
import com.android.settingslib.drawer.SwitchController.MetaData;
import org.junit.Before;
@@ -124,8 +124,8 @@ public class SwitchesProviderTest {
}
@Test
public void getSwitchData_shouldNotReturnMasterSwitchData() {
final SwitchController controller = new TestMasterSwitchController("123");
public void getSwitchData_shouldNotReturnPrimarySwitchData() {
final SwitchController controller = new TestPrimarySwitchController("123");
mSwitchesProvider.addSwitchController(controller);
mSwitchesProvider.attachInfo(mContext, mProviderInfo);

View File

@@ -47,7 +47,7 @@ import org.robolectric.shadows.ShadowPackageManager;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowDefaultDialerManager.class, ShadowSmsApplication.class})
public class PowerWhitelistBackendTest {
public class PowerAllowlistBackendTest {
private static final String PACKAGE_ONE = "com.example.packageone";
private static final String PACKAGE_TWO = "com.example.packagetwo";
@@ -56,7 +56,7 @@ public class PowerWhitelistBackendTest {
private IDeviceIdleController mDeviceIdleService;
@Mock
private DevicePolicyManager mDevicePolicyManager;
private PowerWhitelistBackend mPowerWhitelistBackend;
private PowerAllowlistBackend mPowerAllowlistBackend;
private ShadowPackageManager mPackageManager;
private Context mContext;
@@ -74,81 +74,81 @@ public class PowerWhitelistBackendTest {
mPackageManager.setSystemFeature(PackageManager.FEATURE_TELEPHONY, true);
doReturn(mDevicePolicyManager).when(mContext).getSystemService(DevicePolicyManager.class);
mPowerWhitelistBackend = new PowerWhitelistBackend(mContext, mDeviceIdleService);
mPowerAllowlistBackend = new PowerAllowlistBackend(mContext, mDeviceIdleService);
}
@Test
public void testIsWhitelisted() throws Exception {
public void testIsAllowlisted() throws Exception {
doReturn(new String[] {PACKAGE_ONE}).when(mDeviceIdleService).getFullPowerWhitelist();
mPowerWhitelistBackend.refreshList();
mPowerAllowlistBackend.refreshList();
assertThat(mPowerWhitelistBackend.isWhitelisted(PACKAGE_ONE)).isTrue();
assertThat(mPowerWhitelistBackend.isWhitelisted(PACKAGE_TWO)).isFalse();
assertThat(mPowerWhitelistBackend.isWhitelisted(new String[] {PACKAGE_ONE})).isTrue();
assertThat(mPowerWhitelistBackend.isWhitelisted(new String[] {PACKAGE_TWO})).isFalse();
assertThat(mPowerAllowlistBackend.isAllowlisted(PACKAGE_ONE)).isTrue();
assertThat(mPowerAllowlistBackend.isAllowlisted(PACKAGE_TWO)).isFalse();
assertThat(mPowerAllowlistBackend.isAllowlisted(new String[] {PACKAGE_ONE})).isTrue();
assertThat(mPowerAllowlistBackend.isAllowlisted(new String[] {PACKAGE_TWO})).isFalse();
mPowerWhitelistBackend.addApp(PACKAGE_TWO);
mPowerAllowlistBackend.addApp(PACKAGE_TWO);
verify(mDeviceIdleService, atLeastOnce()).addPowerSaveWhitelistApp(PACKAGE_TWO);
assertThat(mPowerWhitelistBackend.isWhitelisted(PACKAGE_ONE)).isTrue();
assertThat(mPowerWhitelistBackend.isWhitelisted(PACKAGE_TWO)).isTrue();
assertThat(mPowerWhitelistBackend.isWhitelisted(
assertThat(mPowerAllowlistBackend.isAllowlisted(PACKAGE_ONE)).isTrue();
assertThat(mPowerAllowlistBackend.isAllowlisted(PACKAGE_TWO)).isTrue();
assertThat(mPowerAllowlistBackend.isAllowlisted(
new String[] {PACKAGE_ONE, PACKAGE_TWO})).isTrue();
mPowerWhitelistBackend.removeApp(PACKAGE_TWO);
mPowerAllowlistBackend.removeApp(PACKAGE_TWO);
verify(mDeviceIdleService, atLeastOnce()).removePowerSaveWhitelistApp(PACKAGE_TWO);
assertThat(mPowerWhitelistBackend.isWhitelisted(PACKAGE_ONE)).isTrue();
assertThat(mPowerWhitelistBackend.isWhitelisted(PACKAGE_TWO)).isFalse();
assertThat(mPowerWhitelistBackend.isWhitelisted(new String[] {PACKAGE_ONE})).isTrue();
assertThat(mPowerWhitelistBackend.isWhitelisted(new String[] {PACKAGE_TWO})).isFalse();
assertThat(mPowerAllowlistBackend.isAllowlisted(PACKAGE_ONE)).isTrue();
assertThat(mPowerAllowlistBackend.isAllowlisted(PACKAGE_TWO)).isFalse();
assertThat(mPowerAllowlistBackend.isAllowlisted(new String[] {PACKAGE_ONE})).isTrue();
assertThat(mPowerAllowlistBackend.isAllowlisted(new String[] {PACKAGE_TWO})).isFalse();
mPowerWhitelistBackend.removeApp(PACKAGE_ONE);
mPowerAllowlistBackend.removeApp(PACKAGE_ONE);
verify(mDeviceIdleService, atLeastOnce()).removePowerSaveWhitelistApp(PACKAGE_ONE);
assertThat(mPowerWhitelistBackend.isWhitelisted(PACKAGE_ONE)).isFalse();
assertThat(mPowerWhitelistBackend.isWhitelisted(PACKAGE_TWO)).isFalse();
assertThat(mPowerWhitelistBackend.isWhitelisted(
assertThat(mPowerAllowlistBackend.isAllowlisted(PACKAGE_ONE)).isFalse();
assertThat(mPowerAllowlistBackend.isAllowlisted(PACKAGE_TWO)).isFalse();
assertThat(mPowerAllowlistBackend.isAllowlisted(
new String[] {PACKAGE_ONE, PACKAGE_TWO})).isFalse();
}
@Test
public void isWhitelisted_shouldWhitelistDefaultSms() {
public void isAllowlisted_shouldAllowlistDefaultSms() {
final String testSms = "com.android.test.defaultsms";
ShadowSmsApplication.setDefaultSmsApplication(new ComponentName(testSms, "receiver"));
mPowerWhitelistBackend.refreshList();
mPowerAllowlistBackend.refreshList();
assertThat(mPowerWhitelistBackend.isWhitelisted(testSms)).isTrue();
assertThat(mPowerWhitelistBackend.isDefaultActiveApp(testSms)).isTrue();
assertThat(mPowerAllowlistBackend.isAllowlisted(testSms)).isTrue();
assertThat(mPowerAllowlistBackend.isDefaultActiveApp(testSms)).isTrue();
}
@Test
public void isWhitelisted_shouldWhitelistDefaultDialer() {
public void isAllowlisted_shouldAllowlistDefaultDialer() {
final String testDialer = "com.android.test.defaultdialer";
ShadowDefaultDialerManager.setDefaultDialerApplication(testDialer);
mPowerWhitelistBackend.refreshList();
mPowerAllowlistBackend.refreshList();
assertThat(mPowerWhitelistBackend.isWhitelisted(testDialer)).isTrue();
assertThat(mPowerWhitelistBackend.isDefaultActiveApp(testDialer)).isTrue();
assertThat(mPowerAllowlistBackend.isAllowlisted(testDialer)).isTrue();
assertThat(mPowerAllowlistBackend.isDefaultActiveApp(testDialer)).isTrue();
}
@Test
public void isWhitelisted_shouldWhitelistActiveDeviceAdminApp() {
public void isAllowlisted_shouldAllowlistActiveDeviceAdminApp() {
doReturn(true).when(mDevicePolicyManager).packageHasActiveAdmins(PACKAGE_ONE);
assertThat(mPowerWhitelistBackend.isWhitelisted(PACKAGE_ONE)).isTrue();
assertThat(mPowerWhitelistBackend.isDefaultActiveApp(PACKAGE_ONE)).isTrue();
assertThat(mPowerAllowlistBackend.isAllowlisted(PACKAGE_ONE)).isTrue();
assertThat(mPowerAllowlistBackend.isDefaultActiveApp(PACKAGE_ONE)).isTrue();
}
@Test
public void testIsSystemWhitelisted() throws Exception {
public void testIsSystemAllowlisted() throws Exception {
doReturn(new String[] {PACKAGE_ONE}).when(mDeviceIdleService).getSystemPowerWhitelist();
mPowerWhitelistBackend.refreshList();
mPowerAllowlistBackend.refreshList();
assertThat(mPowerWhitelistBackend.isSysWhitelisted(PACKAGE_ONE)).isTrue();
assertThat(mPowerWhitelistBackend.isSysWhitelisted(PACKAGE_TWO)).isFalse();
assertThat(mPowerWhitelistBackend.isWhitelisted(PACKAGE_ONE)).isFalse();
assertThat(mPowerAllowlistBackend.isSysAllowlisted(PACKAGE_ONE)).isTrue();
assertThat(mPowerAllowlistBackend.isSysAllowlisted(PACKAGE_TWO)).isFalse();
assertThat(mPowerAllowlistBackend.isAllowlisted(PACKAGE_ONE)).isFalse();
}
}

View File

@@ -197,61 +197,61 @@ public class InputMethodAndSubtypeUtilCompatTest {
public void isValidSystemNonAuxAsciiCapableIme() {
// System IME w/ no subtype
assertThat(InputMethodAndSubtypeUtilCompat.isValidSystemNonAuxAsciiCapableIme(
createDummyIme(true, false)))
createFakeIme(true, false)))
.isFalse();
// System IME w/ non-Aux and non-ASCII-capable "keyboard" subtype
assertThat(InputMethodAndSubtypeUtilCompat.isValidSystemNonAuxAsciiCapableIme(
createDummyIme(true, false, createDummySubtype("keyboard", false, false))))
createFakeIme(true, false, createFakeSubtype("keyboard", false, false))))
.isFalse();
// System IME w/ non-Aux and ASCII-capable "keyboard" subtype
assertThat(InputMethodAndSubtypeUtilCompat.isValidSystemNonAuxAsciiCapableIme(
createDummyIme(true, false, createDummySubtype("keyboard", false, true))))
createFakeIme(true, false, createFakeSubtype("keyboard", false, true))))
.isTrue();
// System IME w/ Aux and ASCII-capable "keyboard" subtype
assertThat(InputMethodAndSubtypeUtilCompat.isValidSystemNonAuxAsciiCapableIme(
createDummyIme(true, true, createDummySubtype("keyboard", true, true))))
createFakeIme(true, true, createFakeSubtype("keyboard", true, true))))
.isFalse();
// System IME w/ non-Aux and ASCII-capable "voice" subtype
assertThat(InputMethodAndSubtypeUtilCompat.isValidSystemNonAuxAsciiCapableIme(
createDummyIme(true, false, createDummySubtype("voice", false, true))))
createFakeIme(true, false, createFakeSubtype("voice", false, true))))
.isFalse();
// System IME w/ non-Aux and non-ASCII-capable subtype + Non-Aux and ASCII-capable subtype
assertThat(InputMethodAndSubtypeUtilCompat.isValidSystemNonAuxAsciiCapableIme(
createDummyIme(true, false,
createDummySubtype("keyboard", false, true),
createDummySubtype("keyboard", false, false))))
createFakeIme(true, false,
createFakeSubtype("keyboard", false, true),
createFakeSubtype("keyboard", false, false))))
.isTrue();
// Non-system IME w/ non-Aux and ASCII-capable "keyboard" subtype
assertThat(InputMethodAndSubtypeUtilCompat.isValidSystemNonAuxAsciiCapableIme(
createDummyIme(false, false, createDummySubtype("keyboard", false, true))))
createFakeIme(false, false, createFakeSubtype("keyboard", false, true))))
.isFalse();
}
private static InputMethodInfo createDummyIme(boolean isSystem, boolean isAuxIme,
private static InputMethodInfo createFakeIme(boolean isSystem, boolean isAuxIme,
InputMethodSubtype... subtypes) {
final ResolveInfo ri = new ResolveInfo();
final ServiceInfo si = new ServiceInfo();
final ApplicationInfo ai = new ApplicationInfo();
ai.packageName = "com.example.android.dummyime";
ai.packageName = "com.example.android.fakeime";
ai.enabled = true;
ai.flags |= (isSystem ? ApplicationInfo.FLAG_SYSTEM : 0);
si.applicationInfo = ai;
si.enabled = true;
si.packageName = "com.example.android.dummyime";
si.name = "Dummy IME";
si.packageName = "com.example.android.fakeime";
si.name = "Fake IME";
si.exported = true;
si.nonLocalizedLabel = "Dummy IME";
si.nonLocalizedLabel = "Fake IME";
ri.serviceInfo = si;
return new InputMethodInfo(ri, isAuxIme, "", Arrays.asList(subtypes), 1, false);
}
private static InputMethodSubtype createDummySubtype(
private static InputMethodSubtype createFakeSubtype(
String mode, boolean isAuxiliary, boolean isAsciiCapable) {
return new InputMethodSubtypeBuilder()
.setSubtypeNameResId(0)

View File

@@ -195,55 +195,55 @@ public class InputMethodAndSubtypeUtilTest {
public void isValidNonAuxAsciiCapableIme() {
// IME w/ no subtype
assertThat(InputMethodAndSubtypeUtil.isValidNonAuxAsciiCapableIme(
createDummyIme(false)))
createFakeIme(false)))
.isFalse();
// IME w/ non-Aux and non-ASCII-capable "keyboard" subtype
assertThat(InputMethodAndSubtypeUtil.isValidNonAuxAsciiCapableIme(
createDummyIme(false, createDummySubtype("keyboard", false, false))))
createFakeIme(false, createFakeSubtype("keyboard", false, false))))
.isFalse();
// IME w/ non-Aux and ASCII-capable "keyboard" subtype
assertThat(InputMethodAndSubtypeUtil.isValidNonAuxAsciiCapableIme(
createDummyIme(false, createDummySubtype("keyboard", false, true))))
createFakeIme(false, createFakeSubtype("keyboard", false, true))))
.isTrue();
// IME w/ Aux and ASCII-capable "keyboard" subtype
assertThat(InputMethodAndSubtypeUtil.isValidNonAuxAsciiCapableIme(
createDummyIme(true, createDummySubtype("keyboard", true, true))))
createFakeIme(true, createFakeSubtype("keyboard", true, true))))
.isFalse();
// IME w/ non-Aux and ASCII-capable "voice" subtype
assertThat(InputMethodAndSubtypeUtil.isValidNonAuxAsciiCapableIme(
createDummyIme(false, createDummySubtype("voice", false, true))))
createFakeIme(false, createFakeSubtype("voice", false, true))))
.isFalse();
// IME w/ non-Aux and non-ASCII-capable subtype + Non-Aux and ASCII-capable subtype
assertThat(InputMethodAndSubtypeUtil.isValidNonAuxAsciiCapableIme(
createDummyIme(false,
createDummySubtype("keyboard", false, true),
createDummySubtype("keyboard", false, false))))
createFakeIme(false,
createFakeSubtype("keyboard", false, true),
createFakeSubtype("keyboard", false, false))))
.isTrue();
}
private static InputMethodInfo createDummyIme(boolean isAuxIme,
private static InputMethodInfo createFakeIme(boolean isAuxIme,
InputMethodSubtype... subtypes) {
final ResolveInfo ri = new ResolveInfo();
final ServiceInfo si = new ServiceInfo();
final ApplicationInfo ai = new ApplicationInfo();
ai.packageName = "com.example.android.dummyime";
ai.packageName = "com.example.android.fakeime";
ai.enabled = true;
si.applicationInfo = ai;
si.enabled = true;
si.packageName = "com.example.android.dummyime";
si.name = "Dummy IME";
si.packageName = "com.example.android.fakeime";
si.name = "Fake IME";
si.exported = true;
si.nonLocalizedLabel = "Dummy IME";
si.nonLocalizedLabel = "Fake IME";
ri.serviceInfo = si;
return new InputMethodInfo(ri, isAuxIme, "", Arrays.asList(subtypes), 1, false);
}
private static InputMethodSubtype createDummySubtype(
private static InputMethodSubtype createFakeSubtype(
String mode, boolean isAuxiliary, boolean isAsciiCapable) {
return new InputMethodSubtypeBuilder()
.setSubtypeNameResId(0)