From a13172285b16df63fb7a2c3a75bfa49866a88c6b Mon Sep 17 00:00:00 2001 From: Nicolo' Mazzucato Date: Wed, 20 Nov 2024 11:44:07 +0000 Subject: Add ShadeDisplaysInteractor to ShadeDisplayAwareModule The optional bindings is provided as in other sysui variants (e.g. TV) the WindowRootView is not provided. In such cases, The ShadeDisplaysInteractor should never be created. Bug: 362719719 Bug: 374267505 Test: ShadeDisplaysInteractorTest Flag: com.android.systemui.shade_window_goes_around Change-Id: I139b27218a92e56dd9695386d8332dc28847d6e0 --- .../interactor/ShadeDisplaysInteractorTest.kt | 3 ++- .../systemui/shade/ShadeDisplayAwareModule.kt | 22 +++++++++++++++++++++- .../domain/interactor/ShadeDisplaysInteractor.kt | 13 ++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractorTest.kt index 08a22a87c2ba..016a24acd461 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractorTest.kt @@ -31,6 +31,7 @@ import com.android.systemui.display.shared.model.DisplayWindowProperties import com.android.systemui.scene.ui.view.WindowRootView import com.android.systemui.shade.data.repository.FakeShadeDisplayRepository import com.android.systemui.statusbar.phone.ConfigurationForwarder +import java.util.Optional import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.UnconfinedTestDispatcher @@ -65,7 +66,7 @@ class ShadeDisplaysInteractorTest : SysuiTestCase() { private val interactor = ShadeDisplaysInteractor( - shadeRootview, + Optional.of(shadeRootview), positionRepository, MutableContextWrapper(defaultContext), resources, diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayAwareModule.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayAwareModule.kt index bf2ea56b0c67..0b36e685d914 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayAwareModule.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayAwareModule.kt @@ -29,16 +29,20 @@ import com.android.systemui.common.ui.data.repository.ConfigurationRepositoryImp import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractorImpl import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.scene.ui.view.WindowRootView import com.android.systemui.shade.data.repository.ShadeDisplaysRepository import com.android.systemui.shade.data.repository.ShadeDisplaysRepositoryImpl +import com.android.systemui.shade.domain.interactor.ShadeDisplaysInteractor import com.android.systemui.shade.shared.flag.ShadeWindowGoesAround import com.android.systemui.statusbar.phone.ConfigurationControllerImpl import com.android.systemui.statusbar.phone.ConfigurationForwarder import com.android.systemui.statusbar.policy.ConfigurationController +import dagger.BindsOptionalOf import dagger.Module import dagger.Provides import dagger.multibindings.ClassKey import dagger.multibindings.IntoMap +import javax.inject.Provider /** * Module responsible for managing display-specific components and resources for the notification @@ -52,7 +56,7 @@ import dagger.multibindings.IntoMap * By using this dedicated module, we ensure the notification shade window always utilizes the * correct display context and resources, regardless of the display it's on. */ -@Module +@Module(includes = [OptionalShadeDisplayAwareBindings::class]) object ShadeDisplayAwareModule { /** Creates a new context for the shade window. */ @@ -169,4 +173,20 @@ object ShadeDisplayAwareModule { CoreStartable.NOP } } + + @Provides + @IntoMap + @ClassKey(ShadeDisplaysInteractor::class) + fun provideShadeDisplaysInteractor(impl: Provider): CoreStartable { + return if (ShadeWindowGoesAround.isEnabled) { + impl.get() + } else { + CoreStartable.NOP + } + } +} + +@Module +internal interface OptionalShadeDisplayAwareBindings { + @BindsOptionalOf fun bindOptionalOfWindowRootView(): WindowRootView } diff --git a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractor.kt b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractor.kt index 18dbba1d0d25..432d5f553fbb 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractor.kt @@ -38,6 +38,8 @@ import com.android.systemui.shade.ShadeWindowLayoutParams import com.android.systemui.shade.data.repository.ShadeDisplaysRepository import com.android.systemui.shade.shared.flag.ShadeWindowGoesAround import com.android.systemui.statusbar.phone.ConfigurationForwarder +import com.android.systemui.util.kotlin.getOrNull +import java.util.Optional import javax.inject.Inject import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.CoroutineScope @@ -48,7 +50,7 @@ import kotlinx.coroutines.withContext class ShadeDisplaysInteractor @Inject constructor( - private val shadeRootView: WindowRootView, + optionalShadeRootView: Optional, private val shadePositionRepository: ShadeDisplaysRepository, @ShadeDisplayAware private val shadeContext: Context, @ShadeDisplayAware private val shadeResources: Resources, @@ -58,6 +60,15 @@ constructor( @Main private val mainThreadContext: CoroutineContext, ) : CoreStartable { + private val shadeRootView = + optionalShadeRootView.getOrNull() + ?: error( + """ + ShadeRootView must be provided for this ShadeDisplayInteractor to work. + If it is not, it means this is being instantiated in a SystemUI variant that shouldn't. + """ + .trimIndent() + ) // TODO: b/362719719 - Get rid of this callback as the root view should automatically get the // correct configuration once it's moved to another window. private var unregisterConfigChangedCallbacks: (() -> Unit)? = null -- cgit v1.2.3-59-g8ed1b