Replace ECM AppOps call with service
A new ECM service was introcuded in changeId I831391e4437b51b3312b5273a2360bd029a3d8ee. We begin calling it, and update/cleanup method signatures to match. Note: There are two feature flags: 1. enhancedConfirmationModeApisEnabled - read only, protects the mainline API. 2. extendEcmToAllSettings - runtime - gates calls to the above APIs. We use both so we can ramp up in teamfood as needed. Bug: 297372999 Test: Tested on device Test: atest SpaPrivilegedLibTests Test: atest com.android.settings.applications.specialaccess.notificationaccess Test: atest com.android.settings.datausage Test: atest PremiumSmsAccessTest Test: atest RestrictedPreferenceHelperTest Change-Id: I945ec51df5cd63de548a8ffdd1acc4f09f2301e5
This commit is contained in:
@@ -38,6 +38,7 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@@ -57,7 +58,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link AccessibilityDetailsSettingsFragment}. */
|
||||
@Config(shadows = ShadowDevicePolicyManager.class)
|
||||
@Config(shadows = {
|
||||
ShadowDevicePolicyManager.class,
|
||||
ShadowRestrictedLockUtilsInternal.class
|
||||
})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AccessibilityDetailsSettingsFragmentTest {
|
||||
private static final String PACKAGE_NAME = "com.foo.bar";
|
||||
|
||||
@@ -52,6 +52,7 @@ import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowApplicationPackageManager;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
@@ -87,6 +88,7 @@ import java.util.List;
|
||||
ShadowUserManager.class,
|
||||
ShadowColorDisplayManager.class,
|
||||
ShadowApplicationPackageManager.class,
|
||||
ShadowRestrictedLockUtilsInternal.class,
|
||||
})
|
||||
public class AccessibilitySettingsTest {
|
||||
private static final String PACKAGE_NAME = "com.android.test";
|
||||
|
||||
@@ -31,8 +31,10 @@ import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.security.Flags;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
@@ -81,6 +83,8 @@ public class RestrictedPreferenceHelperTest {
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
@Test
|
||||
public void createAccessibilityServicePreferenceList_hasOneInfo_containsSameKey() {
|
||||
@@ -96,8 +100,9 @@ public class RestrictedPreferenceHelperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(value = {android.security.Flags.FLAG_EXTEND_ECM_TO_ALL_SETTINGS,
|
||||
android.permission.flags.Flags.FLAG_ENHANCED_CONFIRMATION_MODE_APIS_ENABLED})
|
||||
public void createAccessibilityServicePreferenceList_ecmRestricted_prefIsEcmRestricted() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_EXTEND_ECM_TO_ALL_SETTINGS);
|
||||
ShadowRestrictedLockUtilsInternal.setEcmRestrictedPkgs(
|
||||
mServiceInfo.getResolveInfo().serviceInfo.packageName);
|
||||
final List<AccessibilityServiceInfo> infoList = new ArrayList<>(
|
||||
@@ -111,8 +116,9 @@ public class RestrictedPreferenceHelperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(value = {android.security.Flags.FLAG_EXTEND_ECM_TO_ALL_SETTINGS,
|
||||
android.permission.flags.Flags.FLAG_ENHANCED_CONFIRMATION_MODE_APIS_ENABLED})
|
||||
public void createAccessibilityServicePreferenceList_ecmNotRestricted_prefIsNotEcmRestricted() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_EXTEND_ECM_TO_ALL_SETTINGS);
|
||||
ShadowRestrictedLockUtilsInternal.setEcmRestrictedPkgs();
|
||||
final List<AccessibilityServiceInfo> infoList = new ArrayList<>(
|
||||
singletonList(mServiceInfo));
|
||||
|
||||
@@ -124,8 +124,6 @@ public class PremiumSmsAccessTest {
|
||||
|
||||
doAnswer((invocation) -> {
|
||||
final RestrictedDropDownPreference preference = invocation.getArgument(0);
|
||||
final ApplicationsState.AppEntry entry = ReflectionHelpers
|
||||
.getField(preference, "mAppEntry");
|
||||
// Verify preference is disabled by ecm and the summary is changed accordingly.
|
||||
assertThat(preference.isDisabledByEcm()).isTrue();
|
||||
assertThat(preference.getSummary().toString()).isEqualTo(
|
||||
@@ -156,13 +154,11 @@ public class PremiumSmsAccessTest {
|
||||
doReturn(preferenceManager).when(mFragment).getPreferenceManager();
|
||||
doReturn(preferenceScreen).when(mFragment).getPreferenceScreen();
|
||||
final String testPkg = "com.example.enabled";
|
||||
doNothing().when(mContext).startActivity(any());
|
||||
ShadowRestrictedLockUtilsInternal.setEcmRestrictedPkgs();
|
||||
|
||||
|
||||
doAnswer((invocation) -> {
|
||||
final RestrictedDropDownPreference preference = invocation.getArgument(0);
|
||||
final ApplicationsState.AppEntry entry = ReflectionHelpers
|
||||
.getField(preference, "mAppEntry");
|
||||
assertThat(preference.isDisabledByEcm()).isFalse();
|
||||
assertThat(preference.getSummary().toString()).isEqualTo("");
|
||||
preference.onBindViewHolder(holder);
|
||||
@@ -195,4 +191,3 @@ public class PremiumSmsAccessTest {
|
||||
return appEntries;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -167,11 +167,11 @@ public class UnrestrictedDataAccessPreferenceControllerTest {
|
||||
@Test
|
||||
public void onRebuildComplete_ecmRestricted_shouldBeDisabled() {
|
||||
mFragment = spy(new UnrestrictedDataAccess());
|
||||
mContext = spy(mContext);
|
||||
doNothing().when(mFragment).setLoading(anyBoolean(), anyBoolean());
|
||||
mController.setParentFragment(mFragment);
|
||||
final Context context = spy(mContext);
|
||||
mPreferenceManager = new PreferenceManager(context);
|
||||
mPreferenceScreen = spy(mPreferenceManager.createPreferenceScreen(context));
|
||||
mPreferenceManager = new PreferenceManager(mContext);
|
||||
mPreferenceScreen = spy(mPreferenceManager.createPreferenceScreen(mContext));
|
||||
doReturn(mPreferenceManager).when(mFragment).getPreferenceManager();
|
||||
doReturn(mPreferenceScreen).when(mFragment).getPreferenceScreen();
|
||||
doReturn(0).when(mPreferenceScreen).getPreferenceCount();
|
||||
@@ -180,12 +180,11 @@ public class UnrestrictedDataAccessPreferenceControllerTest {
|
||||
ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
|
||||
|
||||
final String testPkg = "com.example.disabled";
|
||||
doNothing().when(context).startActivity(any());
|
||||
doNothing().when(mContext).startActivity(any());
|
||||
ShadowRestrictedLockUtilsInternal.setEcmRestrictedPkgs(testPkg);
|
||||
|
||||
doAnswer((invocation) -> {
|
||||
final UnrestrictedDataAccessPreference preference = invocation.getArgument(0);
|
||||
final AppEntry entry = preference.getEntry();
|
||||
// Verify preference is disabled by ecm and the summary is changed accordingly.
|
||||
assertThat(preference.isDisabledByEcm()).isTrue();
|
||||
assertThat(preference.getSummary().toString()).isEqualTo(
|
||||
@@ -195,7 +194,7 @@ public class UnrestrictedDataAccessPreferenceControllerTest {
|
||||
preference.performClick();
|
||||
// Verify that when the preference is clicked, ecm details intent is launched
|
||||
assertThat(preference.isChecked()).isFalse();
|
||||
verify(context).startActivity(any());
|
||||
verify(mContext).startActivity(any());
|
||||
|
||||
return null;
|
||||
}).when(mPreferenceScreen).addPreference(any(UnrestrictedDataAccessPreference.class));
|
||||
@@ -207,11 +206,11 @@ public class UnrestrictedDataAccessPreferenceControllerTest {
|
||||
@Test
|
||||
public void onRebuildComplete_ecmNotRestricted_notDisabled() {
|
||||
mFragment = spy(new UnrestrictedDataAccess());
|
||||
mContext = spy(mContext);
|
||||
doNothing().when(mFragment).setLoading(anyBoolean(), anyBoolean());
|
||||
mController.setParentFragment(mFragment);
|
||||
final Context context = spy(mContext);
|
||||
mPreferenceManager = new PreferenceManager(context);
|
||||
mPreferenceScreen = spy(mPreferenceManager.createPreferenceScreen(context));
|
||||
mPreferenceManager = new PreferenceManager(mContext);
|
||||
mPreferenceScreen = spy(mPreferenceManager.createPreferenceScreen(mContext));
|
||||
doReturn(mPreferenceManager).when(mFragment).getPreferenceManager();
|
||||
doReturn(mPreferenceScreen).when(mFragment).getPreferenceScreen();
|
||||
doReturn(0).when(mPreferenceScreen).getPreferenceCount();
|
||||
@@ -220,19 +219,18 @@ public class UnrestrictedDataAccessPreferenceControllerTest {
|
||||
ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
|
||||
|
||||
final String testPkg = "com.example.enabled";
|
||||
doNothing().when(context).startActivity(any());
|
||||
doNothing().when(mContext).startActivity(any());
|
||||
ShadowRestrictedLockUtilsInternal.setEcmRestrictedPkgs();
|
||||
|
||||
doAnswer((invocation) -> {
|
||||
final UnrestrictedDataAccessPreference preference = invocation.getArgument(0);
|
||||
final AppEntry entry = preference.getEntry();
|
||||
assertThat(preference.isDisabledByEcm()).isFalse();
|
||||
assertThat(preference.getSummary()).isEqualTo("");
|
||||
assertThat(preference.isChecked()).isFalse();
|
||||
preference.performClick();
|
||||
// Verify that when the preference is clicked, ecm details intent is not launched
|
||||
assertThat(preference.isChecked()).isTrue();
|
||||
verify(context, never()).startActivity(any());
|
||||
verify(mContext, never()).startActivity(any());
|
||||
|
||||
return null;
|
||||
}).when(mPreferenceScreen).addPreference(any(UnrestrictedDataAccessPreference.class));
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
@@ -122,9 +121,7 @@ public class ShadowRestrictedLockUtilsInternal {
|
||||
|
||||
@Implementation
|
||||
public static Intent checkIfRequiresEnhancedConfirmation(@NonNull Context context,
|
||||
@NonNull String restriction,
|
||||
int uid,
|
||||
@Nullable String packageName) {
|
||||
@NonNull String settingIdentifier, @NonNull String packageName) {
|
||||
if (ArrayUtils.contains(sEcmRestrictedPkgs, packageName)) {
|
||||
return new Intent();
|
||||
}
|
||||
@@ -132,6 +129,12 @@ public class ShadowRestrictedLockUtilsInternal {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static boolean isEnhancedConfirmationRestricted(@NonNull Context context,
|
||||
@NonNull String settingIdentifier, @NonNull String packageName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setRestricted(boolean restricted) {
|
||||
sIsRestricted = restricted;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user