Merge "Add device/profile app check in background check" into oc-mr1-dev am: f5d7db2cfa

am: ec8007b426

Change-Id: I118fee2b974a0815d21d422358250281da9804f0
This commit is contained in:
Lei Yu
2017-08-30 17:21:30 +00:00
committed by android-build-merger
8 changed files with 95 additions and 40 deletions

View File

@@ -277,7 +277,7 @@ public class InstalledAppDetails extends AppInfoBase
// We don't allow uninstalling DO/PO on *any* users, because if it's a system app,
// "uninstall" is actually "downgrade to the system version + disable", and "downgrade"
// will clear data on all users.
if (isProfileOrDeviceOwner(mPackageInfo.packageName)) {
if (Utils.isProfileOrDeviceOwner(mUserManager, mDpm, mPackageInfo.packageName)) {
enabled = false;
}
@@ -352,23 +352,6 @@ public class InstalledAppDetails extends AppInfoBase
return enabled;
}
/** Returns if the supplied package is device owner or profile owner of at least one user */
private boolean isProfileOrDeviceOwner(String packageName) {
List<UserInfo> userInfos = mUserManager.getUsers();
DevicePolicyManager dpm = (DevicePolicyManager)
getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
if (dpm.isDeviceOwnerAppOnAnyUser(packageName)) {
return true;
}
for (UserInfo userInfo : userInfos) {
ComponentName cn = dpm.getProfileOwnerAsUser(userInfo.id);
if (cn != null && cn.getPackageName().equals(packageName)) {
return true;
}
}
return false;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {