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

Commit 29f9b0f9 authored by Chris Göllner's avatar Chris Göllner
Browse files

Start using DarkIconDispatcherStore and LightBarControllerStore

- Uses DarkIconDispatcherStore to provide per display instances to
  LightBarController
- Uses LightBarControllerStore in Dagger, so that all places use the
  same instances of LightBarController
- Initializes LightBarController for each display

Test: MultiDisplayStatusBarStarterTest
Test: Manually build & run
Bug: 369337696
Flag: com.android.systemui.status_bar_connected_displays
Change-Id: I0c1f69fe4599d70e58c406eaf98278f2b8e24b75
parent 57807815
Loading
Loading
Loading
Loading
+74 −0
Original line number Diff line number Diff line
@@ -23,9 +23,11 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.display.data.repository.displayRepository
import com.android.systemui.kosmos.testScope
import com.android.systemui.statusbar.data.repository.fakeLightBarControllerStore
import com.android.systemui.statusbar.data.repository.fakePrivacyDotWindowControllerStore
import com.android.systemui.testKosmos
import com.google.common.truth.Expect
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
@@ -48,6 +50,7 @@ class MultiDisplayStatusBarStarterTest : SysuiTestCase() {
    private val fakeOrchestratorFactory = kosmos.fakeStatusBarOrchestratorFactory
    private val fakeInitializerStore = kosmos.fakeStatusBarInitializerStore
    private val fakePrivacyDotStore = kosmos.fakePrivacyDotWindowControllerStore
    private val fakeLightBarStore = kosmos.fakeLightBarControllerStore
    // Lazy, so that @EnableFlags is set before initializer is instantiated.
    private val underTest by lazy { kosmos.multiDisplayStatusBarStarter }

@@ -94,6 +97,31 @@ class MultiDisplayStatusBarStarterTest : SysuiTestCase() {
            verify(fakePrivacyDotStore.forDisplay(displayId = 2)).start()
        }

    @Test
    fun start_doesNotStartLightBarControllerForCurrentDisplays() =
        testScope.runTest {
            fakeDisplayRepository.addDisplay(displayId = 1)
            fakeDisplayRepository.addDisplay(displayId = 2)

            underTest.start()
            runCurrent()

            verify(fakeLightBarStore.forDisplay(displayId = 1), never()).start()
            verify(fakeLightBarStore.forDisplay(displayId = 2), never()).start()
        }

    @Test
    fun start_createsLightBarControllerForCurrentDisplays() =
        testScope.runTest {
            fakeDisplayRepository.addDisplay(displayId = 1)
            fakeDisplayRepository.addDisplay(displayId = 2)

            underTest.start()
            runCurrent()

            assertThat(fakeLightBarStore.perDisplayMocks.keys).containsExactly(1, 2)
        }

    @Test
    fun start_doesNotStartPrivacyDotForDefaultDisplay() =
        testScope.runTest {
@@ -144,6 +172,30 @@ class MultiDisplayStatusBarStarterTest : SysuiTestCase() {
            verify(fakePrivacyDotStore.forDisplay(displayId = 3)).start()
        }

    @Test
    fun displayAdded_lightBarForNewDisplayIsCreated() =
        testScope.runTest {
            underTest.start()
            runCurrent()

            fakeDisplayRepository.addDisplay(displayId = 3)
            runCurrent()

            assertThat(fakeLightBarStore.perDisplayMocks.keys).containsExactly(3)
        }

    @Test
    fun displayAdded_lightBarForNewDisplayIsNotStarted() =
        testScope.runTest {
            underTest.start()
            runCurrent()

            fakeDisplayRepository.addDisplay(displayId = 3)
            runCurrent()

            verify(fakeLightBarStore.forDisplay(displayId = 3), never()).start()
        }

    @Test
    fun displayAddedDuringStart_initializerForNewDisplayIsStarted() =
        testScope.runTest {
@@ -178,4 +230,26 @@ class MultiDisplayStatusBarStarterTest : SysuiTestCase() {

            verify(fakePrivacyDotStore.forDisplay(displayId = 3)).start()
        }

    @Test
    fun displayAddedDuringStart_lightBarForNewDisplayIsCreated() =
        testScope.runTest {
            underTest.start()

            fakeDisplayRepository.addDisplay(displayId = 3)
            runCurrent()

            assertThat(fakeLightBarStore.perDisplayMocks.keys).containsExactly(3)
        }

    @Test
    fun displayAddedDuringStart_lightBarForNewDisplayIsNotStarted() =
        testScope.runTest {
            underTest.start()

            fakeDisplayRepository.addDisplay(displayId = 3)
            runCurrent()

            verify(fakeLightBarStore.forDisplay(displayId = 3), never()).start()
        }
}
+10 −15
Original line number Diff line number Diff line
@@ -16,10 +16,8 @@

package com.android.systemui.dagger;

import android.content.Context;

import com.android.systemui.classifier.FalsingManagerProxy;
import com.android.systemui.dagger.qualifiers.Default;
import com.android.systemui.globalactions.GlobalActionsComponent;
import com.android.systemui.globalactions.GlobalActionsImpl;
import com.android.systemui.plugins.ActivityStarter;
@@ -29,8 +27,9 @@ import com.android.systemui.plugins.GlobalActions;
import com.android.systemui.plugins.VolumeDialogController;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.StatusBarStateControllerImpl;
import com.android.systemui.statusbar.data.repository.DarkIconDispatcherStore;
import com.android.systemui.statusbar.data.repository.SysuiDarkIconDispatcherStore;
import com.android.systemui.statusbar.phone.ActivityStarterImpl;
import com.android.systemui.statusbar.phone.DarkIconDispatcherImpl;
import com.android.systemui.statusbar.phone.SysuiDarkIconDispatcher;
import com.android.systemui.volume.VolumeDialogControllerImpl;

@@ -53,20 +52,16 @@ public abstract class PluginModule {
    /** */
    @Provides
    @SysUISingleton
    @Default
    static DarkIconDispatcherImpl darkIconDispatcherImpl(
            DarkIconDispatcherImpl.Factory factory, Context context) {
        return factory.create(context.getDisplayId(), context);
    static DarkIconDispatcher provideDarkIconDispatcher(DarkIconDispatcherStore store) {
        return store.getDefaultDisplay();
    }

    /** */
    @Binds
    abstract DarkIconDispatcher provideDarkIconDispatcher(
            @Default DarkIconDispatcherImpl controllerImpl);

    @Binds
    abstract SysuiDarkIconDispatcher provideSysuiDarkIconDispatcher(
            @Default DarkIconDispatcherImpl controllerImpl);
    @Provides
    @SysUISingleton
    static SysuiDarkIconDispatcher provideSysuiDarkIconDispatcher(
            SysuiDarkIconDispatcherStore store) {
        return store.getDefaultDisplay();
    }

    /** */
    @Binds
+10 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.display.data.repository.DisplayRepository
import com.android.systemui.display.data.repository.DisplayScopeRepository
import com.android.systemui.statusbar.data.repository.LightBarControllerStore
import com.android.systemui.statusbar.data.repository.PrivacyDotWindowControllerStore
import com.android.systemui.statusbar.data.repository.StatusBarModeRepositoryStore
import com.android.systemui.statusbar.window.StatusBarWindowControllerStore
@@ -50,6 +51,7 @@ constructor(
    private val statusBarWindowControllerStore: StatusBarWindowControllerStore,
    private val statusBarInitializerStore: StatusBarInitializerStore,
    private val privacyDotWindowControllerStore: PrivacyDotWindowControllerStore,
    private val lightBarControllerStore: LightBarControllerStore,
) : CoreStartable {

    init {
@@ -74,6 +76,14 @@ constructor(
        createAndStartOrchestratorForDisplay(displayId)
        createAndStartInitializerForDisplay(displayId)
        startPrivacyDotForDisplay(displayId)
        createLightBarControllerForDisplay(displayId)
    }

    private fun createLightBarControllerForDisplay(displayId: Int) {
        // Explicitly not calling `start()`, because the store is already calling `start()`.
        // This is to maintain the legacy behavior with NavigationBar, that was already expecting
        // LightBarController to start at construction time.
        lightBarControllerStore.forDisplay(displayId)
    }

    private fun createAndStartOrchestratorForDisplay(displayId: Int) {
+2 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ constructor(
    private val factory: LightBarControllerImpl.Factory,
    private val displayScopeRepository: DisplayScopeRepository,
    private val statusBarModeRepositoryStore: StatusBarModeRepositoryStore,
    private val darkIconDispatcherStore: DarkIconDispatcherStore,
) :
    LightBarControllerStore,
    PerDisplayStoreImpl<LightBarController>(backgroundApplicationScope, displayRepository) {
@@ -53,6 +54,7 @@ constructor(
            .create(
                displayId,
                displayScopeRepository.scopeForDisplay(displayId),
                darkIconDispatcherStore.forDisplay(displayId),
                statusBarModeRepositoryStore.forDisplay(displayId),
            )
            .also { it.start() }
+2 −1
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ public class LightBarControllerImpl implements
    public LightBarControllerImpl(
            @Assisted int displayId,
            @Assisted CoroutineScope coroutineScope,
            DarkIconDispatcher darkIconDispatcher,
            @Assisted DarkIconDispatcher darkIconDispatcher,
            BatteryController batteryController,
            NavigationModeController navModeController,
            @Assisted StatusBarModePerDisplayRepository statusBarModeRepository,
@@ -487,6 +487,7 @@ public class LightBarControllerImpl implements
        LightBarControllerImpl create(
                int displayId,
                CoroutineScope coroutineScope,
                DarkIconDispatcher darkIconDispatcher,
                StatusBarModePerDisplayRepository statusBarModePerDisplayRepository);
    }
}
Loading