3

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

Floern
  • 33,559
  • 24
  • 104
  • 119
user1429322
  • 1,266
  • 2
  • 24
  • 38

2 Answers2

1

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

PasinduJay
  • 487
  • 5
  • 17
0

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

bmg
  • 153
  • 2
  • 8