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

Commit 948cc871 authored by Yasin Kilicdere's avatar Yasin Kilicdere Committed by Android (Google) Code Review
Browse files

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

parents eda8dd1d 1e565843
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
+18 −0
Original line number Diff line number Diff line
@@ -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)
    }
}