Merge "Prevent the disabling of specified apps" into main am: d06d6affb4
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/2774892 Change-Id: I71870eb897d63bd00a7ad4d436bcc1dd91315144 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -30,6 +30,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;
|
||||||
@@ -54,6 +55,8 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
|||||||
private final IPackageManager mPms;
|
private final IPackageManager mPms;
|
||||||
private final DevicePolicyManager mDpm;
|
private final DevicePolicyManager mDpm;
|
||||||
private final UserManager mUm;
|
private final UserManager mUm;
|
||||||
|
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
|
||||||
@@ -66,6 +69,7 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
|||||||
mPms = pms;
|
mPms = pms;
|
||||||
mDpm = dpm;
|
mDpm = dpm;
|
||||||
mUm = UserManager.get(mContext);
|
mUm = UserManager.get(mContext);
|
||||||
|
mSystemConfigManager = context.getSystemService(SystemConfigManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -167,6 +171,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;
|
||||||
|
|
||||||
@@ -76,6 +77,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
|
||||||
@@ -88,6 +92,8 @@ public final class ApplicationFeatureProviderImplTest {
|
|||||||
private DevicePolicyManager mDevicePolicyManager;
|
private DevicePolicyManager mDevicePolicyManager;
|
||||||
@Mock
|
@Mock
|
||||||
private LocationManager mLocationManager;
|
private LocationManager mLocationManager;
|
||||||
|
@Mock
|
||||||
|
private SystemConfigManager mSystemConfigManager;
|
||||||
|
|
||||||
private ApplicationFeatureProvider mProvider;
|
private ApplicationFeatureProvider mProvider;
|
||||||
|
|
||||||
@@ -101,6 +107,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);
|
mPackageManagerService, mDevicePolicyManager);
|
||||||
@@ -356,6 +363,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