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

Commit 57c726a7 authored by Nicolò Mazzucato's avatar Nicolò Mazzucato
Browse files

Propagate onMovedToDisplay with ConfigurationController

This enables the propagation of onMovedToDisplay (a special type of configuration change that also includes a new display id) using ConfigurationController.

It will be used to measure the performance of moving the shade between displays in a follow up cl

Bug: 362719719
Bug: 378688537
Bug: 378686382
Test: ConfigurationControllerImplTest, NotificationShadeWindowViewTest
Flag: com.android.systemui.shade_window_goes_around
Change-Id: I4c31ee431275d90d1766aca33ffa11f50ac730e4
parent 3b86d10b
Loading
Loading
Loading
Loading
+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
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -169,6 +169,9 @@ public class NotificationShadeWindowView extends WindowRootView {
    public void onMovedToDisplay(int displayId, Configuration config) {
        super.onMovedToDisplay(displayId, config);
        ShadeWindowGoesAround.isUnexpectedlyInLegacyMode();
        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);
+7 −0
Original line number Diff line number Diff line
@@ -65,6 +65,13 @@ constructor(@Assisted private val context: Context) :
        listeners.filterForEach({ this.listeners.contains(it) }) { it.onThemeChanged() }
    }

    override fun dispatchOnMovedToDisplay(newDisplayId: Int, newConfiguration: Configuration) {
        val listeners = synchronized(this.listeners) { ArrayList(this.listeners) }
        listeners.filterForEach({ this.listeners.contains(it) }) {
            it.onMovedToDisplay(newDisplayId, newConfiguration)
        }
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        // Avoid concurrent modification exception
        val listeners = synchronized(this.listeners) { ArrayList(this.listeners) }
+9 −0
Original line number Diff line number Diff line
@@ -28,4 +28,13 @@ import android.content.res.Configuration
interface ConfigurationForwarder {
    /** Should be called when a new configuration is received. */
    fun onConfigurationChanged(newConfiguration: Configuration)

    /**
     * Should be called when the view associated to this configuration forwarded moved to another
     * display, usually as a consequence of [View.onMovedToDisplay].
     *
     * For the default configuration forwarder (associated with the global configuration) this is
     * never expected to be called.
     */
    fun dispatchOnMovedToDisplay(newDisplayId: Int, newConfiguration: Configuration)
}
Loading