From 1f774adcf4e68ee0038c75e6995618ae77c78875 Mon Sep 17 00:00:00 2001 From: Caitlin Shkuratov Date: Fri, 14 Apr 2023 20:00:19 +0000 Subject: [PATCH] [Central Surfaces] Make NotificationShadeWindowView a singleton. Bug: 277762009 Test: compiles; notification shade still works Change-Id: I58546516fe6daa3efb9ab0879fd962caf08d8b00 --- .../systemui/dagger/SystemUIModule.java | 2 + .../com/android/systemui/shade/ShadeModule.kt | 44 +++++++++++++++++++ .../statusbar/phone/CentralSurfacesImpl.java | 2 + .../phone/dagger/StatusBarViewModule.java | 15 ------- 4 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index 044dd6a47241d..6dc19078c2c75 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -71,6 +71,7 @@ import com.android.systemui.screenshot.dagger.ScreenshotModule; import com.android.systemui.security.data.repository.SecurityRepositoryModule; import com.android.systemui.settings.DisplayTracker; import com.android.systemui.shade.ShadeController; +import com.android.systemui.shade.ShadeModule; import com.android.systemui.shade.transition.LargeScreenShadeInterpolator; import com.android.systemui.shade.transition.LargeScreenShadeInterpolatorImpl; import com.android.systemui.smartspace.dagger.SmartspaceModule; @@ -174,6 +175,7 @@ import javax.inject.Named; SecurityRepositoryModule.class, ScreenRecordModule.class, SettingsUtilModule.class, + ShadeModule.class, SmartRepliesInflationModule.class, SmartspaceModule.class, StatusBarPipelineModule.class, diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt new file mode 100644 index 0000000000000..8adb21d3b44b8 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2023 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.shade + +import android.view.LayoutInflater +import com.android.systemui.R +import com.android.systemui.dagger.SysUISingleton +import dagger.Module +import dagger.Provides + +/** Module for classes related to the notification shade. */ +@Module +abstract class ShadeModule { + companion object { + @Provides + @SysUISingleton + // TODO(b/277762009): Do something similar to + // {@link StatusBarWindowModule.InternalWindowView} so that only + // {@link NotificationShadeWindowViewController} can inject this view. + fun providesNotificationShadeWindowView( + layoutInflater: LayoutInflater, + ): NotificationShadeWindowView { + return layoutInflater.inflate(R.layout.super_notification_shade, /* root= */ null) + as NotificationShadeWindowView? + ?: throw IllegalStateException( + "R.layout.super_notification_shade could not be properly inflated" + ) + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java index fab334c5ebc4a..85142ca92f32c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java @@ -1637,6 +1637,8 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { mNotificationShadeWindowView = mCentralSurfacesComponent.getNotificationShadeWindowView(); mNotificationShadeWindowViewController = mCentralSurfacesComponent .getNotificationShadeWindowViewController(); + // TODO(b/277762009): Inject [NotificationShadeWindowView] directly into the controller. + // (Right now, there's a circular dependency.) mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView); mNotificationShadeWindowViewController.setupExpandedStatusBar(); NotificationPanelViewController npvc = diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarViewModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarViewModule.java index 015ee7b5682a3..7e226ad66b5ec 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarViewModule.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarViewModule.java @@ -95,21 +95,6 @@ public abstract class StatusBarViewModule { public static final String SHADE_HEADER = "large_screen_shade_header"; public static final String STATUS_BAR_FRAGMENT = "status_bar_fragment"; - /** */ - @Provides - @CentralSurfacesComponent.CentralSurfacesScope - public static NotificationShadeWindowView providesNotificationShadeWindowView( - LayoutInflater layoutInflater) { - NotificationShadeWindowView notificationShadeWindowView = (NotificationShadeWindowView) - layoutInflater.inflate(R.layout.super_notification_shade, /* root= */ null); - if (notificationShadeWindowView == null) { - throw new IllegalStateException( - "R.layout.super_notification_shade could not be properly inflated"); - } - - return notificationShadeWindowView; - } - /** */ @Provides @CentralSurfacesComponent.CentralSurfacesScope