Merge "[Bouncer] Remove duplicate manage users." into tm-qpr-dev
This commit is contained in:
@@ -321,6 +321,7 @@ constructor(
|
|||||||
return when {
|
return when {
|
||||||
isAddUser -> false
|
isAddUser -> false
|
||||||
isAddSupervisedUser -> false
|
isAddSupervisedUser -> false
|
||||||
|
isManageUsers -> false
|
||||||
isGuest -> info != null
|
isGuest -> info != null
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
@@ -346,6 +347,7 @@ constructor(
|
|||||||
isAddUser -> UserActionModel.ADD_USER
|
isAddUser -> UserActionModel.ADD_USER
|
||||||
isAddSupervisedUser -> UserActionModel.ADD_SUPERVISED_USER
|
isAddSupervisedUser -> UserActionModel.ADD_SUPERVISED_USER
|
||||||
isGuest -> UserActionModel.ENTER_GUEST_MODE
|
isGuest -> UserActionModel.ENTER_GUEST_MODE
|
||||||
|
isManageUsers -> UserActionModel.NAVIGATE_TO_USER_MANAGEMENT
|
||||||
else -> error("Don't know how to convert to UserActionModel: $this")
|
else -> error("Don't know how to convert to UserActionModel: $this")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,18 +236,7 @@ constructor(
|
|||||||
}
|
}
|
||||||
.flatMapLatest { isActionable ->
|
.flatMapLatest { isActionable ->
|
||||||
if (isActionable) {
|
if (isActionable) {
|
||||||
repository.actions.map { actions ->
|
repository.actions
|
||||||
actions +
|
|
||||||
if (actions.isNotEmpty()) {
|
|
||||||
// If we have actions, we add NAVIGATE_TO_USER_MANAGEMENT
|
|
||||||
// because that's a user switcher specific action that is
|
|
||||||
// not known to the our data source or other features.
|
|
||||||
listOf(UserActionModel.NAVIGATE_TO_USER_MANAGEMENT)
|
|
||||||
} else {
|
|
||||||
// If no actions, don't add the navigate action.
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// If not actionable it means that we're not allowed to show actions
|
// If not actionable it means that we're not allowed to show actions
|
||||||
// when
|
// when
|
||||||
|
|||||||
@@ -62,17 +62,7 @@ private constructor(
|
|||||||
val isMenuVisible: Flow<Boolean> = _isMenuVisible
|
val isMenuVisible: Flow<Boolean> = _isMenuVisible
|
||||||
/** The user action menu. */
|
/** The user action menu. */
|
||||||
val menu: Flow<List<UserActionViewModel>> =
|
val menu: Flow<List<UserActionViewModel>> =
|
||||||
userInteractor.actions.map { actions ->
|
userInteractor.actions.map { actions -> actions.map { action -> toViewModel(action) } }
|
||||||
if (isNewImpl && actions.isNotEmpty()) {
|
|
||||||
// If we have actions, we add NAVIGATE_TO_USER_MANAGEMENT because that's a user
|
|
||||||
// switcher specific action that is not known to the our data source or other
|
|
||||||
// features.
|
|
||||||
actions + listOf(UserActionModel.NAVIGATE_TO_USER_MANAGEMENT)
|
|
||||||
} else {
|
|
||||||
actions
|
|
||||||
}
|
|
||||||
.map { action -> toViewModel(action) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Whether the button to open the user action menu is visible. */
|
/** Whether the button to open the user action menu is visible. */
|
||||||
val isOpenMenuButtonVisible: Flow<Boolean> = menu.map { it.isNotEmpty() }
|
val isOpenMenuButtonVisible: Flow<Boolean> = menu.map { it.isNotEmpty() }
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ class UserRepositoryImplUnrefactoredTest : UserRepositoryImplTest() {
|
|||||||
createUserRecord(2),
|
createUserRecord(2),
|
||||||
createActionRecord(UserActionModel.ADD_SUPERVISED_USER),
|
createActionRecord(UserActionModel.ADD_SUPERVISED_USER),
|
||||||
createActionRecord(UserActionModel.ENTER_GUEST_MODE),
|
createActionRecord(UserActionModel.ENTER_GUEST_MODE),
|
||||||
|
createActionRecord(UserActionModel.NAVIGATE_TO_USER_MANAGEMENT),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
var models: List<UserModel>? = null
|
var models: List<UserModel>? = null
|
||||||
@@ -176,15 +177,17 @@ class UserRepositoryImplUnrefactoredTest : UserRepositoryImplTest() {
|
|||||||
createUserRecord(2),
|
createUserRecord(2),
|
||||||
createActionRecord(UserActionModel.ADD_SUPERVISED_USER),
|
createActionRecord(UserActionModel.ADD_SUPERVISED_USER),
|
||||||
createActionRecord(UserActionModel.ENTER_GUEST_MODE),
|
createActionRecord(UserActionModel.ENTER_GUEST_MODE),
|
||||||
|
createActionRecord(UserActionModel.NAVIGATE_TO_USER_MANAGEMENT),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
var models: List<UserActionModel>? = null
|
var models: List<UserActionModel>? = null
|
||||||
val job = underTest.actions.onEach { models = it }.launchIn(this)
|
val job = underTest.actions.onEach { models = it }.launchIn(this)
|
||||||
|
|
||||||
assertThat(models).hasSize(3)
|
assertThat(models).hasSize(4)
|
||||||
assertThat(models?.get(0)).isEqualTo(UserActionModel.ADD_USER)
|
assertThat(models?.get(0)).isEqualTo(UserActionModel.ADD_USER)
|
||||||
assertThat(models?.get(1)).isEqualTo(UserActionModel.ADD_SUPERVISED_USER)
|
assertThat(models?.get(1)).isEqualTo(UserActionModel.ADD_SUPERVISED_USER)
|
||||||
assertThat(models?.get(2)).isEqualTo(UserActionModel.ENTER_GUEST_MODE)
|
assertThat(models?.get(2)).isEqualTo(UserActionModel.ENTER_GUEST_MODE)
|
||||||
|
assertThat(models?.get(3)).isEqualTo(UserActionModel.NAVIGATE_TO_USER_MANAGEMENT)
|
||||||
job.cancel()
|
job.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +203,7 @@ class UserRepositoryImplUnrefactoredTest : UserRepositoryImplTest() {
|
|||||||
isAddUser = action == UserActionModel.ADD_USER,
|
isAddUser = action == UserActionModel.ADD_USER,
|
||||||
isAddSupervisedUser = action == UserActionModel.ADD_SUPERVISED_USER,
|
isAddSupervisedUser = action == UserActionModel.ADD_SUPERVISED_USER,
|
||||||
isGuest = action == UserActionModel.ENTER_GUEST_MODE,
|
isGuest = action == UserActionModel.ENTER_GUEST_MODE,
|
||||||
|
isManageUsers = action == UserActionModel.NAVIGATE_TO_USER_MANAGEMENT,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,13 +64,7 @@ open class UserInteractorUnrefactoredTest : UserInteractorTest() {
|
|||||||
@Test
|
@Test
|
||||||
fun `actions - not actionable when locked and not locked`() =
|
fun `actions - not actionable when locked and not locked`() =
|
||||||
runBlocking(IMMEDIATE) {
|
runBlocking(IMMEDIATE) {
|
||||||
userRepository.setActions(
|
setActions()
|
||||||
listOf(
|
|
||||||
UserActionModel.ENTER_GUEST_MODE,
|
|
||||||
UserActionModel.ADD_USER,
|
|
||||||
UserActionModel.ADD_SUPERVISED_USER,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
userRepository.setActionableWhenLocked(false)
|
userRepository.setActionableWhenLocked(false)
|
||||||
keyguardRepository.setKeyguardShowing(false)
|
keyguardRepository.setKeyguardShowing(false)
|
||||||
|
|
||||||
@@ -92,13 +86,7 @@ open class UserInteractorUnrefactoredTest : UserInteractorTest() {
|
|||||||
@Test
|
@Test
|
||||||
fun `actions - actionable when locked and not locked`() =
|
fun `actions - actionable when locked and not locked`() =
|
||||||
runBlocking(IMMEDIATE) {
|
runBlocking(IMMEDIATE) {
|
||||||
userRepository.setActions(
|
setActions()
|
||||||
listOf(
|
|
||||||
UserActionModel.ENTER_GUEST_MODE,
|
|
||||||
UserActionModel.ADD_USER,
|
|
||||||
UserActionModel.ADD_SUPERVISED_USER,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
userRepository.setActionableWhenLocked(true)
|
userRepository.setActionableWhenLocked(true)
|
||||||
keyguardRepository.setKeyguardShowing(false)
|
keyguardRepository.setKeyguardShowing(false)
|
||||||
|
|
||||||
@@ -120,13 +108,7 @@ open class UserInteractorUnrefactoredTest : UserInteractorTest() {
|
|||||||
@Test
|
@Test
|
||||||
fun `actions - actionable when locked and locked`() =
|
fun `actions - actionable when locked and locked`() =
|
||||||
runBlocking(IMMEDIATE) {
|
runBlocking(IMMEDIATE) {
|
||||||
userRepository.setActions(
|
setActions()
|
||||||
listOf(
|
|
||||||
UserActionModel.ENTER_GUEST_MODE,
|
|
||||||
UserActionModel.ADD_USER,
|
|
||||||
UserActionModel.ADD_SUPERVISED_USER,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
userRepository.setActionableWhenLocked(true)
|
userRepository.setActionableWhenLocked(true)
|
||||||
keyguardRepository.setKeyguardShowing(true)
|
keyguardRepository.setKeyguardShowing(true)
|
||||||
|
|
||||||
@@ -182,6 +164,10 @@ open class UserInteractorUnrefactoredTest : UserInteractorTest() {
|
|||||||
verify(activityStarter).startActivity(any(), anyBoolean())
|
verify(activityStarter).startActivity(any(), anyBoolean())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setActions() {
|
||||||
|
userRepository.setActions(UserActionModel.values().toList())
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val IMMEDIATE = Dispatchers.Main.immediate
|
private val IMMEDIATE = Dispatchers.Main.immediate
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,6 +267,26 @@ class UserSwitcherViewModelTest : SysuiTestCase() {
|
|||||||
job.cancel()
|
job.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `menu actions`() =
|
||||||
|
runBlocking(IMMEDIATE) {
|
||||||
|
userRepository.setActions(UserActionModel.values().toList())
|
||||||
|
var actions: List<UserActionViewModel>? = null
|
||||||
|
val job = underTest.menu.onEach { actions = it }.launchIn(this)
|
||||||
|
|
||||||
|
assertThat(actions?.map { it.viewKey })
|
||||||
|
.isEqualTo(
|
||||||
|
listOf(
|
||||||
|
UserActionModel.ENTER_GUEST_MODE.ordinal.toLong(),
|
||||||
|
UserActionModel.ADD_USER.ordinal.toLong(),
|
||||||
|
UserActionModel.ADD_SUPERVISED_USER.ordinal.toLong(),
|
||||||
|
UserActionModel.NAVIGATE_TO_USER_MANAGEMENT.ordinal.toLong(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `isFinishRequested - finishes when user is switched`() =
|
fun `isFinishRequested - finishes when user is switched`() =
|
||||||
runBlocking(IMMEDIATE) {
|
runBlocking(IMMEDIATE) {
|
||||||
|
|||||||
Reference in New Issue
Block a user