Merge "DPC can be uninstalled in personal profile in New COPE" into rvc-dev

This commit is contained in:
Alex Johnston
2020-03-13 14:28:15 +00:00
committed by Android (Google) Code Review
3 changed files with 65 additions and 8 deletions

View File

@@ -887,6 +887,27 @@ public final class Utils extends com.android.settingslib.Utils {
return false;
}
/**
* Return {@code true} if the supplied package is the device owner or profile owner of a
* given user.
*
* @param devicePolicyManager used to check whether it is device owner and profile owner app
* @param packageName package to check about
* @param userId the if of the relevant user
*/
public static boolean isProfileOrDeviceOwner(DevicePolicyManager devicePolicyManager,
String packageName, int userId) {
if ((devicePolicyManager.getDeviceOwnerUserId() == userId)
&& devicePolicyManager.isDeviceOwnerApp(packageName)) {
return true;
}
final ComponentName cn = devicePolicyManager.getProfileOwnerAsUser(userId);
if (cn != null && cn.getPackageName().equals(packageName)) {
return true;
}
return false;
}
/**
* Return the resource id to represent the install status for an app
*/

View File

@@ -25,8 +25,8 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.om.OverlayManager;
import android.content.om.OverlayInfo;
import android.content.om.OverlayManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -393,11 +393,19 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
enabled = false;
}
// We don't allow uninstalling DO/PO on *any* users, because if it's a system app,
// We don't allow uninstalling DO/PO on *any* users if it's a system app, because
// "uninstall" is actually "downgrade to the system version + disable", and "downgrade"
// will clear data on all users.
if (Utils.isProfileOrDeviceOwner(mUserManager, mDpm, mPackageInfo.packageName)) {
enabled = false;
if (Utils.isSystemPackage(mActivity.getResources(), mPm, mPackageInfo)) {
if (Utils.isProfileOrDeviceOwner(mUserManager, mDpm, mPackageInfo.packageName)) {
enabled = false;
}
// We allow uninstalling if the calling user is not a DO/PO and if it's not a system app,
// because this will not have device-wide consequences.
} else {
if (Utils.isProfileOrDeviceOwner(mDpm, mPackageInfo.packageName, mUserId)) {
enabled = false;
}
}
// Don't allow uninstalling the device provisioning package.