diff options
| author | 2025-02-12 22:35:44 +0000 | |
|---|---|---|
| committer | 2025-02-13 09:59:43 +0000 | |
| commit | d10e301f95be2a46b91e9642c50ab8a18ef49c0c (patch) | |
| tree | 3744e6e06c4412106f35ea7025efd2012a1eaacd | |
| parent | a29cd592167888badd9f0073767c418ce049f5d5 (diff) | |
Cleanup ShadeDisplayAware dagger modules
shadeDisplaysInteractor was bound in SystemUIModule (that is available for all sysui variants), despite using NotificationStackRebindingHider, ShadeExpandedStateInteractor and WindowRootView (that were only provided in ShadeModule, not available in SysUI variants other than Google and aosp).
The issue was mistakenly fixed using optional bindings. This cl properly fixes it by binding it only in ShadeModule.
It is **not** possible to bind the entire ShadeDisplayAwareModule in the same way (as an include of ShadeModule, for example) as there are several classes in SystemUIModule that need the objects provided by ShadeDisplayAwareModule.
Bug: 362719719
Bug: 396159919
Test: Builds
Flag: com.android.systemui.shade_window_goes_around
Change-Id: If9d9e476c50013501fbabd41234012e31304e401
9 files changed, 32 insertions, 104 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSystemUIModule.java index 8bff090959ab..3c68e3a09f02 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSystemUIModule.java @@ -74,7 +74,6 @@ import com.android.systemui.statusbar.NotificationShadeWindowController; import com.android.systemui.statusbar.SysuiStatusBarStateController; import com.android.systemui.statusbar.dagger.CentralSurfacesModule; import com.android.systemui.statusbar.dagger.StartCentralSurfacesModule; -import com.android.systemui.statusbar.notification.dagger.NotificationStackModule; import com.android.systemui.statusbar.notification.dagger.ReferenceNotificationsModule; import com.android.systemui.statusbar.notification.headsup.HeadsUpModule; import com.android.systemui.statusbar.phone.CentralSurfaces; @@ -170,7 +169,6 @@ import javax.inject.Named; WallpaperModule.class, ShortcutHelperModule.class, ContextualEducationModule.class, - NotificationStackModule.class, }) public abstract class ReferenceSystemUIModule { diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayAwareModule.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayAwareModule.kt index f926d39760fe..96b224fbd4f3 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayAwareModule.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayAwareModule.kt @@ -42,12 +42,12 @@ import com.android.systemui.shade.display.ShadeDisplayPolicyModule import com.android.systemui.shade.domain.interactor.ShadeDialogContextInteractor import com.android.systemui.shade.domain.interactor.ShadeDialogContextInteractorImpl import com.android.systemui.shade.domain.interactor.ShadeDisplaysInteractor -import com.android.systemui.shade.domain.interactor.ShadeExpandedStateInteractor import com.android.systemui.shade.shared.flag.ShadeWindowGoesAround +import com.android.systemui.statusbar.notification.stack.NotificationStackRebindingHider +import com.android.systemui.statusbar.notification.stack.NotificationStackRebindingHiderImpl 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 @@ -67,7 +67,7 @@ import javax.inject.Qualifier * 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(includes = [OptionalShadeDisplayAwareBindings::class, ShadeDisplayPolicyModule::class]) +@Module(includes = [ShadeDisplayPolicyModule::class]) object ShadeDisplayAwareModule { /** Creates a new context for the shade window. */ @@ -242,17 +242,6 @@ object ShadeDisplayAwareModule { } } - @Provides - @IntoMap - @ClassKey(ShadeDisplaysInteractor::class) - fun provideShadeDisplaysInteractor(impl: Provider<ShadeDisplaysInteractor>): CoreStartable { - return if (ShadeWindowGoesAround.isEnabled) { - impl.get() - } else { - CoreStartable.NOP - } - } - /** * Provided for making classes easier to test. In tests, a custom method to wait for the next * frame can be easily provided. @@ -264,11 +253,25 @@ object ShadeDisplayAwareModule { fun provideShadeOnDefaultDisplayWhenLocked(): Boolean = true } +/** Module that should be included only if the shade window [WindowRootView] is available. */ @Module -internal interface OptionalShadeDisplayAwareBindings { - @BindsOptionalOf fun bindOptionalOfWindowRootView(): WindowRootView +object ShadeDisplayAwareWithShadeWindowModule { + @Provides + @IntoMap + @ClassKey(ShadeDisplaysInteractor::class) + fun provideShadeDisplaysInteractor(impl: Provider<ShadeDisplaysInteractor>): CoreStartable { + return if (ShadeWindowGoesAround.isEnabled) { + impl.get() + } else { + CoreStartable.NOP + } + } - @BindsOptionalOf fun bindOptionalOShadeExpandedStateInteractor(): ShadeExpandedStateInteractor + @Provides + @SysUISingleton + fun bindNotificationStackRebindingHider( + impl: NotificationStackRebindingHiderImpl + ): NotificationStackRebindingHider = impl } /** diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayChangeLatencyTracker.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayChangeLatencyTracker.kt index 13b540aa54ba..5fda998dac2d 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayChangeLatencyTracker.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeDisplayChangeLatencyTracker.kt @@ -24,8 +24,6 @@ import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.scene.ui.view.WindowRootView import com.android.systemui.shade.data.repository.ShadeDisplaysRepository -import com.android.systemui.util.kotlin.getOrNull -import java.util.Optional import java.util.concurrent.CancellationException import javax.inject.Inject import kotlin.time.Duration.Companion.seconds @@ -51,22 +49,13 @@ import kotlinx.coroutines.withTimeout class ShadeDisplayChangeLatencyTracker @Inject constructor( - optionalShadeRootView: Optional<WindowRootView>, + private val shadeRootView: WindowRootView, @ShadeDisplayAware private val configurationRepository: ConfigurationRepository, private val latencyTracker: LatencyTracker, @Background private val bgScope: CoroutineScope, private val choreographerUtils: ChoreographerUtils, ) { - private val shadeRootView = - optionalShadeRootView.getOrNull() - ?: error( - """ - ShadeRootView must be provided for ShadeDisplayChangeLatencyTracker to work. - If it is not, it means this is being instantiated in a SystemUI variant that shouldn't. - """ - .trimIndent() - ) /** * We need to keep this always up to date eagerly to avoid delays receiving the new display ID. */ diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt index 7d4b0ed6304c..c44e066aad3a 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt @@ -54,7 +54,12 @@ import javax.inject.Provider /** Module for classes related to the notification shade. */ @Module( includes = - [StartShadeModule::class, ShadeViewProviderModule::class, WindowRootViewBlurModule::class] + [ + StartShadeModule::class, + ShadeViewProviderModule::class, + WindowRootViewBlurModule::class, + ShadeDisplayAwareWithShadeWindowModule::class, + ] ) abstract class ShadeModule { companion object { 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 e746274a39c1..9a5c96824e77 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 @@ -39,9 +39,7 @@ import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotif import com.android.systemui.statusbar.notification.row.NotificationRebindingTracker import com.android.systemui.statusbar.notification.stack.NotificationStackRebindingHider import com.android.systemui.statusbar.phone.ConfigurationForwarder -import com.android.systemui.util.kotlin.getOrNull import com.android.window.flags.Flags -import java.util.Optional import javax.inject.Inject import kotlin.coroutines.CoroutineContext import kotlin.time.Duration.Companion.seconds @@ -63,17 +61,14 @@ constructor( @Background private val bgScope: CoroutineScope, @Main private val mainThreadContext: CoroutineContext, private val shadeDisplayChangeLatencyTracker: ShadeDisplayChangeLatencyTracker, - shadeExpandedInteractor: Optional<ShadeExpandedStateInteractor>, + private val shadeExpandedInteractor: ShadeExpandedStateInteractor, private val shadeExpansionIntent: ShadeExpansionIntent, private val activeNotificationsInteractor: ActiveNotificationsInteractor, private val notificationRebindingTracker: NotificationRebindingTracker, - notificationStackRebindingHider: Optional<NotificationStackRebindingHider>, + private val notificationStackRebindingHider: NotificationStackRebindingHider, @ShadeDisplayAware private val configForwarder: ConfigurationForwarder, ) : CoreStartable { - private val shadeExpandedInteractor = requireOptional(shadeExpandedInteractor) - private val notificationStackRebindingHider = requireOptional(notificationStackRebindingHider) - private val hasActiveNotifications: Boolean get() = activeNotificationsInteractor.areAnyNotificationsPresentValue @@ -224,24 +219,5 @@ constructor( const val TAG = "ShadeDisplaysInteractor" const val COLLAPSE_EXPAND_REASON = "Shade window move" val TIMEOUT = 1.seconds - - /** - * [ShadeDisplaysInteractor] is bound in the SystemUI module for all variants, but needs - * some specific dependencies to be bound from each variant (e.g. - * [ShadeExpandedStateInteractor] or [NotificationStackRebindingHider]). When those are not - * bound, this class is not expected to be instantiated, and trying to instantiate it would - * crash. - */ - inline fun <reified T> requireOptional(optional: Optional<T>): T { - return optional.getOrNull() - ?: error( - """ - ${T::class.java.simpleName} must be provided for ShadeDisplaysInteractor to work. - If it is not, it means this is being instantiated in a SystemUI variant that - shouldn't. - """ - .trimIndent() - ) - } } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationStackOptionalModule.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationStackOptionalModule.kt deleted file mode 100644 index bcaf1878a869..000000000000 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationStackOptionalModule.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2025 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.statusbar.notification.dagger - -import com.android.systemui.statusbar.notification.stack.NotificationStackRebindingHider -import com.android.systemui.statusbar.notification.stack.NotificationStackRebindingHiderImpl -import dagger.Binds -import dagger.BindsOptionalOf -import dagger.Module - -/** - * This is meant to be bound in SystemUI variants with [NotificationStackScrollLayoutController]. - */ -@Module -interface NotificationStackModule { - @Binds - fun bindNotificationStackRebindingHider( - impl: NotificationStackRebindingHiderImpl - ): NotificationStackRebindingHider -} - -/** This is meant to be used by all SystemUI variants, also those without NSSL. */ -@Module -interface NotificationStackOptionalModule { - @BindsOptionalOf - fun bindOptionalOfNotificationStackRebindingHider(): NotificationStackRebindingHider -} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java index 34f4969127e3..53d5dbc58677 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java @@ -121,7 +121,6 @@ import javax.inject.Provider; NotificationMemoryModule.class, NotificationStatsLoggerModule.class, NotificationsLogModule.class, - NotificationStackOptionalModule.class, }) public interface NotificationsModule { @Binds diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ShadeDisplayChangeLatencyTrackerKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ShadeDisplayChangeLatencyTrackerKosmos.kt index 67dd0ad896d5..0892e66b8b86 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ShadeDisplayChangeLatencyTrackerKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/ShadeDisplayChangeLatencyTrackerKosmos.kt @@ -27,7 +27,7 @@ import java.util.Optional val Kosmos.shadeDisplayChangeLatencyTracker by Fixture { ShadeDisplayChangeLatencyTracker( - Optional.of(mockShadeRootView), + mockShadeRootView, configurationRepository, latencyTracker, testScope.backgroundScope, diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractorKosmos.kt index 46314135c574..1397d974cbc5 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractorKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/domain/interactor/ShadeDisplaysInteractorKosmos.kt @@ -29,7 +29,6 @@ import com.android.systemui.statusbar.notification.domain.interactor.activeNotif import com.android.systemui.statusbar.notification.row.notificationRebindingTracker import com.android.systemui.statusbar.notification.stack.notificationStackRebindingHider import com.android.systemui.statusbar.policy.configurationController -import java.util.Optional import org.mockito.kotlin.any import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @@ -55,11 +54,11 @@ val Kosmos.shadeDisplaysInteractor by testScope.backgroundScope, testScope.backgroundScope.coroutineContext, mockedShadeDisplayChangeLatencyTracker, - Optional.of(shadeExpandedStateInteractor), + shadeExpandedStateInteractor, shadeExpansionIntent, activeNotificationsInteractor, notificationRebindingTracker, - Optional.of(notificationStackRebindingHider), + notificationStackRebindingHider, configurationController, ) } |