Android APIs
public class

UserManager

extends Object
java.lang.Object
   ↳ android.os.UserManager

Class Overview

Manages users and user details on a multi-user system.

Summary

Constants
String DISALLOW_ADD_USER Key for user restrictions.
String DISALLOW_ADJUST_VOLUME Key for user restrictions.
String DISALLOW_CONFIG_APPS Key for user restrictions.
String DISALLOW_CONFIG_BLUETOOTH Key for user restrictions.
String DISALLOW_CONFIG_CELL_BROADCASTS Key for user restrictions.
String DISALLOW_CONFIG_CREDENTIALS Key for user restrictions.
String DISALLOW_CONFIG_MOBILE_NETWORKS Key for user restrictions.
String DISALLOW_CONFIG_TETHERING Key for user restrictions.
String DISALLOW_CONFIG_VPN Key for user restrictions.
String DISALLOW_CONFIG_WIFI Key for user restrictions.
String DISALLOW_DEBUGGING_FEATURES Key for user restrictions.
String DISALLOW_FACTORY_RESET Key for user restrictions.
String DISALLOW_INSTALL_APPS Key for user restrictions.
String DISALLOW_INSTALL_UNKNOWN_SOURCES Key for user restrictions.
String DISALLOW_MODIFY_ACCOUNTS Key for user restrictions.
String DISALLOW_MOUNT_PHYSICAL_MEDIA Key for user restrictions.
String DISALLOW_REMOVE_USER Key for user restrictions.
String DISALLOW_SHARE_LOCATION Key for user restrictions.
String DISALLOW_TELEPHONY Key for user restrictions.
String DISALLOW_UNINSTALL_APPS Key for user restrictions.
String DISALLOW_UNMUTE_MICROPHONE Key for user restrictions.
String DISALLOW_USB_FILE_TRANSFER Key for user restrictions.
String ENSURE_VERIFY_APPS Key for user restrictions.
Public Methods
Bundle getApplicationRestrictions(String packageName)
Returns a Bundle containing any saved application restrictions for this user, for the given package name.
Drawable getBadgedDrawableForUser(Drawable icon, UserHandle user)
If the target user is a managed profile of the calling user or the caller is itself a managed profile, then this returns a badged copy of the given icon to be able to distinguish it from the original icon.
long getSerialNumberForUser(UserHandle user)
Return the serial number for a user.
int getUserCount()
Return the number of users currently created on the device.
UserHandle getUserForSerialNumber(long serialNumber)
Return the user associated with a serial number previously returned by getSerialNumberForUser(UserHandle).
String getUserName()
Returns the user name of the user making this call.
List<UserHandle> getUserProfiles()
Returns a list of UserHandles for profiles associated with the user that the calling process is running on, including the user itself.
Bundle getUserRestrictions()
Returns the user-wide restrictions imposed on this user.
Bundle getUserRestrictions(UserHandle userHandle)
Returns the user-wide restrictions imposed on the user specified by userHandle.
boolean isUserAGoat()
Used to determine whether the user making this call is subject to teleportations.
boolean isUserRunning(UserHandle user)
Return whether the given user is actively running.
boolean isUserRunningOrStopping(UserHandle user)
Return whether the given user is actively running or stopping.
boolean setRestrictionsChallenge(String newPin)
Sets a new challenge PIN for restrictions.
void setUserRestriction(String key, boolean value)
Sets the value of a specific restriction.
void setUserRestrictions(Bundle restrictions)
Sets all the user-wide restrictions for this user.
void setUserRestrictions(Bundle restrictions, UserHandle userHandle)
Sets all the user-wide restrictions for the specified user.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String DISALLOW_ADD_USER

Key for user restrictions. Specifies if a user is disallowed from adding new users and profiles. The default value is false.

Type: Boolean

Constant Value: "no_add_user"

public static final String DISALLOW_ADJUST_VOLUME

Key for user restrictions. Specifies if a user is disallowed from adjusting the master volume. The default value is false.

Type: Boolean

Constant Value: "no_adjust_volume"

public static final String DISALLOW_CONFIG_APPS

Key for user restrictions. Specifies if a user is disallowed from configuring applications in Settings. The default value is false.

Type: Boolean

Constant Value: "no_config_apps"

public static final String DISALLOW_CONFIG_BLUETOOTH

Added in API level 18

Key for user restrictions. Specifies if a user is disallowed from configuring bluetooth. The default value is false.

Type: Boolean

Constant Value: "no_config_bluetooth"

public static final String DISALLOW_CONFIG_CELL_BROADCASTS

Key for user restrictions. Specifies if a user is disallowed from configuring cell broadcasts. The default value is false.

Type: Boolean

Constant Value: "no_config_cell_broadcasts"

public static final String DISALLOW_CONFIG_CREDENTIALS

Added in API level 18

Key for user restrictions. Specifies if a user is disallowed from configuring user credentials. The default value is false.

Type: Boolean

Constant Value: "no_config_credentials"

public static final String DISALLOW_CONFIG_MOBILE_NETWORKS

Key for user restrictions. Specifies if a user is disallowed from configuring mobile networks. The default value is false.

Type: Boolean

Constant Value: "no_config_mobile_networks"

public static final String DISALLOW_CONFIG_TETHERING

Key for user restrictions. Specifies if a user is disallowed from configuring Tethering & portable hotspots. The default value is false.

Type: Boolean

Constant Value: "no_config_tethering"

public static final String DISALLOW_CONFIG_VPN

Key for user restrictions. Specifies if a user is disallowed from configuring VPN. The default value is false.

Type: Boolean

Constant Value: "no_config_vpn"

public static final String DISALLOW_CONFIG_WIFI

Added in API level 18

Key for user restrictions. Specifies if a user is disallowed from changing Wi-Fi access points. The default value is false.

Type: Boolean

Constant Value: "no_config_wifi"

public static final String DISALLOW_DEBUGGING_FEATURES

Key for user restrictions. Specifies if a user is disallowed from enabling or accessing debugging features. The default value is false.

Type: Boolean

Constant Value: "no_debugging_features"

public static final String DISALLOW_FACTORY_RESET

Key for user restrictions. Specifies if a user is disallowed from factory resetting from Settings. The default value is false.

Constant Value: "no_factory_reset"

public static final String DISALLOW_INSTALL_APPS

Added in API level 18

Key for user restrictions. Specifies if a user is disallowed from installing applications. The default value is false.

Type: Boolean

Constant Value: "no_install_apps"

public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES

Added in API level 18

Key for user restrictions. Specifies if a user is disallowed from enabling the "Unknown Sources" setting, that allows installation of apps from unknown sources. The default value is false.

Type: Boolean

Constant Value: "no_install_unknown_sources"

public static final String DISALLOW_MODIFY_ACCOUNTS

Added in API level 18

Key for user restrictions. Specifies if a user is disallowed from adding and removing accounts. The default value is false.

Type: Boolean

Constant Value: "no_modify_accounts"

public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA

Key for user restrictions. Specifies if a user is disallowed from mounting physical external media. The default value is false.

Type: Boolean

Constant Value: "no_physical_media"

public static final String DISALLOW_REMOVE_USER

Added in API level 18

Key for user restrictions. Specifies if a user is disallowed from removing users. The default value is false.

Type: Boolean

Constant Value: "no_remove_user"

public static final String DISALLOW_SHARE_LOCATION

Added in API level 18

Key for user restrictions. Specifies if a user is disallowed from toggling location sharing. The default value is false.

Type: Boolean

Constant Value: "no_share_location"

public static final String DISALLOW_TELEPHONY

Key for user restrictions. Specifies that the user is not allowed to send or receive phone calls or text messages. Emergency calls may still be permitted. The default value is false.

Type: Boolean

Constant Value: "no_telephony"

public static final String DISALLOW_UNINSTALL_APPS

Added in API level 18

Key for user restrictions. Specifies if a user is disallowed from uninstalling applications. The default value is false.

Type: Boolean

Constant Value: "no_uninstall_apps"

public static final String DISALLOW_UNMUTE_MICROPHONE

Key for user restrictions. Specifies if a user is disallowed from adjusting microphone volume. The default value is false.

Type: Boolean

Constant Value: "no_unmute_microphone"

public static final String DISALLOW_USB_FILE_TRANSFER

Added in API level 18

Key for user restrictions. Specifies if a user is disallowed from transferring files over USB. The default value is false.

Type: Boolean

Constant Value: "no_usb_file_transfer"

public static final String ENSURE_VERIFY_APPS

Key for user restrictions. Specifies if a user is disallowed from disabling application verification. The default value is false.

Type: Boolean

Constant Value: "ensure_verify_apps"

Public Methods

public Bundle getApplicationRestrictions (String packageName)

Added in API level 18

Returns a Bundle containing any saved application restrictions for this user, for the given package name. Only an application with this package name can call this method.

Parameters
packageName the package name of the calling application
Returns
  • a Bundle with the restrictions as key/value pairs, or null if there are no saved restrictions. The values can be of type Boolean, String or String[], depending on the restriction type, as defined by the application.

public Drawable getBadgedDrawableForUser (Drawable icon, UserHandle user)

If the target user is a managed profile of the calling user or the caller is itself a managed profile, then this returns a badged copy of the given icon to be able to distinguish it from the original icon.

If the original drawable is not a BitmapDrawable, then the original drawable is returned.

Parameters
icon The icon to badge.
user The target user.
Returns
  • A drawable that combines the original icon and a badge as determined by the system.

public long getSerialNumberForUser (UserHandle user)

Added in API level 17

Return the serial number for a user. This is a device-unique number assigned to that user; if the user is deleted and then a new user created, the new users will not be given the same serial number.

Parameters
user The user whose serial number is to be retrieved.
Returns
  • The serial number of the given user; returns -1 if the given UserHandle does not exist.

public int getUserCount ()

Added in API level 17

Return the number of users currently created on the device.

public UserHandle getUserForSerialNumber (long serialNumber)

Added in API level 17

Return the user associated with a serial number previously returned by getSerialNumberForUser(UserHandle).

Parameters
serialNumber The serial number of the user that is being retrieved.
Returns
  • Return the user associated with the serial number, or null if there is not one.

public String getUserName ()

Added in API level 17

Returns the user name of the user making this call. This call is only available to applications on the system image; it requires the MANAGE_USERS permission.

Returns
  • the user name

public List<UserHandle> getUserProfiles ()

Returns a list of UserHandles for profiles associated with the user that the calling process is running on, including the user itself.

Returns
  • A non-empty list of UserHandles associated with the calling user.

public Bundle getUserRestrictions ()

Added in API level 18

Returns the user-wide restrictions imposed on this user.

Returns
  • a Bundle containing all the restrictions.

public Bundle getUserRestrictions (UserHandle userHandle)

Added in API level 18

Returns the user-wide restrictions imposed on the user specified by userHandle.

Parameters
userHandle the UserHandle of the user for whom to retrieve the restrictions.
Returns
  • a Bundle containing all the restrictions.

public boolean isUserAGoat ()

Added in API level 17

Used to determine whether the user making this call is subject to teleportations.

Returns
  • whether the user making this call is a goat

public boolean isUserRunning (UserHandle user)

Added in API level 17

Return whether the given user is actively running. This means that the user is in the "started" state, not "stopped" -- it is currently allowed to run code through scheduled alarms, receiving broadcasts, etc. A started user may be either the current foreground user or a background user; the result here does not distinguish between the two.

Parameters
user The user to retrieve the running state for.

public boolean isUserRunningOrStopping (UserHandle user)

Added in API level 17

Return whether the given user is actively running or stopping. This is like isUserRunning(UserHandle), but will also return true if the user had been running but is in the process of being stopped (but is not yet fully stopped, and still running some code).

Parameters
user The user to retrieve the running state for.

public boolean setRestrictionsChallenge (String newPin)

Added in API level 19

Sets a new challenge PIN for restrictions. This is only for use by pre-installed apps and requires the MANAGE_USERS permission.

Parameters
newPin the PIN to use for challenge dialogs.
Returns
  • Returns true if the challenge PIN was set successfully.

public void setUserRestriction (String key, boolean value)

Added in API level 18

Sets the value of a specific restriction. Requires the MANAGE_USERS permission.

Parameters
key the key of the restriction
value the value for the restriction

public void setUserRestrictions (Bundle restrictions)

Added in API level 18

Sets all the user-wide restrictions for this user. Requires the MANAGE_USERS permission.

Parameters
restrictions the Bundle containing all the restrictions.

public void setUserRestrictions (Bundle restrictions, UserHandle userHandle)

Added in API level 18

Sets all the user-wide restrictions for the specified user. Requires the MANAGE_USERS permission.

Parameters
restrictions the Bundle containing all the restrictions.
userHandle the UserHandle of the user for whom to set the restrictions.