diff options
author | Esteban Talavera <etalavera@google.com> | 2014-09-08 17:49:01 +0100 |
---|---|---|
committer | Esteban Talavera <etalavera@google.com> | 2014-09-12 11:33:59 +0100 |
commit | b5ef162129ced7e9636052af6b7f08d677a01f13 (patch) | |
tree | f099a30cd7116e41a64ef8b94827813bb94a2b9a /services | |
parent | c96e3927657558f0d01626c252cf480624749120 (diff) | |
download | frameworks_base-b5ef162129ced7e9636052af6b7f08d677a01f13.zip frameworks_base-b5ef162129ced7e9636052af6b7f08d677a01f13.tar.gz frameworks_base-b5ef162129ced7e9636052af6b7f08d677a01f13.tar.bz2 |
Add new adb dpm (= DevicePolicyManager) command
Adds new adb command to execute DevicePolicyManager tasks. First subcommand
allows us to set a device owner on a provisioned device (provided no accounts
are associated with the device). This is required as GTS tests run on provisioned
devices. We plan to add more subcomands required for new GTS tests, such as the
ability to create a managed profile.
Bug: 17312478, 17316711
Change-Id: I2613178ea82a6c6268e7f8012e74c4a852fea0d4
Diffstat (limited to 'services')
-rw-r--r-- | services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java | 18 |
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 5ad9825..225465b 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; @@ -3548,7 +3549,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."); } @@ -3847,9 +3848,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) { |