Merge "Prevent the disabling of specified apps" into main

This commit is contained in:
Chris Antol
2024-01-12 18:54:58 +00:00
committed by Android (Google) Code Review
2 changed files with 22 additions and 0 deletions

View File

@@ -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;
import android.platform.test.annotations.RequiresFlagsDisabled;
@@ -89,6 +90,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
@@ -103,6 +107,8 @@ public final class ApplicationFeatureProviderImplTest {
private LocationManager mLocationManager;
@Mock
private WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
@Mock
private SystemConfigManager mSystemConfigManager;
private ApplicationFeatureProvider mProvider;
@@ -116,6 +122,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, mWebViewUpdateServiceWrapper);
@@ -395,6 +402,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),