Merge "Fixed getCurrentUserName() method always returning "Owner" instead of current."
This commit is contained in:
committed by
Android (Google) Code Review
commit
948cc87172
@@ -656,7 +656,7 @@ public class UserSwitcherController implements Dumpable {
|
||||
/** Returns the name of the current user of the phone. */
|
||||
public String getCurrentUserName() {
|
||||
if (mUsers.isEmpty()) return null;
|
||||
UserRecord item = mUsers.get(0);
|
||||
UserRecord item = mUsers.stream().filter(x -> x.isCurrent).findFirst().orElse(null);
|
||||
if (item == null || item.info == null) return null;
|
||||
if (item.isGuest) return mContext.getString(
|
||||
com.android.settingslib.R.string.guest_nickname);
|
||||
|
||||
@@ -276,4 +276,22 @@ class UserSwitcherControllerTest : SysuiTestCase() {
|
||||
assertEquals(1, uiEventLogger.numLogs())
|
||||
assertEquals(QSUserSwitcherEvent.QS_USER_GUEST_CONTINUE.id, uiEventLogger.eventId(0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test_getCurrentUserName_shouldReturnNameOfTheCurrentUser() {
|
||||
fun addUser(id: Int, name: String, isCurrent: Boolean) {
|
||||
userSwitcherController.users.add(UserSwitcherController.UserRecord(
|
||||
UserInfo(id, name, 0),
|
||||
null, false, isCurrent, false,
|
||||
false, false
|
||||
))
|
||||
}
|
||||
val bgUserName = "background_user"
|
||||
val fgUserName = "foreground_user"
|
||||
|
||||
addUser(1, bgUserName, false)
|
||||
addUser(2, fgUserName, true)
|
||||
|
||||
assertEquals(fgUserName, userSwitcherController.currentUserName)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user