Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 555573bf authored by Liam, Lee Pong Lam's avatar Liam, Lee Pong Lam
Browse files

Handle doze time tick for smartspace

Found that doze time tick is missing after keyguard refactor

Bug: 406664072
Flag: EXEMPT bugfix
Test: Unit test/ manual
Change-Id: Ia2426ee6ba8dd1cec60cf114b7c7afac97279dfb
parent 91f39e34
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -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
@@ -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
@@ -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)
        }
}
+6 −1
Original line number Diff line number Diff line
@@ -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 {
@@ -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
@@ -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() }
                }
            }
        }
    }
+5 −0
Original line number Diff line number Diff line
@@ -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
@@ -27,6 +28,7 @@ class SmartspaceViewModel
@AssistedInject
constructor(
    powerInteractor: PowerInteractor,
    keyguardInteractor: KeyguardInteractor,
    @Assisted val surfaceName: String,
) {

@@ -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
+8 −2
Original line number Diff line number Diff line
@@ -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
@@ -346,7 +348,7 @@ constructor(
                surfaceName = SmartspaceViewModel.SURFACE_DATE_VIEW,
                parent = parent,
                plugin = datePlugin,
                isLargeClock = isLargeClock
                isLargeClock = isLargeClock,
            )
        connectSession()

@@ -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,
                )
            }
        }
    }
+3 −1
Original line number Diff line number Diff line
@@ -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
@@ -26,7 +27,8 @@ val Kosmos.smartspaceViewModelFactory by
            override fun create(surfaceName: String): SmartspaceViewModel {
                return SmartspaceViewModel(
                    powerInteractor = powerInteractor,
                    surfaceName = surfaceName
                    keyguardInteractor = keyguardInteractor,
                    surfaceName = surfaceName,
                )
            }
        }