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

Commit 6827ed77 authored by Tetiana Meronyk's avatar Tetiana Meronyk
Browse files

Disable multiuser toggle when more than 1 user is created

It makes more sense to have the toggle as on permanently as long as there are other users on the device. Otherwise if we toggle off "Allow multiple users", other users get hidden. Also with current behaviour the any admin can switch the toggle and this can block any other user, including main, from being able to use the device.

Bug: 295183792
Test: atest UserManagerTest
Change-Id: Ibf926223deec9c231917e279017222ee2cfba14f
parent a0752490
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -4617,6 +4617,26 @@ public class UserManager {
                /* excludePreCreated= */ true);
    }

    /**
     * Returns number of full users on the device.
     * @hide
     */
    @RequiresPermission(anyOf = {
            android.Manifest.permission.MANAGE_USERS,
            android.Manifest.permission.CREATE_USERS
    })
    public int getFullUserCount() {
        List<UserInfo> users = getUsers(/* excludePartial= */ true, /* excludeDying= */ true,
                /* excludePreCreated= */ true);
        int count = 0;
        for (UserInfo user : users) {
            if (user.isFull()) {
                count++;
            }
        }
        return count;
    }

    /**
     * @deprecated use {@link #getAliveUsers()} for {@code getUsers(true)}, or
     * {@link #getUsers()} for @code getUsers(false)}.
+18 −0
Original line number Diff line number Diff line
@@ -326,6 +326,24 @@ public final class UserManagerTest {
        assertThat(hasUser(user2.id)).isTrue();
    }


    @MediumTest
    @Test
    public void testGetFullUserCount() throws Exception {
        assertThat(mUserManager.getFullUserCount()).isEqualTo(1);
        UserInfo user1 = createUser("User 1", UserInfo.FLAG_FULL);
        UserInfo user2 = createUser("User 2", UserInfo.FLAG_ADMIN);

        assertThat(user1).isNotNull();
        assertThat(user2).isNotNull();

        assertThat(mUserManager.getFullUserCount()).isEqualTo(3);
        removeUser(user1.id);
        assertThat(mUserManager.getFullUserCount()).isEqualTo(2);
        removeUser(user2.id);
        assertThat(mUserManager.getFullUserCount()).isEqualTo(1);
    }

    /**
     * Tests that UserManager knows how many users can be created.
     *