[User Switcher] Set default value if setting null.

Copies the logic of user manager which defaults to the device resources
in order to determine if user switcher is enabled by default.

Fixes: 254240785
Test: Added a unit test.
Test: wipe device. Skip setup. Open user switcher, observe that there
should be an add button in the fullscreen user switcher.

Change-Id: I0864de61e7bb9dd7436082f2bf486cf4887a192a
This commit is contained in:
Aaron Liu
2022-11-28 14:21:28 -08:00
parent 45fdabd5f9
commit 1203527128
2 changed files with 27 additions and 1 deletions

View File

@@ -242,7 +242,15 @@ constructor(
val isUserSwitcherEnabled =
globalSettings.getIntForUser(
Settings.Global.USER_SWITCHER_ENABLED,
0,
if (
appContext.resources.getBoolean(
com.android.internal.R.bool.config_showUserSwitcherByDefault
)
) {
1
} else {
0
},
UserHandle.USER_SYSTEM,
) != 0

View File

@@ -94,6 +94,24 @@ class UserRepositoryImplTest : SysuiTestCase() {
)
}
@Test
fun userSwitcherSettings_isUserSwitcherEnabled_notInitialized() = runSelfCancelingTest {
underTest = create(this)
var value: UserSwitcherSettingsModel? = null
underTest.userSwitcherSettings.onEach { value = it }.launchIn(this)
assertUserSwitcherSettings(
model = value,
expectedSimpleUserSwitcher = false,
expectedAddUsersFromLockscreen = false,
expectedUserSwitcherEnabled =
context.resources.getBoolean(
com.android.internal.R.bool.config_showUserSwitcherByDefault
),
)
}
@Test
fun refreshUsers() = runSelfCancelingTest {
underTest = create(this)