Merge "Never restricts Accessibility Activities based on ECM/admin." into main

This commit is contained in:
Daniel Norman
2024-08-05 22:59:40 +00:00
committed by Android (Google) Code Review
3 changed files with 55 additions and 8 deletions

View File

@@ -71,6 +71,16 @@ flag {
}
}
flag {
name: "never_restrict_accessibility_activity"
namespace: "accessibility"
description: "Stops possibly restricting AccessibilityActivityPreferences"
bug: "331990900"
metadata {
purpose: PURPOSE_BUGFIX
}
}
flag {
name: "remove_qs_tooltip_in_suw"
namespace: "accessibility"

View File

@@ -128,7 +128,13 @@ public class RestrictedPreferenceHelper {
AccessibilityActivityPreference preference = new AccessibilityActivityPreference(
mContext, componentName.getPackageName(), activityInfo.applicationInfo.uid,
info);
setRestrictedPreferenceEnabled(preference, permittedServices, serviceEnabled);
if (Flags.neverRestrictAccessibilityActivity()) {
// Accessibility Activities do not have elevated privileges so restricting
// them based on ECM or device admin does not give any value.
preference.setEnabled(true);
} else {
setRestrictedPreferenceEnabled(preference, permittedServices, serviceEnabled);
}
preferenceList.add(preference);
}
return preferenceList;

View File

@@ -31,9 +31,8 @@ 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.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import androidx.test.core.app.ApplicationProvider;
@@ -83,8 +82,6 @@ public class RestrictedPreferenceHelperTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
@Test
public void createAccessibilityServicePreferenceList_hasOneInfo_containsSameKey() {
@@ -100,7 +97,7 @@ public class RestrictedPreferenceHelperTest {
}
@Test
@RequiresFlagsEnabled(value = {android.security.Flags.FLAG_EXTEND_ECM_TO_ALL_SETTINGS,
@EnableFlags(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() {
ShadowRestrictedLockUtilsInternal.setEcmRestrictedPkgs(
@@ -116,7 +113,7 @@ public class RestrictedPreferenceHelperTest {
}
@Test
@RequiresFlagsEnabled(value = {android.security.Flags.FLAG_EXTEND_ECM_TO_ALL_SETTINGS,
@EnableFlags(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() {
ShadowRestrictedLockUtilsInternal.setEcmRestrictedPkgs();
@@ -144,6 +141,40 @@ public class RestrictedPreferenceHelperTest {
assertThat(preference.getKey()).isEqualTo(key);
}
@Test
@EnableFlags(value = {android.security.Flags.FLAG_EXTEND_ECM_TO_ALL_SETTINGS,
android.permission.flags.Flags.FLAG_ENHANCED_CONFIRMATION_MODE_APIS_ENABLED})
@DisableFlags(Flags.FLAG_NEVER_RESTRICT_ACCESSIBILITY_ACTIVITY)
public void createAccessibilityActivityPreference_ecmRestricted_prefIsEcmRestricted() {
setMockAccessibilityShortcutInfo(mShortcutInfo);
ShadowRestrictedLockUtilsInternal.setEcmRestrictedPkgs(PACKAGE_NAME);
final List<AccessibilityActivityPreference> preferenceList =
mHelper.createAccessibilityActivityPreferenceList(List.of(mShortcutInfo));
assertThat(preferenceList).hasSize(1);
final RestrictedPreference preference = preferenceList.get(0);
assertThat(preference.isDisabledByEcm()).isTrue();
}
@Test
@EnableFlags(value = {
android.security.Flags.FLAG_EXTEND_ECM_TO_ALL_SETTINGS,
android.permission.flags.Flags.FLAG_ENHANCED_CONFIRMATION_MODE_APIS_ENABLED,
Flags.FLAG_NEVER_RESTRICT_ACCESSIBILITY_ACTIVITY,
})
public void createAccessibilityActivityPreference_ecmRestricted_prefIsNotEcmRestricted() {
setMockAccessibilityShortcutInfo(mShortcutInfo);
ShadowRestrictedLockUtilsInternal.setEcmRestrictedPkgs(PACKAGE_NAME);
final List<AccessibilityActivityPreference> preferenceList =
mHelper.createAccessibilityActivityPreferenceList(List.of(mShortcutInfo));
assertThat(preferenceList).hasSize(1);
final RestrictedPreference preference = preferenceList.get(0);
assertThat(preference.isDisabledByEcm()).isFalse();
}
private AccessibilityServiceInfo getMockAccessibilityServiceInfo(String packageName,
String className) {
final ApplicationInfo applicationInfo = new ApplicationInfo();