From 90c9dbc91910a77b8660ec66de0725aee472e0ab Mon Sep 17 00:00:00 2001 From: Ricky Wai Date: Tue, 31 May 2016 17:48:23 +0100 Subject: [PATCH] Do not get device owner admin info when device owner is null Bug: 29043723 Change-Id: I355c549f891a5e71f654f42ed16a7139da86482a --- .../devicepolicy/DevicePolicyManagerService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 1af9ccbbcfd7b..9a7e64b3a9235 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -3810,12 +3810,16 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { // If caller has PO (or DO) it can change the password, so see if that's the case first. ActiveAdmin admin = getActiveAdminWithPolicyForUidLocked( null, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER, callingUid); - final boolean preN = getTargetSdk(admin.info.getPackageName(), - userHandle) <= android.os.Build.VERSION_CODES.M; - if (admin == null) { + final boolean preN; + if (admin != null) { + preN = getTargetSdk(admin.info.getPackageName(), + userHandle) <= android.os.Build.VERSION_CODES.M; + } else { // Otherwise, make sure the caller has any active admin with the right policy. admin = getActiveAdminForCallerLocked(null, DeviceAdminInfo.USES_POLICY_RESET_PASSWORD); + preN = getTargetSdk(admin.info.getPackageName(), + userHandle) <= android.os.Build.VERSION_CODES.M; // As of N, password resetting to empty/null is not allowed anymore. // TODO Should we allow DO/PO to set an empty password?