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

Commit 52df26be authored by Darrell Shi's avatar Darrell Shi
Browse files

Add isSystemUser() in UserSwitcherController.

This is a small util function to check whether the current user is the
system user.

Bug: 213906356
Test: atest UserSwitcherControllerTest
Change-Id: I53d452ea9d557d76632c74986d34ff4c4ed34c05
parent 2bbbc9a2
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -455,6 +455,13 @@ public class UserSwitcherController implements Dumpable {
        }
    }

    /**
     * Returns whether the current user is a system user.
     */
    public boolean isSystemUser() {
        return mUserTracker.getUserId() == UserHandle.USER_SYSTEM;
    }

    public void removeUserId(int userId) {
        if (userId == UserHandle.USER_SYSTEM) {
            Log.w(TAG, "User " + userId + " could not removed.");
+12 −0
Original line number Diff line number Diff line
@@ -400,4 +400,16 @@ class UserSwitcherControllerTest : SysuiTestCase() {

        assertEquals(fgUserName, userSwitcherController.currentUserName)
    }

    @Test
    fun isSystemUser_currentUserIsSystemUser_shouldReturnTrue() {
        `when`(userTracker.userId).thenReturn(UserHandle.USER_SYSTEM)
        assertEquals(true, userSwitcherController.isSystemUser)
    }

    @Test
    fun isSystemUser_currentUserIsNotSystemUser_shouldReturnFalse() {
        `when`(userTracker.userId).thenReturn(1)
        assertEquals(false, userSwitcherController.isSystemUser)
    }
}