Merge "Fixed getCurrentUserName() method always returning "Owner" instead of current."

This commit is contained in:
Yasin Kilicdere
2021-11-01 19:50:13 +00:00
committed by Android (Google) Code Review
2 changed files with 19 additions and 1 deletions

View File

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

View File

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