Add block uninstall delegation in DPMS.
Implement the uninstall blocker delegation scope API in
DevicePolicyManagerSercice.
This feature gives a device owner or profile owner the ability to
delegate some of its privileges to another application.
Bug: 33105718
Test: cts-tradefed run cts-dev --module CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.MixedDeviceOwnerTest#testDelegation
Change-Id: Ieb347ce3fb6219fe7f04cafbcd1e6b7359b31a10
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index f06d19c..abab6bf 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -1224,6 +1224,12 @@
public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
/**
+ * Delegation of application uninstall block. This scope grants access to the
+ * {@link #setUninstallBlocked} API.
+ */
+ public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
+
+ /**
* No management for current user in-effect. This is the default.
* @hide
*/
@@ -6127,19 +6133,25 @@
}
/**
- * Called by profile or device owners to change whether a user can uninstall a package.
+ * Change whether a user can uninstall a package. This function can be called by a device owner,
+ * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
+ * {@link #setDelegatedScopes}.
*
- * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+ * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
+ * {@code null} if the caller is a block uninstall delegate.
* @param packageName package to change.
* @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
* @throws SecurityException if {@code admin} is not a device or profile owner.
+ * @see #setDelegatedScopes
+ * @see #DELEGATION_BLOCK_UNINSTALL
*/
- public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
+ public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
boolean uninstallBlocked) {
throwIfParentInstance("setUninstallBlocked");
if (mService != null) {
try {
- mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
+ mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
+ uninstallBlocked);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}