summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java45
1 files changed, 26 insertions, 19 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 2483f152dcab..89a280930c60 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -15413,24 +15413,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
}
- final String[] feature_allow =
- { DevicePolicyManager.ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED };
- final String[] feature_disallow =
- { DevicePolicyManager.ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED };
-
- boolean compatible = true;
- for (Account account : accounts) {
- if (hasAccountFeatures(am, account, feature_disallow)) {
- Slogf.e(LOG_TAG, "%s has %s", account, feature_disallow[0]);
- compatible = false;
- break;
- }
- if (!hasAccountFeatures(am, account, feature_allow)) {
- Slogf.e(LOG_TAG, "%s doesn't have %s", account, feature_allow[0]);
- compatible = false;
- break;
- }
- }
+ boolean compatible = !hasIncompatibleAccounts(am, accounts);
if (compatible) {
Slogf.w(LOG_TAG, "All accounts are compatible");
} else {
@@ -15440,6 +15423,27 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
});
}
+ private boolean hasIncompatibleAccounts(AccountManager am, Account[] accounts) {
+ // TODO(b/244284408): Add test
+ final String[] feature_allow =
+ { DevicePolicyManager.ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED };
+ final String[] feature_disallow =
+ { DevicePolicyManager.ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED };
+
+ for (Account account : accounts) {
+ if (hasAccountFeatures(am, account, feature_disallow)) {
+ Slogf.e(LOG_TAG, "%s has %s", account, feature_disallow[0]);
+ return true;
+ }
+ if (!hasAccountFeatures(am, account, feature_allow)) {
+ Slogf.e(LOG_TAG, "%s doesn't have %s", account, feature_allow[0]);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private boolean hasAccountFeatures(AccountManager am, Account account, String[] features) {
try {
return am.hasFeatures(account, features, null, null).getResult();
@@ -18703,7 +18707,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
AccountManager am = AccountManager.get(mContext);
Account[] accounts = am.getAccounts();
- return accounts.length == 0;
+ if (accounts.length == 0) {
+ return true;
+ }
+ return !hasIncompatibleAccounts(am, accounts);
}
private void setBypassDevicePolicyManagementRoleQualificationStateInternal(