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

Commit 262c84cf authored by Franciszek Juras's avatar Franciszek Juras
Browse files

Move StateFlow to ViewModel scope

Follow up to ag/33983794.
After making KeyguardStatusBarViewModel activateable, move collection
of isVisible StateFlow to viewmodel's activation scope.

Test: atest KeyguardStatusBarViewModelTest
Test: manual - Sign out button visible on Keyguard's status bar
Flag: com.android.systemui.sign_out_button_on_keyguard_status_bar
Bug: 392052370
Change-Id: I8762cda73fe70ca1300584a144b04f1cf69c141c
parent 16b177a4
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -92,7 +92,6 @@ class KeyguardStatusBarViewModelTest(flags: FlagsParameterization) : SysuiTestCa
    fun setup() {
        underTest =
            KeyguardStatusBarViewModel(
                testScope.backgroundScope,
                headsUpNotificationInteractor,
                kosmos.sceneInteractor,
                keyguardInteractor,
+27 −20
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.ui.viewmodel

import com.android.systemui.Flags
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.lifecycle.HydratedActivatable
import com.android.systemui.scene.domain.interactor.SceneInteractor
@@ -33,15 +32,16 @@ import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChang
import com.android.systemui.user.domain.interactor.UserLogoutInteractor
import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

/**
 * A view model for the status bar displayed on keyguard (lockscreen).
@@ -55,9 +55,8 @@ import kotlinx.coroutines.flow.stateIn
class KeyguardStatusBarViewModel
@Inject
constructor(
    @Application scope: CoroutineScope,
    headsUpNotificationInteractor: HeadsUpNotificationInteractor,
    sceneInteractor: SceneInteractor,
    private val sceneInteractor: SceneInteractor,
    private val keyguardInteractor: KeyguardInteractor,
    keyguardStatusBarInteractor: KeyguardStatusBarInteractor,
    private val userLogoutInteractor: UserLogoutInteractor,
@@ -71,8 +70,13 @@ constructor(
            flowOf(false)
        }

    private val _isVisible = MutableStateFlow(false)
    /** True if this view should be visible and false otherwise. */
    val isVisible: StateFlow<Boolean> =
    val isVisible: StateFlow<Boolean> = _isVisible.asStateFlow()

    override suspend fun onActivated() {
        coroutineScope {
            launch {
                combine(
                        sceneInteractor.currentScene,
                        sceneInteractor.currentOverlays,
@@ -86,7 +90,10 @@ constructor(
                            !isDozing &&
                            !showHeadsUpStatusBar
                    }
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)
                    .collect { _isVisible.value = it }
            }
        }
    }

    /** True if the device's battery is currently charging and false otherwise. */
    // Note: Never make this an eagerly-started state flow so that the callback is removed when the
+0 −2
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.ui.viewmodel

import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.statusbar.domain.interactor.keyguardStatusBarInteractor
import com.android.systemui.statusbar.notification.stack.domain.interactor.headsUpNotificationInteractor
@@ -28,7 +27,6 @@ import com.android.systemui.user.domain.interactor.userLogoutInteractor
val Kosmos.keyguardStatusBarViewModel: KeyguardStatusBarViewModel by
    Kosmos.Fixture {
        KeyguardStatusBarViewModel(
            applicationCoroutineScope,
            headsUpNotificationInteractor,
            sceneInteractor,
            keyguardInteractor,