Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ece10449 authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Android (Google) Code Review
Browse files

Merge "sys user split: update createUser method"

parents 9bd7ccd2 cfe64c8a
Loading
Loading
Loading
Loading
+10 −31
Original line number Diff line number Diff line
@@ -839,7 +839,8 @@ public class UserManager {
    }

    /**
     * Creates a user with the specified name and options.
     * 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
@@ -850,12 +851,18 @@ public class UserManager {
     * @hide
     */
    public UserInfo createUser(String name, int flags) {
        UserInfo user = null;
        try {
            return mService.createUser(name, flags);
            user = mService.createUser(name, flags);
            if (user != null && !user.isAdmin()) {
                Bundle userRestrictions = mService.getUserRestrictions(user.id);
                addDefaultUserRestrictions(userRestrictions);
                mService.setUserRestrictions(userRestrictions, user.id);
            }
        } catch (RemoteException re) {
            Log.w(TAG, "Could not create a user", re);
            return null;
        }
        return user;
    }

    /**
@@ -881,34 +888,6 @@ public class UserManager {
        return guest;
    }

    /**
     * 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
     */
    public UserInfo createSecondaryUser(String name, int flags) {
        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;
        }
    }

    private static void addDefaultUserRestrictions(Bundle restrictions) {
        restrictions.putBoolean(DISALLOW_OUTGOING_CALLS, true);
        restrictions.putBoolean(DISALLOW_SMS, true);
+1 −1
Original line number Diff line number Diff line
@@ -621,7 +621,7 @@ public class UserSwitcherController {
                if (ActivityManager.isUserAMonkey()) {
                    return;
                }
                UserInfo user = mUserManager.createSecondaryUser(
                UserInfo user = mUserManager.createUser(
                        mContext.getString(R.string.user_new_user_name), 0 /* flags */);
                if (user == null) {
                    // Couldn't create user, most likely because there are too many, but we haven't