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
This commit is contained in:
Darrell Shi
2022-01-28 14:23:49 -08:00
parent 2bbbc9a2e8
commit 52df26be0b
2 changed files with 19 additions and 0 deletions

View File

@@ -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.");

View File

@@ -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)
}
}