user1429322
user1429322

Reputation: 1286

Android managed profile - Profile owners cannot set user restriction no_add_user

As a profile owner, I am trying to disable user addition and the code that I am using is

 devicePolicyManager.addUserRestriction(myComponent, UserManager.DISALLOW_ADD_USER)

When I call this I get a security exception that says

Process: net.notify.notifymdm, PID: 32626
java.lang.SecurityException: Profile owners cannot set user restriction no_add_user
        at android.os.Parcel.readException(Parcel.java:1546)
        at android.os.Parcel.readException(Parcel.java:1499)

The official documentation here says the caller must be Policy or Device owner. Is this a bug or am I doing something wrong here? The OS is 5.1

Upvotes: 3

Views: 2165

Answers (2)

bmg
bmg

Reputation: 153

The documentation explicitly mentions this now:

This restriction has no effect on secondary users and managed profiles since only the primary user can add other users.

https://developer.android.com/reference/android/os/UserManager.html#DISALLOW_ADD_USER

Upvotes: 0

PasinduJay
PasinduJay

Reputation: 485

I've faced the same problem. The issues is seemed to be although we can can access the method 'addUserRestriction' by being a profile/device owner, we can not pass UserManager keys under that privileges.

To use them we will be needing the MANAGE_USERS permission which has a protection level of signature|system. Therefore the application has to be signed with the platform key.

Refer this for more information: xdaDevelopers Enabling MultiUser

Upvotes: 1

Related Questions