Loading packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/SmartspaceViewModelTest.kt +23 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository import com.android.systemui.kosmos.testScope import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest Loading @@ -41,6 +42,7 @@ class SmartspaceViewModelTest : SysuiTestCase() { private val testScope = kosmos.testScope private val powerInteractor = kosmos.powerInteractor private val fakeKeyguardRepository = kosmos.fakeKeyguardRepository private val smartspaceViewModelFactory = kosmos.smartspaceViewModelFactory private lateinit var underTest: SmartspaceViewModel Loading Loading @@ -100,4 +102,25 @@ class SmartspaceViewModelTest : SysuiTestCase() { assertThat(isAwake).isNull() } @Test fun generalView_dozeTimeTick_aodTimeTick() = testScope.runTest { underTest = smartspaceViewModelFactory.create(SmartspaceViewModel.SURFACE_GENERAL_VIEW) fakeKeyguardRepository.dozeTimeTick() val dozeTimeTick by collectLastValue(underTest.aodTimeTick) assertThat(dozeTimeTick).isEqualTo(1) } @Test fun generalView_noDozeTimeTick_noAodTimeTick() = testScope.runTest { underTest = smartspaceViewModelFactory.create(SmartspaceViewModel.SURFACE_GENERAL_VIEW) val dozeTimeTick by collectLastValue(underTest.aodTimeTick) assertThat(dozeTimeTick).isEqualTo(0) } } packages/SystemUI/src/com/android/systemui/smartspace/ui/binder/SmartspaceViewBinder.kt +6 −1 Original line number Diff line number Diff line Loading @@ -19,10 +19,10 @@ package com.android.systemui.smartspace.ui.binder import android.view.View import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle import com.android.app.tracing.coroutines.launchTraced as launch import com.android.systemui.lifecycle.repeatWhenAttached import com.android.systemui.plugins.BcSmartspaceDataPlugin.SmartspaceView import com.android.systemui.smartspace.ui.viewmodel.SmartspaceViewModel import com.android.app.tracing.coroutines.launchTraced as launch /** Binds the view and view-model for the smartspace. */ object SmartspaceViewBinder { Loading @@ -30,6 +30,7 @@ object SmartspaceViewBinder { /** Binds the view and view-model for the smartspace. */ fun bind( smartspaceView: SmartspaceView, refreshInvoker: () -> Unit, viewModel: SmartspaceViewModel, ) { val view = smartspaceView as View Loading @@ -39,6 +40,10 @@ object SmartspaceViewBinder { // Observe screen on/off changes viewModel.isAwake.collect { isAwake -> smartspaceView.setScreenOn(isAwake) } } launch { // Observe aod tick tick event viewModel.aodTimeTick.collect { refreshInvoker.invoke() } } } } } Loading packages/SystemUI/src/com/android/systemui/smartspace/ui/viewmodel/SmartspaceViewModel.kt +5 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.smartspace.ui.viewmodel import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor import com.android.systemui.power.domain.interactor.PowerInteractor import dagger.assisted.Assisted import dagger.assisted.AssistedFactory Loading @@ -27,6 +28,7 @@ class SmartspaceViewModel @AssistedInject constructor( powerInteractor: PowerInteractor, keyguardInteractor: KeyguardInteractor, @Assisted val surfaceName: String, ) { Loading @@ -34,6 +36,9 @@ constructor( val isAwake: Flow<Boolean> = powerInteractor.isAwake.filter { surfaceName != SURFACE_WEATHER_VIEW } /** Time tick flow */ val aodTimeTick: Flow<Long> = keyguardInteractor.dozeTimeTick @AssistedFactory interface Factory { fun create(surfaceName: String): SmartspaceViewModel Loading packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +8 −2 Original line number Diff line number Diff line Loading @@ -143,6 +143,8 @@ constructor( private var managedUserHandle: UserHandle? = null private var mSplitShadeEnabled = false private val refreshInvoker: () -> Unit = { session?.requestSmartspaceUpdate() } var suppressDisconnects = false set(value) { field = value Loading Loading @@ -346,7 +348,7 @@ constructor( surfaceName = SmartspaceViewModel.SURFACE_DATE_VIEW, parent = parent, plugin = datePlugin, isLargeClock = isLargeClock isLargeClock = isLargeClock, ) connectSession() Loading Loading @@ -460,7 +462,11 @@ constructor( if (smartspaceLockscreenViewmodel()) { val viewModel = smartspaceViewModelFactory.create(surfaceName) SmartspaceViewBinder.bind(smartspaceView = ssView, viewModel = viewModel) SmartspaceViewBinder.bind( smartspaceView = ssView, refreshInvoker = refreshInvoker, viewModel = viewModel, ) } } } Loading packages/SystemUI/tests/utils/src/com/android/systemui/smartspace/viewmodel/SmartspaceViewModelKosmos.kt +3 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.smartspace.viewmodel import com.android.systemui.keyguard.domain.interactor.keyguardInteractor import com.android.systemui.kosmos.Kosmos import com.android.systemui.power.domain.interactor.powerInteractor import com.android.systemui.smartspace.ui.viewmodel.SmartspaceViewModel Loading @@ -26,7 +27,8 @@ val Kosmos.smartspaceViewModelFactory by override fun create(surfaceName: String): SmartspaceViewModel { return SmartspaceViewModel( powerInteractor = powerInteractor, surfaceName = surfaceName keyguardInteractor = keyguardInteractor, surfaceName = surfaceName, ) } } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/SmartspaceViewModelTest.kt +23 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository import com.android.systemui.kosmos.testScope import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest Loading @@ -41,6 +42,7 @@ class SmartspaceViewModelTest : SysuiTestCase() { private val testScope = kosmos.testScope private val powerInteractor = kosmos.powerInteractor private val fakeKeyguardRepository = kosmos.fakeKeyguardRepository private val smartspaceViewModelFactory = kosmos.smartspaceViewModelFactory private lateinit var underTest: SmartspaceViewModel Loading Loading @@ -100,4 +102,25 @@ class SmartspaceViewModelTest : SysuiTestCase() { assertThat(isAwake).isNull() } @Test fun generalView_dozeTimeTick_aodTimeTick() = testScope.runTest { underTest = smartspaceViewModelFactory.create(SmartspaceViewModel.SURFACE_GENERAL_VIEW) fakeKeyguardRepository.dozeTimeTick() val dozeTimeTick by collectLastValue(underTest.aodTimeTick) assertThat(dozeTimeTick).isEqualTo(1) } @Test fun generalView_noDozeTimeTick_noAodTimeTick() = testScope.runTest { underTest = smartspaceViewModelFactory.create(SmartspaceViewModel.SURFACE_GENERAL_VIEW) val dozeTimeTick by collectLastValue(underTest.aodTimeTick) assertThat(dozeTimeTick).isEqualTo(0) } }
packages/SystemUI/src/com/android/systemui/smartspace/ui/binder/SmartspaceViewBinder.kt +6 −1 Original line number Diff line number Diff line Loading @@ -19,10 +19,10 @@ package com.android.systemui.smartspace.ui.binder import android.view.View import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle import com.android.app.tracing.coroutines.launchTraced as launch import com.android.systemui.lifecycle.repeatWhenAttached import com.android.systemui.plugins.BcSmartspaceDataPlugin.SmartspaceView import com.android.systemui.smartspace.ui.viewmodel.SmartspaceViewModel import com.android.app.tracing.coroutines.launchTraced as launch /** Binds the view and view-model for the smartspace. */ object SmartspaceViewBinder { Loading @@ -30,6 +30,7 @@ object SmartspaceViewBinder { /** Binds the view and view-model for the smartspace. */ fun bind( smartspaceView: SmartspaceView, refreshInvoker: () -> Unit, viewModel: SmartspaceViewModel, ) { val view = smartspaceView as View Loading @@ -39,6 +40,10 @@ object SmartspaceViewBinder { // Observe screen on/off changes viewModel.isAwake.collect { isAwake -> smartspaceView.setScreenOn(isAwake) } } launch { // Observe aod tick tick event viewModel.aodTimeTick.collect { refreshInvoker.invoke() } } } } } Loading
packages/SystemUI/src/com/android/systemui/smartspace/ui/viewmodel/SmartspaceViewModel.kt +5 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.smartspace.ui.viewmodel import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor import com.android.systemui.power.domain.interactor.PowerInteractor import dagger.assisted.Assisted import dagger.assisted.AssistedFactory Loading @@ -27,6 +28,7 @@ class SmartspaceViewModel @AssistedInject constructor( powerInteractor: PowerInteractor, keyguardInteractor: KeyguardInteractor, @Assisted val surfaceName: String, ) { Loading @@ -34,6 +36,9 @@ constructor( val isAwake: Flow<Boolean> = powerInteractor.isAwake.filter { surfaceName != SURFACE_WEATHER_VIEW } /** Time tick flow */ val aodTimeTick: Flow<Long> = keyguardInteractor.dozeTimeTick @AssistedFactory interface Factory { fun create(surfaceName: String): SmartspaceViewModel Loading
packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +8 −2 Original line number Diff line number Diff line Loading @@ -143,6 +143,8 @@ constructor( private var managedUserHandle: UserHandle? = null private var mSplitShadeEnabled = false private val refreshInvoker: () -> Unit = { session?.requestSmartspaceUpdate() } var suppressDisconnects = false set(value) { field = value Loading Loading @@ -346,7 +348,7 @@ constructor( surfaceName = SmartspaceViewModel.SURFACE_DATE_VIEW, parent = parent, plugin = datePlugin, isLargeClock = isLargeClock isLargeClock = isLargeClock, ) connectSession() Loading Loading @@ -460,7 +462,11 @@ constructor( if (smartspaceLockscreenViewmodel()) { val viewModel = smartspaceViewModelFactory.create(surfaceName) SmartspaceViewBinder.bind(smartspaceView = ssView, viewModel = viewModel) SmartspaceViewBinder.bind( smartspaceView = ssView, refreshInvoker = refreshInvoker, viewModel = viewModel, ) } } } Loading
packages/SystemUI/tests/utils/src/com/android/systemui/smartspace/viewmodel/SmartspaceViewModelKosmos.kt +3 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.smartspace.viewmodel import com.android.systemui.keyguard.domain.interactor.keyguardInteractor import com.android.systemui.kosmos.Kosmos import com.android.systemui.power.domain.interactor.powerInteractor import com.android.systemui.smartspace.ui.viewmodel.SmartspaceViewModel Loading @@ -26,7 +27,8 @@ val Kosmos.smartspaceViewModelFactory by override fun create(surfaceName: String): SmartspaceViewModel { return SmartspaceViewModel( powerInteractor = powerInteractor, surfaceName = surfaceName keyguardInteractor = keyguardInteractor, surfaceName = surfaceName, ) } } Loading