FileDocCategorySizeDatePackage
UserManager.javaAPI DocAndroid 5.1 API48524Thu Mar 12 22:22:10 GMT 2015android.os

UserManager

public class UserManager extends Object
Manages users and user details on a multi-user system.

Fields Summary
private static String
TAG
private final IUserManager
mService
private final android.content.Context
mContext
public static final String
DISALLOW_MODIFY_ACCOUNTS
Specifies if a user is disallowed from adding and removing accounts. The default value is false.

Key for user restrictions.

Type: Boolean

public static final String
DISALLOW_CONFIG_WIFI
Specifies if a user is disallowed from changing Wi-Fi access points. The default value is false.

This restriction has no effect in a managed profile.

Key for user restrictions.

Type: Boolean

public static final String
DISALLOW_INSTALL_APPS
Specifies if a user is disallowed from installing applications. The default value is false.

Key for user restrictions.

Type: Boolean

public static final String
DISALLOW_UNINSTALL_APPS
Specifies if a user is disallowed from uninstalling applications. The default value is false.

Key for user restrictions.

Type: Boolean

public static final String
DISALLOW_SHARE_LOCATION
Specifies if a user is disallowed from turning on location sharing. The default value is 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
Specifies if a user is disallowed from enabling the "Unknown Sources" setting, that allows installation of apps from unknown sources. The default value is false.

Key for user restrictions.

Type: Boolean

public static final String
DISALLOW_CONFIG_BLUETOOTH
Specifies if a user is disallowed from configuring bluetooth. The default value is false.

This restriction has no effect in a managed profile.

Key for user restrictions.

Type: Boolean

public static final String
DISALLOW_USB_FILE_TRANSFER
Specifies if a user is disallowed from transferring files over USB. 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_CONFIG_CREDENTIALS
Specifies if a user is disallowed from configuring user credentials. The default value is false.

Key for user restrictions.

Type: Boolean

public static final String
DISALLOW_REMOVE_USER
When set on the primary user this specifies if the user can remove other users. When set on a secondary user, this specifies if the user can remove itself. This restriction has no effect on managed profiles. The default value is false.

Key for user restrictions.

Type: Boolean

public static final String
DISALLOW_DEBUGGING_FEATURES
Specifies if a user is disallowed from enabling or accessing debugging features. The default value is false.

Key for user restrictions.

Type: Boolean

public static final String
DISALLOW_CONFIG_VPN
Specifies if a user is disallowed from configuring VPN. The default value is false. This restriction has no effect in a managed profile.

Key for user restrictions.

Type: Boolean

public static final String
DISALLOW_CONFIG_TETHERING
Specifies if a user is disallowed from configuring Tethering & portable hotspots. 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_FACTORY_RESET
Specifies if a user is disallowed from factory resetting from Settings. This can only be set by device owners and profile owners on the primary user. The default value is 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
Specifies if a user is disallowed from adding new users and profiles. This can only be set by device owners and profile owners on the primary user. The default value is 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
Specifies if a user is disallowed from disabling application verification. The default value is false.

Key for user restrictions.

Type: Boolean

public static final String
DISALLOW_CONFIG_CELL_BROADCASTS
Specifies if a user is disallowed from configuring cell broadcasts. This can only be set by device owners and profile owners on the primary user. The default value is 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
Specifies if a user is disallowed from configuring mobile networks. This can only be set by device owners and profile owners on the primary user. The default value is 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
Specifies if a user is disallowed from modifying applications in Settings or launchers. The following actions will not be allowed when this restriction is enabled:
  • uninstalling apps
  • disabling apps
  • clearing app caches
  • clearing app data
  • force stopping apps
  • clearing app defaults
  • The default value is false.

    Key for user restrictions.

    Type: Boolean

    public static final String
    DISALLOW_MOUNT_PHYSICAL_MEDIA
    Specifies if a user is disallowed from mounting physical external media. 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_UNMUTE_MICROPHONE
    Specifies if a user is disallowed from adjusting microphone volume. If set, the microphone will be muted. 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_ADJUST_VOLUME
    Specifies if a user is disallowed from adjusting the master volume. If set, the master volume will be muted. 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_OUTGOING_CALLS
    Specifies that the user is not allowed to make outgoing phone calls. Emergency calls are still permitted. The default value is false.

    This restriction has no effect on managed profiles since call intents are normally forwarded to the primary user.

    Key for user restrictions.

    Type: Boolean

    public static final String
    DISALLOW_SMS
    Specifies that the user is not allowed to send or receive SMS messages. The default value is false.

    Key for user restrictions.

    Type: Boolean

    public static final String
    DISALLOW_CREATE_WINDOWS
    Specifies that windows besides app windows should not be created. This will block the creation of the following types of windows.
  • {@link LayoutParams#TYPE_TOAST}
  • {@link LayoutParams#TYPE_PHONE}
  • {@link LayoutParams#TYPE_PRIORITY_PHONE}
  • {@link LayoutParams#TYPE_SYSTEM_ALERT}
  • {@link LayoutParams#TYPE_SYSTEM_ERROR}
  • {@link 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
    Specifies if what is copied in the clipboard of this profile can be pasted in related profiles. Does not restrict if the clipboard of related profiles can be pasted in this profile. The default value is false.

    Key for user restrictions.

    Type: Boolean

    public static final String
    DISALLOW_OUTGOING_BEAM
    Specifies if the user is not allowed to use NFC to beam out data from apps. The default value is false.

    Key for user restrictions.

    Type: Boolean

    public static final String
    KEY_RESTRICTIONS_PENDING
    Application restriction key that is used to indicate the pending arrival of real restrictions for the app.

    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 int
    PIN_VERIFICATION_FAILED_INCORRECT
    public static final int
    PIN_VERIFICATION_FAILED_NOT_SET
    public static final int
    PIN_VERIFICATION_SUCCESS
    private static UserManager
    sInstance
    Constructors Summary
    public UserManager(android.content.Context context, IUserManager service)

    hide

            mService = service;
            mContext = context;
        
    Methods Summary
    private static voidaddDefaultUserRestrictions(Bundle restrictions)

            restrictions.putBoolean(DISALLOW_OUTGOING_CALLS, true);
            restrictions.putBoolean(DISALLOW_SMS, true);
        
    public booleancanAddMoreUsers()
    Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS permission.

    return
    true if more users can be added, false if limit has been reached.
    hide

            final List<UserInfo> users = getUsers(true);
            final int totalUserCount = users.size();
            int aliveUserCount = 0;
            for (int i = 0; i < totalUserCount; i++) {
                UserInfo user = users.get(i);
                if (!user.isGuest()) {
                    aliveUserCount++;
                }
            }
            return aliveUserCount < getMaxSupportedUsers();
        
    public intcheckRestrictionsChallenge(java.lang.String pin)

    hide
    param
    pin The PIN to verify, or null to get the number of milliseconds to wait for before allowing the user to enter the PIN.
    return
    Returns a positive number (including zero) for how many milliseconds before you can accept another PIN, when the input is null or the input doesn't match the saved PIN. Returns {@link #PIN_VERIFICATION_SUCCESS} if the input matches the saved PIN. Returns {@link #PIN_VERIFICATION_FAILED_NOT_SET} if there is no PIN set.

            try {
                return mService.checkRestrictionsChallenge(pin);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not check restrictions pin");
            }
            return PIN_VERIFICATION_FAILED_INCORRECT;
        
    public android.content.pm.UserInfocreateGuest(android.content.Context context, java.lang.String name)
    Creates a guest user and configures it.

    param
    context an application context
    param
    name the name to set for the user
    hide

            UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
            if (guest != null) {
                Settings.Secure.putStringForUser(context.getContentResolver(),
                        Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
                try {
                    Bundle guestRestrictions = mService.getDefaultGuestRestrictions();
                    guestRestrictions.putBoolean(DISALLOW_SMS, true);
                    guestRestrictions.putBoolean(DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
                    mService.setUserRestrictions(guestRestrictions, guest.id);
                } catch (RemoteException re) {
                    Log.w(TAG, "Could not update guest restrictions");
                }
            }
            return guest;
        
    public android.content.pm.UserInfocreateProfileForUser(java.lang.String name, int flags, int userHandle)
    Creates a user with the specified name and options as a profile of another user. Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

    param
    name the user's name
    param
    flags flags that identify the type of user and other properties.
    see
    UserInfo
    param
    userHandle new user will be a profile of this use.
    return
    the UserInfo object for the created user, or null if the user could not be created.
    hide

            try {
                return mService.createProfileForUser(name, flags, userHandle);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not create a user", re);
                return null;
            }
        
    public android.content.pm.UserInfocreateSecondaryUser(java.lang.String name, int flags)
    Creates a secondary user with the specified name and options and configures it with default restrictions. Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

    param
    name the user's name
    param
    flags flags that identify the type of user and other properties.
    see
    UserInfo
    return
    the UserInfo object for the created user, or null if the user could not be created.
    hide

            try {
                UserInfo user = mService.createUser(name, flags);
                if (user == null) {
                    return null;
                }
                Bundle userRestrictions = mService.getUserRestrictions(user.id);
                addDefaultUserRestrictions(userRestrictions);
                mService.setUserRestrictions(userRestrictions, user.id);
                return user;
            } catch (RemoteException re) {
                Log.w(TAG, "Could not create a user", re);
                return null;
            }
        
    public android.content.pm.UserInfocreateUser(java.lang.String name, int flags)
    Creates a user with the specified name and options. Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

    param
    name the user's name
    param
    flags flags that identify the type of user and other properties.
    see
    UserInfo
    return
    the UserInfo object for the created user, or null if the user could not be created.
    hide

            try {
                return mService.createUser(name, flags);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not create a user", re);
                return null;
            }
        
    public static synchronized android.os.UserManagerget(android.content.Context context)

    hide

    
          
              
            if (sInstance == null) {
                sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
            }
            return sInstance;
        
    public BundlegetApplicationRestrictions(java.lang.String packageName)
    Returns a Bundle containing any saved application restrictions for this user, for the given package name. Only an application with this package name can call this method.

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

            try {
                return mService.getApplicationRestrictions(packageName);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get application restrictions for package " + packageName);
            }
            return null;
        
    public BundlegetApplicationRestrictions(java.lang.String packageName, UserHandle user)

    hide

            try {
                return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
            }
            return null;
        
    public android.graphics.drawable.DrawablegetBadgedDrawableForUser(android.graphics.drawable.Drawable badgedDrawable, UserHandle user, android.graphics.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. The caller can specify the location in the bounds of the drawable to be badged where the badge should be applied as well as the density of the badge to be used.

    If the original drawable is a BitmapDrawable and the backing bitmap is mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading is performed in place and the original drawable is returned.

    param
    badgedDrawable The drawable to badge.
    param
    user The target user.
    param
    badgeLocation Where in the bounds of the badged drawable to place the badge. If not provided, the badge is applied on top of the entire drawable being badged.
    param
    badgeDensity The optional desired density for the badge as per {@link android.util.DisplayMetrics#densityDpi}. If not provided, the density of the display is used.
    return
    A drawable that combines the original drawable and a badge as determined by the system.
    removed

            return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user,
                    badgeLocation, badgeDensity);
        
    public android.graphics.drawable.DrawablegetBadgedIconForUser(android.graphics.drawable.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. For badging an arbitrary drawable use {@link #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 {@link android.graphics.Bitmap#isMutable()}, the bading is performed in place and the original drawable is returned.

    param
    icon The icon to badge.
    param
    user The target user.
    return
    A drawable that combines the original icon and a badge as determined by the system.
    removed

            return mContext.getPackageManager().getUserBadgedIcon(icon, user);
        
    public java.lang.CharSequencegetBadgedLabelForUser(java.lang.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. E.g. passing in "Email" and it might return "Work Email" for Email in the work profile.

    param
    label The label to change.
    param
    user The target user.
    return
    A label that combines the original label and a badge as determined by the system.
    removed

            return mContext.getPackageManager().getUserBadgedLabel(label, user);
        
    public BundlegetDefaultGuestRestrictions()

    hide
    Gets the default guest restrictions.

            try {
                return mService.getDefaultGuestRestrictions();
            } catch (RemoteException re) {
                Log.w(TAG, "Could not set guest restrictions");
            }
            return new Bundle();
        
    public static intgetMaxSupportedUsers()
    Returns the maximum number of users that can be created on this device. A return value of 1 means that it is a single user device.

    hide
    return
    a value greater than or equal to 1

            // Don't allow multiple users on certain builds
            if (android.os.Build.ID.startsWith("JVP")) return 1;
            // Svelte devices don't get multi-user.
            if (ActivityManager.isLowRamDeviceStatic()) return 1;
            return SystemProperties.getInt("fw.max_users",
                    Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
        
    public android.content.pm.UserInfogetProfileParent(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.

    hide

            try {
                return mService.getProfileParent(userHandle);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get profile parent", re);
                return null;
            }
        
    public java.util.ListgetProfiles(int userHandle)
    Returns list of the profiles of userHandle including userHandle itself. Note that this returns both enabled and not enabled profiles. See {@link #getUserProfiles()} if you need only the enabled ones. Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

    param
    userHandle profiles of this user will be returned.
    return
    the list of profiles.
    hide

            try {
                return mService.getProfiles(userHandle, false /* enabledOnly */);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get user list", re);
                return null;
            }
        
    public longgetSerialNumberForUser(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.

    param
    user The user whose serial number is to be retrieved.
    return
    The serial number of the given user; returns -1 if the given UserHandle does not exist.
    see
    #getUserForSerialNumber(long)

            return getUserSerialNumber(user.getIdentifier());
        
    public intgetUserCount()
    Return the number of users currently created on the device.

            List<UserInfo> users = getUsers();
            return users != null ? users.size() : 1;
        
    public UserHandlegetUserForSerialNumber(long serialNumber)
    Return the user associated with a serial number previously returned by {@link #getSerialNumberForUser(UserHandle)}.

    param
    serialNumber The serial number of the user that is being retrieved.
    return
    Return the user associated with the serial number, or null if there is not one.
    see
    #getSerialNumberForUser(UserHandle)

            int ident = getUserHandle((int)serialNumber);
            return ident >= 0 ? new UserHandle(ident) : null;
        
    public intgetUserHandle()
    Returns the user handle for the user that the calling process is running on.

    return
    the user handle of the user making this call.
    hide

            return UserHandle.myUserId();
        
    public intgetUserHandle(int userSerialNumber)
    Returns a userHandle on this device for a given user serial number. User handles can be recycled when deleting and creating users, but serial numbers are not reused until the device is wiped.

    param
    userSerialNumber
    return
    the userHandle associated with that user serial number, or -1 if the serial number is not valid.
    hide

            try {
                return mService.getUserHandle(userSerialNumber);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
            }
            return -1;
        
    public android.graphics.BitmapgetUserIcon(int userHandle)
    Returns a file descriptor for the user's photo. PNG data can be read from this file.

    param
    userHandle the user whose photo we want to read.
    return
    a {@link Bitmap} of the user's photo, or null if there's no photo.
    see
    com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
    hide

            try {
                return mService.getUserIcon(userHandle);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get the user icon ", re);
                return null;
            }
        
    public android.content.pm.UserInfogetUserInfo(int userHandle)
    Returns the UserInfo object describing a specific user. Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

    param
    userHandle the user handle of the user whose information is being requested.
    return
    the UserInfo object for a specific user.
    hide

            try {
                return mService.getUserInfo(userHandle);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get user info", re);
                return null;
            }
        
    public java.lang.StringgetUserName()
    Returns the user name of the user making this call. This call is only available to applications on the system image; it requires the MANAGE_USERS permission.

    return
    the user name

            try {
                return mService.getUserInfo(getUserHandle()).name;
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get user name", re);
                return "";
            }
        
    public java.util.ListgetUserProfiles()
    Returns a list of UserHandles for profiles associated with the user that the calling process is running on, including the user itself.

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

            ArrayList<UserHandle> profiles = new ArrayList<UserHandle>();
            List<UserInfo> users = new ArrayList<UserInfo>();
            try {
                users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get user list", re);
                return null;
            }
            for (UserInfo info : users) {
                UserHandle userHandle = new UserHandle(info.id);
                profiles.add(userHandle);
            }
            return profiles;
        
    public BundlegetUserRestrictions()
    Returns the user-wide restrictions imposed on this user.

    return
    a Bundle containing all the restrictions.

            return getUserRestrictions(Process.myUserHandle());
        
    public BundlegetUserRestrictions(UserHandle userHandle)
    Returns the user-wide restrictions imposed on the user specified by userHandle.

    param
    userHandle the UserHandle of the user for whom to retrieve the restrictions.
    return
    a Bundle containing all the restrictions.

            try {
                return mService.getUserRestrictions(userHandle.getIdentifier());
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get user restrictions", re);
                return Bundle.EMPTY;
            }
        
    public intgetUserSerialNumber(int userHandle)
    Returns a serial number on this device for a given userHandle. User handles can be recycled when deleting and creating users, but serial numbers are not reused until the device is wiped.

    param
    userHandle
    return
    a serial number associated with that user, or -1 if the userHandle is not valid.
    hide

            try {
                return mService.getUserSerialNumber(userHandle);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get serial number for user " + userHandle);
            }
            return -1;
        
    public java.util.ListgetUsers()
    Returns information for all users on this device. Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

    return
    the list of users that were created.
    hide

            try {
                return mService.getUsers(false);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get user list", re);
                return null;
            }
        
    public java.util.ListgetUsers(boolean excludeDying)
    Returns information for all users on this device. Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

    param
    excludeDying specify if the list should exclude users being removed.
    return
    the list of users that were created.
    hide

            try {
                return mService.getUsers(excludeDying);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not get user list", re);
                return null;
            }
        
    public booleanhasRestrictionsChallenge()

    hide
    Checks whether the user has restrictions that are PIN-protected. An application that participates in restrictions can check if the owner has requested a PIN challenge for any restricted operations. If there is a PIN in effect, the application should launch the PIN challenge activity {@link android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE}.
    see
    android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE
    return
    whether a restrictions PIN is in effect.

            try {
                return mService.hasRestrictionsChallenge();
            } catch (RemoteException re) {
                Log.w(TAG, "Could not change restrictions pin");
            }
            return false;
        
    public booleanhasUserRestriction(java.lang.String restrictionKey)
    Returns whether the current user has been disallowed from performing certain actions or setting certain settings.

    param
    restrictionKey The string key representing the restriction.
    return
    {@code true} if the current user has the given restriction, {@code false} otherwise.

            return hasUserRestriction(restrictionKey, Process.myUserHandle());
        
    public booleanhasUserRestriction(java.lang.String restrictionKey, UserHandle userHandle)

    hide
    Returns whether the given user has been disallowed from performing certain actions or setting certain settings.
    param
    restrictionKey the string key representing the restriction
    param
    userHandle the UserHandle of the user for whom to retrieve the restrictions.

            try {
                return mService.hasUserRestriction(restrictionKey,
                        userHandle.getIdentifier());
            } catch (RemoteException re) {
                Log.w(TAG, "Could not check user restrictions", re);
                return false;
            }
        
    public booleanisGuestUser()
    Checks if the calling app is running as a guest user.

    return
    whether the caller is a guest user.
    hide

            UserInfo user = getUserInfo(UserHandle.myUserId());
            return user != null ? user.isGuest() : false;
        
    public booleanisLinkedUser()
    Used to check if the user making this call is linked to another user. Linked users may have a reduced number of available apps, app restrictions and account restrictions.

    return
    whether the user making this call is a linked user
    hide

            try {
                return mService.isRestricted();
            } catch (RemoteException re) {
                Log.w(TAG, "Could not check if user is limited ", re);
                return false;
            }
        
    public booleanisManagedProfile()
    Checks if the calling app is running in a managed profile. Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

    return
    whether the caller is in a managed profile.
    hide

            UserInfo user = getUserInfo(UserHandle.myUserId());
            return user != null ? user.isManagedProfile() : false;
        
    public booleanisUserAGoat()
    Used to determine whether the user making this call is subject to teleportations.

    As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can now automatically identify goats using advanced goat recognition technology.

    return
    Returns true if the user making this call is a goat.

            return mContext.getPackageManager()
                    .isPackageAvailable("com.coffeestainstudios.goatsimulator");
        
    public booleanisUserRunning(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.

    param
    user The user to retrieve the running state for.

            try {
                return ActivityManagerNative.getDefault().isUserRunning(
                        user.getIdentifier(), false);
            } catch (RemoteException e) {
                return false;
            }
        
    public booleanisUserRunningOrStopping(UserHandle user)
    Return whether the given user is actively running or stopping. This is like {@link #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).

    param
    user The user to retrieve the running state for.

            try {
                return ActivityManagerNative.getDefault().isUserRunning(
                        user.getIdentifier(), true);
            } catch (RemoteException e) {
                return false;
            }
        
    public booleanisUserSwitcherEnabled()
    Returns true if the user switcher should be shown, this will be if there are multiple users that aren't managed profiles.

    hide
    return
    true if user switcher should be shown.

            List<UserInfo> users = getUsers(true);
            if (users == null) {
               return false;
            }
            int switchableUserCount = 0;
            for (UserInfo user : users) {
                if (user.supportsSwitchTo()) {
                    ++switchableUserCount;
                }
            }
            final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
                    Settings.Global.GUEST_USER_ENABLED, 0) == 1;
            return switchableUserCount > 1 || guestEnabled;
        
    public booleanmarkGuestForDeletion(int userHandle)

    hide
    Marks the guest user for deletion to allow a new guest to be created before deleting the current user who is a guest.
    param
    userHandle
    return

            try {
                return mService.markGuestForDeletion(userHandle);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not mark guest for deletion", re);
                return false;
            }
        
    public voidremoveRestrictions()

    hide

            try {
                mService.removeRestrictions();
            } catch (RemoteException re) {
                Log.w(TAG, "Could not change restrictions pin");
            }
        
    public booleanremoveUser(int userHandle)
    Removes a user and all associated data. Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

    param
    userHandle the integer handle of the user, where 0 is the primary user.
    hide

            try {
                return mService.removeUser(userHandle);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not remove user ", re);
                return false;
            }
        
    public voidsetApplicationRestrictions(java.lang.String packageName, Bundle restrictions, UserHandle user)

    hide

            try {
                mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
            } catch (RemoteException re) {
                Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
            }
        
    public voidsetDefaultGuestRestrictions(Bundle restrictions)

    hide
    Set restrictions that should apply to any future guest user that's created.

            try {
                mService.setDefaultGuestRestrictions(restrictions);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not set guest restrictions");
            }
        
    public booleansetRestrictionsChallenge(java.lang.String newPin)
    Sets a new challenge PIN for restrictions. This is only for use by pre-installed apps and requires the MANAGE_USERS permission.

    param
    newPin the PIN to use for challenge dialogs.
    return
    Returns true if the challenge PIN was set successfully.

            try {
                return mService.setRestrictionsChallenge(newPin);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not change restrictions pin");
            }
            return false;
        
    public voidsetUserEnabled(int userHandle)
    Sets the user as enabled, if such an user exists. Requires {@link android.Manifest.permission#MANAGE_USERS} permission. Note that the default is true, it's only that managed profiles might not be enabled.

    param
    userHandle the id of the profile to enable
    hide

            try {
                mService.setUserEnabled(userHandle);
            } catch (RemoteException e) {
                Log.w(TAG, "Could not enable the profile", e);
            }
        
    public voidsetUserIcon(int userHandle, android.graphics.Bitmap icon)
    Sets the user's photo.

    param
    userHandle the user for whom to change the photo.
    param
    icon the bitmap to set as the photo.
    hide

            try {
                mService.setUserIcon(userHandle, icon);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not set the user icon ", re);
            }
        
    public voidsetUserName(int userHandle, java.lang.String name)
    Updates the user's name. Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

    param
    userHandle the user's integer handle
    param
    name the new name for the user
    hide

            try {
                mService.setUserName(userHandle, name);
            } catch (RemoteException re) {
                Log.w(TAG, "Could not set the user name ", re);
            }
        
    public voidsetUserRestriction(java.lang.String key, boolean value)
    Sets the value of a specific restriction. Requires the MANAGE_USERS permission.

    param
    key the key of the restriction
    param
    value the value for the restriction
    deprecated
    use {@link android.app.admin.DevicePolicyManager#addUserRestriction( android.content.ComponentName, String)} or {@link android.app.admin.DevicePolicyManager#clearUserRestriction( android.content.ComponentName, String)} instead.

            Bundle bundle = getUserRestrictions();
            bundle.putBoolean(key, value);
            setUserRestrictions(bundle);
        
    public voidsetUserRestriction(java.lang.String key, boolean value, UserHandle userHandle)

    hide
    Sets the value of a specific restriction on a specific user. Requires the MANAGE_USERS permission.
    param
    key the key of the restriction
    param
    value the value for the restriction
    param
    userHandle the user whose restriction is to be changed.
    deprecated
    use {@link android.app.admin.DevicePolicyManager#addUserRestriction( android.content.ComponentName, String)} or {@link android.app.admin.DevicePolicyManager#clearUserRestriction( android.content.ComponentName, String)} instead.

            Bundle bundle = getUserRestrictions(userHandle);
            bundle.putBoolean(key, value);
            setUserRestrictions(bundle, userHandle);
        
    public voidsetUserRestrictions(Bundle restrictions)
    Sets all the user-wide restrictions for this user. Requires the MANAGE_USERS permission.

    param
    restrictions the Bundle containing all the restrictions.
    deprecated
    use {@link android.app.admin.DevicePolicyManager#addUserRestriction( android.content.ComponentName, String)} or {@link android.app.admin.DevicePolicyManager#clearUserRestriction( android.content.ComponentName, String)} instead.

            setUserRestrictions(restrictions, Process.myUserHandle());
        
    public voidsetUserRestrictions(Bundle restrictions, UserHandle userHandle)
    Sets all the user-wide restrictions for the specified user. Requires the MANAGE_USERS permission.

    param
    restrictions the Bundle containing all the restrictions.
    param
    userHandle the UserHandle of the user for whom to set the restrictions.
    deprecated
    use {@link android.app.admin.DevicePolicyManager#addUserRestriction( android.content.ComponentName, String)} or {@link android.app.admin.DevicePolicyManager#clearUserRestriction( android.content.ComponentName, String)} instead.

            try {
                mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
            } catch (RemoteException re) {
                Log.w(TAG, "Could not set user restrictions", re);
            }
        
    public static booleansupportsMultipleUsers()
    Returns whether the system supports multiple users.

    return
    true if multiple users can be created by user, false if it is a single user device.
    hide

            return getMaxSupportedUsers() > 1
                    && SystemProperties.getBoolean("fw.show_multiuserui",
                    Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));