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

Commit add9e6f1 authored by Mayank Garg's avatar Mayank Garg
Browse files

Renamed removeUserOrSetEphemeral completely

Remaining Task: add more CTS tests for removeUserWhenPossible

Bug: 199446770
Test: m
Change-Id: I709ad0eeba3d01f11000b2f5647f385b17fa9c63
parent 7627c943
Loading
Loading
Loading
Loading
+0 −27
Original line number Diff line number Diff line
@@ -4756,33 +4756,6 @@ public class UserManager {
        }
    }

    /**
     * Immediately removes the user or, if the user cannot be removed, such as when the user is
     * the current user, then set the user as ephemeral so that it will be removed when it is
     * stopped.
     *
     * @param evenWhenDisallowed when {@code true}, user is removed even if the caller has the
     * {@link #DISALLOW_REMOVE_USER} or {@link #DISALLOW_REMOVE_MANAGED_PROFILE} restriction
     *
     * @return the {@link RemoveResult} code
     *
     * @deprecated  TODO(b/199446770): remove this call after converting all calls to
     * removeUserWhenPossible(UserHandle, boolean)
     *
     * @hide
     */
    @Deprecated
    @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS,
            Manifest.permission.CREATE_USERS})
    public @RemoveResult int removeUserOrSetEphemeral(@UserIdInt int userId,
            boolean evenWhenDisallowed) {
        try {
            return mService.removeUserWhenPossible(userId, evenWhenDisallowed);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Updates the user's name.
     *
+6 −6
Original line number Diff line number Diff line
@@ -309,7 +309,7 @@ public final class UserManagerTest {

    @MediumTest
    @Test
    public void testRemoveUserOrSetEphemeral_restrictedReturnsError() throws Exception {
    public void testRemoveUserWhenPossible_restrictedReturnsError() throws Exception {
        final int currentUser = ActivityManager.getCurrentUser();
        final UserInfo user1 = createUser("User 1", /* flags= */ 0);
        mUserManager.setUserRestriction(UserManager.DISALLOW_REMOVE_USER, /* value= */ true,
@@ -328,7 +328,7 @@ public final class UserManagerTest {

    @MediumTest
    @Test
    public void testRemoveUserOrSetEphemeral_evenWhenRestricted() throws Exception {
    public void testRemoveUserWhenPossible_evenWhenRestricted() throws Exception {
        final int currentUser = ActivityManager.getCurrentUser();
        final UserInfo user1 = createUser("User 1", /* flags= */ 0);
        mUserManager.setUserRestriction(UserManager.DISALLOW_REMOVE_USER, /* value= */ true,
@@ -351,7 +351,7 @@ public final class UserManagerTest {

    @MediumTest
    @Test
    public void testRemoveUserOrSetEphemeral_systemUserReturnsError() throws Exception {
    public void testRemoveUserWhenPossible_systemUserReturnsError() throws Exception {
        assertThat(mUserManager.removeUserWhenPossible(UserHandle.SYSTEM,
                /* overrideDevicePolicy= */ false)).isEqualTo(UserManager.REMOVE_RESULT_ERROR);

@@ -360,7 +360,7 @@ public final class UserManagerTest {

    @MediumTest
    @Test
    public void testRemoveUserOrSetEphemeral_invalidUserReturnsError() throws Exception {
    public void testRemoveUserWhenPossible_invalidUserReturnsError() throws Exception {
        assertThat(hasUser(Integer.MAX_VALUE)).isFalse();
        assertThat(mUserManager.removeUserWhenPossible(UserHandle.of(Integer.MAX_VALUE),
                /* overrideDevicePolicy= */ false)).isEqualTo(UserManager.REMOVE_RESULT_ERROR);
@@ -368,7 +368,7 @@ public final class UserManagerTest {

    @MediumTest
    @Test
    public void testRemoveUserOrSetEphemeral_currentUserSetEphemeral() throws Exception {
    public void testRemoveUserWhenPossible_currentUserSetEphemeral() throws Exception {
        final int startUser = ActivityManager.getCurrentUser();
        final UserInfo user1 = createUser("User 1", /* flags= */ 0);
        // Switch to the user just created.
@@ -392,7 +392,7 @@ public final class UserManagerTest {

    @MediumTest
    @Test
    public void testRemoveUserOrSetEphemeral_nonCurrentUserRemoved() throws Exception {
    public void testRemoveUserWhenPossible_nonCurrentUserRemoved() throws Exception {
        final UserInfo user1 = createUser("User 1", /* flags= */ 0);
        synchronized (mUserRemoveLock) {
            assertThat(mUserManager.removeUserWhenPossible(user1.getUserHandle(),