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 (cherry picked from https://android-review.googlesource.com/q/commit:e6279dd6a20ee254bab9a66e545b9dbaf1895db0) Change-Id: I0b298af76cec20e4f31ec7411bbf3200a2869035
This commit is contained in:
committed by
Chris Antol
parent
d4d9c4fe59
commit
03bde3d8c6
@@ -32,6 +32,7 @@ import android.content.pm.ServiceInfo;
|
|||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.os.SystemConfigManager;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.service.euicc.EuiccService;
|
import android.service.euicc.EuiccService;
|
||||||
import android.telecom.DefaultDialerManager;
|
import android.telecom.DefaultDialerManager;
|
||||||
@@ -58,6 +59,8 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
|||||||
private final DevicePolicyManager mDpm;
|
private final DevicePolicyManager mDpm;
|
||||||
private final UserManager mUm;
|
private final UserManager mUm;
|
||||||
private final WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
|
private final WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
|
||||||
|
private final SystemConfigManager mSystemConfigManager;
|
||||||
|
|
||||||
/** Flags to use when querying PackageManager for Euicc component implementations. */
|
/** Flags to use when querying PackageManager for Euicc component implementations. */
|
||||||
private static final int EUICC_QUERY_FLAGS =
|
private static final int EUICC_QUERY_FLAGS =
|
||||||
PackageManager.MATCH_SYSTEM_ONLY | PackageManager.MATCH_DEBUG_TRIAGED_MISSING
|
PackageManager.MATCH_SYSTEM_ONLY | PackageManager.MATCH_DEBUG_TRIAGED_MISSING
|
||||||
@@ -75,6 +78,7 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
|||||||
mDpm = dpm;
|
mDpm = dpm;
|
||||||
mUm = UserManager.get(mContext);
|
mUm = UserManager.get(mContext);
|
||||||
mWebViewUpdateServiceWrapper = wvusWrapper;
|
mWebViewUpdateServiceWrapper = wvusWrapper;
|
||||||
|
mSystemConfigManager = context.getSystemService(SystemConfigManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -184,6 +188,7 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
|||||||
if (locationHistoryPackage != null) {
|
if (locationHistoryPackage != null) {
|
||||||
keepEnabledPackages.add(locationHistoryPackage);
|
keepEnabledPackages.add(locationHistoryPackage);
|
||||||
}
|
}
|
||||||
|
keepEnabledPackages.addAll(mSystemConfigManager.getPreventUserDisablePackages());
|
||||||
return keepEnabledPackages;
|
return keepEnabledPackages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@ import android.content.pm.ResolveInfo;
|
|||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.SystemConfigManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||||
@@ -89,6 +90,9 @@ public final class ApplicationFeatureProviderImplTest {
|
|||||||
|
|
||||||
private final String PERMISSION = "some.permission";
|
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
|
@Mock
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -103,6 +107,8 @@ public final class ApplicationFeatureProviderImplTest {
|
|||||||
private LocationManager mLocationManager;
|
private LocationManager mLocationManager;
|
||||||
@Mock
|
@Mock
|
||||||
private WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
|
private WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
|
||||||
|
@Mock
|
||||||
|
private SystemConfigManager mSystemConfigManager;
|
||||||
|
|
||||||
private ApplicationFeatureProvider mProvider;
|
private ApplicationFeatureProvider mProvider;
|
||||||
|
|
||||||
@@ -116,6 +122,7 @@ public final class ApplicationFeatureProviderImplTest {
|
|||||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||||
when(mContext.getSystemService(Context.LOCATION_SERVICE)).thenReturn(mLocationManager);
|
when(mContext.getSystemService(Context.LOCATION_SERVICE)).thenReturn(mLocationManager);
|
||||||
|
when(mContext.getSystemService(SystemConfigManager.class)).thenReturn(mSystemConfigManager);
|
||||||
|
|
||||||
mProvider = new ApplicationFeatureProviderImpl(mContext, mPackageManager,
|
mProvider = new ApplicationFeatureProviderImpl(mContext, mPackageManager,
|
||||||
mPackageManagerService, mDevicePolicyManager, mWebViewUpdateServiceWrapper);
|
mPackageManagerService, mDevicePolicyManager, mWebViewUpdateServiceWrapper);
|
||||||
@@ -395,6 +402,16 @@ public final class ApplicationFeatureProviderImplTest {
|
|||||||
assertThat(allowlist).contains("com.android.packageinstaller");
|
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() {
|
private void setUpUsersAndInstalledApps() {
|
||||||
when(mUserManager.getProfiles(UserHandle.myUserId())).thenReturn(Arrays.asList(
|
when(mUserManager.getProfiles(UserHandle.myUserId())).thenReturn(Arrays.asList(
|
||||||
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
|
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
|
||||||
|
Reference in New Issue
Block a user