Add device/profile app check in background check

If app is device or profile app, we disable the background check
toggle. This cl also create an util method for this check and
remove duplicate code

Bug: 64665807
Test: RunSettingsRoboTests
Change-Id: Id8336eadaac8832327bc3653aaa7dfbacde352ac
This commit is contained in:
jackqdyulei
2017-08-22 11:25:30 -07:00
parent efcc8be05c
commit 00015fbf50
8 changed files with 95 additions and 40 deletions

View File

@@ -274,7 +274,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;
}
@@ -349,23 +349,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) {