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
This commit is contained in:
Felipe Leme
2021-03-08 13:43:19 -08:00
parent fd8f4ae270
commit 8cf30ff9c7

View File

@@ -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"