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

Commit 4f52f105 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

Replaces unnecessary collectLatest with collect

When hydrating local MutableStateFlows, there's no need for
collectLatest, just collect can do. collectLatest has worse performance
characteristics so cleaning those up.

Bug: 354269846
Test: smoke test with flexiglass - visited every scene before/after
unlock and after relock
Flag: com.android.systemui.scene_container

Change-Id: Iccc30601f28c193832dcf3fb50688f224910ef09
parent a3faba29
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@@ -64,14 +63,10 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {

    private val underTest by lazy { kosmos.quickSettingsShadeSceneActionsViewModel }

    @Before
    fun setUp() {
        underTest.activateIn(testScope)
    }

    @Test
    fun upTransitionSceneKey_deviceLocked_lockscreen() =
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            lockDevice()
@@ -85,6 +80,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    fun upTransitionSceneKey_deviceLocked_keyguardDisabled_gone() =
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            lockDevice()
@@ -98,6 +94,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    fun upTransitionSceneKey_deviceUnlocked_gone() =
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            lockDevice()
@@ -113,6 +110,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    fun downTransitionSceneKey_deviceLocked_bottomAligned_lockscreen() =
        testScope.runTest {
            kosmos.fakeShadeRepository.setDualShadeAlignedToBottom(true)
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            lockDevice()
@@ -127,6 +125,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    fun downTransitionSceneKey_deviceUnlocked_bottomAligned_gone() =
        testScope.runTest {
            kosmos.fakeShadeRepository.setDualShadeAlignedToBottom(true)
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            lockDevice()
@@ -141,6 +140,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    fun upTransitionSceneKey_authMethodSwipe_lockscreenNotDismissed_goesToLockscreen() =
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            kosmos.fakeDeviceEntryRepository.setLockscreenEnabled(true)
@@ -157,6 +157,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    fun upTransitionSceneKey_authMethodSwipe_lockscreenDismissed_goesToGone() =
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            kosmos.fakeDeviceEntryRepository.setLockscreenEnabled(true)
@@ -174,6 +175,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    fun backTransitionSceneKey_notEditing_Home() =
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)

            assertThat((actions?.get(Back) as? UserActionResult.ChangeScene)?.toScene)
@@ -183,6 +185,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    fun backTransition_editing_noDestination() =
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            kosmos.editModeViewModel.startEditing()

+1 −2
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Test
@@ -123,7 +122,7 @@ class SceneActionsViewModelTest : SysuiTestCase() {
        override suspend fun hydrateActions(
            setActions: (Map<UserAction, UserActionResult>) -> Unit,
        ) {
            upstream.collectLatest { setActions(it) }
            upstream.collect { setActions(it) }
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ constructor(
                    emptyFlow()
                }
            }
            .collectLatest { messageViewModel -> message.value = messageViewModel }
            .collect { messageViewModel -> message.value = messageViewModel }
    }

    private suspend fun listenForSimBouncerEvents() {
@@ -171,7 +171,7 @@ constructor(
                    emptyFlow()
                }
            }
            .collectLatest {
            .collect {
                if (it != null) {
                    message.value = it
                } else {
+1 −2
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.systemui.bouncer.domain.interactor.BouncerInteractor
import com.android.systemui.scene.ui.viewmodel.SceneActionsViewModel
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.map

/**
@@ -46,7 +45,7 @@ constructor(
                    Swipe(SwipeDirection.Down) to UserActionResult(prevScene),
                )
            }
            .collectLatest { actions -> setActions(actions) }
            .collect { actions -> setActions(actions) }
    }

    @AssistedFactory
+7 −9
Original line number Diff line number Diff line
@@ -160,7 +160,7 @@ constructor(
            launch {
                userSwitcher.selectedUser
                    .map { it.image.toBitmap() }
                    .collectLatest { _selectedUserImage.value = it }
                    .collect { _selectedUserImage.value = it }
            }

            launch {
@@ -187,34 +187,32 @@ constructor(
                                )
                            }
                    }
                    .collectLatest { _userSwitcherDropdown.value = it }
                    .collect { _userSwitcherDropdown.value = it }
            }

            launch {
                combine(wipeDialogMessage, lockoutDialogMessage) { _, _ -> createDialogViewModel() }
                    .collectLatest { _dialogViewModel.value = it }
                    .collect { _dialogViewModel.value = it }
            }

            launch {
                actionButtonInteractor.actionButton.collectLatest { _actionButton.value = it }
            }
            launch { actionButtonInteractor.actionButton.collect { _actionButton.value = it } }

            launch {
                authMethodViewModel
                    .map { authMethod -> isSideBySideSupported(authMethod) }
                    .collectLatest { _isSideBySideSupported.value = it }
                    .collect { _isSideBySideSupported.value = it }
            }

            launch {
                authMethodViewModel
                    .map { authMethod -> isFoldSplitRequired(authMethod) }
                    .collectLatest { _isFoldSplitRequired.value = it }
                    .collect { _isFoldSplitRequired.value = it }
            }

            launch {
                message.isLockoutMessagePresent
                    .map { lockoutMessagePresent -> !lockoutMessagePresent }
                    .collectLatest { _isInputEnabled.value = it }
                    .collect { _isInputEnabled.value = it }
            }

            awaitCancellation()
Loading