Merge "Add isSystemUser() in UserSwitcherController."

This commit is contained in:
TreeHugger Robot
2022-01-31 22:46:40 +00:00
committed by Android (Google) Code Review
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)
}
}