summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorEsteban Talavera <etalavera@google.com>2014-09-12 10:35:42 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-09-12 10:35:44 +0000
commitd09fbafa9242e67450c2f85807a159152d4761c8 (patch)
tree7d22060f5861a49fb5e5f60835920b59e50446cd /services
parent11f72c0d975cc9f3b9b800639c38c15e89e9be66 (diff)
parentb5ef162129ced7e9636052af6b7f08d677a01f13 (diff)
downloadframeworks_base-d09fbafa9242e67450c2f85807a159152d4761c8.zip
frameworks_base-d09fbafa9242e67450c2f85807a159152d4761c8.tar.gz
frameworks_base-d09fbafa9242e67450c2f85807a159152d4761c8.tar.bz2
Merge "Add new adb dpm (= DevicePolicyManager) command" into lmp-dev
Diffstat (limited to 'services')
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java18
1 files changed, 14 insertions, 4 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 8e82e2a..efaf253 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -19,6 +19,7 @@ package com.android.server.devicepolicy;
import static android.Manifest.permission.MANAGE_CA_CERTIFICATES;
import android.accessibilityservice.AccessibilityServiceInfo;
+import android.accounts.AccountManager;
import android.app.Activity;
import android.app.ActivityManagerNative;
import android.app.AlarmManager;
@@ -3579,7 +3580,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
+ " for device owner");
}
synchronized (this) {
- if (isDeviceProvisioned()) {
+ if (!allowedToSetDeviceOwnerOnDevice()) {
throw new IllegalStateException(
"Trying to set device owner but device is already provisioned.");
}
@@ -3878,9 +3879,18 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
return null;
}
- private boolean isDeviceProvisioned() {
- return Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.DEVICE_PROVISIONED, 0) > 0;
+ /**
+ * Device owner can only be set on an unprovisioned device, unless it was initiated by "adb", in
+ * which case we allow it if no account is associated with the device.
+ */
+ private boolean allowedToSetDeviceOwnerOnDevice() {
+ int callingId = Binder.getCallingUid();
+ if (callingId == Process.SHELL_UID || callingId == Process.ROOT_UID) {
+ return AccountManager.get(mContext).getAccounts().length == 0;
+ } else {
+ return Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.DEVICE_PROVISIONED, 0) == 0;
+ }
}
private boolean isUserSetupComplete(int userId) {