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

Commit 51c1f149 authored by Nicolò Mazzucato's avatar Nicolò Mazzucato Committed by Android (Google) Code Review
Browse files

Merge changes I16f03794,Ie369b7e8,I4c31ee43 into main

* changes:
  Introduce ShadeTraceLogger
  Propagate onMovedToDisplay with ConfigurationRepository
  Propagate onMovedToDisplay with ConfigurationController
parents cfcbc6ae 87f0e837
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 {
+10 −0
Original line number Diff line number Diff line
@@ -253,6 +253,16 @@ class NotificationShadeWindowViewTest : SysuiTestCase() {
        verify(configurationForwarder).onConfigurationChanged(eq(config))
    }

    @Test
    @EnableFlags(AConfigFlags.FLAG_SHADE_WINDOW_GOES_AROUND)
    fun onMovedToDisplay_configForwarderSet_propagatesConfig() {
        val config = Configuration()

        underTest.onMovedToDisplay(1, config)

        verify(configurationForwarder).dispatchOnMovedToDisplay(eq(1), eq(config))
    }

    private fun captureInteractionEventHandler() {
        verify(underTest).setInteractionEventHandler(interactionEventHandlerCaptor.capture())
        interactionEventHandler = interactionEventHandlerCaptor.value
+33 −6
Original line number Diff line number Diff line
@@ -21,11 +21,13 @@ import android.content.res.Configuration.UI_MODE_NIGHT_NO
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.content.res.Configuration.UI_MODE_TYPE_CAR
import android.os.LocaleList
import android.view.Display
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener
import com.google.common.truth.Truth.assertThat
import java.util.Locale
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
@@ -34,7 +36,6 @@ import org.mockito.Mockito.doAnswer
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import java.util.Locale

@RunWith(AndroidJUnit4::class)
@SmallTest
@@ -66,7 +67,9 @@ class ConfigurationControllerImplTest : SysuiTestCase() {
        doAnswer {
                mConfigurationController.removeCallback(listener2)
                null
        }.`when`(listener).onThemeChanged()
            }
            .`when`(listener)
            .onThemeChanged()

        mConfigurationController.notifyThemeChanged()
        verify(listener).onThemeChanged()
@@ -208,7 +211,6 @@ class ConfigurationControllerImplTest : SysuiTestCase() {
        assertThat(listener.maxBoundsChanged).isTrue()
    }


    @Test
    fun localeListChanged_listenerNotified() {
        val config = mContext.resources.configuration
@@ -289,7 +291,6 @@ class ConfigurationControllerImplTest : SysuiTestCase() {
        assertThat(listener.orientationChanged).isTrue()
    }


    @Test
    fun multipleUpdates_listenerNotifiedOfAll() {
        val config = mContext.resources.configuration
@@ -312,6 +313,17 @@ class ConfigurationControllerImplTest : SysuiTestCase() {
        assertThat(listener.uiModeChanged).isTrue()
    }

    @Test
    fun onMovedToDisplay_dispatchedToChildren() {
        val config = mContext.resources.configuration
        val listener = createAndAddListener()

        mConfigurationController.dispatchOnMovedToDisplay(newDisplayId = 1, config)

        assertThat(listener.display).isEqualTo(1)
        assertThat(listener.changedConfig).isEqualTo(config)
    }

    @Test
    @Ignore("b/261408895")
    fun equivalentConfigObject_listenerNotNotified() {
@@ -343,35 +355,49 @@ class ConfigurationControllerImplTest : SysuiTestCase() {
        var localeListChanged = false
        var layoutDirectionChanged = false
        var orientationChanged = false
        var display = Display.DEFAULT_DISPLAY

        override fun onConfigChanged(newConfig: Configuration?) {
            changedConfig = newConfig
        }

        override fun onDensityOrFontScaleChanged() {
            densityOrFontScaleChanged = true
        }

        override fun onSmallestScreenWidthChanged() {
            smallestScreenWidthChanged = true
        }

        override fun onMaxBoundsChanged() {
            maxBoundsChanged = true
        }

        override fun onUiModeChanged() {
            uiModeChanged = true
        }

        override fun onThemeChanged() {
            themeChanged = true
        }

        override fun onLocaleListChanged() {
            localeListChanged = true
        }

        override fun onLayoutDirectionChanged(isLayoutRtl: Boolean) {
            layoutDirectionChanged = true
        }

        override fun onOrientationChanged(orientation: Int) {
            orientationChanged = true
        }

        override fun onMovedToDisplay(newDisplayId: Int, newConfiguration: Configuration?) {
            display = newDisplayId
            changedConfig = newConfiguration
        }

        fun assertNoMethodsCalled() {
            assertThat(densityOrFontScaleChanged).isFalse()
            assertThat(smallestScreenWidthChanged).isFalse()
@@ -391,6 +417,7 @@ class ConfigurationControllerImplTest : SysuiTestCase() {
            themeChanged = false
            localeListChanged = false
            layoutDirectionChanged = false
            display = Display.DEFAULT_DISPLAY
        }
    }
}
+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
+5 −0
Original line number Diff line number Diff line
@@ -169,6 +169,10 @@ public class NotificationShadeWindowView extends WindowRootView {
    public void onMovedToDisplay(int displayId, Configuration config) {
        super.onMovedToDisplay(displayId, config);
        ShadeWindowGoesAround.isUnexpectedlyInLegacyMode();
        ShadeTraceLogger.INSTANCE.logOnMovedToDisplay(displayId, config);
        if (mConfigurationForwarder != null) {
            mConfigurationForwarder.dispatchOnMovedToDisplay(displayId, config);
        }
        // When the window is moved we're only receiving a call to this method instead of the
        // onConfigurationChange itself. Let's just trigegr a normal config change.
        onConfigurationChanged(config);
@@ -177,6 +181,7 @@ public class NotificationShadeWindowView extends WindowRootView {
    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        ShadeTraceLogger.INSTANCE.logOnConfigChanged(newConfig);
        if (mConfigurationForwarder != null) {
            ShadeWindowGoesAround.isUnexpectedlyInLegacyMode();
            mConfigurationForwarder.onConfigurationChanged(newConfig);
Loading