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

Commit 38baf5e2 authored by Xiaowen Lei's avatar Xiaowen Lei
Browse files

Switch to CommunalSmartspaceController for hub mode live activities.

Flag: ACONFIG com.android.systemui.communal_hub DEVELOPMENT
Fix: 314203588
Test: CommunalInteractorTest,CommunalEditModeViewModelTest,CommunalViewModelTest
Test: Trigger timer on hub mode: go/enable-glanceable-hub#bookmark=id.ehm3r6mv8vps
Change-Id: Id301d41c6fb5a628c14a3cd58c3edfbb46361b8e
parent 8b96b1b8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ class CommunalInteractorTest : SysuiTestCase() {
            whenever(target1.remoteViews).thenReturn(mock(RemoteViews::class.java))

            val targets = listOf(target1, target2, target3)
            smartspaceRepository.setLockscreenSmartspaceTargets(targets)
            smartspaceRepository.setCommunalSmartspaceTargets(targets)

            val smartspaceContent by collectLastValue(underTest.smartspaceContent)
            assertThat(smartspaceContent?.size).isEqualTo(1)
+1 −1
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {
            whenever(target.smartspaceTargetId).thenReturn("target")
            whenever(target.featureType).thenReturn(SmartspaceTarget.FEATURE_TIMER)
            whenever(target.remoteViews).thenReturn(Mockito.mock(RemoteViews::class.java))
            smartspaceRepository.setLockscreenSmartspaceTargets(listOf(target))
            smartspaceRepository.setCommunalSmartspaceTargets(listOf(target))

            // Media playing.
            mediaRepository.mediaPlaying.value = true
+1 −1
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ class CommunalViewModelTest : SysuiTestCase() {
            whenever(target.smartspaceTargetId).thenReturn("target")
            whenever(target.featureType).thenReturn(SmartspaceTarget.FEATURE_TIMER)
            whenever(target.remoteViews).thenReturn(Mockito.mock(RemoteViews::class.java))
            smartspaceRepository.setLockscreenSmartspaceTargets(listOf(target))
            smartspaceRepository.setCommunalSmartspaceTargets(listOf(target))

            // Media playing.
            mediaRepository.mediaPlaying.value = true
+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ constructor(
        if (!smartspaceRepository.isSmartspaceRemoteViewsEnabled) {
            flowOf(emptyList())
        } else {
            smartspaceRepository.lockscreenSmartspaceTargets.map { targets ->
            smartspaceRepository.communalSmartspaceTargets.map { targets ->
                targets
                    .filter { target ->
                        target.featureType == SmartspaceTarget.FEATURE_TIMER &&
+11 −11
Original line number Diff line number Diff line
@@ -19,9 +19,9 @@ package com.android.systemui.smartspace.data.repository
import android.app.smartspace.SmartspaceTarget
import android.os.Parcelable
import android.widget.RemoteViews
import com.android.systemui.communal.smartspace.CommunalSmartspaceController
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.plugins.BcSmartspaceDataPlugin
import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
@@ -32,37 +32,37 @@ interface SmartspaceRepository {
    /** Whether [RemoteViews] are passed through smartspace targets. */
    val isSmartspaceRemoteViewsEnabled: Boolean

    /** Smartspace targets for the lockscreen surface. */
    val lockscreenSmartspaceTargets: Flow<List<SmartspaceTarget>>
    /** Smartspace targets for the communal surface. */
    val communalSmartspaceTargets: Flow<List<SmartspaceTarget>>
}

@SysUISingleton
class SmartspaceRepositoryImpl
@Inject
constructor(
    private val lockscreenSmartspaceController: LockscreenSmartspaceController,
    private val communalSmartspaceController: CommunalSmartspaceController,
) : SmartspaceRepository, BcSmartspaceDataPlugin.SmartspaceTargetListener {

    override val isSmartspaceRemoteViewsEnabled: Boolean
        get() = android.app.smartspace.flags.Flags.remoteViews()

    private val _lockscreenSmartspaceTargets: MutableStateFlow<List<SmartspaceTarget>> =
    private val _communalSmartspaceTargets: MutableStateFlow<List<SmartspaceTarget>> =
        MutableStateFlow(emptyList())
    override val lockscreenSmartspaceTargets: Flow<List<SmartspaceTarget>> =
        _lockscreenSmartspaceTargets
    override val communalSmartspaceTargets: Flow<List<SmartspaceTarget>> =
        _communalSmartspaceTargets
            .onStart {
                lockscreenSmartspaceController.addListener(listener = this@SmartspaceRepositoryImpl)
                communalSmartspaceController.addListener(listener = this@SmartspaceRepositoryImpl)
            }
            .onCompletion {
                lockscreenSmartspaceController.removeListener(
                communalSmartspaceController.removeListener(
                    listener = this@SmartspaceRepositoryImpl
                )
            }

    override fun onSmartspaceTargetsUpdated(targetsNullable: MutableList<out Parcelable>?) {
        targetsNullable?.let { targets ->
            _lockscreenSmartspaceTargets.value = targets.filterIsInstance<SmartspaceTarget>()
            _communalSmartspaceTargets.value = targets.filterIsInstance<SmartspaceTarget>()
        }
            ?: run { _lockscreenSmartspaceTargets.value = emptyList() }
            ?: run { _communalSmartspaceTargets.value = emptyList() }
    }
}
Loading