From Lollipop was introduced the concept of Device Owner, a sort of super-user with high privileges (not like the system root btw).
As Device Owner you can use methods in the DevicePolicyManager class to take fine-grain control of the configuration, security, and apps on managed devices.
Among the various methods you can find

addUserRestriction(ComponentName admin, String key)

that allow you to set some very interesting restrictions to your app user, for example:

- DISALLOW_ADD_USER: Specifies if a user is disallowed from adding new users and profiles
- DISALLOW_INSTALL_APPS: Specifies if a user is disallowed from installing applications.
- DISALLOW_FACTORY_RESET: Specifies if a user is disallowed from factory resetting from Settings.

… and many more…
If you wanna try I’ve assembled a very simple app-example with all the User Restrictions actually available, you can find it on my github page 🙂

Screen Shot 2016-01-31 at 17.58.06
Moreover there is a restriction kinda strange on the documentation:

- DISALLOW_FUN: Specifies if the user is not allowed to have fun.

Now this mean that someway someone has defined what is “fun” on the device!!
I’m really curious about that, need to try in next days on a device with Marshmallow installed 😉
Oh right, about the post title, UserManager class give you another beautiful method:

boolean isUserAGoat()

Used to determine whether the user making this call is subject to teleportations.
Android Os … so so powerful!

ps: If you want to try the code you need to assign Device Owner privileges to the apps, for doing this you need to be sure that on the device (or simulator) there is no google account active, open a terminal and digit

adb shell

then for assigning the device owner privileges type:

dpm set-device-owner it.paolomoschini.usermanagerrestrictions/it.paolomoschini.usermanagerrestrictions.receiver.MyDeviceAdminReceiver
  • By: paolo.moschini
  • In: android
  • Under: