Merge "[User Switcher] Fix username sync in bouncer." into tm-qpr-dev
This commit is contained in:
@@ -108,6 +108,7 @@ class UserTrackerImpl internal constructor(
|
|||||||
|
|
||||||
val filter = IntentFilter().apply {
|
val filter = IntentFilter().apply {
|
||||||
addAction(Intent.ACTION_USER_SWITCHED)
|
addAction(Intent.ACTION_USER_SWITCHED)
|
||||||
|
addAction(Intent.ACTION_USER_INFO_CHANGED)
|
||||||
// These get called when a managed profile goes in or out of quiet mode.
|
// These get called when a managed profile goes in or out of quiet mode.
|
||||||
addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE)
|
addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE)
|
||||||
addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)
|
addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)
|
||||||
@@ -125,6 +126,7 @@ class UserTrackerImpl internal constructor(
|
|||||||
Intent.ACTION_USER_SWITCHED -> {
|
Intent.ACTION_USER_SWITCHED -> {
|
||||||
handleSwitchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL))
|
handleSwitchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL))
|
||||||
}
|
}
|
||||||
|
Intent.ACTION_USER_INFO_CHANGED,
|
||||||
Intent.ACTION_MANAGED_PROFILE_AVAILABLE,
|
Intent.ACTION_MANAGED_PROFILE_AVAILABLE,
|
||||||
Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE,
|
Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE,
|
||||||
Intent.ACTION_MANAGED_PROFILE_REMOVED,
|
Intent.ACTION_MANAGED_PROFILE_REMOVED,
|
||||||
|
|||||||
@@ -250,6 +250,10 @@ constructor(
|
|||||||
override fun onUserChanged(newUser: Int, userContext: Context) {
|
override fun onUserChanged(newUser: Int, userContext: Context) {
|
||||||
send()
|
send()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onProfilesChanged(profiles: List<UserInfo>) {
|
||||||
|
send()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tracker.addCallback(callback, mainDispatcher.asExecutor())
|
tracker.addCallback(callback, mainDispatcher.asExecutor())
|
||||||
|
|||||||
@@ -310,6 +310,37 @@ class UserTrackerImplTest : SysuiTestCase() {
|
|||||||
assertThat(callback.lastUserProfiles.map { it.id }).containsExactly(0, profileID)
|
assertThat(callback.lastUserProfiles.map { it.id }).containsExactly(0, profileID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testCallbackCalledOnUserInfoChanged() {
|
||||||
|
tracker.initialize(0)
|
||||||
|
val callback = TestCallback()
|
||||||
|
tracker.addCallback(callback, executor)
|
||||||
|
val profileID = tracker.userId + 10
|
||||||
|
|
||||||
|
`when`(userManager.getProfiles(anyInt())).thenAnswer { invocation ->
|
||||||
|
val id = invocation.getArgument<Int>(0)
|
||||||
|
val info = UserInfo(id, "", UserInfo.FLAG_FULL)
|
||||||
|
val infoProfile = UserInfo(
|
||||||
|
id + 10,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
UserInfo.FLAG_MANAGED_PROFILE,
|
||||||
|
UserManager.USER_TYPE_PROFILE_MANAGED
|
||||||
|
)
|
||||||
|
infoProfile.profileGroupId = id
|
||||||
|
listOf(info, infoProfile)
|
||||||
|
}
|
||||||
|
|
||||||
|
val intent = Intent(Intent.ACTION_USER_INFO_CHANGED)
|
||||||
|
.putExtra(Intent.EXTRA_USER, UserHandle.of(profileID))
|
||||||
|
|
||||||
|
tracker.onReceive(context, intent)
|
||||||
|
|
||||||
|
assertThat(callback.calledOnUserChanged).isEqualTo(0)
|
||||||
|
assertThat(callback.calledOnProfilesChanged).isEqualTo(1)
|
||||||
|
assertThat(callback.lastUserProfiles.map { it.id }).containsExactly(0, profileID)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testCallbackRemoved() {
|
fun testCallbackRemoved() {
|
||||||
tracker.initialize(0)
|
tracker.initialize(0)
|
||||||
|
|||||||
@@ -145,6 +145,25 @@ class UserRepositoryImplRefactoredTest : UserRepositoryImplTest() {
|
|||||||
assertThat(userInfos).isEqualTo(expectedUsers)
|
assertThat(userInfos).isEqualTo(expectedUsers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `userTrackerCallback - updates selectedUserInfo`() = runSelfCancelingTest {
|
||||||
|
underTest = create(this)
|
||||||
|
var selectedUserInfo: UserInfo? = null
|
||||||
|
underTest.selectedUserInfo.onEach { selectedUserInfo = it }.launchIn(this)
|
||||||
|
setUpUsers(
|
||||||
|
count = 2,
|
||||||
|
selectedIndex = 0,
|
||||||
|
)
|
||||||
|
tracker.onProfileChanged()
|
||||||
|
assertThat(selectedUserInfo?.id == 0)
|
||||||
|
setUpUsers(
|
||||||
|
count = 2,
|
||||||
|
selectedIndex = 1,
|
||||||
|
)
|
||||||
|
tracker.onProfileChanged()
|
||||||
|
assertThat(selectedUserInfo?.id == 1)
|
||||||
|
}
|
||||||
|
|
||||||
private fun setUpUsers(
|
private fun setUpUsers(
|
||||||
count: Int,
|
count: Int,
|
||||||
isLastGuestUser: Boolean = false,
|
isLastGuestUser: Boolean = false,
|
||||||
|
|||||||
@@ -68,4 +68,8 @@ class FakeUserTracker(
|
|||||||
|
|
||||||
callbacks.forEach { it.onUserChanged(_userId, userContext) }
|
callbacks.forEach { it.onUserChanged(_userId, userContext) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onProfileChanged() {
|
||||||
|
callbacks.forEach { it.onProfilesChanged(_userProfiles) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user