UserManager | API reference | Android Developers
open class UserManager
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. Each user can have their own set of accounts.
See DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE for more on managed profiles.
Summary
| Nested classes | |
|---|---|
| open |
Thrown to indicate user operation failed. |
| Constants | |
|---|---|
| static String |
Allows apps in the parent profile to handle web links from the managed profile. |
| static String |
Specifies if a user is disallowed from adding managed profiles. |
| static String |
Specifies if a user is disallowed from creating a private profile. |
| static String |
Specifies if a user is disallowed from adding new users. |
| static String |
Specifies if a user is disallowed from adding a new Wi-Fi configuration. |
| static String |
Specifies if a user is disallowed from adjusting the global volume. |
| static String |
Specifies if airplane mode is disallowed on the device. |
| static String |
Specifies if ambient display is disallowed for the user. |
| static String |
Specifies if a user is disallowed from modifying applications in Settings or launchers. |
| static String |
This user restriction specifies if assist content is disallowed from being sent to a privileged app such as the Assistant app. |
| static String |
Specifies if a user is not allowed to use Autofill Services. |
| static String |
Specifies if bluetooth is disallowed on the device. |
| static String |
Specifies if outgoing bluetooth sharing is disallowed. |
| static String |
Specifies whether the camera toggle is available to the user. |
| static String |
Specifies if a user is not allowed to use 2g networks. |
| static String |
This user restriction specifies if Near-field communication is disallowed to change on the device. |
| static String |
Specifies if a user is disallowed from enabling/disabling Wi-Fi. |
| static String |
Specifies if a user is disallowed from configuring bluetooth via Settings. |
| static String |
Specifies if a user is disallowed from configuring brightness. |
| static String |
Specifies if a user is disallowed from configuring cell broadcasts. |
| static String |
Specifies if a user is disallowed from configuring user credentials. |
| static String |
Specifies configuring date, time and timezone is disallowed via Settings. |
| static String |
Specifies whether the user is allowed to modify default apps in settings. |
| static String |
Specifies if a user is disallowed from changing the device language. |
| static String |
Specifies if a user is disallowed from enabling or disabling location providers. |
| static String |
Specifies if a user is disallowed from configuring mobile networks. |
| static String |
Specifies whether the user is allowed to modify private DNS settings. |
| static String |
Specifies if a user is disallowed from changing screen off timeout. |
| static String |
Specifies if a user is disallowed from using and configuring Tethering and portable hotspots via Settings. |
| static String |
Specifies if a user is disallowed from configuring a VPN. |
| static String |
Specifies if a user is disallowed from changing Wi-Fi access points via Settings. |
| static String |
Specifies if the contents of a user's screen is not allowed to be captured for artificial intelligence purposes. |
| static String |
Specifies if the current user is able to receive content suggestions for selections based on the contents of their screen. |
| static String |
Specifies that windows besides app windows should not be created. |
| static String |
Specifies if the clipboard contents can be exported by pasting the data into other users or profiles. |
| static String |
Specifies if a user is not allowed to use cellular data when roaming. |
| static String |
Specifies if a user is disallowed from enabling or accessing debugging features. |
| static String |
Specifies if a user is disallowed from factory resetting from Settings. |
| static String |
Specifies if the user is not allowed to have fun. |
| static String |
Restricts a user's ability to possess or grant admin privileges. |
| static String |
Specifies if a user is disallowed from installing applications. |
| static String |
Specifies if a user is disallowed from enabling the "Unknown Sources" setting, that allows installation of apps from unknown sources. |
| static String |
This restriction is a device-wide version of |
| static String |
Specifies whether the microphone toggle is available to the user. |
| static String |
Specifies if a user is disallowed from adding and removing accounts, unless they are android. |
| static String |
Specifies if a user is disallowed from mounting physical external media. |
| static String |
This user restriction specifies if Near-field communication is disallowed on the device. |
| static String |
Specifies if a user is disallowed from resetting network settings from Settings. |
| static String |
Specifies if the user is not allowed to use NFC to beam out data from apps. |
| static String |
Specifies that the user is not allowed to make outgoing phone calls. |
| static String |
Specifies whether the user is allowed to print. |
| static String |
Specifies if managed profiles of this user can be removed, other than by its profile owner. |
| static String |
When set on the admin user this specifies if the user can remove secondary users. |
| static String |
Specifies if the user is not allowed to reboot the device into safe boot mode. |
| static String |
Specifies if a user is not allowed to change their icon. |
| static String |
User restriction to disallow setting a wallpaper. |
| static String |
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. |
| static String |
Specifies if a user is disallowed from turning on location sharing. |
| static String |
Specifies if users are disallowed from sharing Wi-Fi for admin configured networks. |
| static String |
This user restriction specifies if the user is able to add embedded SIMs to the device. |
| static String |
Specifies that the user is not allowed to send or receive SMS messages. |
| static String |
Specifies that system error dialogs for crashed or unresponsive apps should not be shown. |
| static String |
Specifies if the user is not allowed to handoff tasks to other devices. |
| static String |
This user restriction specifies if Thread network is disallowed on the device. |
| static String |
This user restriction specifies if Ultra-wideband is disallowed on the device. |
| static String |
Specifies that the managed profile is not allowed to have unified lock screen challenge with the profile parent. |
| static String |
Specifies if a user is disallowed from uninstalling applications. |
| static String |
Specifies if a user is disallowed from adjusting microphone volume. |
| static String |
Specifies if a user is disallowed from transferring files over USB. |
| static String |
Specifies if user switching is blocked on the current user. |
| static String |
Specifies if a user is disallowed from using Wi-Fi Direct. |
| static String |
Specifies if a user is disallowed from using Wi-Fi tethering. |
| static String |
Specifies if a user is disallowed from disabling application verification. |
| static String |
Application restriction key that is used to indicate the pending arrival of real restrictions for the app. |
| static Int |
Flag passed to #requestQuietModeEnabled to request disabling quiet mode only if there is no need to confirm the user credentials. |
| static Int |
Error result indicating that this user is not allowed to add other users on this device. |
| static Int |
Error result indicating that no more users can be created on this device. |
| static Int |
Indicates user operation failed because the target user is in the foreground. |
| static Int |
Indicates user operation failed because device has low data storage. |
| static Int |
Indicates user operation failed because target user is a managed profile. |
| static Int |
Indicates user operation failed because maximum running user limit has been reached. |
| static Int |
Indicates user operation failed because a relevant maximum user limit has been reached. |
| static Int |
Indicates user operation failed for unknown reason. |
| static Int |
Indicates user operation is successful. |
| static String |
User type representing a clone profile. |
| static String |
User type representing a managed profile, which is a profile that is to be managed by a device policy controller (DPC). |
| static String |
User type representing a private profile. |
| Public methods | |
|---|---|
| open static Intent! |
Returns an intent to create a user for the provided name and account name. |
| open Bundle! |
Returns a |
| open Long |
Return the serial number for a user. |
| open Int |
Return the number of users currently created on the device. |
| open Long |
Returns creation time of the given user. |
| open UserHandle! |
Return the user associated with a serial number previously returned by |
| open String |
Returns the user name of the context user. |
| open MutableList<UserHandle!>! |
Returns a list of the users that are associated with the context user, including the user itself. |
| open Bundle! |
Returns the user-wide restrictions imposed on the context user. |
| open Bundle! |
Returns the user-wide restrictions imposed on the user specified by |
| open Boolean |
Returns whether the context user has been disallowed from performing certain actions or setting certain settings. |
| open Boolean |
Used to check if the context user is an admin user. |
| open Boolean |
Checks if the context user is a demo user. |
| open static Boolean |
Checks whether the device is running in a headless system user mode. |
| open Boolean |
Checks if the context user is a managed profile. |
| open Boolean |
Checks if the context user is running in a profile. |
| open Boolean |
Returns whether the given profile is in quiet mode or not. |
| open Boolean |
Used to check if the context user is the system user. |
| open Boolean |
Used to determine whether the user making this call is subject to teleportations. |
| open Boolean |
Checks if the context user is running in the foreground. |
| open Boolean |
Return whether the given user is actively running. |
| open Boolean |
Return whether the given user is actively running or stopping. |
| open Boolean |
Return whether the context user is running in an "unlocked" state. |
| open Boolean |
Return whether the given user is running in an "unlocked" state. |
| open Boolean |
Enables or disables quiet mode for a profile. |
| open Boolean |
Perform the same operation as |
| open Boolean |
Sets a new challenge PIN for restrictions. |
| open Unit |
Sets the value of a specific restriction on the context user. |
| open Unit |
This will no longer work. |
| open Unit |
This will no longer work. |
| open static Boolean |
Returns whether this device supports multiple switchable users with their own login and customizable space. |
Constants
DISALLOW_CONFIG_DATE_TIME
static val DISALLOW_CONFIG_DATE_TIME: String
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 android.Manifest.permission#MANAGE_DEVICE_POLICY_TIME can set this restriction using the DevicePolicyManager APIs mentioned below.
The default value is false.
Key for user restrictions.
Type: Boolean
Value: "no_config_date_time"
DISALLOW_DEBUGGING_FEATURES
static val DISALLOW_DEBUGGING_FEATURES: String
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 android.Manifest.permission#MANAGE_DEVICE_POLICY_DEBUGGING_FEATURES can set this restriction using the DevicePolicyManager APIs mentioned below.
Default is true for newly created work profile on or after the 2025-04 security patch level. Otherwise, the default is false.
Key for user restrictions.
Type: Boolean
Value: "no_debugging_features"
DISALLOW_NEAR_FIELD_COMMUNICATION_RADIO
static val DISALLOW_NEAR_FIELD_COMMUNICATION_RADIO: String
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
Value: "no_near_field_communication_radio"
QUIET_MODE_DISABLE_ONLY_IF_CREDENTIAL_NOT_REQUIRED
static val QUIET_MODE_DISABLE_ONLY_IF_CREDENTIAL_NOT_REQUIRED: Int
Flag passed to #requestQuietModeEnabled to request disabling quiet mode only if there is no need to confirm the user credentials. If credentials are required to disable quiet mode, #requestQuietModeEnabled will do nothing and return false.
Value: 1
USER_CREATION_FAILED_NOT_PERMITTED
static val USER_CREATION_FAILED_NOT_PERMITTED: Int
Error result indicating that this user is not allowed to add other users on this device. This is a result code returned from the activity created by the intent createUserCreationIntent(String,String,String,PersistableBundle).
Value: 1
USER_CREATION_FAILED_NO_MORE_USERS
static val USER_CREATION_FAILED_NO_MORE_USERS: Int
Error result indicating that no more users can be created on this device. This is a result code returned from the activity created by the intent createUserCreationIntent(String,String,String,PersistableBundle).
Value: 2
USER_OPERATION_ERROR_CURRENT_USER
static val USER_OPERATION_ERROR_CURRENT_USER: Int
Indicates user operation failed because the target user is in the foreground.
Value: 4
USER_OPERATION_ERROR_LOW_STORAGE
static val USER_OPERATION_ERROR_LOW_STORAGE: Int
Indicates user operation failed because device has low data storage.
Value: 5
USER_OPERATION_ERROR_MANAGED_PROFILE
static val USER_OPERATION_ERROR_MANAGED_PROFILE: Int
Indicates user operation failed because target user is a managed profile.
Value: 2
USER_OPERATION_ERROR_MAX_RUNNING_USERS
static val USER_OPERATION_ERROR_MAX_RUNNING_USERS: Int
Indicates user operation failed because maximum running user limit has been reached.
Value: 3
USER_OPERATION_ERROR_MAX_USERS
static val USER_OPERATION_ERROR_MAX_USERS: Int
Indicates user operation failed because a relevant maximum user limit has been reached.
This could include the situation in which limit is 0, such as if a particular type of user is not enabled or is ineligible to be added to the requested parent.
Value: 6
USER_OPERATION_ERROR_UNKNOWN
static val USER_OPERATION_ERROR_UNKNOWN: Int
Indicates user operation failed for unknown reason.
Value: 1
USER_OPERATION_SUCCESS
static val USER_OPERATION_SUCCESS: Int
Indicates user operation is successful.
Value: 0
USER_TYPE_PROFILE_CLONE
static val USER_TYPE_PROFILE_CLONE: String
User type representing a clone profile. Clone profile is a user profile type used to run a second instance of an otherwise single user App (eg, messengers). Currently only the main user (which is the first full user set up on the device, usually the system user) can have a clone profile.
Value: "android.os.usertype.profile.CLONE"
USER_TYPE_PROFILE_MANAGED
static val USER_TYPE_PROFILE_MANAGED: String
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.
Value: "android.os.usertype.profile.MANAGED"
USER_TYPE_PROFILE_PRIVATE
static val USER_TYPE_PROFILE_PRIVATE: String
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.
Value: "android.os.usertype.profile.PRIVATE"
Public methods
createUserCreationIntent
open static fun createUserCreationIntent(
userName: String?,
accountName: String?,
accountType: String?,
accountOptions: PersistableBundle?
): Intent!
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. On success, the result code will be Activity.RESULT_OK.
Use supportsMultipleUsers() 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 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. |
| Return | |
|---|---|
Intent! |
An Intent that can be launched from an Activity. |
getApplicationRestrictions
open fun getApplicationRestrictions(packageName: String!): Bundle!
Returns a Bundle containing any saved application restrictions for the context user, for the given package name. Only an application with this package name can call this method.
The returned Bundle consists of key-value pairs, as defined by the application, where the types of values may be:
booleanintStringorString[]- From
android.os.Build.VERSION_CODES#M,BundleorBundle[]
NOTE: The method performs disk I/O and shouldn't be called on the main thread
Starting from Android version android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE, it is possible for there to be multiple managing apps on the device with the ability to set app restrictions, e.g. an Enterprise Device Policy Controller (DPC) and a Supervision admin. This method will always return the app restrictions set by the DPC, if the DPC has set one. Beginning from SDK level 36.1, if the DPC has not set any app restriction while other managing apps have set some, this method will return app restrictions set by one of those managing apps. There is no guarantee on which managing apps app restriction will be returned. To retrieve restrictions set by all managing apps, use android.content.RestrictionsManager#getApplicationRestrictionsPerAdmin instead.
This method may take several seconds to complete, so it should only be called from a worker thread.
| Parameters | |
|---|---|
packageName |
String!: the package name of the calling application |
| Return | |
|---|---|
Bundle! |
a Bundle with the restrictions for that package, or an empty Bundle if there are no saved restrictions. |
getSerialNumberForUser
open fun getSerialNumberForUser(user: UserHandle!): Long
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. |
| Return | |
|---|---|
Long |
The serial number of the given user; returns -1 if the given UserHandle does not exist. |
getUserCount
open fun getUserCount(): Int
Return the number of users currently created on the device.
Requires android.Manifest.permission.MANAGE_USERS or android.Manifest.permission.CREATE_USERS
getUserCreationTime
open fun getUserCreationTime(userHandle: UserHandle!): Long
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. |
| Return | |
|---|---|
Long |
creation time in milliseconds since Epoch time. |
getUserForSerialNumber
open fun getUserForSerialNumber(serialNumber: Long): UserHandle!
Return the user associated with a serial number previously returned by getSerialNumberForUser(UserHandle).
| Parameters | |
|---|---|
serialNumber |
Long: The serial number of the user that is being retrieved. |
| Return | |
|---|---|
UserHandle! |
Return the user associated with the serial number, or null if there is not one. |
getUserName
open fun getUserName(): String
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 android.Manifest.permission#GET_ACCOUNTS_PRIVILEGED
| Return | |
|---|---|
String |
the user name. This value cannot be null. |
getUserProfiles
open fun getUserProfiles(): MutableList<UserHandle!>!
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).
| Return | |
|---|---|
MutableList<UserHandle!>! |
A non-empty list of UserHandles associated with the context user. |
getUserRestrictions
open fun getUserRestrictions(): Bundle!
Returns the user-wide restrictions imposed on the context user.
| Return | |
|---|---|
Bundle! |
a Bundle containing all the restrictions. |
getUserRestrictions
open fun getUserRestrictions(userHandle: UserHandle!): Bundle!
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. |
| Return | |
|---|---|
Bundle! |
a Bundle containing all the restrictions.
Requires |
isAdminUser
open fun isAdminUser(): Boolean
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.
| Return | |
|---|---|
Boolean |
whether the context user is an admin user. |
isDemoUser
open fun isDemoUser(): Boolean
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.
| Return | |
|---|---|
Boolean |
whether the context user is a demo user. |
isHeadlessSystemUserMode
open static fun isHeadlessSystemUserMode(): Boolean
Checks whether the device is running in a headless system user mode.
Headless system user mode means the system user 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.
| Return | |
|---|---|
Boolean |
whether the device is running in a headless system user mode. |
isManagedProfile
open fun isManagedProfile(): Boolean
Checks if the context user is a managed profile. Note that this applies specifically to managed profiles. For profiles in general, use isProfile() instead.
| Return | |
|---|---|
Boolean |
whether the context user is a managed profile. |
isProfile
open fun isProfile(): Boolean
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 is a type of profile.
| Return | |
|---|---|
Boolean |
whether the context user is in a profile. |
isQuietModeEnabled
open fun isQuietModeEnabled(userHandle: UserHandle!): Boolean
Returns whether the given profile is in quiet mode or not.
| Parameters | |
|---|---|
userHandle |
UserHandle!: The user handle of the profile to be queried. |
| Return | |
|---|---|
Boolean |
true if the profile is in quiet mode, false otherwise. |
isSystemUser
open fun isSystemUser(): Boolean
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.
| Return | |
|---|---|
Boolean |
whether the context user is the system user. |
isUserAGoat
open fun isUserAGoat(): Boolean
Used to determine whether the user making this call is subject to teleportations.
As of android.os.Build.VERSION_CODES#LOLLIPOP, this method can now automatically identify goats using advanced goat recognition technology.
As of android.os.Build.VERSION_CODES#R, this method always returns false in order to protect goat privacy.
| Return | |
|---|---|
Boolean |
Returns whether the user making this call is a goat. |
isUserForeground
open fun isUserForeground(): Boolean
Checks if the context user is running in the foreground.
| Return | |
|---|---|
Boolean |
whether the context user is running in the foreground. |
isUserRunning
open fun isUserRunning(user: UserHandle!): Boolean
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; android.os.Build.VERSION_CODES#N, this API required a system permission in order to check other profile's status. Since Android Nougat MR1 (SDK version >= 25; android.os.Build.VERSION_CODES#N_MR1), the restriction has been relaxed, and now it'll accept any android.os.UserHandle within the same profile group as the caller.
| Parameters | |
|---|---|
user |
UserHandle!: The user to retrieve the running state for. |
isUserRunningOrStopping
open fun isUserRunningOrStopping(user: UserHandle!): Boolean
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).
Note prior to Android Nougat MR1 (SDK version <= 24; android.os.Build.VERSION_CODES#N, this API required a system permission in order to check other profile's status. Since Android Nougat MR1 (SDK version >= 25; android.os.Build.VERSION_CODES#N_MR1), the restriction has been relaxed, and now it'll accept any android.os.UserHandle within the same profile group as the caller.
| Parameters | |
|---|---|
user |
UserHandle!: The user to retrieve the running state for. |
isUserUnlocked
open fun isUserUnlocked(): Boolean
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.
isUserUnlocked
open fun isUserUnlocked(user: UserHandle!): Boolean
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 or android.permission.INTERACT_ACROSS_USERS, otherwise specified user must be the calling user or a profile associated with it.
| Parameters | |
|---|---|
user |
UserHandle!: to retrieve the unlocked state for. |
requestQuietModeEnabled
open fun requestQuietModeEnabled(
enableQuietMode: Boolean,
userHandle: UserHandle
): Boolean
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 and Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE 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 and Intent.ACTION_PROFILE_UNAVAILABLE 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(UserHandle).
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. |
| Return | |
|---|---|
Boolean |
false if user's credential is needed in order to turn off quiet mode, true otherwise |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
if userHandle is not a profile |
java.lang.SecurityException |
if the caller is invalid |
requestQuietModeEnabled
open fun requestQuietModeEnabled(
enableQuietMode: Boolean,
userHandle: UserHandle,
flags: Int
): Boolean
Perform the same operation as requestQuietModeEnabled(boolean,UserHandle), but with a flag to tweak the behavior of the request.
| Parameters | |
|---|---|
enableQuietMode |
Boolean: whether quiet mode should be enabled or disabled |
userHandle |
UserHandle: user handle of the profile. This value cannot be null. |
flags |
Int: Can be 0 or QUIET_MODE_DISABLE_ONLY_IF_CREDENTIAL_NOT_REQUIRED. Value is either 0 or a combination of the following:
|
| Return | |
|---|---|
Boolean |
false if user's credential is needed in order to turn off quiet mode, true otherwise |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
if userHandle is not a managed profile |
java.lang.SecurityException |
if the caller is invalid |
setRestrictionsChallenge
open funsetRestrictionsChallenge(newPin: String!): Boolean
Deprecated: 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. |
| Return | |
|---|---|
Boolean |
Returns true if the challenge PIN was set successfully. |
supportsMultipleUsers
open static fun supportsMultipleUsers(): Boolean
Returns whether this device supports multiple switchable users with their own login and customizable space.
Note that, even if false, multiple users might still be possible, as long as no login UI is required; e.g., profiles might still be supported, as they do not require a login UI.
| Return | |
|---|---|
Boolean |
whether the device supports multiple switchable users. |