Merge "Shift "Add guest" button in User switcher for tablets" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8533b9d802
@@ -156,17 +156,35 @@ constructor(
|
|||||||
keyguardInteractor.isKeyguardShowing,
|
keyguardInteractor.isKeyguardShowing,
|
||||||
) { _, userInfos, settings, isDeviceLocked ->
|
) { _, userInfos, settings, isDeviceLocked ->
|
||||||
buildList {
|
buildList {
|
||||||
|
if (!isDeviceLocked || settings.isAddUsersFromLockscreen) {
|
||||||
|
// The device is locked and our setting to allow actions that add users
|
||||||
|
// from the lock-screen is not enabled. We can finish building the list
|
||||||
|
// here.
|
||||||
|
val isFullScreen = featureFlags.isEnabled(Flags.FULL_SCREEN_USER_SWITCHER)
|
||||||
|
|
||||||
|
val actionList: List<UserActionModel> =
|
||||||
|
if (isFullScreen) {
|
||||||
|
listOf(
|
||||||
|
UserActionModel.ADD_USER,
|
||||||
|
UserActionModel.ADD_SUPERVISED_USER,
|
||||||
|
UserActionModel.ENTER_GUEST_MODE,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
listOf(
|
||||||
|
UserActionModel.ENTER_GUEST_MODE,
|
||||||
|
UserActionModel.ADD_USER,
|
||||||
|
UserActionModel.ADD_SUPERVISED_USER,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
actionList.map {
|
||||||
|
when (it) {
|
||||||
|
UserActionModel.ENTER_GUEST_MODE -> {
|
||||||
val hasGuestUser = userInfos.any { it.isGuest }
|
val hasGuestUser = userInfos.any { it.isGuest }
|
||||||
if (!hasGuestUser && canCreateGuestUser(settings)) {
|
if (!hasGuestUser && canCreateGuestUser(settings)) {
|
||||||
add(UserActionModel.ENTER_GUEST_MODE)
|
add(UserActionModel.ENTER_GUEST_MODE)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!isDeviceLocked || settings.isAddUsersFromLockscreen) {
|
UserActionModel.ADD_USER -> {
|
||||||
// The device is locked and our setting to allow actions that add users
|
|
||||||
// from the lock-screen is not enabled. The guest action from above is
|
|
||||||
// always allowed, even when the device is locked, but the various "add
|
|
||||||
// user" actions below are not. We can finish building the list here.
|
|
||||||
|
|
||||||
val canCreateUsers =
|
val canCreateUsers =
|
||||||
UserActionsUtil.canCreateUser(
|
UserActionsUtil.canCreateUser(
|
||||||
manager,
|
manager,
|
||||||
@@ -178,7 +196,8 @@ constructor(
|
|||||||
if (canCreateUsers) {
|
if (canCreateUsers) {
|
||||||
add(UserActionModel.ADD_USER)
|
add(UserActionModel.ADD_USER)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
UserActionModel.ADD_SUPERVISED_USER -> {
|
||||||
if (
|
if (
|
||||||
UserActionsUtil.canCreateSupervisedUser(
|
UserActionsUtil.canCreateSupervisedUser(
|
||||||
manager,
|
manager,
|
||||||
@@ -191,7 +210,10 @@ constructor(
|
|||||||
add(UserActionModel.ADD_SUPERVISED_USER)
|
add(UserActionModel.ADD_SUPERVISED_USER)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else -> Unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
UserActionsUtil.canManageUsers(
|
UserActionsUtil.canManageUsers(
|
||||||
repository,
|
repository,
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ class UserInteractorTest : SysuiTestCase() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
featureFlags = FakeFeatureFlags()
|
featureFlags = FakeFeatureFlags()
|
||||||
|
featureFlags.set(Flags.FULL_SCREEN_USER_SWITCHER, false)
|
||||||
userRepository = FakeUserRepository()
|
userRepository = FakeUserRepository()
|
||||||
keyguardRepository = FakeKeyguardRepository()
|
keyguardRepository = FakeKeyguardRepository()
|
||||||
telephonyRepository = FakeTelephonyRepository()
|
telephonyRepository = FakeTelephonyRepository()
|
||||||
@@ -310,6 +311,32 @@ class UserInteractorTest : SysuiTestCase() {
|
|||||||
job.cancel()
|
job.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `actions - device unlocked - full screen`() =
|
||||||
|
runBlocking(IMMEDIATE) {
|
||||||
|
featureFlags.set(Flags.FULL_SCREEN_USER_SWITCHER, true)
|
||||||
|
val userInfos = createUserInfos(count = 2, includeGuest = false)
|
||||||
|
|
||||||
|
userRepository.setUserInfos(userInfos)
|
||||||
|
userRepository.setSelectedUserInfo(userInfos[0])
|
||||||
|
userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = true))
|
||||||
|
keyguardRepository.setKeyguardShowing(false)
|
||||||
|
var value: List<UserActionModel>? = null
|
||||||
|
val job = underTest.actions.onEach { value = it }.launchIn(this)
|
||||||
|
|
||||||
|
assertThat(value)
|
||||||
|
.isEqualTo(
|
||||||
|
listOf(
|
||||||
|
UserActionModel.ADD_USER,
|
||||||
|
UserActionModel.ADD_SUPERVISED_USER,
|
||||||
|
UserActionModel.ENTER_GUEST_MODE,
|
||||||
|
UserActionModel.NAVIGATE_TO_USER_MANAGEMENT,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `actions - device unlocked user not primary - empty list`() =
|
fun `actions - device unlocked user not primary - empty list`() =
|
||||||
runBlocking(IMMEDIATE) {
|
runBlocking(IMMEDIATE) {
|
||||||
@@ -373,7 +400,37 @@ class UserInteractorTest : SysuiTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `actions - device locked - only guest action and manage user is shown`() =
|
fun `actions - device locked add from lockscreen set - full list - full screen`() =
|
||||||
|
runBlocking(IMMEDIATE) {
|
||||||
|
featureFlags.set(Flags.FULL_SCREEN_USER_SWITCHER, true)
|
||||||
|
val userInfos = createUserInfos(count = 2, includeGuest = false)
|
||||||
|
userRepository.setUserInfos(userInfos)
|
||||||
|
userRepository.setSelectedUserInfo(userInfos[0])
|
||||||
|
userRepository.setSettings(
|
||||||
|
UserSwitcherSettingsModel(
|
||||||
|
isUserSwitcherEnabled = true,
|
||||||
|
isAddUsersFromLockscreen = true,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
keyguardRepository.setKeyguardShowing(false)
|
||||||
|
var value: List<UserActionModel>? = null
|
||||||
|
val job = underTest.actions.onEach { value = it }.launchIn(this)
|
||||||
|
|
||||||
|
assertThat(value)
|
||||||
|
.isEqualTo(
|
||||||
|
listOf(
|
||||||
|
UserActionModel.ADD_USER,
|
||||||
|
UserActionModel.ADD_SUPERVISED_USER,
|
||||||
|
UserActionModel.ENTER_GUEST_MODE,
|
||||||
|
UserActionModel.NAVIGATE_TO_USER_MANAGEMENT,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `actions - device locked - only manage user is shown`() =
|
||||||
runBlocking(IMMEDIATE) {
|
runBlocking(IMMEDIATE) {
|
||||||
val userInfos = createUserInfos(count = 2, includeGuest = false)
|
val userInfos = createUserInfos(count = 2, includeGuest = false)
|
||||||
userRepository.setUserInfos(userInfos)
|
userRepository.setUserInfos(userInfos)
|
||||||
@@ -383,13 +440,7 @@ class UserInteractorTest : SysuiTestCase() {
|
|||||||
var value: List<UserActionModel>? = null
|
var value: List<UserActionModel>? = null
|
||||||
val job = underTest.actions.onEach { value = it }.launchIn(this)
|
val job = underTest.actions.onEach { value = it }.launchIn(this)
|
||||||
|
|
||||||
assertThat(value)
|
assertThat(value).isEqualTo(listOf(UserActionModel.NAVIGATE_TO_USER_MANAGEMENT))
|
||||||
.isEqualTo(
|
|
||||||
listOf(
|
|
||||||
UserActionModel.ENTER_GUEST_MODE,
|
|
||||||
UserActionModel.NAVIGATE_TO_USER_MANAGEMENT
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
job.cancel()
|
job.cancel()
|
||||||
}
|
}
|
||||||
@@ -664,6 +715,33 @@ class UserInteractorTest : SysuiTestCase() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun userRecordsFullScreen() =
|
||||||
|
runBlocking(IMMEDIATE) {
|
||||||
|
featureFlags.set(Flags.FULL_SCREEN_USER_SWITCHER, true)
|
||||||
|
val userInfos = createUserInfos(count = 3, includeGuest = false)
|
||||||
|
userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = true))
|
||||||
|
userRepository.setUserInfos(userInfos)
|
||||||
|
userRepository.setSelectedUserInfo(userInfos[0])
|
||||||
|
keyguardRepository.setKeyguardShowing(false)
|
||||||
|
|
||||||
|
testCoroutineScope.advanceUntilIdle()
|
||||||
|
|
||||||
|
assertRecords(
|
||||||
|
records = underTest.userRecords.value,
|
||||||
|
userIds = listOf(0, 1, 2),
|
||||||
|
selectedUserIndex = 0,
|
||||||
|
includeGuest = false,
|
||||||
|
expectedActions =
|
||||||
|
listOf(
|
||||||
|
UserActionModel.ADD_USER,
|
||||||
|
UserActionModel.ADD_SUPERVISED_USER,
|
||||||
|
UserActionModel.ENTER_GUEST_MODE,
|
||||||
|
UserActionModel.NAVIGATE_TO_USER_MANAGEMENT,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun selectedUserRecord() =
|
fun selectedUserRecord() =
|
||||||
runBlocking(IMMEDIATE) {
|
runBlocking(IMMEDIATE) {
|
||||||
@@ -728,8 +806,6 @@ class UserInteractorTest : SysuiTestCase() {
|
|||||||
@Test
|
@Test
|
||||||
fun `show user switcher - full screen disabled - shows dialog switcher`() =
|
fun `show user switcher - full screen disabled - shows dialog switcher`() =
|
||||||
runBlocking(IMMEDIATE) {
|
runBlocking(IMMEDIATE) {
|
||||||
featureFlags.set(Flags.FULL_SCREEN_USER_SWITCHER, false)
|
|
||||||
|
|
||||||
var dialogRequest: ShowDialogRequestModel? = null
|
var dialogRequest: ShowDialogRequestModel? = null
|
||||||
val expandable = mock<Expandable>()
|
val expandable = mock<Expandable>()
|
||||||
underTest.showUserSwitcher(context, expandable)
|
underTest.showUserSwitcher(context, expandable)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import com.android.systemui.GuestResumeSessionReceiver
|
|||||||
import com.android.systemui.SysuiTestCase
|
import com.android.systemui.SysuiTestCase
|
||||||
import com.android.systemui.common.shared.model.Text
|
import com.android.systemui.common.shared.model.Text
|
||||||
import com.android.systemui.flags.FakeFeatureFlags
|
import com.android.systemui.flags.FakeFeatureFlags
|
||||||
|
import com.android.systemui.flags.Flags
|
||||||
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
|
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
|
||||||
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
|
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
|
||||||
import com.android.systemui.plugins.ActivityStarter
|
import com.android.systemui.plugins.ActivityStarter
|
||||||
@@ -241,7 +242,8 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
|
|||||||
KeyguardInteractor(
|
KeyguardInteractor(
|
||||||
repository = keyguardRepository,
|
repository = keyguardRepository,
|
||||||
),
|
),
|
||||||
featureFlags = featureFlags,
|
featureFlags =
|
||||||
|
FakeFeatureFlags().apply { set(Flags.FULL_SCREEN_USER_SWITCHER, false) },
|
||||||
manager = manager,
|
manager = manager,
|
||||||
applicationScope = testScope.backgroundScope,
|
applicationScope = testScope.backgroundScope,
|
||||||
telephonyInteractor =
|
telephonyInteractor =
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import com.android.systemui.GuestResumeSessionReceiver
|
|||||||
import com.android.systemui.SysuiTestCase
|
import com.android.systemui.SysuiTestCase
|
||||||
import com.android.systemui.common.shared.model.Text
|
import com.android.systemui.common.shared.model.Text
|
||||||
import com.android.systemui.flags.FakeFeatureFlags
|
import com.android.systemui.flags.FakeFeatureFlags
|
||||||
|
import com.android.systemui.flags.Flags
|
||||||
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
|
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
|
||||||
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
|
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
|
||||||
import com.android.systemui.plugins.ActivityStarter
|
import com.android.systemui.plugins.ActivityStarter
|
||||||
@@ -148,7 +149,10 @@ class UserSwitcherViewModelTest : SysuiTestCase() {
|
|||||||
KeyguardInteractor(
|
KeyguardInteractor(
|
||||||
repository = keyguardRepository,
|
repository = keyguardRepository,
|
||||||
),
|
),
|
||||||
featureFlags = FakeFeatureFlags(),
|
featureFlags =
|
||||||
|
FakeFeatureFlags().apply {
|
||||||
|
set(Flags.FULL_SCREEN_USER_SWITCHER, false)
|
||||||
|
},
|
||||||
manager = manager,
|
manager = manager,
|
||||||
applicationScope = injectedScope,
|
applicationScope = injectedScope,
|
||||||
telephonyInteractor =
|
telephonyInteractor =
|
||||||
|
|||||||
Reference in New Issue
Block a user