Loading packages/SystemUI/src/com/android/systemui/settings/MultiUserUtilsModule.java +1 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ public abstract class MultiUserUtilsModule { @Background CoroutineDispatcher backgroundDispatcher, @Background Handler handler ) { int startingUser = ActivityManager.getCurrentUser(); int startingUser = userManager.getBootUser().getIdentifier(); UserTrackerImpl tracker = new UserTrackerImpl(context, featureFlagsProvider, userManager, iActivityManager, dumpManager, appScope, backgroundDispatcher, handler); tracker.initialize(startingUser); Loading packages/SystemUI/tests/src/com/android/systemui/settings/UserTrackerImplReceiveTest.kt +4 −4 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import com.android.systemui.dump.DumpManager import com.android.systemui.flags.FakeFeatureFlagsClassic import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.capture import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import java.util.concurrent.Executor import kotlinx.coroutines.test.StandardTestDispatcher Loading @@ -29,7 +30,6 @@ import org.mockito.Captor import org.mockito.Mock import org.mockito.Mockito.times import org.mockito.Mockito.verify import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations @SmallTest Loading Loading @@ -73,8 +73,8 @@ class UserTrackerImplReceiveTest : SysuiTestCase() { fun setUp() { MockitoAnnotations.initMocks(this) `when`(context.user).thenReturn(UserHandle.SYSTEM) `when`(context.createContextAsUser(ArgumentMatchers.any(), anyInt())).thenReturn(context) whenever(context.user).thenReturn(UserHandle.SYSTEM) whenever(context.createContextAsUser(ArgumentMatchers.any(), anyInt())).thenReturn(context) } @Test Loading @@ -94,7 +94,7 @@ class UserTrackerImplReceiveTest : SysuiTestCase() { tracker.addCallback(callback, executor) val profileID = tracker.userId + 10 `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val id = invocation.getArgument<Int>(0) val info = UserInfo(id, "", UserInfo.FLAG_FULL) val infoProfile = Loading packages/SystemUI/tests/src/com/android/systemui/settings/UserTrackerImplTest.kt +321 −316 Original line number Diff line number Diff line Loading @@ -33,9 +33,11 @@ import com.android.systemui.flags.FakeFeatureFlagsClassic import com.android.systemui.flags.Flags import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.mockito.capture import com.android.systemui.util.mockito.whenever import com.android.systemui.util.time.FakeSystemClock import com.google.common.truth.Truth.assertThat import com.google.common.truth.TruthJUnit.assume import java.util.concurrent.Executor import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope Loading @@ -54,10 +56,7 @@ import org.mockito.ArgumentMatchers.isNull import org.mockito.Mock import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations import java.util.concurrent.Executor @OptIn(ExperimentalCoroutinesApi::class) @SmallTest Loading @@ -71,27 +70,19 @@ class UserTrackerImplTest : SysuiTestCase() { fun isBackgroundUserTrackerEnabled(): Iterable<Boolean> = listOf(true, false) } @Mock private lateinit var context: Context @Mock private lateinit var context: Context @Mock private lateinit var userManager: UserManager @Mock private lateinit var userManager: UserManager @Mock private lateinit var iActivityManager: IActivityManager @Mock private lateinit var iActivityManager: IActivityManager @Mock private lateinit var userSwitchingReply: IRemoteCallback @Mock private lateinit var userSwitchingReply: IRemoteCallback @Mock(stubOnly = true) private lateinit var dumpManager: DumpManager @Mock(stubOnly = true) private lateinit var dumpManager: DumpManager @Mock(stubOnly = true) private lateinit var handler: Handler @Mock(stubOnly = true) private lateinit var handler: Handler @Parameterized.Parameter @JvmField var isBackgroundUserTrackerEnabled: Boolean = false @Parameterized.Parameter @JvmField var isBackgroundUserTrackerEnabled: Boolean = false private val testScope = TestScope() private val testDispatcher = StandardTestDispatcher(testScope.testScheduler) Loading @@ -104,15 +95,15 @@ class UserTrackerImplTest : SysuiTestCase() { fun setUp() { MockitoAnnotations.initMocks(this) `when`(context.userId).thenReturn(UserHandle.USER_SYSTEM) `when`(context.user).thenReturn(UserHandle.SYSTEM) `when`(context.createContextAsUser(any(), anyInt())).thenAnswer { invocation -> whenever(context.userId).thenReturn(UserHandle.USER_SYSTEM) whenever(context.user).thenReturn(UserHandle.SYSTEM) whenever(context.createContextAsUser(any(), anyInt())).thenAnswer { invocation -> val user = invocation.getArgument<UserHandle>(0) `when`(context.user).thenReturn(user) `when`(context.userId).thenReturn(user.identifier) whenever(context.user).thenReturn(user) whenever(context.userId).thenReturn(user.identifier) context } `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val info = UserInfo(invocation.getArgument<Int>(0), "", UserInfo.FLAG_FULL) listOf(info) } Loading @@ -131,45 +122,35 @@ class UserTrackerImplTest : SysuiTestCase() { ) } @Test fun testNotInitialized() = testScope.runTest { assertThat(tracker.initialized).isFalse() } @Test fun testNotInitialized() = testScope.runTest { assertThat(tracker.initialized).isFalse() } @Test(expected = IllegalStateException::class) fun testGetUserIdBeforeInitThrowsException() = testScope.runTest { tracker.userId } fun testGetUserIdBeforeInitThrowsException() = testScope.runTest { tracker.userId } @Test(expected = IllegalStateException::class) fun testGetUserHandleBeforeInitThrowsException() = testScope.runTest { tracker.userHandle } fun testGetUserHandleBeforeInitThrowsException() = testScope.runTest { tracker.userHandle } @Test(expected = IllegalStateException::class) fun testGetUserContextBeforeInitThrowsException() = testScope.runTest { tracker.userContext } fun testGetUserContextBeforeInitThrowsException() = testScope.runTest { tracker.userContext } @Test(expected = IllegalStateException::class) fun testGetUserContentResolverBeforeInitThrowsException() = testScope.runTest { tracker.userContentResolver } fun testGetUserContentResolverBeforeInitThrowsException() = testScope.runTest { tracker.userContentResolver } @Test(expected = IllegalStateException::class) fun testGetUserProfilesBeforeInitThrowsException() = testScope.runTest { tracker.userProfiles } fun testGetUserProfilesBeforeInitThrowsException() = testScope.runTest { tracker.userProfiles } @Test fun testInitialize() = testScope.runTest { fun testInitialize() = testScope.runTest { tracker.initialize(0) assertThat(tracker.initialized).isTrue() } @Test fun testReceiverRegisteredOnInitialize() = testScope.runTest { fun testReceiverRegisteredOnInitialize() = testScope.runTest { tracker.initialize(0) val captor = ArgumentCaptor.forClass(IntentFilter::class.java) Loading @@ -193,7 +174,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testInitialValuesSet() = testScope.runTest { fun testInitialValuesSet() = testScope.runTest { val testID = 4 tracker.initialize(testID) Loading @@ -210,7 +192,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testUserSwitch() = testScope.runTest { fun testUserSwitch() = testScope.runTest { tracker.initialize(0) val newID = 5 Loading @@ -234,14 +217,16 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testManagedProfileAvailable() = testScope.runTest { fun testManagedProfileAvailable() = testScope.runTest { tracker.initialize(0) val profileID = tracker.userId + 10 `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val id = invocation.getArgument<Int>(0) val info = UserInfo(id, "", UserInfo.FLAG_FULL) val infoProfile = UserInfo( val infoProfile = UserInfo( id + 10, "", "", Loading @@ -252,22 +237,26 @@ class UserTrackerImplTest : SysuiTestCase() { listOf(info, infoProfile) } val intent = Intent(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) val intent = Intent(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) .putExtra(Intent.EXTRA_USER, UserHandle.of(profileID)) tracker.onReceive(context, intent) assertThat(tracker.userProfiles.map { it.id }).containsExactly(tracker.userId, profileID) assertThat(tracker.userProfiles.map { it.id }) .containsExactly(tracker.userId, profileID) } @Test fun testManagedProfileUnavailable() = testScope.runTest { fun testManagedProfileUnavailable() = testScope.runTest { tracker.initialize(0) val profileID = tracker.userId + 10 `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val id = invocation.getArgument<Int>(0) val info = UserInfo(id, "", UserInfo.FLAG_FULL) val infoProfile = UserInfo( val infoProfile = UserInfo( id + 10, "", "", Loading @@ -278,22 +267,26 @@ class UserTrackerImplTest : SysuiTestCase() { listOf(info, infoProfile) } val intent = Intent(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE) 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) assertThat(tracker.userProfiles.map { it.id }) .containsExactly(tracker.userId, profileID) } @Test fun testManagedProfileStartedAndRemoved() = testScope.runTest { fun testManagedProfileStartedAndRemoved() = testScope.runTest { tracker.initialize(0) val profileID = tracker.userId + 10 `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val id = invocation.getArgument<Int>(0) val info = UserInfo(id, "", UserInfo.FLAG_FULL) val infoProfile = UserInfo( val infoProfile = UserInfo( id + 10, "", "", Loading @@ -305,17 +298,20 @@ class UserTrackerImplTest : SysuiTestCase() { } // Managed profile started val intent = Intent(Intent.ACTION_MANAGED_PROFILE_UNLOCKED) 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) assertThat(tracker.userProfiles.map { it.id }) .containsExactly(tracker.userId, profileID) `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> listOf(UserInfo(invocation.getArgument(0), "", UserInfo.FLAG_FULL)) } val intent2 = Intent(Intent.ACTION_MANAGED_PROFILE_REMOVED) val intent2 = Intent(Intent.ACTION_MANAGED_PROFILE_REMOVED) .putExtra(Intent.EXTRA_USER, UserHandle.of(profileID)) tracker.onReceive(context, intent2) Loading @@ -323,7 +319,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testCallbackNotCalledOnAdd() = testScope.runTest { fun testCallbackNotCalledOnAdd() = testScope.runTest { tracker.initialize(0) val callback = TestCallback() Loading @@ -334,7 +331,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testCallbackCalledOnUserChanging() = testScope.runTest { fun testCallbackCalledOnUserChanging() = testScope.runTest { tracker.initialize(0) val callback = TestCallback() tracker.addCallback(callback, executor) Loading @@ -354,7 +352,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testAsyncCallbackWaitsUserToChange() = testScope.runTest { fun testAsyncCallbackWaitsUserToChange() = testScope.runTest { // Skip this test for CountDownLatch variation. The problem is that there would be a // deadlock if the callbacks processing runs on the same thread as the callback (which // is blocked by the latch). Before the change it works because the callbacks are Loading Loading @@ -386,7 +385,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testCallbackCalledOnUserChanged() = testScope.runTest { fun testCallbackCalledOnUserChanged() = testScope.runTest { tracker.initialize(0) val callback = TestCallback() tracker.addCallback(callback, executor) Loading @@ -407,16 +407,18 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testCallbackCalledOnUserInfoChanged() = testScope.runTest { fun testCallbackCalledOnUserInfoChanged() = testScope.runTest { tracker.initialize(0) val callback = TestCallback() tracker.addCallback(callback, executor) val profileID = tracker.userId + 10 `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val id = invocation.getArgument<Int>(0) val info = UserInfo(id, "", UserInfo.FLAG_FULL) val infoProfile = UserInfo( val infoProfile = UserInfo( id + 10, "", "", Loading @@ -427,7 +429,8 @@ class UserTrackerImplTest : SysuiTestCase() { listOf(info, infoProfile) } val intent = Intent(Intent.ACTION_USER_INFO_CHANGED) val intent = Intent(Intent.ACTION_USER_INFO_CHANGED) .putExtra(Intent.EXTRA_USER, UserHandle.of(profileID)) tracker.onReceive(context, intent) Loading @@ -438,7 +441,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testCallbackRemoved() = testScope.runTest { fun testCallbackRemoved() = testScope.runTest { tracker.initialize(0) val newID = 5 val profileID = newID + 10 Loading @@ -454,7 +458,8 @@ class UserTrackerImplTest : SysuiTestCase() { verify(userSwitchingReply).sendResult(any()) captor.value.onUserSwitchComplete(newID) val intentProfiles = Intent(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) val intentProfiles = Intent(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) .putExtra(Intent.EXTRA_USER, UserHandle.of(profileID)) tracker.onReceive(context, intentProfiles) Loading Loading
packages/SystemUI/src/com/android/systemui/settings/MultiUserUtilsModule.java +1 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ public abstract class MultiUserUtilsModule { @Background CoroutineDispatcher backgroundDispatcher, @Background Handler handler ) { int startingUser = ActivityManager.getCurrentUser(); int startingUser = userManager.getBootUser().getIdentifier(); UserTrackerImpl tracker = new UserTrackerImpl(context, featureFlagsProvider, userManager, iActivityManager, dumpManager, appScope, backgroundDispatcher, handler); tracker.initialize(startingUser); Loading
packages/SystemUI/tests/src/com/android/systemui/settings/UserTrackerImplReceiveTest.kt +4 −4 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import com.android.systemui.dump.DumpManager import com.android.systemui.flags.FakeFeatureFlagsClassic import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.capture import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import java.util.concurrent.Executor import kotlinx.coroutines.test.StandardTestDispatcher Loading @@ -29,7 +30,6 @@ import org.mockito.Captor import org.mockito.Mock import org.mockito.Mockito.times import org.mockito.Mockito.verify import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations @SmallTest Loading Loading @@ -73,8 +73,8 @@ class UserTrackerImplReceiveTest : SysuiTestCase() { fun setUp() { MockitoAnnotations.initMocks(this) `when`(context.user).thenReturn(UserHandle.SYSTEM) `when`(context.createContextAsUser(ArgumentMatchers.any(), anyInt())).thenReturn(context) whenever(context.user).thenReturn(UserHandle.SYSTEM) whenever(context.createContextAsUser(ArgumentMatchers.any(), anyInt())).thenReturn(context) } @Test Loading @@ -94,7 +94,7 @@ class UserTrackerImplReceiveTest : SysuiTestCase() { tracker.addCallback(callback, executor) val profileID = tracker.userId + 10 `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val id = invocation.getArgument<Int>(0) val info = UserInfo(id, "", UserInfo.FLAG_FULL) val infoProfile = Loading
packages/SystemUI/tests/src/com/android/systemui/settings/UserTrackerImplTest.kt +321 −316 Original line number Diff line number Diff line Loading @@ -33,9 +33,11 @@ import com.android.systemui.flags.FakeFeatureFlagsClassic import com.android.systemui.flags.Flags import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.mockito.capture import com.android.systemui.util.mockito.whenever import com.android.systemui.util.time.FakeSystemClock import com.google.common.truth.Truth.assertThat import com.google.common.truth.TruthJUnit.assume import java.util.concurrent.Executor import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope Loading @@ -54,10 +56,7 @@ import org.mockito.ArgumentMatchers.isNull import org.mockito.Mock import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations import java.util.concurrent.Executor @OptIn(ExperimentalCoroutinesApi::class) @SmallTest Loading @@ -71,27 +70,19 @@ class UserTrackerImplTest : SysuiTestCase() { fun isBackgroundUserTrackerEnabled(): Iterable<Boolean> = listOf(true, false) } @Mock private lateinit var context: Context @Mock private lateinit var context: Context @Mock private lateinit var userManager: UserManager @Mock private lateinit var userManager: UserManager @Mock private lateinit var iActivityManager: IActivityManager @Mock private lateinit var iActivityManager: IActivityManager @Mock private lateinit var userSwitchingReply: IRemoteCallback @Mock private lateinit var userSwitchingReply: IRemoteCallback @Mock(stubOnly = true) private lateinit var dumpManager: DumpManager @Mock(stubOnly = true) private lateinit var dumpManager: DumpManager @Mock(stubOnly = true) private lateinit var handler: Handler @Mock(stubOnly = true) private lateinit var handler: Handler @Parameterized.Parameter @JvmField var isBackgroundUserTrackerEnabled: Boolean = false @Parameterized.Parameter @JvmField var isBackgroundUserTrackerEnabled: Boolean = false private val testScope = TestScope() private val testDispatcher = StandardTestDispatcher(testScope.testScheduler) Loading @@ -104,15 +95,15 @@ class UserTrackerImplTest : SysuiTestCase() { fun setUp() { MockitoAnnotations.initMocks(this) `when`(context.userId).thenReturn(UserHandle.USER_SYSTEM) `when`(context.user).thenReturn(UserHandle.SYSTEM) `when`(context.createContextAsUser(any(), anyInt())).thenAnswer { invocation -> whenever(context.userId).thenReturn(UserHandle.USER_SYSTEM) whenever(context.user).thenReturn(UserHandle.SYSTEM) whenever(context.createContextAsUser(any(), anyInt())).thenAnswer { invocation -> val user = invocation.getArgument<UserHandle>(0) `when`(context.user).thenReturn(user) `when`(context.userId).thenReturn(user.identifier) whenever(context.user).thenReturn(user) whenever(context.userId).thenReturn(user.identifier) context } `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val info = UserInfo(invocation.getArgument<Int>(0), "", UserInfo.FLAG_FULL) listOf(info) } Loading @@ -131,45 +122,35 @@ class UserTrackerImplTest : SysuiTestCase() { ) } @Test fun testNotInitialized() = testScope.runTest { assertThat(tracker.initialized).isFalse() } @Test fun testNotInitialized() = testScope.runTest { assertThat(tracker.initialized).isFalse() } @Test(expected = IllegalStateException::class) fun testGetUserIdBeforeInitThrowsException() = testScope.runTest { tracker.userId } fun testGetUserIdBeforeInitThrowsException() = testScope.runTest { tracker.userId } @Test(expected = IllegalStateException::class) fun testGetUserHandleBeforeInitThrowsException() = testScope.runTest { tracker.userHandle } fun testGetUserHandleBeforeInitThrowsException() = testScope.runTest { tracker.userHandle } @Test(expected = IllegalStateException::class) fun testGetUserContextBeforeInitThrowsException() = testScope.runTest { tracker.userContext } fun testGetUserContextBeforeInitThrowsException() = testScope.runTest { tracker.userContext } @Test(expected = IllegalStateException::class) fun testGetUserContentResolverBeforeInitThrowsException() = testScope.runTest { tracker.userContentResolver } fun testGetUserContentResolverBeforeInitThrowsException() = testScope.runTest { tracker.userContentResolver } @Test(expected = IllegalStateException::class) fun testGetUserProfilesBeforeInitThrowsException() = testScope.runTest { tracker.userProfiles } fun testGetUserProfilesBeforeInitThrowsException() = testScope.runTest { tracker.userProfiles } @Test fun testInitialize() = testScope.runTest { fun testInitialize() = testScope.runTest { tracker.initialize(0) assertThat(tracker.initialized).isTrue() } @Test fun testReceiverRegisteredOnInitialize() = testScope.runTest { fun testReceiverRegisteredOnInitialize() = testScope.runTest { tracker.initialize(0) val captor = ArgumentCaptor.forClass(IntentFilter::class.java) Loading @@ -193,7 +174,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testInitialValuesSet() = testScope.runTest { fun testInitialValuesSet() = testScope.runTest { val testID = 4 tracker.initialize(testID) Loading @@ -210,7 +192,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testUserSwitch() = testScope.runTest { fun testUserSwitch() = testScope.runTest { tracker.initialize(0) val newID = 5 Loading @@ -234,14 +217,16 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testManagedProfileAvailable() = testScope.runTest { fun testManagedProfileAvailable() = testScope.runTest { tracker.initialize(0) val profileID = tracker.userId + 10 `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val id = invocation.getArgument<Int>(0) val info = UserInfo(id, "", UserInfo.FLAG_FULL) val infoProfile = UserInfo( val infoProfile = UserInfo( id + 10, "", "", Loading @@ -252,22 +237,26 @@ class UserTrackerImplTest : SysuiTestCase() { listOf(info, infoProfile) } val intent = Intent(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) val intent = Intent(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) .putExtra(Intent.EXTRA_USER, UserHandle.of(profileID)) tracker.onReceive(context, intent) assertThat(tracker.userProfiles.map { it.id }).containsExactly(tracker.userId, profileID) assertThat(tracker.userProfiles.map { it.id }) .containsExactly(tracker.userId, profileID) } @Test fun testManagedProfileUnavailable() = testScope.runTest { fun testManagedProfileUnavailable() = testScope.runTest { tracker.initialize(0) val profileID = tracker.userId + 10 `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val id = invocation.getArgument<Int>(0) val info = UserInfo(id, "", UserInfo.FLAG_FULL) val infoProfile = UserInfo( val infoProfile = UserInfo( id + 10, "", "", Loading @@ -278,22 +267,26 @@ class UserTrackerImplTest : SysuiTestCase() { listOf(info, infoProfile) } val intent = Intent(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE) 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) assertThat(tracker.userProfiles.map { it.id }) .containsExactly(tracker.userId, profileID) } @Test fun testManagedProfileStartedAndRemoved() = testScope.runTest { fun testManagedProfileStartedAndRemoved() = testScope.runTest { tracker.initialize(0) val profileID = tracker.userId + 10 `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val id = invocation.getArgument<Int>(0) val info = UserInfo(id, "", UserInfo.FLAG_FULL) val infoProfile = UserInfo( val infoProfile = UserInfo( id + 10, "", "", Loading @@ -305,17 +298,20 @@ class UserTrackerImplTest : SysuiTestCase() { } // Managed profile started val intent = Intent(Intent.ACTION_MANAGED_PROFILE_UNLOCKED) 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) assertThat(tracker.userProfiles.map { it.id }) .containsExactly(tracker.userId, profileID) `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> listOf(UserInfo(invocation.getArgument(0), "", UserInfo.FLAG_FULL)) } val intent2 = Intent(Intent.ACTION_MANAGED_PROFILE_REMOVED) val intent2 = Intent(Intent.ACTION_MANAGED_PROFILE_REMOVED) .putExtra(Intent.EXTRA_USER, UserHandle.of(profileID)) tracker.onReceive(context, intent2) Loading @@ -323,7 +319,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testCallbackNotCalledOnAdd() = testScope.runTest { fun testCallbackNotCalledOnAdd() = testScope.runTest { tracker.initialize(0) val callback = TestCallback() Loading @@ -334,7 +331,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testCallbackCalledOnUserChanging() = testScope.runTest { fun testCallbackCalledOnUserChanging() = testScope.runTest { tracker.initialize(0) val callback = TestCallback() tracker.addCallback(callback, executor) Loading @@ -354,7 +352,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testAsyncCallbackWaitsUserToChange() = testScope.runTest { fun testAsyncCallbackWaitsUserToChange() = testScope.runTest { // Skip this test for CountDownLatch variation. The problem is that there would be a // deadlock if the callbacks processing runs on the same thread as the callback (which // is blocked by the latch). Before the change it works because the callbacks are Loading Loading @@ -386,7 +385,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testCallbackCalledOnUserChanged() = testScope.runTest { fun testCallbackCalledOnUserChanged() = testScope.runTest { tracker.initialize(0) val callback = TestCallback() tracker.addCallback(callback, executor) Loading @@ -407,16 +407,18 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testCallbackCalledOnUserInfoChanged() = testScope.runTest { fun testCallbackCalledOnUserInfoChanged() = testScope.runTest { tracker.initialize(0) val callback = TestCallback() tracker.addCallback(callback, executor) val profileID = tracker.userId + 10 `when`(userManager.getProfiles(anyInt())).thenAnswer { invocation -> whenever(userManager.getProfiles(anyInt())).thenAnswer { invocation -> val id = invocation.getArgument<Int>(0) val info = UserInfo(id, "", UserInfo.FLAG_FULL) val infoProfile = UserInfo( val infoProfile = UserInfo( id + 10, "", "", Loading @@ -427,7 +429,8 @@ class UserTrackerImplTest : SysuiTestCase() { listOf(info, infoProfile) } val intent = Intent(Intent.ACTION_USER_INFO_CHANGED) val intent = Intent(Intent.ACTION_USER_INFO_CHANGED) .putExtra(Intent.EXTRA_USER, UserHandle.of(profileID)) tracker.onReceive(context, intent) Loading @@ -438,7 +441,8 @@ class UserTrackerImplTest : SysuiTestCase() { } @Test fun testCallbackRemoved() = testScope.runTest { fun testCallbackRemoved() = testScope.runTest { tracker.initialize(0) val newID = 5 val profileID = newID + 10 Loading @@ -454,7 +458,8 @@ class UserTrackerImplTest : SysuiTestCase() { verify(userSwitchingReply).sendResult(any()) captor.value.onUserSwitchComplete(newID) val intentProfiles = Intent(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) val intentProfiles = Intent(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) .putExtra(Intent.EXTRA_USER, UserHandle.of(profileID)) tracker.onReceive(context, intentProfiles) Loading