public class UserManager extends Object
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.
Modifier and Type | Class and Description |
---|---|
static interface |
UserManager.UserRestrictionSource |
Modifier and Type | Field and Description |
---|---|
static String |
ALLOW_PARENT_PROFILE_APP_LINKING
Allows apps in the parent profile to handle web links from the managed profile.
|
static String |
DISALLLOW_UNMUTE_DEVICE
Specifies if a user is not allowed to unmute the device's master volume.
|
static String |
DISALLOW_ADD_USER
Specifies if a user is disallowed from adding new users and
profiles.
|
static String |
DISALLOW_ADJUST_VOLUME
Specifies if a user is disallowed from adjusting the master
volume.
|
static String |
DISALLOW_APPS_CONTROL
Specifies if a user is disallowed from modifying
applications in Settings or launchers.
|
static String |
DISALLOW_CAMERA
Specifies if a user is not allowed to use the camera.
|
static String |
DISALLOW_CONFIG_BLUETOOTH
Specifies if a user is disallowed from configuring bluetooth.
|
static String |
DISALLOW_CONFIG_CELL_BROADCASTS
Specifies if a user is disallowed from configuring cell
broadcasts.
|
static String |
DISALLOW_CONFIG_CREDENTIALS
Specifies if a user is disallowed from configuring user
credentials.
|
static String |
DISALLOW_CONFIG_MOBILE_NETWORKS
Specifies if a user is disallowed from configuring mobile
networks.
|
static String |
DISALLOW_CONFIG_TETHERING
Specifies if a user is disallowed from configuring Tethering
& portable hotspots.
|
static String |
DISALLOW_CONFIG_VPN
Specifies if a user is disallowed from configuring VPN.
|
static String |
DISALLOW_CONFIG_WIFI
Specifies if a user is disallowed from changing Wi-Fi
access points.
|
static String |
DISALLOW_CREATE_WINDOWS
Specifies that windows besides app windows should not be
created.
|
static String |
DISALLOW_CROSS_PROFILE_COPY_PASTE
Specifies if what is copied in the clipboard of this profile can
be pasted in related profiles.
|
static String |
DISALLOW_DATA_ROAMING
Specifies if a user is not allowed to use cellular data when roaming.
|
static String |
DISALLOW_DEBUGGING_FEATURES
Specifies if a user is disallowed from enabling or
accessing debugging features.
|
static String |
DISALLOW_FACTORY_RESET
Specifies if a user is disallowed from factory resetting
from Settings.
|
static String |
DISALLOW_FUN
Specifies if the user is not allowed to have fun.
|
static String |
DISALLOW_INSTALL_APPS
Specifies if a user is disallowed from installing applications.
|
static 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.
|
static String |
DISALLOW_MODIFY_ACCOUNTS
Specifies if a user is disallowed from adding and removing accounts, unless they are
programmatically added by
Authenticator. |
static String |
DISALLOW_MOUNT_PHYSICAL_MEDIA
Specifies if a user is disallowed from mounting
physical external media.
|
static String |
DISALLOW_NETWORK_RESET
Specifies if a user is disallowed from resetting network settings
from Settings.
|
static String |
DISALLOW_OEM_UNLOCK
Specifies if a user is not allowed to enable the oem unlock setting.
|
static String |
DISALLOW_OUTGOING_BEAM
Specifies if the user is not allowed to use NFC to beam out data from apps.
|
static String |
DISALLOW_OUTGOING_CALLS
Specifies that the user is not allowed to make outgoing
phone calls.
|
static String |
DISALLOW_RECORD_AUDIO
Specifies if a user is not allowed to record audio.
|
static String |
DISALLOW_REMOVE_USER
When set on the primary user this specifies if the user can remove other users.
|
static String |
DISALLOW_RUN_IN_BACKGROUND
Specifies if a user is not allowed to run in the background and should be stopped during
user switch.
|
static String |
DISALLOW_SAFE_BOOT
Specifies if the user is not allowed to reboot the device into safe boot mode.
|
static String |
DISALLOW_SET_USER_ICON
Specifies if a user is not allowed to change their icon.
|
static String |
DISALLOW_SET_WALLPAPER
User restriction to disallow setting a wallpaper.
|
static String |
DISALLOW_SHARE_LOCATION
Specifies if a user is disallowed from turning on location sharing.
|
static String |
DISALLOW_SMS
Specifies that the user is not allowed to send or receive
SMS messages.
|
static String |
DISALLOW_UNINSTALL_APPS
Specifies if a user is disallowed from uninstalling applications.
|
static String |
DISALLOW_UNMUTE_MICROPHONE
Specifies if a user is disallowed from adjusting microphone
volume.
|
static String |
DISALLOW_USB_FILE_TRANSFER
Specifies if a user is disallowed from transferring files over
USB.
|
static String |
DISALLOW_WALLPAPER
Hidden user restriction to disallow access to wallpaper manager APIs.
|
static String |
ENSURE_VERIFY_APPS
Specifies if a user is disallowed from disabling application
verification.
|
static String |
EXTRA_USER_ACCOUNT_NAME
Extra containing account name for the user being created.
|
static String |
EXTRA_USER_ACCOUNT_OPTIONS
Extra containing account-specific data for the user being created.
|
static String |
EXTRA_USER_ACCOUNT_TYPE
Extra containing account type for the user being created.
|
static String |
EXTRA_USER_NAME
Extra containing a name for the user being created.
|
static String |
KEY_RESTRICTIONS_PENDING
Application restriction key that is used to indicate the pending arrival
of real restrictions for the app.
|
static int |
PIN_VERIFICATION_FAILED_INCORRECT |
static int |
PIN_VERIFICATION_FAILED_NOT_SET |
static int |
PIN_VERIFICATION_SUCCESS |
static int |
RESTRICTION_NOT_SET |
static int |
RESTRICTION_SOURCE_DEVICE_OWNER |
static int |
RESTRICTION_SOURCE_PROFILE_OWNER |
static int |
RESTRICTION_SOURCE_SYSTEM |
static int |
USER_CREATION_FAILED_NO_MORE_USERS
Error result indicating that no more users can be created on this device.
|
static int |
USER_CREATION_FAILED_NOT_PERMITTED
Error result indicating that this user is not allowed to add other users on this device.
|
Constructor and Description |
---|
UserManager(Context context,
IUserManager service) |
Modifier and Type | Method and Description |
---|---|
boolean |
canAddMoreManagedProfiles(int userId,
boolean allowedToRemoveOne)
Checks whether it's possible to add more managed profiles.
|
boolean |
canAddMoreUsers()
Checks whether it's possible to add more users.
|
boolean |
canHaveRestrictedProfile(int userId)
Checks if specified user can have restricted profile.
|
boolean |
canSwitchUsers()
Returns whether switching users is currently allowed.
|
void |
clearSeedAccountData() |
UserInfo |
createGuest(Context context,
String name)
Creates a guest user and configures it.
|
UserInfo |
createProfileForUser(String name,
int flags,
int userHandle)
Creates a user with the specified name and options as a profile of another user.
|
UserInfo |
createRestrictedProfile(String name)
Creates a restricted profile with the specified name.
|
UserInfo |
createUser(String name,
int flags)
Creates a user with the specified name and options.
|
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.
|
static UserManager |
get(Context context) |
Bundle |
getApplicationRestrictions(String packageName)
Returns a
Bundle containing any saved application restrictions for this user, for the
given package name. |
Bundle |
getApplicationRestrictions(String packageName,
UserHandle user) |
Drawable |
getBadgedDrawableForUser(Drawable badgedDrawable,
UserHandle user,
Rect badgeLocation,
int badgeDensity)
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
drawable allowing the user to distinguish it from the original drawable.
|
Drawable |
getBadgedIconForUser(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.
|
CharSequence |
getBadgedLabelForUser(CharSequence label,
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 copy of the label with
badging for accessibility services like talkback.
|
int |
getCredentialOwnerProfile(int userHandle)
Returns the device credential owner id of the profile from
which this method is called, or userHandle if called from a user that
is not a profile.
|
Bundle |
getDefaultGuestRestrictions() |
int[] |
getEnabledProfileIds(int userId) |
List<UserInfo> |
getEnabledProfiles(int userHandle)
Returns list of the profiles of userHandle including
userHandle itself.
|
static int |
getMaxSupportedUsers()
Returns the maximum number of users that can be created on this device.
|
UserInfo |
getPrimaryUser()
Returns information for Primary user.
|
int[] |
getProfileIds(int userId,
boolean enabledOnly)
Returns a list of ids for profiles associated with the specified user including the user
itself.
|
int[] |
getProfileIdsWithDisabled(int userId) |
UserInfo |
getProfileParent(int userHandle)
Returns the parent of the profile which this method is called from
or null if called from a user that is not a profile.
|
List<UserInfo> |
getProfiles(int userHandle)
Returns list of the profiles of userHandle including
userHandle itself.
|
String |
getSeedAccountName() |
PersistableBundle |
getSeedAccountOptions() |
String |
getSeedAccountType() |
long |
getSerialNumberForUser(UserHandle user)
Return the serial number for a user.
|
long[] |
getSerialNumbersOfUsers(boolean excludeDying)
Returns serial numbers of all users on this device.
|
String |
getUserAccount(int userHandle) |
int |
getUserCount()
Return the number of users currently created on the device.
|
long |
getUserCreationTime(UserHandle userHandle)
Returns creation time of the user or of a managed profile associated with the calling user.
|
UserHandle |
getUserForSerialNumber(long serialNumber)
Return the user associated with a serial number previously
returned by
getSerialNumberForUser(UserHandle) . |
int |
getUserHandle()
Returns the user handle for the user that this process is running under.
|
int |
getUserHandle(int userSerialNumber)
Returns a userHandle on this device for a given user serial number.
|
Bitmap |
getUserIcon(int userHandle)
Returns a file descriptor for the user's photo.
|
UserInfo |
getUserInfo(int userHandle)
Returns the UserInfo object describing a specific user.
|
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 . |
int |
getUserRestrictionSource(String restrictionKey,
UserHandle userHandle) |
List<UserInfo> |
getUsers()
Returns information for all users on this device, including ones marked for deletion.
|
List<UserInfo> |
getUsers(boolean excludeDying)
Returns information for all users on this device.
|
int |
getUserSerialNumber(int userHandle)
Returns a serial number on this device for a given userHandle.
|
boolean |
hasBaseUserRestriction(String restrictionKey,
UserHandle userHandle) |
boolean |
hasUserRestriction(String restrictionKey)
Returns whether the current user has been disallowed from performing certain actions
or setting certain settings.
|
boolean |
hasUserRestriction(String restrictionKey,
UserHandle userHandle) |
boolean |
isAdminUser() |
boolean |
isDemoUser()
Checks if the calling app is running in a demo user.
|
static boolean |
isDeviceInDemoMode(Context context) |
boolean |
isEphemeralUser()
Checks if the calling app is running as an ephemeral user.
|
boolean |
isGuestUser()
Checks if the calling app is running as a guest user.
|
boolean |
isLinkedUser()
Used to check if the user making this call is linked to another user.
|
boolean |
isManagedProfile()
Checks if the calling app is running in a managed profile.
|
boolean |
isManagedProfile(int userId)
Checks if the specified user is a managed profile.
|
boolean |
isPrimaryUser()
Used to check if this process is running under the primary user.
|
boolean |
isQuietModeEnabled(UserHandle userHandle)
Returns whether the given profile is in quiet mode or not.
|
boolean |
isSameProfileGroup(int userId,
int otherUserId)
Requires
android.Manifest.permission#MANAGE_USERS permission. |
static boolean |
isSplitSystemUser() |
boolean |
isSystemUser()
Used to check if this process is running under the system user.
|
boolean |
isUserAdmin(int userId) |
boolean |
isUserAGoat()
Used to determine whether the user making this call is subject to
teleportations.
|
boolean |
isUserEphemeral(int userId)
Returns whether the specified user is ephemeral.
|
boolean |
isUserRunning(int userId) |
boolean |
isUserRunning(UserHandle user)
Return whether the given user is actively running.
|
boolean |
isUserRunningAndLocked()
Deprecated.
|
boolean |
isUserRunningAndLocked(UserHandle user)
Deprecated.
|
boolean |
isUserRunningAndUnlocked()
Deprecated.
|
boolean |
isUserRunningAndUnlocked(UserHandle user)
Deprecated.
|
boolean |
isUserRunningOrStopping(UserHandle user)
Return whether the given user is actively running or stopping.
|
boolean |
isUserSwitcherEnabled()
Returns true if the user switcher should be shown, this will be if device supports multi-user
and there are at least 2 users available that are not managed profiles.
|
boolean |
isUserUnlocked()
Return whether the calling user is running in an "unlocked" state.
|
boolean |
isUserUnlocked(int userId) |
boolean |
isUserUnlocked(UserHandle user)
Return whether the given user is running in an "unlocked" state.
|
boolean |
isUserUnlockingOrUnlocked(int userId) |
boolean |
isUserUnlockingOrUnlocked(UserHandle user) |
boolean |
markGuestForDeletion(int userHandle) |
boolean |
removeUser(int userHandle)
Removes a user and all associated data.
|
void |
setApplicationRestrictions(String packageName,
Bundle restrictions,
UserHandle user) |
void |
setDefaultGuestRestrictions(Bundle restrictions) |
void |
setQuietModeEnabled(int userHandle,
boolean enableQuietMode)
Set quiet mode of a managed profile.
|
boolean |
setRestrictionsChallenge(String newPin)
Deprecated.
The restrictions PIN functionality is no longer provided by the system.
This method is preserved for backwards compatibility reasons and always returns false.
|
void |
setSeedAccountData(int userId,
String accountName,
String accountType,
PersistableBundle accountOptions) |
void |
setUserAccount(int userHandle,
String accountName)
Set account name for the given user.
|
void |
setUserEnabled(int userHandle)
Sets the user as enabled, if such an user exists.
|
void |
setUserIcon(int userHandle,
Bitmap icon)
Sets the user's photo.
|
void |
setUserName(int userHandle,
String name)
Updates the user's name.
|
void |
setUserRestriction(String key,
boolean value)
|
void |
setUserRestriction(String key,
boolean value,
UserHandle userHandle)
|
void |
setUserRestrictions(Bundle restrictions)
Deprecated.
|
void |
setUserRestrictions(Bundle restrictions,
UserHandle userHandle)
Deprecated.
|
boolean |
someUserHasSeedAccount(String accountName,
String accountType) |
static boolean |
supportsMultipleUsers()
Returns whether this device supports multiple users with their own login and customizable
space.
|
boolean |
trySetQuietModeDisabled(int userHandle,
IntentSender target)
Tries disabling quiet mode for a given user.
|
public static final int RESTRICTION_NOT_SET
public static final int RESTRICTION_SOURCE_SYSTEM
public static final int RESTRICTION_SOURCE_DEVICE_OWNER
public static final int RESTRICTION_SOURCE_PROFILE_OWNER
public static final String DISALLOW_MODIFY_ACCOUNTS
programmatically
added by
Authenticator.
The default value is false
.
From Build.VERSION_CODES.N
a profile or device owner app can still
use android.accounts.AccountManager
APIs to add or remove accounts when account
management is disallowed.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_CONFIG_WIFI
false
.
This restriction has no effect in a managed profile.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_INSTALL_APPS
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_UNINSTALL_APPS
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_SHARE_LOCATION
false
.
In a managed profile, location sharing always reflects the primary user's setting, but can be overridden and forced off by setting this restriction to true in the managed profile.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_CONFIG_BLUETOOTH
false
.
This restriction has no effect in a managed profile.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_USB_FILE_TRANSFER
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_CONFIG_CREDENTIALS
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_REMOVE_USER
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_DEBUGGING_FEATURES
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_CONFIG_VPN
false
.
This restriction has an effect in a managed profile only from
Build.VERSION_CODES.M
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_CONFIG_TETHERING
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_NETWORK_RESET
false
.
This restriction has no effect on secondary users and managed profiles since only the primary user can reset the network settings of the device.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_FACTORY_RESET
false
.
This restriction has no effect on secondary users and managed profiles since only the primary user can factory reset the device.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_ADD_USER
false
.
This restriction has no effect on secondary users and managed profiles since only the primary user can add other users.
Key for user restrictions.
Type: Boolean
public static final String ENSURE_VERIFY_APPS
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_CONFIG_CELL_BROADCASTS
false
.
This restriction has no effect on secondary users and managed profiles since only the primary user can configure cell broadcasts.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_CONFIG_MOBILE_NETWORKS
false
.
This restriction has no effect on secondary users and managed profiles since only the primary user can configure mobile networks.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_APPS_CONTROL
The default value is false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_UNMUTE_MICROPHONE
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_ADJUST_VOLUME
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_OUTGOING_CALLS
false
.
This restriction has no effect on managed profiles.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_SMS
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_FUN
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_CREATE_WINDOWS
WindowManager.LayoutParams.TYPE_TOAST
WindowManager.LayoutParams.TYPE_PHONE
WindowManager.LayoutParams.TYPE_PRIORITY_PHONE
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY
This can only be set by device owners and profile owners on the primary user.
The default value is false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_OUTGOING_BEAM
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_WALLPAPER
public static final String DISALLOW_SET_WALLPAPER
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_SAFE_BOOT
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_RECORD_AUDIO
false
.public static final String DISALLOW_RUN_IN_BACKGROUND
false
.
This restriction can be set by device owners and profile owners.
public static final String DISALLOW_CAMERA
public static final String DISALLLOW_UNMUTE_DEVICE
public static final String DISALLOW_DATA_ROAMING
false
.public static final String DISALLOW_SET_USER_ICON
false
.
Key for user restrictions.
Type: Boolean
public static final String DISALLOW_OEM_UNLOCK
false
. Setting this restriction has no effect if the bootloader is already
unlocked.public static final String ALLOW_PARENT_PROFILE_APP_LINKING
Intent.ACTION_VIEW
,
category Intent.CATEGORY_BROWSABLE
, scheme http or https, and which
define a host can handle intents from the managed profile.
The default value is false
.
Key for user restrictions.
Type: Boolean
public static final String KEY_RESTRICTIONS_PENDING
Applications that support restrictions should check for the presence of this key.
A true
value indicates that restrictions may be applied in the near
future but are not available yet. It is the responsibility of any
management application that sets this flag to update it when the final
restrictions are enforced.
Key for application restrictions.
Type: Boolean
public static final String EXTRA_USER_NAME
public static final String EXTRA_USER_ACCOUNT_NAME
public static final String EXTRA_USER_ACCOUNT_TYPE
public static final String EXTRA_USER_ACCOUNT_OPTIONS
public static final int PIN_VERIFICATION_FAILED_INCORRECT
public static final int PIN_VERIFICATION_FAILED_NOT_SET
public static final int PIN_VERIFICATION_SUCCESS
public static final int USER_CREATION_FAILED_NOT_PERMITTED
createUserCreationIntent(String, String, String, PersistableBundle)
.public static final int USER_CREATION_FAILED_NO_MORE_USERS
createUserCreationIntent(String, String, String, PersistableBundle)
.public UserManager(Context context, IUserManager service)
public static UserManager get(Context context)
public static boolean supportsMultipleUsers()
public static boolean isSplitSystemUser()
public boolean canSwitchUsers()
For instance switching users is not allowed if the current user is in a phone call, or system user hasn't been unlocked yet
public int getUserHandle()
public String getUserName()
public boolean isUserAGoat()
As of Build.VERSION_CODES.LOLLIPOP
, this method can
now automatically identify goats using advanced goat recognition technology.
public boolean isPrimaryUser()
public boolean isSystemUser()
public boolean isAdminUser()
public boolean isUserAdmin(int userId)
public boolean isLinkedUser()
public boolean canHaveRestrictedProfile(int userId)
public boolean isGuestUser()
public boolean isDemoUser()
public boolean isManagedProfile()
android.Manifest.permission#MANAGE_USERS
permission.public boolean isManagedProfile(int userId)
android.Manifest.permission#MANAGE_USERS
permission, otherwise the caller
must be in the same profile group of specified user.public boolean isEphemeralUser()
public boolean isUserEphemeral(int userId)
public boolean isUserRunning(UserHandle user)
user
- The user to retrieve the running state for.public boolean isUserRunning(int userId)
public boolean isUserRunningOrStopping(UserHandle user)
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).user
- The user to retrieve the running state for.@Deprecated public boolean isUserRunningAndLocked()
@Deprecated public boolean isUserRunningAndLocked(UserHandle user)
@Deprecated public boolean isUserRunningAndUnlocked()
@Deprecated public boolean isUserRunningAndUnlocked(UserHandle user)
public boolean isUserUnlocked()
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.
public boolean isUserUnlocked(UserHandle user)
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.
user
- to retrieve the unlocked state for.Intent.ACTION_USER_UNLOCKED
,
Context.createDeviceProtectedStorageContext()
public boolean isUserUnlocked(int userId)
public boolean isUserUnlockingOrUnlocked(UserHandle user)
public boolean isUserUnlockingOrUnlocked(int userId)
public UserInfo getUserInfo(int userHandle)
android.Manifest.permission#MANAGE_USERS
permission.userHandle
- the user handle of the user whose information is being requested.public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle)
restrictionKey
- the string key representing the restrictionuserHandle
- the UserHandle of the user for whom to retrieve the restrictions.RESTRICTION_NOT_SET
,
RESTRICTION_SOURCE_SYSTEM
, RESTRICTION_SOURCE_DEVICE_OWNER
and RESTRICTION_SOURCE_PROFILE_OWNER
public Bundle getUserRestrictions()
public Bundle getUserRestrictions(UserHandle userHandle)
userHandle
.userHandle
- the UserHandle of the user for whom to retrieve the restrictions.public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle)
restrictionKey
- the string key representing the restrictionuserHandle
- the UserHandle of the user for whom to retrieve the restrictions.@Deprecated public void setUserRestrictions(Bundle restrictions)
DevicePolicyManager.addUserRestriction(ComponentName, String)
instead.@Deprecated public void setUserRestrictions(Bundle restrictions, UserHandle userHandle)
DevicePolicyManager.addUserRestriction(ComponentName, String)
instead.@Deprecated public void setUserRestriction(String key, boolean value)
DevicePolicyManager.addUserRestriction(
android.content.ComponentName, String)
or
DevicePolicyManager.clearUserRestriction(
android.content.ComponentName, String)
instead.key
- the key of the restrictionvalue
- the value for the restriction@Deprecated public void setUserRestriction(String key, boolean value, UserHandle userHandle)
DevicePolicyManager.addUserRestriction(
android.content.ComponentName, String)
or
DevicePolicyManager.clearUserRestriction(
android.content.ComponentName, String)
instead.key
- the key of the restrictionvalue
- the value for the restrictionuserHandle
- the user whose restriction is to be changed.public boolean hasUserRestriction(String restrictionKey)
restrictionKey
- The string key representing the restriction.true
if the current user has the given restriction, false
otherwise.public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle)
restrictionKey
- the string key representing the restrictionuserHandle
- the UserHandle of the user for whom to retrieve the restrictions.public long getSerialNumberForUser(UserHandle user)
user
- The user whose serial number is to be retrieved.getUserForSerialNumber(long)
public UserHandle getUserForSerialNumber(long serialNumber)
getSerialNumberForUser(UserHandle)
.serialNumber
- The serial number of the user that is being
retrieved.getSerialNumberForUser(UserHandle)
public UserInfo createUser(String name, int flags)
android.Manifest.permission#MANAGE_USERS
permission.name
- the user's nameflags
- flags that identify the type of user and other properties.UserInfo
public UserInfo createGuest(Context context, String name)
context
- an application contextname
- the name to set for the userpublic UserInfo createProfileForUser(String name, int flags, int userHandle)
android.Manifest.permission#MANAGE_USERS
permission.name
- the user's nameflags
- flags that identify the type of user and other properties.userHandle
- new user will be a profile of this use.UserInfo
public UserInfo createRestrictedProfile(String name)
name
- profile's namepublic static Intent createUserCreationIntent(String userName, String accountName, String accountType, PersistableBundle accountOptions)
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.
userName
- Optional name to assign to the user.accountName
- Optional account name that will be used by the setup wizard to initialize
the user.accountType
- Optional account type for the account to be created. This is required
if the account name is specified.accountOptions
- 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)
.USER_CREATION_FAILED_NOT_PERMITTED
,
USER_CREATION_FAILED_NO_MORE_USERS
,
supportsMultipleUsers()
public String getSeedAccountName()
public String getSeedAccountType()
public PersistableBundle getSeedAccountOptions()
public void setSeedAccountData(int userId, String accountName, String accountType, PersistableBundle accountOptions)
userId
- accountName
- accountType
- accountOptions
- createUserCreationIntent(String, String, String, PersistableBundle)
public void clearSeedAccountData()
public boolean markGuestForDeletion(int userHandle)
userHandle
- public void setUserEnabled(int userHandle)
Requires android.Manifest.permission#MANAGE_USERS
permission.
Note that the default is true, it's only that managed profiles might not be enabled. Also ephemeral users can be disabled to indicate that their removal is in progress and they shouldn't be re-entered. Therefore ephemeral users should not be re-enabled once disabled.
userHandle
- the id of the profile to enablepublic int getUserCount()
public List<UserInfo> getUsers()
getUsers(boolean)
.
Requires android.Manifest.permission#MANAGE_USERS
permission.
public long[] getSerialNumbersOfUsers(boolean excludeDying)
android.Manifest.permission#MANAGE_USERS
permission.excludeDying
- specify if the list should exclude users being removed.public String getUserAccount(int userHandle)
public void setUserAccount(int userHandle, String accountName)
public UserInfo getPrimaryUser()
android.Manifest.permission#MANAGE_USERS
permission.public boolean canAddMoreUsers()
public boolean canAddMoreManagedProfiles(int userId, boolean allowedToRemoveOne)
public List<UserInfo> getProfiles(int userHandle)
getEnabledProfiles(int)
if you need only the enabled ones.
Requires android.Manifest.permission#MANAGE_USERS
permission.userHandle
- profiles of this user will be returned.public boolean isSameProfileGroup(int userId, int otherUserId)
android.Manifest.permission#MANAGE_USERS
permission.userId
- one of the two user ids to check.otherUserId
- one of the two user ids to check.public List<UserInfo> getEnabledProfiles(int userHandle)
android.Manifest.permission#MANAGE_USERS
permission.userHandle
- profiles of this user will be returned.public List<UserHandle> getUserProfiles()
public int[] getProfileIds(int userId, boolean enabledOnly)
userId
- id of the user to return profiles forenabledOnly
- whether return only enabled
profilespublic int[] getProfileIdsWithDisabled(int userId)
getProfileIds(int, boolean)
public int[] getEnabledProfileIds(int userId)
getProfileIds(int, boolean)
public int getCredentialOwnerProfile(int userHandle)
public UserInfo getProfileParent(int userHandle)
public void setQuietModeEnabled(int userHandle, boolean enableQuietMode)
userHandle
- The user handle of the profile.enableQuietMode
- Whether quiet mode should be enabled or disabled.public boolean isQuietModeEnabled(UserHandle userHandle)
userHandle
- The user handle of the profile to be queried.public boolean trySetQuietModeDisabled(int userHandle, IntentSender target)
setQuietModeEnabled(int, boolean)
directly.public Drawable getBadgedIconForUser(Drawable icon, UserHandle user)
getBadgedDrawableForUser(
android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)
.
If the original drawable is a BitmapDrawable and the backing bitmap is
mutable as per Bitmap.isMutable()
, the badging
is performed in place and the original drawable is returned.
icon
- The icon to badge.user
- The target user.public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user, Rect badgeLocation, int badgeDensity)
If the original drawable is a BitmapDrawable and the backing bitmap is
mutable as per Bitmap.isMutable()
, the badging
is performed in place and the original drawable is returned.
badgedDrawable
- The drawable to badge.user
- The target user.badgeLocation
- Where in the bounds of the badged drawable to place
the badge. If it's null
, the badge is applied on top of the entire
drawable being badged.badgeDensity
- The optional desired density for the badge as per
DisplayMetrics.densityDpi
. If it's not positive,
the density of the display is used.public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user)
label
- The label to change.user
- The target user.public List<UserInfo> getUsers(boolean excludeDying)
android.Manifest.permission#MANAGE_USERS
permission.excludeDying
- specify if the list should exclude users being
removed.public boolean removeUser(int userHandle)
android.Manifest.permission#MANAGE_USERS
permission.userHandle
- the integer handle of the user, where 0 is the primary user.public void setUserName(int userHandle, String name)
android.Manifest.permission#MANAGE_USERS
permission.userHandle
- the user's integer handlename
- the new name for the userpublic void setUserIcon(int userHandle, Bitmap icon)
userHandle
- the user for whom to change the photo.icon
- the bitmap to set as the photo.public Bitmap getUserIcon(int userHandle)
userHandle
- the user whose photo we want to read.Bitmap
of the user's photo, or null if there's no photo.for a default.
public static int getMaxSupportedUsers()
public boolean isUserSwitcherEnabled()
public static boolean isDeviceInDemoMode(Context context)
public int getUserSerialNumber(int userHandle)
userHandle
- public int getUserHandle(int userSerialNumber)
userSerialNumber
- public Bundle getApplicationRestrictions(String packageName)
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.
The returned Bundle
consists of key-value pairs, as defined by the application,
where the types of values may be:
boolean
int
String
or String[]
Build.VERSION_CODES.M
, Bundle
or Bundle[]
packageName
- the package name of the calling applicationBundle
with the restrictions for that package, or an empty Bundle
if there are no saved restrictions.KEY_RESTRICTIONS_PENDING
public Bundle getApplicationRestrictions(String packageName, UserHandle user)
public void setApplicationRestrictions(String packageName, Bundle restrictions, UserHandle user)
public boolean setRestrictionsChallenge(String newPin)
newPin
- the PIN to use for challenge dialogs.public void setDefaultGuestRestrictions(Bundle restrictions)
public Bundle getDefaultGuestRestrictions()
public long getUserCreationTime(UserHandle userHandle)
userHandle
- user handle of the user or a managed profile associated with the
calling user.