UserManager | API reference | Android Developers (original) (raw)
public class UserManager
extends [Object](/reference/java/lang/Object)
``
Manages users and user details on a multi-user system. There are two major categories of users: fully customizable users with their own login, and profiles that share a workspace with a related user.
Users are different from accounts, which are managed by[AccountManager](/reference/android/accounts/AccountManager)
. Each user can have their own set of accounts.
See [DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE](/reference/android/app/admin/DevicePolicyManager#ACTION%5FPROVISION%5FMANAGED%5FPROFILE)
for more on managed profiles.
Summary
Nested classes | |
---|---|
class | UserManager.UserOperationException Thrown to indicate user operation failed. |
Constants | |
---|---|
String | ALLOW_PARENT_PROFILE_APP_LINKING Allows apps in the parent profile to handle web links from the managed profile. |
String | DISALLOW_ADD_MANAGED_PROFILE This constant was deprecated in API level 30. As the ability to have a managed profile on a fully-managed device has been removed from the platform, this restriction will be silently ignored when applied by the device owner. |
String | DISALLOW_ADD_PRIVATE_PROFILE Specifies if a user is disallowed from creating a private profile. |
String | DISALLOW_ADD_USER Specifies if a user is disallowed from adding new users. |
String | DISALLOW_ADD_WIFI_CONFIG Specifies if a user is disallowed from adding a new Wi-Fi configuration. |
String | DISALLOW_ADJUST_VOLUME Specifies if a user is disallowed from adjusting the global volume. |
String | DISALLOW_AIRPLANE_MODE Specifies if airplane mode is disallowed on the device. |
String | DISALLOW_AMBIENT_DISPLAY Specifies if ambient display is disallowed for the user. |
String | DISALLOW_APPS_CONTROL Specifies if a user is disallowed from modifying applications in Settings or launchers. |
String | DISALLOW_ASSIST_CONTENT This user restriction specifies if assist content is disallowed from being sent to a privileged app such as the Assistant app. |
String | DISALLOW_AUTOFILL Specifies if a user is not allowed to use Autofill Services. |
String | DISALLOW_BLUETOOTH Specifies if bluetooth is disallowed on the device. |
String | DISALLOW_BLUETOOTH_SHARING Specifies if outgoing bluetooth sharing is disallowed. |
String | DISALLOW_CAMERA_TOGGLE Specifies whether the camera toggle is available to the user. |
String | DISALLOW_CELLULAR_2G Specifies if a user is not allowed to use 2g networks. |
String | DISALLOW_CHANGE_NEAR_FIELD_COMMUNICATION_RADIO This user restriction specifies if Near-field communication is disallowed to change on the device. |
String | DISALLOW_CHANGE_WIFI_STATE Specifies if a user is disallowed from enabling/disabling Wi-Fi. |
String | DISALLOW_CONFIG_BLUETOOTH Specifies if a user is disallowed from configuring bluetooth via Settings. |
String | DISALLOW_CONFIG_BRIGHTNESS Specifies if a user is disallowed from configuring brightness. |
String | DISALLOW_CONFIG_CELL_BROADCASTS Specifies if a user is disallowed from configuring cell broadcasts. |
String | DISALLOW_CONFIG_CREDENTIALS Specifies if a user is disallowed from configuring user credentials. |
String | DISALLOW_CONFIG_DATE_TIME Specifies configuring date, time and timezone is disallowed via Settings. |
String | DISALLOW_CONFIG_DEFAULT_APPS Specifies whether the user is allowed to modify default apps in settings. |
String | DISALLOW_CONFIG_LOCALE Specifies if a user is disallowed from changing the device language. |
String | DISALLOW_CONFIG_LOCATION Specifies if a user is disallowed from enabling or disabling location providers. |
String | DISALLOW_CONFIG_MOBILE_NETWORKS Specifies if a user is disallowed from configuring mobile networks. |
String | DISALLOW_CONFIG_PRIVATE_DNS Specifies whether the user is allowed to modify private DNS settings. |
String | DISALLOW_CONFIG_SCREEN_TIMEOUT Specifies if a user is disallowed from changing screen off timeout. |
String | DISALLOW_CONFIG_TETHERING Specifies if a user is disallowed from using and configuring Tethering and portable hotspots via Settings. |
String | DISALLOW_CONFIG_VPN Specifies if a user is disallowed from configuring a VPN. |
String | DISALLOW_CONFIG_WIFI Specifies if a user is disallowed from changing Wi-Fi access points via Settings. |
String | DISALLOW_CONTENT_CAPTURE Specifies if the contents of a user's screen is not allowed to be captured for artificial intelligence purposes. |
String | DISALLOW_CONTENT_SUGGESTIONS Specifies if the current user is able to receive content suggestions for selections based on the contents of their screen. |
String | DISALLOW_CREATE_WINDOWS Specifies that windows besides app windows should not be created. |
String | DISALLOW_CROSS_PROFILE_COPY_PASTE Specifies if the clipboard contents can be exported by pasting the data into other users or profiles. |
String | DISALLOW_DATA_ROAMING Specifies if a user is not allowed to use cellular data when roaming. |
String | DISALLOW_DEBUGGING_FEATURES Specifies if a user is disallowed from enabling or accessing debugging features. |
String | DISALLOW_FACTORY_RESET Specifies if a user is disallowed from factory resetting from Settings. |
String | DISALLOW_FUN Specifies if the user is not allowed to have fun. |
String | DISALLOW_GRANT_ADMIN Restricts a user's ability to possess or grant admin privileges. |
String | DISALLOW_INSTALL_APPS Specifies if a user is disallowed from installing applications. |
String | DISALLOW_INSTALL_UNKNOWN_SOURCES Specifies if a user is disallowed from enabling the "Unknown Sources" setting, that allows installation of apps from unknown sources. |
String | DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY This restriction is a device-wide version of DISALLOW_INSTALL_UNKNOWN_SOURCES. |
String | DISALLOW_MICROPHONE_TOGGLE Specifies whether the microphone toggle is available to the user. |
String | DISALLOW_MODIFY_ACCOUNTS Specifies if a user is disallowed from adding and removing accounts, unless they areprogrammatically added by Authenticator. |
String | DISALLOW_MOUNT_PHYSICAL_MEDIA Specifies if a user is disallowed from mounting physical external media. |
String | DISALLOW_NEAR_FIELD_COMMUNICATION_RADIO This user restriction specifies if Near-field communication is disallowed on the device. |
String | DISALLOW_NETWORK_RESET Specifies if a user is disallowed from resetting network settings from Settings. |
String | DISALLOW_OUTGOING_BEAM Specifies if the user is not allowed to use NFC to beam out data from apps. |
String | DISALLOW_OUTGOING_CALLS Specifies that the user is not allowed to make outgoing phone calls. |
String | DISALLOW_PRINTING Specifies whether the user is allowed to print. |
String | DISALLOW_REMOVE_MANAGED_PROFILE This constant was deprecated in API level 30. As the ability to have a managed profile on a fully-managed device has been removed from the platform, this restriction will be silently ignored when applied by the device owner. When the device is provisioned with a managed profile on an organization-owned device, the managed profile could not be removed anyway. |
String | DISALLOW_REMOVE_USER When set on the admin user this specifies if the user can remove secondary users. |
String | DISALLOW_SAFE_BOOT Specifies if the user is not allowed to reboot the device into safe boot mode. |
String | DISALLOW_SET_USER_ICON Specifies if a user is not allowed to change their icon. |
String | DISALLOW_SET_WALLPAPER User restriction to disallow setting a wallpaper. |
String | DISALLOW_SHARE_INTO_MANAGED_PROFILE Specifies whether the user can share file / picture / data from the primary user into the managed profile, either by sending them from the primary side, or by picking up data within an app in the managed profile. |
String | DISALLOW_SHARE_LOCATION Specifies if a user is disallowed from turning on location sharing. |
String | DISALLOW_SHARING_ADMIN_CONFIGURED_WIFI Specifies if users are disallowed from sharing Wi-Fi for admin configured networks. |
String | DISALLOW_SIM_GLOBALLY This user restriction specifies if the user is able to add embedded SIMs to the device. |
String | DISALLOW_SMS Specifies that the user is not allowed to send or receive SMS messages. |
String | DISALLOW_SYSTEM_ERROR_DIALOGS Specifies that system error dialogs for crashed or unresponsive apps should not be shown. |
String | DISALLOW_THREAD_NETWORK This user restriction specifies if Thread network is disallowed on the device. |
String | DISALLOW_ULTRA_WIDEBAND_RADIO This user restriction specifies if Ultra-wideband is disallowed on the device. |
String | DISALLOW_UNIFIED_PASSWORD Specifies that the managed profile is not allowed to have unified lock screen challenge with the primary user. |
String | DISALLOW_UNINSTALL_APPS Specifies if a user is disallowed from uninstalling applications. |
String | DISALLOW_UNMUTE_MICROPHONE Specifies if a user is disallowed from adjusting microphone volume. |
String | DISALLOW_USB_FILE_TRANSFER Specifies if a user is disallowed from transferring files over USB. |
String | DISALLOW_USER_SWITCH Specifies if user switching is blocked on the current user. |
String | DISALLOW_WIFI_DIRECT Specifies if a user is disallowed from using Wi-Fi Direct. |
String | DISALLOW_WIFI_TETHERING Specifies if a user is disallowed from using Wi-Fi tethering. |
String | ENSURE_VERIFY_APPS Specifies if a user is disallowed from disabling application verification. |
String | KEY_RESTRICTIONS_PENDING Application restriction key that is used to indicate the pending arrival of real restrictions for the app. |
int | QUIET_MODE_DISABLE_ONLY_IF_CREDENTIAL_NOT_REQUIRED Flag passed to requestQuietModeEnabled(boolean, UserHandle) to request disabling quiet mode only if there is no need to confirm the user credentials. |
int | USER_CREATION_FAILED_NOT_PERMITTED Error result indicating that this user is not allowed to add other users on this device. |
int | USER_CREATION_FAILED_NO_MORE_USERS Error result indicating that no more users can be created on this device. |
int | USER_OPERATION_ERROR_CURRENT_USER Indicates user operation failed because the target user is in the foreground. |
int | USER_OPERATION_ERROR_LOW_STORAGE Indicates user operation failed because device has low data storage. |
int | USER_OPERATION_ERROR_MANAGED_PROFILE Indicates user operation failed because target user is a managed profile. |
int | USER_OPERATION_ERROR_MAX_RUNNING_USERS Indicates user operation failed because maximum running user limit has been reached. |
int | USER_OPERATION_ERROR_MAX_USERS Indicates user operation failed because maximum user limit has been reached. |
int | USER_OPERATION_ERROR_UNKNOWN Indicates user operation failed for unknown reason. |
int | USER_OPERATION_SUCCESS Indicates user operation is successful. |
String | USER_TYPE_PROFILE_CLONE User type representing a clone profile. |
String | USER_TYPE_PROFILE_MANAGED User type representing a managed profile, which is a profile that is to be managed by a device policy controller (DPC). |
String | USER_TYPE_PROFILE_PRIVATE User type representing a private profile. |
Public methods | |
---|---|
staticIntent | createUserCreationIntent(String userName, String accountName, String accountType, PersistableBundle accountOptions) Returns an intent to create a user for the provided name and account name. |
Bundle | getApplicationRestrictions(String packageName) Returns a Bundle containing any saved application restrictions for the context user, for the given package name. |
long | getSerialNumberForUser(UserHandle user) Return the serial number for a user. |
int | getUserCount() Return the number of users currently created on the device. |
long | getUserCreationTime(UserHandle userHandle) Returns creation time of the given user. |
UserHandle | getUserForSerialNumber(long serialNumber) Return the user associated with a serial number previously returned by getSerialNumberForUser(android.os.UserHandle). |
String | getUserName() Returns the user name of the context user. |
List<UserHandle> | getUserProfiles() Returns a list of the users that are associated with the context user, including the user itself. |
Bundle | getUserRestrictions(UserHandle userHandle) Returns the user-wide restrictions imposed on the user specified by userHandle. |
Bundle | getUserRestrictions() Returns the user-wide restrictions imposed on the context user. |
boolean | hasUserRestriction(String restrictionKey) Returns whether the context user has been disallowed from performing certain actions or setting certain settings. |
boolean | isAdminUser() Used to check if the context user is an admin user. |
boolean | isDemoUser() Checks if the context user is a demo user. |
static boolean | isHeadlessSystemUserMode() Checks whether the device is running in a headless system user mode. |
boolean | isManagedProfile() Checks if the context user is a managed profile. |
boolean | isProfile() Checks if the context user is running in a profile. |
boolean | isQuietModeEnabled(UserHandle userHandle) Returns whether the given profile is in quiet mode or not. |
boolean | isSystemUser() Used to check if the context user is the system user. |
boolean | isUserAGoat() Used to determine whether the user making this call is subject to teleportations. |
boolean | isUserForeground() Checks if the context user is running in the foreground. |
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 | isUserUnlocked(UserHandle user) Return whether the given user is running in an "unlocked" state. |
boolean | isUserUnlocked() Return whether the context user is running in an "unlocked" state. |
boolean | requestQuietModeEnabled(boolean enableQuietMode, UserHandle userHandle, int flags) Perform the same operation as requestQuietModeEnabled(boolean, android.os.UserHandle), but with a flag to tweak the behavior of the request. |
boolean | requestQuietModeEnabled(boolean enableQuietMode, UserHandle userHandle) Enables or disables quiet mode for a profile. |
boolean | setRestrictionsChallenge(String newPin) This method was deprecated in API level 23. The restrictions PIN functionality is no longer provided by the system. This method is preserved for backwards compatibility reasons and always returns false. |
void | setUserRestriction(String key, boolean value) This method was deprecated in API level 21. use DevicePolicyManager.addUserRestriction(android.content.ComponentName, String) orDevicePolicyManager.clearUserRestriction(android.content.ComponentName, String) instead. |
void | setUserRestrictions(Bundle restrictions, UserHandle userHandle) This will no longer work. |
void | setUserRestrictions(Bundle restrictions) This will no longer work. |
static boolean | supportsMultipleUsers() Returns whether this device supports multiple users with their own login and customizable space. |
Inherited methods |
---|
From class java.lang.Object Object clone() Creates and returns a copy of this object. boolean equals(Object obj) Indicates whether some other object is "equal to" this one. void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. finalClass<?> getClass() Returns the runtime class of this Object. int hashCode() Returns a hash code value for the object. final void notify() Wakes up a single thread that is waiting on this object's monitor. final void notifyAll() Wakes up all threads that are waiting on this object's monitor. String toString() Returns a string representation of the object. final void wait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait() Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
Constants
DISALLOW_ADD_MANAGED_PROFILE
public static final String DISALLOW_ADD_MANAGED_PROFILE
This constant was deprecated in API level 30.
As the ability to have a managed profile on a fully-managed device has been removed from the platform, this restriction will be silently ignored when applied by the device owner.
Specifies if a user is disallowed from adding managed profiles.
The default value for an unmanaged user is false
. For users with a device owner set, the default is true
.
This restriction has no effect on managed profiles.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_add_managed_profile"
DISALLOW_ASSIST_CONTENT
public static final String DISALLOW_ASSIST_CONTENT
This user restriction specifies if assist content is disallowed from being sent to a privileged app such as the Assistant app. Assist content includes screenshots and information about an app, such as package name.
This restriction can only be set by a device owner or a profile owner. When it is set by a device owner, it disables the assist contextual data on the entire device. When it is set by a profile owner, it disables assist content on the profile.
Default is false
.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_assist_content"
DISALLOW_BLUETOOTH
public static final String DISALLOW_BLUETOOTH
Specifies if bluetooth is disallowed on the device. If bluetooth is disallowed on the device, bluetooth cannot be turned on or configured via Settings.
This restriction can only be set by a device owner, a profile owner on the primary user or a profile owner of an organization-owned managed profile on the parent profile. When it is set by a device owner, it applies globally - i.e., it disables bluetooth on the entire device and all users will be affected. When it is set by a profile owner on the primary user or by a profile owner of an organization-owned managed profile on the parent profile, it disables the primary user from using bluetooth and configuring bluetooth in Settings.
Holders of the permission[Manifest.permission.MANAGE_DEVICE_POLICY_BLUETOOTH](/reference/android/Manifest.permission#MANAGE%5FDEVICE%5FPOLICY%5FBLUETOOTH)
can set this restriction using the DevicePolicyManager APIs mentioned below.
The default value is false
.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_bluetooth"
DISALLOW_CELLULAR_2G
public static final String DISALLOW_CELLULAR_2G
Specifies if a user is not allowed to use 2g networks.
This is a security feature. 2g has no mutual authentication between a device and cellular base station and downgrading a device's connection to 2g is a common tactic for several types of privacy and security compromising attacks that could allow an adversary to intercept, inject, or modify cellular communications.
This restriction can only be set by a device owner or a profile owner of an organization-owned managed profile on the parent profile. In all cases, the setting applies globally on the device.
Cellular connectivity loss (where a device would have otherwise successfully connected to a 2g network) occurs if the device is in an area where only 2g networks are available. Emergency calls are an exception and are never impacted. The device will still scan for and connect to a 2g network for emergency calls.
Holders of the permission[Manifest.permission.MANAGE_DEVICE_POLICY_MOBILE_NETWORK](/reference/android/Manifest.permission#MANAGE%5FDEVICE%5FPOLICY%5FMOBILE%5FNETWORK)
can set this restriction using the DevicePolicyManager APIs mentioned below.
The default value is false
.
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_cellular_2g"
DISALLOW_CHANGE_NEAR_FIELD_COMMUNICATION_RADIO
public static final String DISALLOW_CHANGE_NEAR_FIELD_COMMUNICATION_RADIO
This user restriction specifies if Near-field communication is disallowed to change on the device. If Near-field communication is disallowed it cannot be changed via Settings.
This restriction can only be set by a device owner or a profile owner of an organization-owned managed profile on the parent profile. In both cases, the restriction applies globally on the device and will not allow Near-field communication state being changed.
Near-field communication (NFC) is a radio technology that allows two devices (like your phone and a payments terminal) to communicate with each other when they're close together.
Default is false
.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_change_near_field_communication_radio"
DISALLOW_CONFIG_BLUETOOTH
public static final String DISALLOW_CONFIG_BLUETOOTH
Specifies if a user is disallowed from configuring bluetooth via Settings. This does_not_ restrict the user from turning bluetooth on or off.
This restriction doesn't prevent the user from using bluetooth. For disallowing usage of bluetooth completely on the device, use [DISALLOW_BLUETOOTH](/reference/android/os/UserManager#DISALLOW%5FBLUETOOTH)
.
A device owner and a profile owner can set this restriction, although the restriction has no effect in a managed profile. When it is set by a device owner, a profile owner on the primary user or by a profile owner of an organization-owned managed profile on the parent profile, it disallows the primary user from configuring bluetooth.
Holders of the permission[Manifest.permission.MANAGE_DEVICE_POLICY_BLUETOOTH](/reference/android/Manifest.permission#MANAGE%5FDEVICE%5FPOLICY%5FBLUETOOTH)
can set this restriction using the DevicePolicyManager APIs mentioned below.
The default value is false
.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_config_bluetooth"
DISALLOW_CONFIG_CELL_BROADCASTS
public static final String DISALLOW_CONFIG_CELL_BROADCASTS
Specifies if a user is disallowed from configuring cell broadcasts.
This restriction can only be set by a device owner, a profile owner on the main user or a profile owner of an organization-owned managed profile on the parent profile. When it is set by a device owner, it applies globally. When it is set by a profile owner on the main user or by a profile owner of an organization-owned managed profile on the parent profile, it disables the user from configuring cell broadcasts.
Holders of the permission[Manifest.permission.MANAGE_DEVICE_POLICY_MOBILE_NETWORK](/reference/android/Manifest.permission#MANAGE%5FDEVICE%5FPOLICY%5FMOBILE%5FNETWORK)
can set this restriction using the DevicePolicyManager APIs mentioned below.
The default value is false
.
This restriction has no effect on non-Admin users since they cannot configure cell broadcasts.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_config_cell_broadcasts"
DISALLOW_CONFIG_DATE_TIME
public static final String DISALLOW_CONFIG_DATE_TIME
Specifies configuring date, time and timezone is disallowed via Settings.
A device owner and a profile owner can set this restriction, although the restriction has no effect in a managed profile. When it is set by a device owner or by a profile owner of an organization-owned managed profile on the parent profile, it applies globally - i.e., it disables date, time and timezone setting on the entire device and all users are affected. When it is set by a profile owner on the primary user, it disables the primary user from configuring date, time and timezone and disables all configuring of date, time and timezone in Settings.
Holders of the permission[Manifest.permission.MANAGE_DEVICE_POLICY_TIME](/reference/android/Manifest.permission#MANAGE%5FDEVICE%5FPOLICY%5FTIME)
can set this restriction using the DevicePolicyManager APIs mentioned below.
The default value is false
.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_config_date_time"
DISALLOW_CONFIG_DEFAULT_APPS
public static final String DISALLOW_CONFIG_DEFAULT_APPS
Specifies whether the user is allowed to modify default apps in settings.
A device owner and a profile owner can set this restriction. When it is set by a device owner, it applies globally - i.e., modifying of default apps in Settings for all users is disallowed. When it is set by a profile owner on the primary user or by a profile owner of an organization-owned managed profile on the parent profile, modifying of default apps in Settings for the primary user is disallowed.
The default value is false
.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "disallow_config_default_apps"
DISALLOW_CONFIG_MOBILE_NETWORKS
public static final String DISALLOW_CONFIG_MOBILE_NETWORKS
Specifies if a user is disallowed from configuring mobile networks.
This restriction can only be set by a device owner, a profile owner on the main user or a profile owner of an organization-owned managed profile on the parent profile. When it is set by a device owner, it applies globally. When it is set by a profile owner on the main user or by a profile owner of an organization-owned managed profile on the parent profile, it disables the user from configuring mobile networks.
Holders of the permission[Manifest.permission.MANAGE_DEVICE_POLICY_MOBILE_NETWORK](/reference/android/Manifest.permission#MANAGE%5FDEVICE%5FPOLICY%5FMOBILE%5FNETWORK)
can set this restriction using the DevicePolicyManager APIs mentioned below.
The default value is false
.
This restriction has no effect on non-Admin users since they cannot configure mobile networks.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_config_mobile_networks"
DISALLOW_CONFIG_TETHERING
public static final String DISALLOW_CONFIG_TETHERING
Specifies if a user is disallowed from using and configuring Tethering and portable hotspots via Settings.
This restriction can only be set by a device owner, a profile owner on the primary user or a profile owner of an organization-owned managed profile on the parent profile. When it is set by a device owner, it applies globally. When it is set by a profile owner on the primary user or by a profile owner of an organization-owned managed profile on the parent profile, it disables the primary user from using Tethering and hotspots and disables all configuring of Tethering and hotspots in Settings.
Holders of the permission[Manifest.permission.MANAGE_DEVICE_POLICY_MOBILE_NETWORK](/reference/android/Manifest.permission#MANAGE%5FDEVICE%5FPOLICY%5FMOBILE%5FNETWORK)
can set this restriction using the DevicePolicyManager APIs mentioned below.
The default value is false
.
In Android 9.0 or higher, if tethering is enabled when this restriction is set, tethering will be automatically turned off.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_config_tethering"
DISALLOW_DEBUGGING_FEATURES
public static final String DISALLOW_DEBUGGING_FEATURES
Specifies if a user is disallowed from enabling or accessing debugging features.
A device owner and a profile owner can set this restriction. When it is set by a device owner, a profile owner on the primary user or by a profile owner of an organization-owned managed profile on the parent profile, it disables debugging features altogether, including USB debugging. When set on a managed profile or a secondary user, it blocks debugging for that user only, including starting activities, making service calls, accessing content providers, sending broadcasts, installing/uninstalling packages, clearing user data, etc.
Holders of the permission[Manifest.permission.MANAGE_DEVICE_POLICY_DEBUGGING_FEATURES](/reference/android/Manifest.permission#MANAGE%5FDEVICE%5FPOLICY%5FDEBUGGING%5FFEATURES)
can set this restriction using the DevicePolicyManager APIs mentioned below.
The default value is false
.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_debugging_features"
DISALLOW_NEAR_FIELD_COMMUNICATION_RADIO
public static final String DISALLOW_NEAR_FIELD_COMMUNICATION_RADIO
This user restriction specifies if Near-field communication is disallowed on the device. If Near-field communication is disallowed it cannot be turned on via Settings.
This restriction can only be set by a device owner or a profile owner of an organization-owned managed profile on the parent profile. In both cases, the restriction applies globally on the device and will turn off the Near-field communication radio if it's currently on and prevent the radio from being turned on in the future.
Near-field communication (NFC) is a radio technology that allows two devices (like your phone and a payments terminal) to communicate with each other when they're close together.
Default is false
.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_near_field_communication_radio"
DISALLOW_REMOVE_MANAGED_PROFILE
public static final String DISALLOW_REMOVE_MANAGED_PROFILE
This constant was deprecated in API level 30.
As the ability to have a managed profile on a fully-managed device has been removed from the platform, this restriction will be silently ignored when applied by the device owner. When the device is provisioned with a managed profile on an organization-owned device, the managed profile could not be removed anyway.
Specifies if managed profiles of this user can be removed, other than by its profile owner. The default value is false
.
This restriction has no effect on managed profiles, and this restriction does not block the removal of private profiles of this user.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_remove_managed_profile"
DISALLOW_SYSTEM_ERROR_DIALOGS
public static final String DISALLOW_SYSTEM_ERROR_DIALOGS
Specifies that system error dialogs for crashed or unresponsive apps should not be shown. In this case, the system will force-stop the app as if the user chooses the "close app" option on the UI. A feedback report isn't collected as there is no way for the user to provide explicit consent. The default value is false
.
When this user restriction is set by device owners, it's applied to all users. When set by the profile owner of the primary user or a secondary user, the restriction affects only the calling user. This user restriction has no effect on managed profiles.
Holders of the permission[Manifest.permission.MANAGE_DEVICE_POLICY_SYSTEM_DIALOGS](/reference/android/Manifest.permission#MANAGE%5FDEVICE%5FPOLICY%5FSYSTEM%5FDIALOGS)
can set this restriction using the DevicePolicyManager APIs mentioned below.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_system_error_dialogs"
DISALLOW_THREAD_NETWORK
public static final String DISALLOW_THREAD_NETWORK
This user restriction specifies if Thread network is disallowed on the device. If Thread network is disallowed it cannot be turned on via Settings.
This restriction can only be set by a device owner or a profile owner of an organization-owned managed profile on the parent profile. In both cases, the restriction applies globally on the device and will turn off the Thread network radio if it's currently on and prevent the radio from being turned on in the future.
Thread is a low-power and low-latency wireless mesh networking protocol built on IPv6.
Default is false
.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_thread_network"
DISALLOW_ULTRA_WIDEBAND_RADIO
public static final String DISALLOW_ULTRA_WIDEBAND_RADIO
This user restriction specifies if Ultra-wideband is disallowed on the device. If Ultra-wideband is disallowed it cannot be turned on via Settings.
Ultra-wideband (UWB) is a radio technology that can use a very low energy level for short-range, high-bandwidth communications over a large portion of the radio spectrum.
This restriction can only be set by a device owner or a profile owner of an organization-owned managed profile on the parent profile. In both cases, the restriction applies globally on the device and will turn off the ultra-wideband radio if it's currently on and prevent the radio from being turned on in the future.
Holders of the permission[Manifest.permission.MANAGE_DEVICE_POLICY_NEARBY_COMMUNICATION](/reference/android/Manifest.permission#MANAGE%5FDEVICE%5FPOLICY%5FNEARBY%5FCOMMUNICATION)
can set this restriction using the DevicePolicyManager APIs mentioned below.
Default is false
.
Key for user restrictions.
Type: Boolean
See also:
[DevicePolicyManager.addUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#addUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[DevicePolicyManager.clearUserRestriction(ComponentName, String)](/reference/android/app/admin/DevicePolicyManager#clearUserRestriction%28android.content.ComponentName,%20java.lang.String%29)
[getUserRestrictions()](/reference/android/os/UserManager#getUserRestrictions%28%29)
Constant Value: "no_ultra_wideband_radio"
USER_OPERATION_ERROR_CURRENT_USER
public static final int USER_OPERATION_ERROR_CURRENT_USER
Indicates user operation failed because the target user is in the foreground.
Constant Value: 4 (0x00000004)
USER_OPERATION_ERROR_LOW_STORAGE
public static final int USER_OPERATION_ERROR_LOW_STORAGE
Indicates user operation failed because device has low data storage.
Constant Value: 5 (0x00000005)
USER_OPERATION_ERROR_MANAGED_PROFILE
public static final int USER_OPERATION_ERROR_MANAGED_PROFILE
Indicates user operation failed because target user is a managed profile.
Constant Value: 2 (0x00000002)
USER_OPERATION_ERROR_MAX_RUNNING_USERS
public static final int USER_OPERATION_ERROR_MAX_RUNNING_USERS
Indicates user operation failed because maximum running user limit has been reached.
Constant Value: 3 (0x00000003)
USER_OPERATION_ERROR_MAX_USERS
public static final int USER_OPERATION_ERROR_MAX_USERS
Indicates user operation failed because maximum user limit has been reached.
Constant Value: 6 (0x00000006)
USER_OPERATION_ERROR_UNKNOWN
public static final int USER_OPERATION_ERROR_UNKNOWN
Indicates user operation failed for unknown reason.
Constant Value: 1 (0x00000001)
USER_OPERATION_SUCCESS
public static final int USER_OPERATION_SUCCESS
Indicates user operation is successful.
Constant Value: 0 (0x00000000)
USER_TYPE_PROFILE_CLONE
public static final String USER_TYPE_PROFILE_CLONE
User type representing a clone profile. Clone profile is a user profile type used to run second instance of an otherwise single user App (eg, messengers). Currently only the[ERROR(/android.content.pm.UserInfo#isMain())](/)
user can have a clone profile.
Constant Value: "android.os.usertype.profile.CLONE"
USER_TYPE_PROFILE_MANAGED
public static final String USER_TYPE_PROFILE_MANAGED
User type representing a managed profile, which is a profile that is to be managed by a device policy controller (DPC). The intended purpose is for work profiles, which are managed by a corporate entity.
Constant Value: "android.os.usertype.profile.MANAGED"
USER_TYPE_PROFILE_PRIVATE
public static final String USER_TYPE_PROFILE_PRIVATE
User type representing a private profile. Private profile is a user profile that can be used as an alternative user-space to install and use sensitive apps. UI surfaces can adopt an alternative strategy to show apps belonging to this profile, in line with their sensitive nature.
Constant Value: "android.os.usertype.profile.PRIVATE"
Public methods
createUserCreationIntent
public static Intent createUserCreationIntent (String userName, String accountName, String accountType, PersistableBundle accountOptions)
Returns an intent to create a user for the provided name and account name. The name and account name will be used when the setup process for the new user is started.
The intent should be launched using startActivityForResult and the return result will indicate if the user consented to adding a new user and if the operation succeeded. Any errors in creating the user will be returned in the result code. If the user cancels the request, the return result will be [Activity.RESULT_CANCELED](/reference/android/app/Activity#RESULT%5FCANCELED)
. On success, the result code will be [Activity.RESULT_OK](/reference/android/app/Activity#RESULT%5FOK)
.
Use [supportsMultipleUsers()](/reference/android/os/UserManager#supportsMultipleUsers%28%29)
to first check if the device supports this operation at all.
The new user is created but not initialized. After switching into the user for the first time, the preferred user name and account information are used by the setup process for that user. This API should only be called if the current user is an [admin](/reference/android/os/UserManager#isAdminUser%28%29)
user, as otherwise the returned intent will not be able to create a user.
Parameters | |
---|---|
userName | String: Optional name to assign to the user. Character limit is 100. This value may be null. |
accountName | String: Optional account name that will be used by the setup wizard to initialize the user. Character limit is 500. This value may be null. |
accountType | String: Optional account type for the account to be created. This is required if the account name is specified. Character limit is 500. This value may be null. |
accountOptions | PersistableBundle: Optional bundle of data to be passed in during account creation in the new user via AccountManager.addAccount(String, String, String[], Bundle, android.app.Activity, android.accounts.AccountManagerCallback, Handler). Character limit is 1000. This value may be null. |
Returns | |
---|---|
Intent | An Intent that can be launched from an Activity. |
See also:
[USER_CREATION_FAILED_NOT_PERMITTED](/reference/android/os/UserManager#USER%5FCREATION%5FFAILED%5FNOT%5FPERMITTED)
[USER_CREATION_FAILED_NO_MORE_USERS](/reference/android/os/UserManager#USER%5FCREATION%5FFAILED%5FNO%5FMORE%5FUSERS)
[supportsMultipleUsers()](/reference/android/os/UserManager#supportsMultipleUsers%28%29)
getSerialNumberForUser
public long getSerialNumberForUser (UserHandle user)
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 | UserHandle: The user whose serial number is to be retrieved. |
Returns | |
---|---|
long | The serial number of the given user; returns -1 if the given UserHandle does not exist. |
getUserCount
public int getUserCount ()
Return the number of users currently created on the device.
Requires android.Manifest.permission.MANAGE_USERS or android.Manifest.permission.CREATE_USERS
Returns |
---|
int |
getUserCreationTime
public long getUserCreationTime (UserHandle userHandle)
Returns creation time of the given user. The given user must be the calling user or a profile associated with it.
Parameters | |
---|---|
userHandle | UserHandle: user handle of the calling user or a profile associated with the calling user. |
Returns | |
---|---|
long | creation time in milliseconds since Epoch time. |
getUserForSerialNumber
public UserHandle getUserForSerialNumber (long serialNumber)
Return the user associated with a serial number previously returned by [getSerialNumberForUser(android.os.UserHandle)](/reference/android/os/UserManager#getSerialNumberForUser%28android.os.UserHandle%29)
.
Parameters | |
---|---|
serialNumber | long: The serial number of the user that is being retrieved. |
Returns | |
---|---|
UserHandle | Return the user associated with the serial number, or null if there is not one. |
getUserName
public String getUserName ()
Returns the user name of the context user. This call is only available to applications on the system image.
Requires android.Manifest.permission.MANAGE_USERS or android.Manifest.permission.CREATE_USERS or android.Manifest.permission.QUERY_USERS or [Manifest.permission.GET_ACCOUNTS_PRIVILEGED](/reference/android/Manifest.permission#GET%5FACCOUNTS%5FPRIVILEGED)
Returns | |
---|---|
String | the user name This value cannot be null. |
getUserProfiles
public List<UserHandle> getUserProfiles ()
Returns a list of the users that are associated with the context user, including the user itself. This includes the user, its profiles, its parent, and its parent's other profiles, as applicable.
Note that this includes all profile types (not including Restricted profiles).
Returns | |
---|---|
List<UserHandle> | A non-empty list of UserHandles associated with the context user. |
getUserRestrictions
public Bundle getUserRestrictions (UserHandle userHandle)
Returns the user-wide restrictions imposed on the user specified by userHandle
.
Parameters | |
---|---|
userHandle | UserHandle: the UserHandle of the user for whom to retrieve the restrictions. |
Returns | |
---|---|
Bundle | a Bundle containing all the restrictions.Requires android.permission.MANAGE_USERS orandroid.permission.INTERACT_ACROSS_USERS, otherwise specified user must be the calling user or a profile associated with it. |
getUserRestrictions
public Bundle getUserRestrictions ()
Returns the user-wide restrictions imposed on the context user.
Returns | |
---|---|
Bundle | a Bundle containing all the restrictions. |
hasUserRestriction
public boolean hasUserRestriction (String restrictionKey)
Returns whether the context user has been disallowed from performing certain actions or setting certain settings.
Returns | |
---|---|
boolean | true if the context user has the given restriction, false otherwise. |
isAdminUser
public boolean isAdminUser ()
Used to check if the context user is an admin user. An admin user may be allowed to modify or configure certain settings that aren't available to non-admin users, create and delete additional users, etc. There can be more than one admin users.
Returns | |
---|---|
boolean | whether the context user is an admin user. |
isDemoUser
public boolean isDemoUser ()
Checks if the context user is a demo user. When running in a demo user, apps can be more helpful to the user, or explain their features in more detail.
Returns | |
---|---|
boolean | whether the context user is a demo user. |
isHeadlessSystemUserMode
public static boolean isHeadlessSystemUserMode ()
Checks whether the device is running in a headless system user mode.
Headless system user mode means the [system user](/reference/android/os/UserManager#isSystemUser%28%29)
runs system services and some system UI, but it is not associated with any real person and additional users must be created to be associated with real persons.
Returns | |
---|---|
boolean | whether the device is running in a headless system user mode. |
isManagedProfile
public boolean isManagedProfile ()
Checks if the context user is a managed profile. Note that this applies specifically to managed profiles. For profiles in general, use [isProfile()](/reference/android/os/UserManager#isProfile%28%29)
instead.
Returns | |
---|---|
boolean | whether the context user is a managed profile. |
isProfile
public boolean isProfile ()
Checks if the context user is running in a profile. A profile is a user that typically has its own separate data but shares its UI with some parent user. For example, a[managed profile](/reference/android/os/UserManager#isManagedProfile%28%29)
is a type of profile.
Returns | |
---|---|
boolean | whether the context user is in a profile. |
isQuietModeEnabled
public boolean isQuietModeEnabled (UserHandle userHandle)
Returns whether the given profile is in quiet mode or not.
Parameters | |
---|---|
userHandle | UserHandle: The user handle of the profile to be queried. |
Returns | |
---|---|
boolean | true if the profile is in quiet mode, false otherwise. |
isSystemUser
public boolean isSystemUser ()
Used to check if the context user is the system user. The system user is the initial user that is implicitly created on first boot and hosts most of the system services.
Returns | |
---|---|
boolean | whether the context user is the system user. |
isUserAGoat
public boolean isUserAGoat ()
Used to determine whether the user making this call is subject to teleportations.
As of [Build.VERSION_CODES.LOLLIPOP](/reference/android/os/Build.VERSION%5FCODES#LOLLIPOP)
, this method can now automatically identify goats using advanced goat recognition technology.
As of [Build.VERSION_CODES.R](/reference/android/os/Build.VERSION%5FCODES#R)
, this method always returnsfalse
in order to protect goat privacy.
Returns | |
---|---|
boolean | Returns whether the user making this call is a goat. |
isUserForeground
public boolean isUserForeground ()
Checks if the context user is running in the foreground.
Returns | |
---|---|
boolean | whether the context user is running in the foreground. |
isUserRunning
public boolean isUserRunning (UserHandle user)
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.
Note prior to Android Nougat MR1 (SDK version <= 24;[Build.VERSION_CODES.N](/reference/android/os/Build.VERSION%5FCODES#N)
, this API required a system permission in order to check other profile's status. Since Android Nougat MR1 (SDK version >= 25;[Build.VERSION_CODES.N_MR1](/reference/android/os/Build.VERSION%5FCODES#N%5FMR1)
), the restriction has been relaxed, and now it'll accept any [UserHandle](/reference/android/os/UserHandle)
within the same profile group as the caller.
Parameters | |
---|---|
user | UserHandle: The user to retrieve the running state for. |
Returns |
---|
boolean |
isUserRunningOrStopping
public boolean isUserRunningOrStopping (UserHandle user)
Return whether the given user is actively running or stopping. This is like [isUserRunning(android.os.UserHandle)](/reference/android/os/UserManager#isUserRunning%28android.os.UserHandle%29)
, 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).
Note prior to Android Nougat MR1 (SDK version <= 24;[Build.VERSION_CODES.N](/reference/android/os/Build.VERSION%5FCODES#N)
, this API required a system permission in order to check other profile's status. Since Android Nougat MR1 (SDK version >= 25;[Build.VERSION_CODES.N_MR1](/reference/android/os/Build.VERSION%5FCODES#N%5FMR1)
), the restriction has been relaxed, and now it'll accept any [UserHandle](/reference/android/os/UserHandle)
within the same profile group as the caller.
Parameters | |
---|---|
user | UserHandle: The user to retrieve the running state for. |
Returns |
---|
boolean |
isUserUnlocked
public boolean isUserUnlocked (UserHandle user)
Return whether the given user is running in an "unlocked" state.
On devices with direct boot, a user is unlocked only after they've entered their credentials (such as a lock pattern or PIN). On devices without direct boot, a user is unlocked as soon as it starts.
When a user is locked, only device-protected data storage is available. When a user is unlocked, both device-protected and credential-protected private app data storage is available.
Requires android.permission.MANAGE_USERS
orandroid.permission.INTERACT_ACROSS_USERS
, otherwise specified [user](/reference/android/os/UserHandle)
must be the calling user or a profile associated with it.
Parameters | |
---|---|
user | UserHandle: to retrieve the unlocked state for. |
Returns |
---|
boolean |
isUserUnlocked
public boolean isUserUnlocked ()
Return whether the context user is running in an "unlocked" state.
On devices with direct boot, a user is unlocked only after they've entered their credentials (such as a lock pattern or PIN). On devices without direct boot, a user is unlocked as soon as it starts.
When a user is locked, only device-protected data storage is available. When a user is unlocked, both device-protected and credential-protected private app data storage is available.
Returns |
---|
boolean |
requestQuietModeEnabled
public boolean requestQuietModeEnabled (boolean enableQuietMode, UserHandle userHandle)
Enables or disables quiet mode for a profile. If quiet mode is enabled, apps in the profile don't run, generate notifications, or consume data or battery.
If a user's credential is needed to turn off quiet mode, a confirm credential screen will be shown to the user.
The change may not happen instantly, however apps can listen for[Intent.ACTION_MANAGED_PROFILE_AVAILABLE](/reference/android/content/Intent#ACTION%5FMANAGED%5FPROFILE%5FAVAILABLE)
and[Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE](/reference/android/content/Intent#ACTION%5FMANAGED%5FPROFILE%5FUNAVAILABLE)
broadcasts in order to be notified of the change of the quiet mode for managed profile. Apps can listen to generic broadcasts [Intent.ACTION_PROFILE_AVAILABLE](/reference/android/content/Intent#ACTION%5FPROFILE%5FAVAILABLE)
and[Intent.ACTION_PROFILE_UNAVAILABLE](/reference/android/content/Intent#ACTION%5FPROFILE%5FUNAVAILABLE)
to be notified of the change in quiet mode for any profiles. Apps can also check the current state of quiet mode by calling[isQuietModeEnabled(android.os.UserHandle)](/reference/android/os/UserManager#isQuietModeEnabled%28android.os.UserHandle%29)
.
The caller must either be the foreground default launcher or have one of these permissions:MANAGE_USERS
or MODIFY_QUIET_MODE
.
Parameters | |
---|---|
enableQuietMode | boolean: whether quiet mode should be enabled or disabled |
userHandle | UserHandle: user handle of the profile This value cannot be null. |
Returns | |
---|---|
boolean | false if user's credential is needed in order to turn off quiet mode,true otherwise |
Throws | |
---|---|
SecurityException | if the caller is invalid |
IllegalArgumentException | if userHandle is not a profile |
setRestrictionsChallenge
public boolean setRestrictionsChallenge (String newPin)
This method was deprecated in API level 23.
The restrictions PIN functionality is no longer provided by the system. This method is preserved for backwards compatibility reasons and always returns false.
Sets a new challenge PIN for restrictions. This is only for use by pre-installed apps and requires the MANAGE_USERS permission.
Parameters | |
---|---|
newPin | String: the PIN to use for challenge dialogs. |
Returns | |
---|---|
boolean | Returns true if the challenge PIN was set successfully. |
supportsMultipleUsers
public static boolean supportsMultipleUsers ()
Returns whether this device supports multiple users with their own login and customizable space.
Returns | |
---|---|
boolean | whether the device supports multiple users. |