Fixed getCurrentUserName() method always returning "Owner" instead of current.
Method was returning name of the user in index 0. Now it finds the current foreground user and returns its name. Bug: 203422515 Test: atest com.android.systemui.statusbar.policy.UserSwitcherControllerTest#test_getCurrentUserName_shouldReturnNameOfTheCurrentUser Change-Id: I8b94fd1394227e6f1858d6903837f7446a6771e1
This commit is contained in:
@@ -651,7 +651,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);
|
||||
|
||||
@@ -272,4 +272,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