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

Commit 26e228da authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Should not switch to a user with removal in progress"

parents 0e496551 84181f7d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -366,8 +366,9 @@ public class UserInfo implements Parcelable {
     * @return true if this user can be switched to.
     **/
    public boolean supportsSwitchTo() {
        if (isEphemeral() && !isEnabled()) {
            // Don't support switching to an ephemeral user with removal in progress.
        if (partial || !isEnabled()) {
            // Don't support switching to disabled or partial users, which includes users with
            // removal in progress.
            return false;
        }
        if (preCreated) {
+18 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.pm;

import static android.content.pm.UserInfo.FLAG_DEMO;
import static android.content.pm.UserInfo.FLAG_DISABLED;
import static android.content.pm.UserInfo.FLAG_EPHEMERAL;
import static android.content.pm.UserInfo.FLAG_FULL;
import static android.content.pm.UserInfo.FLAG_GUEST;
@@ -166,6 +167,23 @@ public class UserManagerServiceUserInfoTest {
        assertTrue(mUserManagerService.isUserOfType(testId, typeName));
    }

    /** Test UserInfo.supportsSwitchTo() for partial user. */
    @Test
    public void testSupportSwitchTo_partial() throws Exception {
        UserInfo userInfo = createUser(100, FLAG_FULL, null);
        userInfo.partial = true;
        assertFalse("Switching to a partial user should be disabled",
                userInfo.supportsSwitchTo());
    }

    /** Test UserInfo.supportsSwitchTo() for disabled user. */
    @Test
    public void testSupportSwitchTo_disabled() throws Exception {
        UserInfo userInfo = createUser(100, FLAG_DISABLED, null);
        assertFalse("Switching to a DISABLED user should be disabled",
                userInfo.supportsSwitchTo());
    }

    /** Test UserInfo.supportsSwitchTo() for precreated users. */
    @Test
    public void testSupportSwitchTo_preCreated() throws Exception {