From 8cf30ff9c7c91ecbccddb553431b775ecbaf98da Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Mon, 8 Mar 2021 13:43:19 -0800 Subject: [PATCH] Fixed mark-profile-owner-on-organization-owned-device for non-profile users It was throwing a NPE as such users are "orphan". Test: adb shell dpm mark-profile-owner-on-organization-owned-device com.afwsamples.testdpc/.DeviceAdminReceiver Fixes: 182189140 Change-Id: Ib02d767a23c53c1c2886728c2f338628149f7868 --- .../server/devicepolicy/DevicePolicyManagerService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 04af5c93160d6..8b82b56dfcf29 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -13639,6 +13639,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { mInjector.binderWithCleanCallingIdentity(() -> { // Clear restriction as user. final UserHandle parentUser = mUserManager.getProfileParent(UserHandle.of(userId)); + if (parentUser == null) { + throw new IllegalStateException(String.format("User %d is not a profile", userId)); + } if (!parentUser.isSystem()) { throw new IllegalStateException( String.format("Only the profile owner of a managed profile on the"