Merge "Prevent the disabling of specified apps" into main
This commit is contained in:
@@ -30,6 +30,7 @@ import android.content.pm.ServiceInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.location.LocationManager;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemConfigManager;
|
||||
import android.os.UserManager;
|
||||
import android.service.euicc.EuiccService;
|
||||
import android.telecom.DefaultDialerManager;
|
||||
@@ -54,6 +55,8 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
||||
private final IPackageManager mPms;
|
||||
private final DevicePolicyManager mDpm;
|
||||
private final UserManager mUm;
|
||||
private final SystemConfigManager mSystemConfigManager;
|
||||
|
||||
/** Flags to use when querying PackageManager for Euicc component implementations. */
|
||||
private static final int EUICC_QUERY_FLAGS =
|
||||
PackageManager.MATCH_SYSTEM_ONLY | PackageManager.MATCH_DEBUG_TRIAGED_MISSING
|
||||
@@ -66,6 +69,7 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
||||
mPms = pms;
|
||||
mDpm = dpm;
|
||||
mUm = UserManager.get(mContext);
|
||||
mSystemConfigManager = context.getSystemService(SystemConfigManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,6 +171,7 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
||||
if (locationHistoryPackage != null) {
|
||||
keepEnabledPackages.add(locationHistoryPackage);
|
||||
}
|
||||
keepEnabledPackages.addAll(mSystemConfigManager.getPreventUserDisablePackages());
|
||||
return keepEnabledPackages;
|
||||
}
|
||||
|
||||
|
@@ -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