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

Commit 5f4a8c13 authored by Nicolò Mazzucato's avatar Nicolò Mazzucato
Browse files

Propagate onMovedToDisplay with ConfigurationRepository

This propagates onMovedToDisplay signal from ConfigurationController to ConfiguratoinRepository, providing a flow that emits the latest display.

For now (and probably forever) the new configuration is neglected, as it's already available from the configuration flow. If it turns out useful in the future, it will be added

Bug: 362719719
Bug: 378688537
Bug: 378686382
Test: ConfigurationRepositoryImplTest
Flag: com.android.systemui.shade_window_goes_around
Change-Id: Ie369b7e89a158cae15b463ccd2806ec4869ae08d
parent 57c726a7
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -97,6 +97,21 @@ class ConfigurationRepositoryImplTest : SysuiTestCase() {
            assertThat(lastAnyConfigurationChange).isNotNull()
        }

    @Test
    fun onMovedToDisplays_updatesOnMovedToDisplay() =
        testScope.runTest {
            val lastOnMovedToDisplay by collectLastValue(underTest.onMovedToDisplay)
            assertThat(lastOnMovedToDisplay).isNull()

            val configurationCallback = withArgCaptor {
                verify(configurationController).addCallback(capture())
            }

            configurationCallback.onMovedToDisplay(1, Configuration())
            runCurrent()
            assertThat(lastOnMovedToDisplay).isEqualTo(1)
        }

    @Test
    fun onAnyConfigurationChange_updatesOnConfigChanged() =
        testScope.runTest {
+18 −0
Original line number Diff line number Diff line
@@ -53,8 +53,12 @@ interface ConfigurationRepository {
    val onConfigurationChange: Flow<Unit>

    val scaleForResolution: Flow<Float>

    val configurationValues: Flow<Configuration>

    /** Emits the latest display this configuration controller has been moved to. */
    val onMovedToDisplay: Flow<Int>

    fun getResolutionScale(): Float

    /** Convenience to context.resources.getDimensionPixelSize() */
@@ -117,6 +121,20 @@ constructor(
        configurationController.addCallback(callback)
        awaitClose { configurationController.removeCallback(callback) }
    }
    override val onMovedToDisplay: Flow<Int>
        get() = conflatedCallbackFlow {
            val callback =
                object : ConfigurationController.ConfigurationListener {
                    override fun onMovedToDisplay(
                        newDisplayId: Int,
                        newConfiguration: Configuration?,
                    ) {
                        trySend(newDisplayId)
                    }
                }
            configurationController.addCallback(callback)
            awaitClose { configurationController.removeCallback(callback) }
        }

    override val scaleForResolution: StateFlow<Float> =
        onConfigurationChange
+10 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.common.ui.data.repository

import android.content.res.Configuration
import android.view.Display
import com.android.systemui.dagger.SysUISingleton
import dagger.Binds
import dagger.Module
@@ -25,6 +26,7 @@ import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow

@@ -46,6 +48,10 @@ class FakeConfigurationRepository @Inject constructor() : ConfigurationRepositor
    override val configurationValues: Flow<Configuration> =
        _configurationChangeValues.asSharedFlow()

    private val _onMovedToDisplay = MutableStateFlow<Int>(Display.DEFAULT_DISPLAY)
    override val onMovedToDisplay: StateFlow<Int>
        get() = _onMovedToDisplay

    private val _scaleForResolution = MutableStateFlow(1f)
    override val scaleForResolution: Flow<Float> = _scaleForResolution.asStateFlow()

@@ -64,6 +70,10 @@ class FakeConfigurationRepository @Inject constructor() : ConfigurationRepositor
        onAnyConfigurationChange()
    }

    fun onMovedToDisplay(newDisplayId: Int) {
        _onMovedToDisplay.value = newDisplayId
    }

    fun setScaleForResolution(scale: Float) {
        _scaleForResolution.value = scale
    }