Java Code Examples for android.content.pm.UserInfo#isAdmin()

The following examples show how to use android.content.pm.UserInfo#isAdmin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void setUserAdmin(int userId) {
    checkManageUserAndAcrossUsersFullPermission("set user admin");

    synchronized (mPackagesLock) {
        UserInfo info;
        synchronized (mUsersLock) {
            info = getUserInfoLU(userId);
        }
        if (info == null || info.isAdmin()) {
            // Exit if no user found with that id, or the user is already an Admin.
            return;
        }

        info.flags ^= UserInfo.FLAG_ADMIN;
        writeUserLP(getUserDataLU(info.id));
    }

    // Remove non-admin restrictions.
    // Keep synchronized with createUserEvenWhenDisallowed.
    setUserRestriction(UserManager.DISALLOW_SMS, false, userId);
    setUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, false, userId);
}
 
Example 2
Source File: UserManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a user with the specified name and options. For non-admin users, default user
 * restrictions are going to be applied.
 * 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
 */
public UserInfo createUser(String name, int flags) {
    UserInfo user = null;
    try {
        user = mService.createUser(name, flags);
        // TODO: Keep this in sync with
        // UserManagerService.LocalService.createUserEvenWhenDisallowed
        if (user != null && !user.isAdmin() && !user.isDemo()) {
            mService.setUserRestriction(DISALLOW_SMS, true, user.id);
            mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id);
        }
    } catch (RemoteException re) {
        throw re.rethrowFromSystemServer();
    }
    return user;
}
 
Example 3
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canHaveRestrictedProfile(int userId) {
    checkManageUsersPermission("canHaveRestrictedProfile");
    synchronized (mUsersLock) {
        final UserInfo userInfo = getUserInfoLU(userId);
        if (userInfo == null || !userInfo.canHaveProfile()) {
            return false;
        }
        if (!userInfo.isAdmin()) {
            return false;
        }
        // restricted profile can be created if there is no DO set and the admin user has no PO;
        return !mIsDeviceManaged && !mIsUserManaged.get(userId);
    }
}
 
Example 4
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public UserInfo createUserEvenWhenDisallowed(String name, int flags,
        String[] disallowedPackages) {
    UserInfo user = createUserInternalUnchecked(name, flags, UserHandle.USER_NULL,
            disallowedPackages);
    // Keep this in sync with UserManager.createUser
    if (user != null && !user.isAdmin() && !user.isDemo()) {
        setUserRestriction(UserManager.DISALLOW_SMS, true, user.id);
        setUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, true, user.id);
    }
    return user;
}
 
Example 5
Source File: UserManager.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * @hide
 * Returns whether the provided user is an admin user. There can be more than one admin
 * user.
 */
public boolean isUserAdmin(@UserIdInt int userId) {
    UserInfo user = getUserInfo(userId);
    return user != null && user.isAdmin();
}