Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/data/repository/CommunalSettingsRepositoryImplTest.kt +4 −5 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.testKosmos import com.android.systemui.util.mockito.nullable import com.android.systemui.util.mockito.whenever import com.android.systemui.util.settings.fakeSettings import com.android.systemui.util.settings.data.repository.userAwareSecureSettingsRepository import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage import org.junit.After Loading Loading @@ -212,19 +212,18 @@ class CommunalSettingsRepositoryImplTest(flags: FlagsParameterization?) : SysuiT @DisableFlags(FLAG_GLANCEABLE_HUB_BLURRED_BACKGROUND) fun backgroundType_defaultValue() = kosmos.runTest { val backgroundType by collectLastValue(underTest.getBackground(PRIMARY_USER)) val backgroundType by collectLastValue(underTest.getBackground()) assertThat(backgroundType).isEqualTo(CommunalBackgroundType.ANIMATED) } @Test fun backgroundType_verifyAllValues() = kosmos.runTest { val backgroundType by collectLastValue(underTest.getBackground(PRIMARY_USER)) val backgroundType by collectLastValue(underTest.getBackground()) for (type in CommunalBackgroundType.entries) { fakeSettings.putIntForUser( kosmos.userAwareSecureSettingsRepository.setInt( GLANCEABLE_HUB_BACKGROUND_SETTING, type.value, PRIMARY_USER.id, ) assertWithMessage( "Expected $type when $GLANCEABLE_HUB_BACKGROUND_SETTING is set to" + Loading packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/data/repository/DreamSettingsRepositoryImplTest.kt +23 −17 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.testKosmos import com.android.systemui.util.settings.fakeSettings import com.android.systemui.util.settings.data.repository.userAwareSecureSettingsRepository import com.google.common.truth.Truth.assertThat import org.junit.After import org.junit.Before Loading Loading @@ -68,6 +68,9 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { @After fun tearDown() { mContext.orCreateTestableResources.removeOverride( com.android.internal.R.bool.config_dreamsEnabledByDefault ) mContext.orCreateTestableResources.removeOverride( com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault ) Loading @@ -82,12 +85,11 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { @Test fun whenToDream_charging() = kosmos.runTest { val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) fakeSettings.putIntForUser( kosmos.userAwareSecureSettingsRepository.setInt( Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, 1, PRIMARY_USER.id, ) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_CHARGING) Loading @@ -101,19 +103,18 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { true, ) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_CHARGING) } @Test fun whenToDream_docked() = kosmos.runTest { val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) fakeSettings.putIntForUser( kosmos.userAwareSecureSettingsRepository.setInt( Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK, 1, PRIMARY_USER.id, ) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_DOCKED) Loading @@ -127,19 +128,18 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { true, ) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_DOCKED) } @Test fun whenToDream_postured() = kosmos.runTest { val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) fakeSettings.putIntForUser( kosmos.userAwareSecureSettingsRepository.setInt( Settings.Secure.SCREENSAVER_ACTIVATE_ON_POSTURED, 1, PRIMARY_USER.id, ) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_POSTURED) Loading @@ -153,7 +153,7 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { true, ) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_POSTURED) } Loading @@ -165,13 +165,19 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { true, ) fakeSettings.putBoolForUser(Settings.Secure.SCREENSAVER_ENABLED, false, PRIMARY_USER.id) kosmos.userAwareSecureSettingsRepository.setBoolean( Settings.Secure.SCREENSAVER_ENABLED, false, ) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) assertThat(whenToDreamState).isEqualTo(WhenToDream.NEVER) fakeSettings.putBoolForUser(Settings.Secure.SCREENSAVER_ENABLED, true, PRIMARY_USER.id) kosmos.userAwareSecureSettingsRepository.setBoolean( Settings.Secure.SCREENSAVER_ENABLED, true, ) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_POSTURED) } Loading @@ -179,7 +185,7 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { @Test fun whenToDream_default() = kosmos.runTest { val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) assertThat(whenToDreamState).isEqualTo(WhenToDream.NEVER) } Loading packages/SystemUI/multivalentTests/src/com/android/systemui/lowlight/LowLightBehaviorCoreStartableTest.kt +10 −17 Original line number Diff line number Diff line Loading @@ -46,13 +46,13 @@ import com.android.systemui.lowlightclock.LowLightLogger import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest import com.android.systemui.power.domain.interactor.powerInteractor import com.android.systemui.res.R import com.android.systemui.settings.userTracker import com.android.systemui.testKosmos import com.android.systemui.user.data.repository.fakeUserRepository import com.android.systemui.user.domain.interactor.selectedUserInteractor import com.android.systemui.user.domain.interactor.userLockedInteractor import com.android.systemui.util.settings.fakeSettings import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.runBlocking import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -135,14 +135,12 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() { false, ) kosmos.lowLightSettingsRepository.setLowLightDisplayBehaviorEnabled( kosmos.userTracker.userInfo, true, ) runBlocking { kosmos.lowLightSettingsRepository.setLowLightDisplayBehaviorEnabled(true) kosmos.lowLightSettingsRepository.setLowLightDisplayBehavior( kosmos.userTracker.userInfo, LowLightDisplayBehavior.LOW_LIGHT_DREAM, LowLightDisplayBehavior.LOW_LIGHT_DREAM ) } kosmos.lowLightRepository.addAction(LowLightDisplayBehavior.LOW_LIGHT_DREAM, action) } Loading Loading @@ -183,10 +181,7 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() { @Test fun testSetAmbientLowLightWhenDisabledInLowLight() = kosmos.runTest { lowLightSettingsRepository.setLowLightDisplayBehaviorEnabled( userTracker.userInfo, false, ) lowLightSettingsRepository.setLowLightDisplayBehaviorEnabled(false) underTest.start() // Turn on screen Loading Loading @@ -254,8 +249,7 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() { kosmos.runTest { lowLightRepository.addAction(LowLightDisplayBehavior.SCREEN_OFF, action) lowLightSettingsRepository.setLowLightDisplayBehavior( userTracker.userInfo, LowLightDisplayBehavior.SCREEN_OFF, LowLightDisplayBehavior.SCREEN_OFF ) setDisplayOn(true) Loading @@ -269,8 +263,7 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() { kosmos.runTest { lowLightRepository.addAction(LowLightDisplayBehavior.SCREEN_OFF, action) lowLightSettingsRepository.setLowLightDisplayBehavior( userTracker.userInfo, LowLightDisplayBehavior.SCREEN_OFF, LowLightDisplayBehavior.SCREEN_OFF ) setDisplayOn(true) Loading packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSettingsRepository.kt +42 −61 Original line number Diff line number Diff line Loading @@ -38,8 +38,7 @@ import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.flags.FeatureFlagsClassic import com.android.systemui.flags.Flags import com.android.systemui.util.kotlin.emitOnStart import com.android.systemui.util.settings.SecureSettings import com.android.systemui.util.settings.SettingsProxyExt.observerFlow import com.android.systemui.util.settings.repository.UserAwareSecureSettingsRepository import javax.inject.Inject import javax.inject.Named import kotlinx.coroutines.CoroutineDispatcher Loading @@ -59,13 +58,13 @@ interface CommunalSettingsRepository { fun setSuppressionReasons(reasons: List<SuppressionReason>) /** * Returns a[WhenToStartHub] for the specified user, indicating what state the device should be * in to automatically display the hub. * Returns a[WhenToStartHub] for the active user, indicating what state the device should be in * to automatically display the hub. */ fun getWhenToStartHubState(user: UserInfo): Flow<WhenToStartHub> fun getWhenToStartHubState(): Flow<WhenToStartHub> /** Returns whether glanceable hub is enabled by the current user. */ fun getSettingEnabledByUser(user: UserInfo): Flow<Boolean> /** Returns whether glanceable hub is enabled by the active user. */ fun getSettingEnabledByUser(): Flow<Boolean> /** * Returns true if any glanceable hub functionality should be enabled via configs and flags. Loading Loading @@ -95,8 +94,11 @@ interface CommunalSettingsRepository { /** Keyguard widgets enabled state by Device Policy Manager for the specified user. */ fun getAllowedByDevicePolicy(user: UserInfo): Flow<Boolean> /** The type of background to use for the hub. Used to experiment with different backgrounds. */ fun getBackground(user: UserInfo): Flow<CommunalBackgroundType> /** * The type of background to use for the hub for the active user. Used to experiment with * different backgrounds. */ fun getBackground(): Flow<CommunalBackgroundType> } @SysUISingleton Loading @@ -106,7 +108,7 @@ constructor( @Background private val bgDispatcher: CoroutineDispatcher, @Main private val resources: Resources, private val featureFlagsClassic: FeatureFlagsClassic, private val secureSettings: SecureSettings, private val userAwareSecureSettingsRepository: UserAwareSecureSettingsRepository, private val broadcastDispatcher: BroadcastDispatcher, private val devicePolicyManager: DevicePolicyManager, @Named(DEFAULT_BACKGROUND_TYPE) private val defaultBackgroundType: CommunalBackgroundType, Loading Loading @@ -143,33 +145,13 @@ constructor( glanceableHubV2() } override fun getWhenToStartHubState(user: UserInfo): Flow<WhenToStartHub> { override fun getWhenToStartHubState(): Flow<WhenToStartHub> { if (!getV2FlagEnabled()) { return MutableStateFlow(WhenToStartHub.NEVER) } return secureSettings .observerFlow( userId = user.id, names = arrayOf(Settings.Secure.WHEN_TO_START_GLANCEABLE_HUB), ) .emitOnStart() .map { when ( secureSettings.getIntForUser( Settings.Secure.WHEN_TO_START_GLANCEABLE_HUB, whenToStartHubByDefault, user.id, ) ) { Settings.Secure.GLANCEABLE_HUB_START_NEVER -> WhenToStartHub.NEVER Settings.Secure.GLANCEABLE_HUB_START_CHARGING -> WhenToStartHub.WHILE_CHARGING Settings.Secure.GLANCEABLE_HUB_START_CHARGING_UPRIGHT -> WhenToStartHub.WHILE_CHARGING_AND_POSTURED Settings.Secure.GLANCEABLE_HUB_START_DOCKED -> WhenToStartHub.WHILE_DOCKED else -> WhenToStartHub.NEVER } } return userAwareSecureSettingsRepository .intSetting(Settings.Secure.WHEN_TO_START_GLANCEABLE_HUB, whenToStartHubByDefault) .map { it.toWhenToStartHub() } .flowOn(bgDispatcher) } Loading @@ -186,34 +168,33 @@ constructor( .emitOnStart() .map { devicePolicyManager.areKeyguardWidgetsAllowed(user.id) } override fun getBackground(user: UserInfo): Flow<CommunalBackgroundType> = secureSettings .observerFlow(userId = user.id, names = arrayOf(GLANCEABLE_HUB_BACKGROUND_SETTING)) .emitOnStart() .map { val intType = secureSettings.getIntForUser( GLANCEABLE_HUB_BACKGROUND_SETTING, defaultBackgroundType.value, user.id, ) CommunalBackgroundType.entries.find { type -> type.value == intType } override fun getBackground(): Flow<CommunalBackgroundType> = userAwareSecureSettingsRepository .intSetting(GLANCEABLE_HUB_BACKGROUND_SETTING, defaultBackgroundType.value) .map { it.toCommunalBackgroundType() } .flowOn(bgDispatcher) override fun getSettingEnabledByUser(): Flow<Boolean> = userAwareSecureSettingsRepository .intSetting(Settings.Secure.GLANCEABLE_HUB_ENABLED, ENABLED_SETTING_DEFAULT) .map { it == 1 } .flowOn(bgDispatcher) private fun Int.toCommunalBackgroundType(): CommunalBackgroundType { return CommunalBackgroundType.entries.find { type -> type.value == this } ?: defaultBackgroundType } override fun getSettingEnabledByUser(user: UserInfo): Flow<Boolean> = secureSettings .observerFlow(userId = user.id, names = arrayOf(Settings.Secure.GLANCEABLE_HUB_ENABLED)) // Force an update .emitOnStart() .map { secureSettings.getIntForUser( Settings.Secure.GLANCEABLE_HUB_ENABLED, ENABLED_SETTING_DEFAULT, user.id, ) == 1 private fun Int.toWhenToStartHub(): WhenToStartHub { return when (this) { Settings.Secure.GLANCEABLE_HUB_START_NEVER -> WhenToStartHub.NEVER Settings.Secure.GLANCEABLE_HUB_START_CHARGING -> WhenToStartHub.WHILE_CHARGING Settings.Secure.GLANCEABLE_HUB_START_CHARGING_UPRIGHT -> WhenToStartHub.WHILE_CHARGING_AND_POSTURED Settings.Secure.GLANCEABLE_HUB_START_DOCKED -> WhenToStartHub.WHILE_DOCKED else -> WhenToStartHub.NEVER } } .flowOn(bgDispatcher) companion object { const val GLANCEABLE_HUB_BACKGROUND_SETTING = "glanceable_hub_background" Loading packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalSettingsInteractor.kt +3 −11 Original line number Diff line number Diff line Loading @@ -76,10 +76,7 @@ constructor( .stateIn(scope = bgScope, started = SharingStarted.Eagerly, initialValue = false) /** When to automatically start hub for the currently selected user. */ val whenToStartHub: Flow<WhenToStartHub> = userInteractor.selectedUserInfo.flatMapLatest { user -> repository.getWhenToStartHubState(user) } val whenToStartHub: Flow<WhenToStartHub> = repository.getWhenToStartHubState() /** Whether communal hub is allowed by device policy for the current user */ val allowedForCurrentUserByDevicePolicy: Flow<Boolean> = Loading @@ -88,10 +85,7 @@ constructor( } /** Whether the hub is enabled for the current user */ val settingEnabledForCurrentUser: Flow<Boolean> = userInteractor.selectedUserInfo.flatMapLatestConflated { user -> repository.getSettingEnabledByUser(user) } val settingEnabledForCurrentUser: Flow<Boolean> = repository.getSettingEnabledByUser() /** * Returns true if any glanceable hub functionality should be enabled via configs and flags. Loading Loading @@ -132,9 +126,7 @@ constructor( /** The type of background to use for the hub. Used to experiment with different backgrounds */ val communalBackground: Flow<CommunalBackgroundType> = userInteractor.selectedUserInfo .flatMapLatest { user -> repository.getBackground(user) } .flowOn(bgDispatcher) repository.getBackground().flowOn(bgDispatcher) private val workProfileUserInfoCallbackFlow: Flow<UserInfo?> = conflatedCallbackFlow { fun send(profiles: List<UserInfo>) { Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/data/repository/CommunalSettingsRepositoryImplTest.kt +4 −5 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.testKosmos import com.android.systemui.util.mockito.nullable import com.android.systemui.util.mockito.whenever import com.android.systemui.util.settings.fakeSettings import com.android.systemui.util.settings.data.repository.userAwareSecureSettingsRepository import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage import org.junit.After Loading Loading @@ -212,19 +212,18 @@ class CommunalSettingsRepositoryImplTest(flags: FlagsParameterization?) : SysuiT @DisableFlags(FLAG_GLANCEABLE_HUB_BLURRED_BACKGROUND) fun backgroundType_defaultValue() = kosmos.runTest { val backgroundType by collectLastValue(underTest.getBackground(PRIMARY_USER)) val backgroundType by collectLastValue(underTest.getBackground()) assertThat(backgroundType).isEqualTo(CommunalBackgroundType.ANIMATED) } @Test fun backgroundType_verifyAllValues() = kosmos.runTest { val backgroundType by collectLastValue(underTest.getBackground(PRIMARY_USER)) val backgroundType by collectLastValue(underTest.getBackground()) for (type in CommunalBackgroundType.entries) { fakeSettings.putIntForUser( kosmos.userAwareSecureSettingsRepository.setInt( GLANCEABLE_HUB_BACKGROUND_SETTING, type.value, PRIMARY_USER.id, ) assertWithMessage( "Expected $type when $GLANCEABLE_HUB_BACKGROUND_SETTING is set to" + Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/data/repository/DreamSettingsRepositoryImplTest.kt +23 −17 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.testKosmos import com.android.systemui.util.settings.fakeSettings import com.android.systemui.util.settings.data.repository.userAwareSecureSettingsRepository import com.google.common.truth.Truth.assertThat import org.junit.After import org.junit.Before Loading Loading @@ -68,6 +68,9 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { @After fun tearDown() { mContext.orCreateTestableResources.removeOverride( com.android.internal.R.bool.config_dreamsEnabledByDefault ) mContext.orCreateTestableResources.removeOverride( com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault ) Loading @@ -82,12 +85,11 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { @Test fun whenToDream_charging() = kosmos.runTest { val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) fakeSettings.putIntForUser( kosmos.userAwareSecureSettingsRepository.setInt( Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, 1, PRIMARY_USER.id, ) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_CHARGING) Loading @@ -101,19 +103,18 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { true, ) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_CHARGING) } @Test fun whenToDream_docked() = kosmos.runTest { val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) fakeSettings.putIntForUser( kosmos.userAwareSecureSettingsRepository.setInt( Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK, 1, PRIMARY_USER.id, ) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_DOCKED) Loading @@ -127,19 +128,18 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { true, ) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_DOCKED) } @Test fun whenToDream_postured() = kosmos.runTest { val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) fakeSettings.putIntForUser( kosmos.userAwareSecureSettingsRepository.setInt( Settings.Secure.SCREENSAVER_ACTIVATE_ON_POSTURED, 1, PRIMARY_USER.id, ) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_POSTURED) Loading @@ -153,7 +153,7 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { true, ) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_POSTURED) } Loading @@ -165,13 +165,19 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { true, ) fakeSettings.putBoolForUser(Settings.Secure.SCREENSAVER_ENABLED, false, PRIMARY_USER.id) kosmos.userAwareSecureSettingsRepository.setBoolean( Settings.Secure.SCREENSAVER_ENABLED, false, ) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) assertThat(whenToDreamState).isEqualTo(WhenToDream.NEVER) fakeSettings.putBoolForUser(Settings.Secure.SCREENSAVER_ENABLED, true, PRIMARY_USER.id) kosmos.userAwareSecureSettingsRepository.setBoolean( Settings.Secure.SCREENSAVER_ENABLED, true, ) assertThat(whenToDreamState).isEqualTo(WhenToDream.WHILE_POSTURED) } Loading @@ -179,7 +185,7 @@ class DreamSettingsRepositoryImplTest : SysuiTestCase() { @Test fun whenToDream_default() = kosmos.runTest { val whenToDreamState by collectLastValue(underTest.getWhenToDreamState(PRIMARY_USER)) val whenToDreamState by collectLastValue(underTest.getWhenToDreamState()) assertThat(whenToDreamState).isEqualTo(WhenToDream.NEVER) } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/lowlight/LowLightBehaviorCoreStartableTest.kt +10 −17 Original line number Diff line number Diff line Loading @@ -46,13 +46,13 @@ import com.android.systemui.lowlightclock.LowLightLogger import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest import com.android.systemui.power.domain.interactor.powerInteractor import com.android.systemui.res.R import com.android.systemui.settings.userTracker import com.android.systemui.testKosmos import com.android.systemui.user.data.repository.fakeUserRepository import com.android.systemui.user.domain.interactor.selectedUserInteractor import com.android.systemui.user.domain.interactor.userLockedInteractor import com.android.systemui.util.settings.fakeSettings import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.runBlocking import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -135,14 +135,12 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() { false, ) kosmos.lowLightSettingsRepository.setLowLightDisplayBehaviorEnabled( kosmos.userTracker.userInfo, true, ) runBlocking { kosmos.lowLightSettingsRepository.setLowLightDisplayBehaviorEnabled(true) kosmos.lowLightSettingsRepository.setLowLightDisplayBehavior( kosmos.userTracker.userInfo, LowLightDisplayBehavior.LOW_LIGHT_DREAM, LowLightDisplayBehavior.LOW_LIGHT_DREAM ) } kosmos.lowLightRepository.addAction(LowLightDisplayBehavior.LOW_LIGHT_DREAM, action) } Loading Loading @@ -183,10 +181,7 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() { @Test fun testSetAmbientLowLightWhenDisabledInLowLight() = kosmos.runTest { lowLightSettingsRepository.setLowLightDisplayBehaviorEnabled( userTracker.userInfo, false, ) lowLightSettingsRepository.setLowLightDisplayBehaviorEnabled(false) underTest.start() // Turn on screen Loading Loading @@ -254,8 +249,7 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() { kosmos.runTest { lowLightRepository.addAction(LowLightDisplayBehavior.SCREEN_OFF, action) lowLightSettingsRepository.setLowLightDisplayBehavior( userTracker.userInfo, LowLightDisplayBehavior.SCREEN_OFF, LowLightDisplayBehavior.SCREEN_OFF ) setDisplayOn(true) Loading @@ -269,8 +263,7 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() { kosmos.runTest { lowLightRepository.addAction(LowLightDisplayBehavior.SCREEN_OFF, action) lowLightSettingsRepository.setLowLightDisplayBehavior( userTracker.userInfo, LowLightDisplayBehavior.SCREEN_OFF, LowLightDisplayBehavior.SCREEN_OFF ) setDisplayOn(true) Loading
packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSettingsRepository.kt +42 −61 Original line number Diff line number Diff line Loading @@ -38,8 +38,7 @@ import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.flags.FeatureFlagsClassic import com.android.systemui.flags.Flags import com.android.systemui.util.kotlin.emitOnStart import com.android.systemui.util.settings.SecureSettings import com.android.systemui.util.settings.SettingsProxyExt.observerFlow import com.android.systemui.util.settings.repository.UserAwareSecureSettingsRepository import javax.inject.Inject import javax.inject.Named import kotlinx.coroutines.CoroutineDispatcher Loading @@ -59,13 +58,13 @@ interface CommunalSettingsRepository { fun setSuppressionReasons(reasons: List<SuppressionReason>) /** * Returns a[WhenToStartHub] for the specified user, indicating what state the device should be * in to automatically display the hub. * Returns a[WhenToStartHub] for the active user, indicating what state the device should be in * to automatically display the hub. */ fun getWhenToStartHubState(user: UserInfo): Flow<WhenToStartHub> fun getWhenToStartHubState(): Flow<WhenToStartHub> /** Returns whether glanceable hub is enabled by the current user. */ fun getSettingEnabledByUser(user: UserInfo): Flow<Boolean> /** Returns whether glanceable hub is enabled by the active user. */ fun getSettingEnabledByUser(): Flow<Boolean> /** * Returns true if any glanceable hub functionality should be enabled via configs and flags. Loading Loading @@ -95,8 +94,11 @@ interface CommunalSettingsRepository { /** Keyguard widgets enabled state by Device Policy Manager for the specified user. */ fun getAllowedByDevicePolicy(user: UserInfo): Flow<Boolean> /** The type of background to use for the hub. Used to experiment with different backgrounds. */ fun getBackground(user: UserInfo): Flow<CommunalBackgroundType> /** * The type of background to use for the hub for the active user. Used to experiment with * different backgrounds. */ fun getBackground(): Flow<CommunalBackgroundType> } @SysUISingleton Loading @@ -106,7 +108,7 @@ constructor( @Background private val bgDispatcher: CoroutineDispatcher, @Main private val resources: Resources, private val featureFlagsClassic: FeatureFlagsClassic, private val secureSettings: SecureSettings, private val userAwareSecureSettingsRepository: UserAwareSecureSettingsRepository, private val broadcastDispatcher: BroadcastDispatcher, private val devicePolicyManager: DevicePolicyManager, @Named(DEFAULT_BACKGROUND_TYPE) private val defaultBackgroundType: CommunalBackgroundType, Loading Loading @@ -143,33 +145,13 @@ constructor( glanceableHubV2() } override fun getWhenToStartHubState(user: UserInfo): Flow<WhenToStartHub> { override fun getWhenToStartHubState(): Flow<WhenToStartHub> { if (!getV2FlagEnabled()) { return MutableStateFlow(WhenToStartHub.NEVER) } return secureSettings .observerFlow( userId = user.id, names = arrayOf(Settings.Secure.WHEN_TO_START_GLANCEABLE_HUB), ) .emitOnStart() .map { when ( secureSettings.getIntForUser( Settings.Secure.WHEN_TO_START_GLANCEABLE_HUB, whenToStartHubByDefault, user.id, ) ) { Settings.Secure.GLANCEABLE_HUB_START_NEVER -> WhenToStartHub.NEVER Settings.Secure.GLANCEABLE_HUB_START_CHARGING -> WhenToStartHub.WHILE_CHARGING Settings.Secure.GLANCEABLE_HUB_START_CHARGING_UPRIGHT -> WhenToStartHub.WHILE_CHARGING_AND_POSTURED Settings.Secure.GLANCEABLE_HUB_START_DOCKED -> WhenToStartHub.WHILE_DOCKED else -> WhenToStartHub.NEVER } } return userAwareSecureSettingsRepository .intSetting(Settings.Secure.WHEN_TO_START_GLANCEABLE_HUB, whenToStartHubByDefault) .map { it.toWhenToStartHub() } .flowOn(bgDispatcher) } Loading @@ -186,34 +168,33 @@ constructor( .emitOnStart() .map { devicePolicyManager.areKeyguardWidgetsAllowed(user.id) } override fun getBackground(user: UserInfo): Flow<CommunalBackgroundType> = secureSettings .observerFlow(userId = user.id, names = arrayOf(GLANCEABLE_HUB_BACKGROUND_SETTING)) .emitOnStart() .map { val intType = secureSettings.getIntForUser( GLANCEABLE_HUB_BACKGROUND_SETTING, defaultBackgroundType.value, user.id, ) CommunalBackgroundType.entries.find { type -> type.value == intType } override fun getBackground(): Flow<CommunalBackgroundType> = userAwareSecureSettingsRepository .intSetting(GLANCEABLE_HUB_BACKGROUND_SETTING, defaultBackgroundType.value) .map { it.toCommunalBackgroundType() } .flowOn(bgDispatcher) override fun getSettingEnabledByUser(): Flow<Boolean> = userAwareSecureSettingsRepository .intSetting(Settings.Secure.GLANCEABLE_HUB_ENABLED, ENABLED_SETTING_DEFAULT) .map { it == 1 } .flowOn(bgDispatcher) private fun Int.toCommunalBackgroundType(): CommunalBackgroundType { return CommunalBackgroundType.entries.find { type -> type.value == this } ?: defaultBackgroundType } override fun getSettingEnabledByUser(user: UserInfo): Flow<Boolean> = secureSettings .observerFlow(userId = user.id, names = arrayOf(Settings.Secure.GLANCEABLE_HUB_ENABLED)) // Force an update .emitOnStart() .map { secureSettings.getIntForUser( Settings.Secure.GLANCEABLE_HUB_ENABLED, ENABLED_SETTING_DEFAULT, user.id, ) == 1 private fun Int.toWhenToStartHub(): WhenToStartHub { return when (this) { Settings.Secure.GLANCEABLE_HUB_START_NEVER -> WhenToStartHub.NEVER Settings.Secure.GLANCEABLE_HUB_START_CHARGING -> WhenToStartHub.WHILE_CHARGING Settings.Secure.GLANCEABLE_HUB_START_CHARGING_UPRIGHT -> WhenToStartHub.WHILE_CHARGING_AND_POSTURED Settings.Secure.GLANCEABLE_HUB_START_DOCKED -> WhenToStartHub.WHILE_DOCKED else -> WhenToStartHub.NEVER } } .flowOn(bgDispatcher) companion object { const val GLANCEABLE_HUB_BACKGROUND_SETTING = "glanceable_hub_background" Loading
packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalSettingsInteractor.kt +3 −11 Original line number Diff line number Diff line Loading @@ -76,10 +76,7 @@ constructor( .stateIn(scope = bgScope, started = SharingStarted.Eagerly, initialValue = false) /** When to automatically start hub for the currently selected user. */ val whenToStartHub: Flow<WhenToStartHub> = userInteractor.selectedUserInfo.flatMapLatest { user -> repository.getWhenToStartHubState(user) } val whenToStartHub: Flow<WhenToStartHub> = repository.getWhenToStartHubState() /** Whether communal hub is allowed by device policy for the current user */ val allowedForCurrentUserByDevicePolicy: Flow<Boolean> = Loading @@ -88,10 +85,7 @@ constructor( } /** Whether the hub is enabled for the current user */ val settingEnabledForCurrentUser: Flow<Boolean> = userInteractor.selectedUserInfo.flatMapLatestConflated { user -> repository.getSettingEnabledByUser(user) } val settingEnabledForCurrentUser: Flow<Boolean> = repository.getSettingEnabledByUser() /** * Returns true if any glanceable hub functionality should be enabled via configs and flags. Loading Loading @@ -132,9 +126,7 @@ constructor( /** The type of background to use for the hub. Used to experiment with different backgrounds */ val communalBackground: Flow<CommunalBackgroundType> = userInteractor.selectedUserInfo .flatMapLatest { user -> repository.getBackground(user) } .flowOn(bgDispatcher) repository.getBackground().flowOn(bgDispatcher) private val workProfileUserInfoCallbackFlow: Flow<UserInfo?> = conflatedCallbackFlow { fun send(profiles: List<UserInfo>) { Loading