Merge "Listen to correct intents in UserTracker" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
87ab812996
@@ -46,6 +46,8 @@ interface UserTracker : UserContentResolverProvider, UserContextProvider {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* List of profiles associated with the current user.
|
* List of profiles associated with the current user.
|
||||||
|
*
|
||||||
|
* Quiet work profiles will still appear here, but will have the `QUIET_MODE` flag.
|
||||||
*/
|
*/
|
||||||
val userProfiles: List<UserInfo>
|
val userProfiles: List<UserInfo>
|
||||||
|
|
||||||
|
|||||||
@@ -108,8 +108,12 @@ class UserTrackerImpl internal constructor(
|
|||||||
|
|
||||||
val filter = IntentFilter().apply {
|
val filter = IntentFilter().apply {
|
||||||
addAction(Intent.ACTION_USER_SWITCHED)
|
addAction(Intent.ACTION_USER_SWITCHED)
|
||||||
|
// 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_REMOVED)
|
addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED)
|
||||||
|
addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED)
|
||||||
}
|
}
|
||||||
context.registerReceiverForAllUsers(this, filter, null /* permission */, backgroundHandler)
|
context.registerReceiverForAllUsers(this, filter, null /* permission */, backgroundHandler)
|
||||||
|
|
||||||
@@ -121,7 +125,10 @@ 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_MANAGED_PROFILE_AVAILABLE, Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE -> {
|
Intent.ACTION_MANAGED_PROFILE_AVAILABLE,
|
||||||
|
Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE,
|
||||||
|
Intent.ACTION_MANAGED_PROFILE_REMOVED,
|
||||||
|
Intent.ACTION_MANAGED_PROFILE_UNLOCKED -> {
|
||||||
handleProfilesChanged()
|
handleProfilesChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,7 +215,7 @@ class UserTrackerImpl internal constructor(
|
|||||||
pw.println("Initialized: $initialized")
|
pw.println("Initialized: $initialized")
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
pw.println("userId: $userId")
|
pw.println("userId: $userId")
|
||||||
val ids = userProfiles.map { it.id }
|
val ids = userProfiles.map { it.toFullString() }
|
||||||
pw.println("userProfiles: $ids")
|
pw.println("userProfiles: $ids")
|
||||||
}
|
}
|
||||||
val list = synchronized(callbacks) {
|
val list = synchronized(callbacks) {
|
||||||
|
|||||||
@@ -189,6 +189,67 @@ class UserTrackerImplTest : SysuiTestCase() {
|
|||||||
assertThat(tracker.userProfiles.map { it.id }).containsExactly(tracker.userId, profileID)
|
assertThat(tracker.userProfiles.map { it.id }).containsExactly(tracker.userId, profileID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testManagedProfileUnavailable() {
|
||||||
|
tracker.initialize(0)
|
||||||
|
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 or UserInfo.FLAG_QUIET_MODE,
|
||||||
|
UserManager.USER_TYPE_PROFILE_MANAGED
|
||||||
|
)
|
||||||
|
infoProfile.profileGroupId = id
|
||||||
|
listOf(info, infoProfile)
|
||||||
|
}
|
||||||
|
|
||||||
|
val intent = Intent(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)
|
||||||
|
.putExtra(Intent.EXTRA_USER, UserHandle.of(profileID))
|
||||||
|
tracker.onReceive(context, intent)
|
||||||
|
|
||||||
|
assertThat(tracker.userProfiles.map { it.id }).containsExactly(tracker.userId, profileID)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testManagedProfileStartedAndRemoved() {
|
||||||
|
tracker.initialize(0)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Managed profile started
|
||||||
|
val intent = Intent(Intent.ACTION_MANAGED_PROFILE_UNLOCKED)
|
||||||
|
.putExtra(Intent.EXTRA_USER, UserHandle.of(profileID))
|
||||||
|
tracker.onReceive(context, intent)
|
||||||
|
|
||||||
|
assertThat(tracker.userProfiles.map { it.id }).containsExactly(tracker.userId, profileID)
|
||||||
|
|
||||||
|
`when`(userManager.getProfiles(anyInt())).thenAnswer { invocation ->
|
||||||
|
listOf(UserInfo(invocation.getArgument(0), "", UserInfo.FLAG_FULL))
|
||||||
|
}
|
||||||
|
|
||||||
|
val intent2 = Intent(Intent.ACTION_MANAGED_PROFILE_REMOVED)
|
||||||
|
.putExtra(Intent.EXTRA_USER, UserHandle.of(profileID))
|
||||||
|
tracker.onReceive(context, intent2)
|
||||||
|
|
||||||
|
assertThat(tracker.userProfiles.map { it.id }).containsExactly(tracker.userId)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testCallbackNotCalledOnAdd() {
|
fun testCallbackNotCalledOnAdd() {
|
||||||
tracker.initialize(0)
|
tracker.initialize(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user