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

Commit ff66fa9e authored by Benjamin Franz's avatar Benjamin Franz Committed by Alex Chau
Browse files

Create a new user restriction to disallow user switching

For multi-user session implementation, we want to block the user from
going back to user 0. Therefore, we block the user switcher in the
secondary user, as well as swtiching via user section in Settings app.

Bug: 64382189
Test: Manually verify user switcher is not displayed in QuickSettings
Test: Manulaly verify not able to remove or switcher user in user
      section in Setting app
Change-Id: I84bc9e67e3fe7fccb75edf0fc49b775b902f5290
parent a674fafb
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -31986,6 +31986,7 @@ package android.os {
    field public static final java.lang.String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
    field public static final java.lang.String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
    field public static final java.lang.String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
    field public static final java.lang.String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
    field public static final java.lang.String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
    field public static final java.lang.String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
    field public static final java.lang.String DISALLOW_USER_SWITCH = "no_user_switch";
    field public static final java.lang.String ENSURE_VERIFY_APPS = "ensure_verify_apps";
    field public static final java.lang.String ENSURE_VERIFY_APPS = "ensure_verify_apps";
    field public static final java.lang.String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
    field public static final java.lang.String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
    field public static final int USER_CREATION_FAILED_NOT_PERMITTED = 1; // 0x1
    field public static final int USER_CREATION_FAILED_NOT_PERMITTED = 1; // 0x1
+1 −0
Original line number Original line Diff line number Diff line
@@ -34839,6 +34839,7 @@ package android.os {
    field public static final java.lang.String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
    field public static final java.lang.String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
    field public static final java.lang.String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
    field public static final java.lang.String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
    field public static final java.lang.String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
    field public static final java.lang.String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
    field public static final java.lang.String DISALLOW_USER_SWITCH = "no_user_switch";
    field public static final java.lang.String ENSURE_VERIFY_APPS = "ensure_verify_apps";
    field public static final java.lang.String ENSURE_VERIFY_APPS = "ensure_verify_apps";
    field public static final java.lang.String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
    field public static final java.lang.String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
    field public static final int RESTRICTION_NOT_SET = 0; // 0x0
    field public static final int RESTRICTION_NOT_SET = 0; // 0x0
+1 −0
Original line number Original line Diff line number Diff line
@@ -32254,6 +32254,7 @@ package android.os {
    field public static final java.lang.String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
    field public static final java.lang.String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
    field public static final java.lang.String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
    field public static final java.lang.String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone";
    field public static final java.lang.String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
    field public static final java.lang.String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
    field public static final java.lang.String DISALLOW_USER_SWITCH = "no_user_switch";
    field public static final java.lang.String ENSURE_VERIFY_APPS = "ensure_verify_apps";
    field public static final java.lang.String ENSURE_VERIFY_APPS = "ensure_verify_apps";
    field public static final java.lang.String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
    field public static final java.lang.String KEY_RESTRICTIONS_PENDING = "restrictions_pending";
    field public static final int USER_CREATION_FAILED_NOT_PERMITTED = 1; // 0x1
    field public static final int USER_CREATION_FAILED_NOT_PERMITTED = 1; // 0x1
+20 −2
Original line number Original line Diff line number Diff line
@@ -791,6 +791,19 @@ public class UserManager {
     */
     */
    public static final String DISALLOW_AUTOFILL = "no_autofill";
    public static final String DISALLOW_AUTOFILL = "no_autofill";


    /**
     * Specifies if user switching is blocked on the current user.
     *
     * <p> This restriction can only be set by the device owner, it will be applied to all users.
     *
     * <p>The default value is <code>false</code>.
     *
     * @see DevicePolicyManager#addUserRestriction(ComponentName, String)
     * @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
     * @see #getUserRestrictions()
     */
    public static final String DISALLOW_USER_SWITCH = "no_user_switch";

    /**
    /**
     * Application restriction key that is used to indicate the pending arrival
     * Application restriction key that is used to indicate the pending arrival
     * of real restrictions for the app.
     * of real restrictions for the app.
@@ -917,7 +930,7 @@ public class UserManager {
    /**
    /**
     * Returns whether switching users is currently allowed.
     * Returns whether switching users is currently allowed.
     * <p>For instance switching users is not allowed if the current user is in a phone call,
     * <p>For instance switching users is not allowed if the current user is in a phone call,
     * or system user hasn't been unlocked yet
     * system user hasn't been unlocked yet, or {@link #DISALLOW_USER_SWITCH} is set.
     * @hide
     * @hide
     */
     */
    public boolean canSwitchUsers() {
    public boolean canSwitchUsers() {
@@ -927,7 +940,9 @@ public class UserManager {
        boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
        boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
        boolean inCall = TelephonyManager.getDefault().getCallState()
        boolean inCall = TelephonyManager.getDefault().getCallState()
                != TelephonyManager.CALL_STATE_IDLE;
                != TelephonyManager.CALL_STATE_IDLE;
        return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall;
        boolean isUserSwitchDisallowed = hasUserRestriction(DISALLOW_USER_SWITCH);
        return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall
                && !isUserSwitchDisallowed;
    }
    }


    /**
    /**
@@ -2298,6 +2313,9 @@ public class UserManager {
        if (!supportsMultipleUsers()) {
        if (!supportsMultipleUsers()) {
            return false;
            return false;
        }
        }
        if (hasUserRestriction(DISALLOW_USER_SWITCH)) {
            return false;
        }
        // If Demo Mode is on, don't show user switcher
        // If Demo Mode is on, don't show user switcher
        if (isDeviceInDemoMode(mContext)) {
        if (isDeviceInDemoMode(mContext)) {
            return false;
            return false;
+3 −1
Original line number Original line Diff line number Diff line
@@ -338,7 +338,9 @@ public class QSFooterImpl extends FrameLayout implements QSFooter,


        final boolean isDemo = UserManager.isDeviceInDemoMode(mContext);
        final boolean isDemo = UserManager.isDeviceInDemoMode(mContext);


        mMultiUserSwitch.setVisibility(mExpanded && mMultiUserSwitch.hasMultipleUsers() && !isDemo

        mMultiUserSwitch.setVisibility(mExpanded
                && UserManager.get(mContext).isUserSwitcherEnabled()
                ? View.VISIBLE : View.INVISIBLE);
                ? View.VISIBLE : View.INVISIBLE);


        mEdit.setVisibility(isDemo || !mExpanded ? View.INVISIBLE : View.VISIBLE);
        mEdit.setVisibility(isDemo || !mExpanded ? View.INVISIBLE : View.VISIBLE);
Loading