diff options
author | 2024-02-03 17:39:57 +0000 | |
---|---|---|
committer | 2024-02-03 17:39:57 +0000 | |
commit | 8e1def731fdaab07953f8d11531dbc518860d94e (patch) | |
tree | f0c8d59e5fd364142853b9b60d657029acb873e3 | |
parent | d9ca2713f9905c942e80ed78aa170bcfe3f8f551 (diff) | |
parent | a123129f70dc00c71ee9f782bb746a1b5e314658 (diff) |
Merge "Adds updateState to UserInteractor" into main
-rw-r--r-- | java/src/com/android/intentresolver/v2/domain/interactor/UserInteractor.kt | 8 | ||||
-rw-r--r-- | tests/unit/src/com/android/intentresolver/v2/domain/interactor/UserInteractorTest.kt | 23 |
2 files changed, 31 insertions, 0 deletions
diff --git a/java/src/com/android/intentresolver/v2/domain/interactor/UserInteractor.kt b/java/src/com/android/intentresolver/v2/domain/interactor/UserInteractor.kt index e1b3fb36..f12d8197 100644 --- a/java/src/com/android/intentresolver/v2/domain/interactor/UserInteractor.kt +++ b/java/src/com/android/intentresolver/v2/domain/interactor/UserInteractor.kt @@ -82,6 +82,14 @@ constructor( } } + /** + * Request the profile state be updated. In the case of enabling, the operation could take + * significant time and/or require user input. + */ + suspend fun updateState(profile: Profile, available: Boolean) { + userRepository.requestState(profile.primary, available) + } + private fun profileFromRole(role: Role): Type = when (role) { Role.PERSONAL -> Type.PERSONAL diff --git a/tests/unit/src/com/android/intentresolver/v2/domain/interactor/UserInteractorTest.kt b/tests/unit/src/com/android/intentresolver/v2/domain/interactor/UserInteractorTest.kt index 6fa055ef..4d246b9a 100644 --- a/tests/unit/src/com/android/intentresolver/v2/domain/interactor/UserInteractorTest.kt +++ b/tests/unit/src/com/android/intentresolver/v2/domain/interactor/UserInteractorTest.kt @@ -176,4 +176,27 @@ class UserInteractorTest { userRepo.removeUser(workUser) assertWithMessage("workAvailable").that(workAvailable).isFalse() } + + /** + * Similar to the above test in reverse: uses UserInteractor to modify state, and verify the + * state of the UserRepository. + */ + @Test + fun updateState() = runTest { + val userRepo = FakeUserRepository(workUser, personalUser) + val userInteractor = + UserInteractor(userRepository = userRepo, launchedAs = personalUser.handle) + val workProfile = Profile(Profile.Type.WORK, workUser) + + val availability by collectLastValue(userRepo.availability) + + // Default state is enabled in FakeUserManager + assertWithMessage("workAvailable").that(availability?.get(workUser)).isTrue() + + userInteractor.updateState(workProfile, false) + assertWithMessage("workAvailable").that(availability?.get(workUser)).isFalse() + + userInteractor.updateState(workProfile, true) + assertWithMessage("workAvailable").that(availability?.get(workUser)).isTrue() + } } |