summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-05-03 00:21:25 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-05-03 00:21:25 +0000
commitaa5e46e290e5cc94416dc6293cf7e96f285d93df (patch)
treeead2ec7915723213ccab32b3f167167fe0d8cd58
parent2a48aff161f420421813d2a4420a9cdb5f9cd9c1 (diff)
parent58cfffc6f21b56d45ba706efb57f975988020af4 (diff)
Merge "Convert LockscreenSmartspaceController.isWeatherEnabled to a flow" into main
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryModule.kt5
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepository.kt55
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardSmartspaceInteractor.kt1
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSection.kt24
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModel.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModel.kt13
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepositoryImplTest.kt83
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSectionTest.kt9
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModelTest.kt99
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardSmartspaceRepository.kt37
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepositoryKosmos.kt2
11 files changed, 301 insertions, 31 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryModule.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryModule.kt
index 6138330c2e76..3956901aaa88 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryModule.kt
@@ -76,4 +76,9 @@ interface KeyguardRepositoryModule {
@Binds fun trustRepository(impl: TrustRepositoryImpl): TrustRepository
@Binds fun keyguardClockRepository(impl: KeyguardClockRepositoryImpl): KeyguardClockRepository
+
+ @Binds
+ fun keyguardSmartspaceRepository(
+ impl: KeyguardSmartspaceRepositoryImpl
+ ): KeyguardSmartspaceRepository
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepository.kt
index afe9151ac7a0..956125ce372f 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepository.kt
@@ -16,19 +16,68 @@
package com.android.systemui.keyguard.data.repository
+import android.content.Context
+import android.provider.Settings
import android.view.View
import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Application
+import com.android.systemui.settings.UserTracker
+import com.android.systemui.util.settings.SecureSettings
+import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
import javax.inject.Inject
+import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.onStart
+import kotlinx.coroutines.flow.stateIn
+
+interface KeyguardSmartspaceRepository {
+ val bcSmartspaceVisibility: StateFlow<Int>
+ val isWeatherEnabled: StateFlow<Boolean>
+ fun setBcSmartspaceVisibility(visibility: Int)
+}
@SysUISingleton
-class KeyguardSmartspaceRepository @Inject constructor() {
+class KeyguardSmartspaceRepositoryImpl
+@Inject
+constructor(
+ context: Context,
+ private val secureSettings: SecureSettings,
+ private val userTracker: UserTracker,
+ @Application private val applicationScope: CoroutineScope,
+) : KeyguardSmartspaceRepository {
private val _bcSmartspaceVisibility: MutableStateFlow<Int> = MutableStateFlow(View.GONE)
- val bcSmartspaceVisibility: StateFlow<Int> = _bcSmartspaceVisibility.asStateFlow()
+ override val bcSmartspaceVisibility: StateFlow<Int> = _bcSmartspaceVisibility.asStateFlow()
+ val defaultValue =
+ context.resources.getBoolean(
+ com.android.internal.R.bool.config_lockscreenWeatherEnabledByDefault
+ )
+ override val isWeatherEnabled: StateFlow<Boolean> =
+ secureSettings
+ .observerFlow(
+ names = arrayOf(Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED),
+ userId = userTracker.userId,
+ )
+ .onStart { emit(Unit) }
+ .map { getLockscreenWeatherEnabled() }
+ .stateIn(
+ scope = applicationScope,
+ started = SharingStarted.WhileSubscribed(),
+ initialValue = getLockscreenWeatherEnabled()
+ )
- fun setBcSmartspaceVisibility(visibility: Int) {
+ override fun setBcSmartspaceVisibility(visibility: Int) {
_bcSmartspaceVisibility.value = visibility
}
+
+ private fun getLockscreenWeatherEnabled(): Boolean {
+ return secureSettings.getIntForUser(
+ Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED,
+ if (defaultValue) 1 else 0,
+ userTracker.userId
+ ) == 1
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardSmartspaceInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardSmartspaceInteractor.kt
index bb633b5169db..45a4b70a2535 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardSmartspaceInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardSmartspaceInteractor.kt
@@ -28,6 +28,7 @@ constructor(
private val keyguardSmartspaceRepository: KeyguardSmartspaceRepository,
) {
val bcSmartspaceVisibility: StateFlow<Int> = keyguardSmartspaceRepository.bcSmartspaceVisibility
+ val isWeatherEnabled: StateFlow<Boolean> = keyguardSmartspaceRepository.isWeatherEnabled
fun setBcSmartspaceVisibility(visibility: Int) {
keyguardSmartspaceRepository.setBcSmartspaceVisibility(visibility)
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSection.kt
index 9ec7a65cf240..487c2e918e5f 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSection.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSection.kt
@@ -42,10 +42,10 @@ constructor(
val context: Context,
val keyguardClockViewModel: KeyguardClockViewModel,
val keyguardSmartspaceViewModel: KeyguardSmartspaceViewModel,
- val keyguardSmartspaceInteractor: KeyguardSmartspaceInteractor,
+ private val keyguardSmartspaceInteractor: KeyguardSmartspaceInteractor,
val smartspaceController: LockscreenSmartspaceController,
val keyguardUnlockAnimationController: KeyguardUnlockAnimationController,
- val blueprintInteractor: Lazy<KeyguardBlueprintInteractor>,
+ private val blueprintInteractor: Lazy<KeyguardBlueprintInteractor>,
) : KeyguardSection() {
private var smartspaceView: View? = null
private var weatherView: View? = null
@@ -61,12 +61,10 @@ constructor(
weatherView = smartspaceController.buildAndConnectWeatherView(constraintLayout)
dateView = smartspaceController.buildAndConnectDateView(constraintLayout)
pastVisibility = smartspaceView?.visibility ?: View.GONE
- if (keyguardSmartspaceViewModel.isSmartspaceEnabled) {
- constraintLayout.addView(smartspaceView)
- if (keyguardSmartspaceViewModel.isDateWeatherDecoupled) {
- constraintLayout.addView(weatherView)
- constraintLayout.addView(dateView)
- }
+ constraintLayout.addView(smartspaceView)
+ if (keyguardSmartspaceViewModel.isDateWeatherDecoupled) {
+ constraintLayout.addView(weatherView)
+ constraintLayout.addView(dateView)
}
keyguardUnlockAnimationController.lockscreenSmartspace = smartspaceView
smartspaceVisibilityListener = OnGlobalLayoutListener {
@@ -205,13 +203,9 @@ constructor(
constraintSet.apply {
val weatherVisibility =
- when (keyguardClockViewModel.hasCustomWeatherDataDisplay.value) {
- true -> ConstraintSet.GONE
- false ->
- when (keyguardSmartspaceViewModel.isWeatherEnabled) {
- true -> ConstraintSet.VISIBLE
- false -> ConstraintSet.GONE
- }
+ when (keyguardSmartspaceViewModel.isWeatherVisible.value) {
+ true -> ConstraintSet.VISIBLE
+ false -> ConstraintSet.GONE
}
setVisibility(sharedR.id.weather_smartspace_view, weatherVisibility)
setAlpha(
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModel.kt
index 1f544c140d2e..198e9f26384a 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModel.kt
@@ -84,8 +84,8 @@ constructor(
combine(
isLargeClockVisible,
currentClock,
- ) { isLargeClock, clock ->
- clock?.let { clock ->
+ ) { isLargeClock, currentClock ->
+ currentClock?.let { clock ->
val face = if (isLargeClock) clock.largeClock else clock.smallClock
face.config.hasCustomWeatherDataDisplay
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModel.kt
index dc053aad7e2b..c0b1f9543abf 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModel.kt
@@ -26,6 +26,7 @@ import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -41,8 +42,8 @@ constructor(
/** Whether the smartspace section is available in the build. */
val isSmartspaceEnabled: Boolean = smartspaceController.isEnabled()
/** Whether the weather area is available in the build. */
- // TODO(b/317891876): this should be a Flow as the value can change over time.
- val isWeatherEnabled: Boolean = smartspaceController.isWeatherEnabled()
+ private val isWeatherEnabled: StateFlow<Boolean> = smartspaceInteractor.isWeatherEnabled
+
/** Whether the data and weather areas are decoupled in the build. */
val isDateWeatherDecoupled: Boolean = smartspaceController.isDateWeatherDecoupled()
@@ -58,8 +59,10 @@ constructor(
/** Whether the weather area should be visible. */
val isWeatherVisible: StateFlow<Boolean> =
- keyguardClockViewModel.hasCustomWeatherDataDisplay
- .map { clockIncludesCustomWeatherDisplay ->
+ combine(
+ isWeatherEnabled,
+ keyguardClockViewModel.hasCustomWeatherDataDisplay,
+ ) { isWeatherEnabled, clockIncludesCustomWeatherDisplay ->
isWeatherVisible(
clockIncludesCustomWeatherDisplay = clockIncludesCustomWeatherDisplay,
isWeatherEnabled = isWeatherEnabled,
@@ -72,7 +75,7 @@ constructor(
isWeatherVisible(
clockIncludesCustomWeatherDisplay =
keyguardClockViewModel.hasCustomWeatherDataDisplay.value,
- isWeatherEnabled = isWeatherEnabled,
+ isWeatherEnabled = smartspaceInteractor.isWeatherEnabled.value,
)
)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepositoryImplTest.kt
new file mode 100644
index 000000000000..a320845be6e4
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepositoryImplTest.kt
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyguard.data.repository
+
+import android.provider.Settings
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.settings.FakeUserTracker
+import com.android.systemui.util.settings.FakeSettings
+import com.google.common.truth.Truth
+import kotlin.test.Test
+import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.test.StandardTestDispatcher
+import kotlinx.coroutines.test.TestCoroutineScheduler
+import kotlinx.coroutines.test.TestScope
+import kotlinx.coroutines.test.runTest
+import org.junit.Before
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.mockito.MockitoAnnotations
+
+@RunWith(JUnit4::class)
+@SmallTest
+class KeyguardSmartspaceRepositoryImplTest : SysuiTestCase() {
+
+ private lateinit var scheduler: TestCoroutineScheduler
+ private lateinit var dispatcher: CoroutineDispatcher
+ private lateinit var scope: TestScope
+
+ private lateinit var underTest: KeyguardSmartspaceRepository
+ private lateinit var fakeSettings: FakeSettings
+ private lateinit var fakeUserTracker: FakeUserTracker
+
+ @Before
+ fun setup() {
+ MockitoAnnotations.initMocks(this)
+ fakeSettings = FakeSettings()
+ fakeUserTracker = FakeUserTracker()
+ fakeSettings.userId = fakeUserTracker.userId
+ scheduler = TestCoroutineScheduler()
+ dispatcher = StandardTestDispatcher(scheduler)
+ scope = TestScope(dispatcher)
+ underTest =
+ KeyguardSmartspaceRepositoryImpl(
+ context = context,
+ secureSettings = fakeSettings,
+ userTracker = fakeUserTracker,
+ applicationScope = scope.backgroundScope,
+ )
+ }
+
+ @Test
+ fun testWeatherEnabled_true() =
+ scope.runTest {
+ fakeSettings.putInt(Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED, 1)
+ val value = collectLastValue(underTest.isWeatherEnabled)
+ Truth.assertThat(value()).isEqualTo(true)
+ }
+
+ @Test
+ fun testWeatherEnabled_false() =
+ scope.runTest {
+ fakeSettings.putInt(Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED, 0)
+
+ val value = collectLastValue(underTest.isWeatherEnabled)
+ Truth.assertThat(value()).isEqualTo(false)
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSectionTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSectionTest.kt
index 8eccde7d6cb8..be10b82193c1 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSectionTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSectionTest.kt
@@ -64,6 +64,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
private val clockShouldBeCentered = MutableStateFlow(false)
private val hasCustomWeatherDataDisplay = MutableStateFlow(false)
+ private val isWeatherVisibleFlow = MutableStateFlow(false)
@Before
fun setup() {
@@ -89,7 +90,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
.thenReturn(hasCustomWeatherDataDisplay)
whenever(keyguardClockViewModel.clockShouldBeCentered).thenReturn(clockShouldBeCentered)
whenever(keyguardSmartspaceViewModel.isSmartspaceEnabled).thenReturn(true)
-
+ whenever(keyguardSmartspaceViewModel.isWeatherVisible).thenReturn(isWeatherVisibleFlow)
constraintSet = ConstraintSet()
}
@@ -124,7 +125,6 @@ class SmartspaceSectionTest : SysuiTestCase() {
@Test
fun testConstraintsWhenNotHasCustomWeatherDataDisplay() {
whenever(keyguardSmartspaceViewModel.isDateWeatherDecoupled).thenReturn(true)
- hasCustomWeatherDataDisplay.value = false
underTest.addViews(constraintLayout)
underTest.applyConstraints(constraintSet)
assertWeatherSmartspaceConstrains(constraintSet)
@@ -149,13 +149,12 @@ class SmartspaceSectionTest : SysuiTestCase() {
@Test
fun testNormalDateWeatherVisibility() {
- hasCustomWeatherDataDisplay.value = false
- whenever(keyguardSmartspaceViewModel.isWeatherEnabled).thenReturn(true)
+ isWeatherVisibleFlow.value = true
underTest.addViews(constraintLayout)
underTest.applyConstraints(constraintSet)
assertThat(constraintSet.getVisibility(weatherView.id)).isEqualTo(VISIBLE)
- whenever(keyguardSmartspaceViewModel.isWeatherEnabled).thenReturn(false)
+ isWeatherVisibleFlow.value = false
underTest.applyConstraints(constraintSet)
assertThat(constraintSet.getVisibility(weatherView.id)).isEqualTo(GONE)
assertThat(constraintSet.getVisibility(dateView.id)).isEqualTo(VISIBLE)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModelTest.kt
new file mode 100644
index 000000000000..78f4dccd18a3
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModelTest.kt
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyguard.ui.viewmodel
+
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.keyguard.data.repository.fakeKeyguardClockRepository
+import com.android.systemui.keyguard.data.repository.keyguardClockRepository
+import com.android.systemui.keyguard.data.repository.keyguardSmartspaceRepository
+import com.android.systemui.keyguard.shared.model.ClockSize
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.plugins.clocks.ClockController
+import com.android.systemui.testKosmos
+import com.android.systemui.util.mockito.whenever
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.test.runTest
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.mockito.Answers
+import org.mockito.Mock
+import org.mockito.MockitoAnnotations
+
+@SmallTest
+@RunWith(JUnit4::class)
+class KeyguardSmartspaceViewModelTest : SysuiTestCase() {
+ val kosmos = testKosmos()
+ val testScope = kosmos.testScope
+ val underTest = kosmos.keyguardSmartspaceViewModel
+ val res = context.resources
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS) private lateinit var clockController: ClockController
+
+ @Before
+ fun setup() {
+ MockitoAnnotations.initMocks(this)
+ kosmos.fakeKeyguardClockRepository.setCurrentClock(clockController)
+ }
+
+ @Test
+ fun testWhenWeatherEnabled_notCustomWeatherDataDisplay_isWeatherVisible_shouldBeTrue() =
+ testScope.runTest {
+ val isWeatherVisible by collectLastValue(underTest.isWeatherVisible)
+ whenever(clockController.largeClock.config.hasCustomWeatherDataDisplay)
+ .thenReturn(false)
+
+ with(kosmos) {
+ keyguardSmartspaceRepository.setIsWeatherEnabled(true)
+ keyguardClockRepository.setClockSize(ClockSize.LARGE)
+ }
+
+ assertThat(isWeatherVisible).isEqualTo(true)
+ }
+
+ @Test
+ fun testWhenWeatherEnabled_hasCustomWeatherDataDisplay_isWeatherVisible_shouldBeFalse() =
+ testScope.runTest {
+ val isWeatherVisible by collectLastValue(underTest.isWeatherVisible)
+ whenever(clockController.largeClock.config.hasCustomWeatherDataDisplay).thenReturn(true)
+
+ with(kosmos) {
+ keyguardSmartspaceRepository.setIsWeatherEnabled(true)
+ keyguardClockRepository.setClockSize(ClockSize.LARGE)
+ }
+
+ assertThat(isWeatherVisible).isEqualTo(false)
+ }
+
+ @Test
+ fun testWhenWeatherEnabled_notCustomWeatherDataDisplay_notIsWeatherVisible_shouldBeFalse() =
+ testScope.runTest {
+ val isWeatherVisible by collectLastValue(underTest.isWeatherVisible)
+ whenever(clockController.largeClock.config.hasCustomWeatherDataDisplay)
+ .thenReturn(false)
+
+ with(kosmos) {
+ keyguardSmartspaceRepository.setIsWeatherEnabled(false)
+ keyguardClockRepository.setClockSize(ClockSize.LARGE)
+ }
+
+ assertThat(isWeatherVisible).isEqualTo(false)
+ }
+}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardSmartspaceRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardSmartspaceRepository.kt
new file mode 100644
index 000000000000..42cb150c572b
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardSmartspaceRepository.kt
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyguard.data.repository
+
+import android.view.View.GONE
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+
+class FakeKeyguardSmartspaceRepository : KeyguardSmartspaceRepository {
+
+ private val _bcSmartspaceVisibility = MutableStateFlow(GONE)
+ override val bcSmartspaceVisibility: StateFlow<Int> = _bcSmartspaceVisibility
+ private val _isWeatherEnabled = MutableStateFlow(true)
+ override val isWeatherEnabled: StateFlow<Boolean> = _isWeatherEnabled
+
+ override fun setBcSmartspaceVisibility(visibility: Int) {
+ _bcSmartspaceVisibility.value = visibility
+ }
+
+ fun setIsWeatherEnabled(isEnabled: Boolean) {
+ _isWeatherEnabled.value = isEnabled
+ }
+}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepositoryKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepositoryKosmos.kt
index dc7103f2c560..2949452f9ab0 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepositoryKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/KeyguardSmartspaceRepositoryKosmos.kt
@@ -18,4 +18,4 @@ package com.android.systemui.keyguard.data.repository
import com.android.systemui.kosmos.Kosmos
-val Kosmos.keyguardSmartspaceRepository by Kosmos.Fixture { KeyguardSmartspaceRepository() }
+val Kosmos.keyguardSmartspaceRepository by Kosmos.Fixture { FakeKeyguardSmartspaceRepository() }