Prevent the disabling of specified apps
Prevent the disabling of specified apps, avoiding cases where disabling the app may result in an unusable system. Bug: 200043113 Test: make RunSettingsRoboTests ROBOTEST_FILTER=ApplicationFeatureProviderImplTest Change-Id: I0b298af76cec20e4f31ec7411bbf3200a2869035 Merged-In: I0b298af76cec20e4f31ec7411bbf3200a2869035
This commit is contained in:
committed by
Chris Antol
parent
4f4bb89a23
commit
49a60a152a
@@ -35,6 +35,7 @@ import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Build;
|
||||
import android.os.SystemConfigManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
@@ -76,6 +77,9 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
|
||||
private final String PERMISSION = "some.permission";
|
||||
|
||||
private final List<String> PREVENT_USER_DISABLE_PACKAGES = List.of(
|
||||
"prevent.disable.package1", "prevent.disable.package2", "prevent.disable.package3");
|
||||
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
@@ -88,6 +92,8 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock
|
||||
private LocationManager mLocationManager;
|
||||
@Mock
|
||||
private SystemConfigManager mSystemConfigManager;
|
||||
|
||||
private ApplicationFeatureProvider mProvider;
|
||||
|
||||
@@ -101,6 +107,7 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
when(mContext.getSystemService(Context.LOCATION_SERVICE)).thenReturn(mLocationManager);
|
||||
when(mContext.getSystemService(SystemConfigManager.class)).thenReturn(mSystemConfigManager);
|
||||
|
||||
mProvider = new ApplicationFeatureProviderImpl(mContext, mPackageManager,
|
||||
mPackageManagerService, mDevicePolicyManager);
|
||||
@@ -356,6 +363,16 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
assertThat(allowlist).contains("com.android.packageinstaller");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKeepEnabledPackages_shouldContainPreventUserDisablePackages() {
|
||||
when(mSystemConfigManager.getPreventUserDisablePackages())
|
||||
.thenReturn(PREVENT_USER_DISABLE_PACKAGES);
|
||||
|
||||
final Set<String> keepEnabledPackages = mProvider.getKeepEnabledPackages();
|
||||
|
||||
assertThat(keepEnabledPackages).containsAtLeastElementsIn(PREVENT_USER_DISABLE_PACKAGES);
|
||||
}
|
||||
|
||||
private void setUpUsersAndInstalledApps() {
|
||||
when(mUserManager.getProfiles(UserHandle.myUserId())).thenReturn(Arrays.asList(
|
||||
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
|
||||
|
||||
Reference in New Issue
Block a user