From f87b174dac87ed9e95e8522bfb836707f4a2239d Mon Sep 17 00:00:00 2001 From: Benjamin Franz Date: Fri, 23 Jan 2015 15:32:30 +0000 Subject: [PATCH] Avoid NullPointerException if createUser returns null If createUser returns null, we run into a NullPointerException in createAndInitializeUser. This can happen when the policy DISALLOW_ADD_USER is set. Bug: 19121141 Change-Id: Id4bda832a243fa42c31eb5a176ecaa248aee68f5 --- .../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 2ca562910f575..2ffc963fecb16 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -4734,6 +4734,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { public UserHandle createAndInitializeUser(ComponentName who, String name, String ownerName, ComponentName profileOwnerComponent, Bundle adminExtras) { UserHandle user = createUser(who, name); + if (user == null) { + return null; + } long id = Binder.clearCallingIdentity(); try { String profileOwnerPkg = profileOwnerComponent.getPackageName();