1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.statusbar.phone.dagger;
18 
19 import android.annotation.Nullable;
20 import android.content.ContentResolver;
21 import android.os.Handler;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewStub;
25 
26 import com.android.keyguard.LockIconView;
27 import com.android.systemui.R;
28 import com.android.systemui.battery.BatteryMeterView;
29 import com.android.systemui.battery.BatteryMeterViewController;
30 import com.android.systemui.biometrics.AuthRippleView;
31 import com.android.systemui.broadcast.BroadcastDispatcher;
32 import com.android.systemui.dagger.qualifiers.Main;
33 import com.android.systemui.flags.FeatureFlags;
34 import com.android.systemui.plugins.statusbar.StatusBarStateController;
35 import com.android.systemui.privacy.OngoingPrivacyChip;
36 import com.android.systemui.statusbar.CommandQueue;
37 import com.android.systemui.statusbar.NotificationShelf;
38 import com.android.systemui.statusbar.NotificationShelfController;
39 import com.android.systemui.statusbar.OperatorNameViewController;
40 import com.android.systemui.statusbar.connectivity.NetworkController;
41 import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler;
42 import com.android.systemui.statusbar.notification.row.dagger.NotificationShelfComponent;
43 import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
44 import com.android.systemui.statusbar.phone.NotificationIconAreaController;
45 import com.android.systemui.statusbar.phone.NotificationPanelView;
46 import com.android.systemui.statusbar.phone.NotificationPanelViewController;
47 import com.android.systemui.statusbar.phone.NotificationShadeWindowView;
48 import com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer;
49 import com.android.systemui.statusbar.phone.StatusBarHideIconsForBouncerManager;
50 import com.android.systemui.statusbar.phone.StatusBarIconController;
51 import com.android.systemui.statusbar.phone.StatusBarLocationPublisher;
52 import com.android.systemui.statusbar.phone.StatusIconContainer;
53 import com.android.systemui.statusbar.phone.TapAgainView;
54 import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment;
55 import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragmentLogger;
56 import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentComponent;
57 import com.android.systemui.statusbar.phone.ongoingcall.OngoingCallController;
58 import com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManager;
59 import com.android.systemui.statusbar.policy.BatteryController;
60 import com.android.systemui.statusbar.policy.ConfigurationController;
61 import com.android.systemui.statusbar.policy.KeyguardStateController;
62 import com.android.systemui.tuner.TunerService;
63 
64 import javax.inject.Named;
65 
66 import dagger.Module;
67 import dagger.Provides;
68 
69 @Module(subcomponents = StatusBarFragmentComponent.class)
70 public abstract class StatusBarViewModule {
71 
72     public static final String SPLIT_SHADE_HEADER = "split_shade_header";
73     private static final String SPLIT_SHADE_BATTERY_VIEW = "split_shade_battery_view";
74     public static final String SPLIT_SHADE_BATTERY_CONTROLLER = "split_shade_battery_controller";
75 
76     /** */
77     @Provides
78     @StatusBarComponent.StatusBarScope
providesNotificationShadeWindowView( LayoutInflater layoutInflater)79     public static NotificationShadeWindowView providesNotificationShadeWindowView(
80             LayoutInflater layoutInflater) {
81         NotificationShadeWindowView notificationShadeWindowView = (NotificationShadeWindowView)
82                 layoutInflater.inflate(R.layout.super_notification_shade, /* root= */ null);
83         if (notificationShadeWindowView == null) {
84             throw new IllegalStateException(
85                     "R.layout.super_notification_shade could not be properly inflated");
86         }
87 
88         return notificationShadeWindowView;
89     }
90 
91     /** */
92     @Provides
93     @StatusBarComponent.StatusBarScope
providesNotificationStackScrollLayout( NotificationShadeWindowView notificationShadeWindowView)94     public static NotificationStackScrollLayout providesNotificationStackScrollLayout(
95             NotificationShadeWindowView notificationShadeWindowView) {
96         return notificationShadeWindowView.findViewById(R.id.notification_stack_scroller);
97     }
98 
99     /** */
100     @Provides
101     @StatusBarComponent.StatusBarScope
providesNotificationShelf(LayoutInflater layoutInflater, NotificationStackScrollLayout notificationStackScrollLayout)102     public static NotificationShelf providesNotificationShelf(LayoutInflater layoutInflater,
103             NotificationStackScrollLayout notificationStackScrollLayout) {
104         NotificationShelf view = (NotificationShelf) layoutInflater.inflate(
105                 R.layout.status_bar_notification_shelf, notificationStackScrollLayout, false);
106 
107         if (view == null) {
108             throw new IllegalStateException(
109                     "R.layout.status_bar_notification_shelf could not be properly inflated");
110         }
111         return view;
112     }
113 
114     /** */
115     @Provides
116     @StatusBarComponent.StatusBarScope
providesStatusBarWindowView( NotificationShelfComponent.Builder notificationShelfComponentBuilder, NotificationShelf notificationShelf)117     public static NotificationShelfController providesStatusBarWindowView(
118             NotificationShelfComponent.Builder notificationShelfComponentBuilder,
119             NotificationShelf notificationShelf) {
120         NotificationShelfComponent component = notificationShelfComponentBuilder
121                 .notificationShelf(notificationShelf)
122                 .build();
123         NotificationShelfController notificationShelfController =
124                 component.getNotificationShelfController();
125         notificationShelfController.init();
126 
127         return notificationShelfController;
128     }
129 
130     /** */
131     @Provides
132     @StatusBarComponent.StatusBarScope
getNotificationPanelView( NotificationShadeWindowView notificationShadeWindowView)133     public static NotificationPanelView getNotificationPanelView(
134             NotificationShadeWindowView notificationShadeWindowView) {
135         return notificationShadeWindowView.getNotificationPanelView();
136     }
137 
138     /** */
139     @Provides
140     @StatusBarComponent.StatusBarScope
getLockIconView( NotificationShadeWindowView notificationShadeWindowView)141     public static LockIconView getLockIconView(
142             NotificationShadeWindowView notificationShadeWindowView) {
143         return notificationShadeWindowView.findViewById(R.id.lock_icon_view);
144     }
145 
146     /** */
147     @Provides
148     @StatusBarComponent.StatusBarScope
149     @Nullable
getAuthRippleView( NotificationShadeWindowView notificationShadeWindowView)150     public static AuthRippleView getAuthRippleView(
151             NotificationShadeWindowView notificationShadeWindowView) {
152         return notificationShadeWindowView.findViewById(R.id.auth_ripple);
153     }
154 
155     /** */
156     @Provides
157     @Named(SPLIT_SHADE_HEADER)
158     @StatusBarComponent.StatusBarScope
getSplitShadeStatusBarView( NotificationShadeWindowView notificationShadeWindowView, FeatureFlags featureFlags)159     public static View getSplitShadeStatusBarView(
160             NotificationShadeWindowView notificationShadeWindowView,
161             FeatureFlags featureFlags) {
162         ViewStub stub = notificationShadeWindowView.findViewById(R.id.qs_header_stub);
163         int layoutId = featureFlags.useCombinedQSHeaders()
164                 ? R.layout.combined_qs_header
165                 : R.layout.split_shade_header;
166         stub.setLayoutResource(layoutId);
167         View v = stub.inflate();
168         return v;
169     }
170 
171     /** */
172     @Provides
173     @StatusBarComponent.StatusBarScope
getSplitShadeOngoingPrivacyChip( @amedSPLIT_SHADE_HEADER) View header)174     public static OngoingPrivacyChip getSplitShadeOngoingPrivacyChip(
175             @Named(SPLIT_SHADE_HEADER) View header) {
176         return header.findViewById(R.id.privacy_chip);
177     }
178 
179     /** */
180     @Provides
181     @StatusBarComponent.StatusBarScope
providesStatusIconContainer(@amedSPLIT_SHADE_HEADER) View header)182     static StatusIconContainer providesStatusIconContainer(@Named(SPLIT_SHADE_HEADER) View header) {
183         return header.findViewById(R.id.statusIcons);
184     }
185 
186     /** */
187     @Provides
188     @StatusBarComponent.StatusBarScope
189     @Named(SPLIT_SHADE_BATTERY_VIEW)
getBatteryMeterView(@amedSPLIT_SHADE_HEADER) View view)190     static BatteryMeterView getBatteryMeterView(@Named(SPLIT_SHADE_HEADER) View view) {
191         return view.findViewById(R.id.batteryRemainingIcon);
192     }
193 
194     @Provides
195     @StatusBarComponent.StatusBarScope
196     @Named(SPLIT_SHADE_BATTERY_CONTROLLER)
getBatteryMeterViewController( @amedSPLIT_SHADE_BATTERY_VIEW) BatteryMeterView batteryMeterView, ConfigurationController configurationController, TunerService tunerService, BroadcastDispatcher broadcastDispatcher, @Main Handler mainHandler, ContentResolver contentResolver, BatteryController batteryController )197     static BatteryMeterViewController getBatteryMeterViewController(
198             @Named(SPLIT_SHADE_BATTERY_VIEW) BatteryMeterView batteryMeterView,
199             ConfigurationController configurationController,
200             TunerService tunerService,
201             BroadcastDispatcher broadcastDispatcher,
202             @Main Handler mainHandler,
203             ContentResolver contentResolver,
204             BatteryController batteryController
205     ) {
206         return new BatteryMeterViewController(
207                 batteryMeterView,
208                 configurationController,
209                 tunerService,
210                 broadcastDispatcher,
211                 mainHandler,
212                 contentResolver,
213                 batteryController);
214 
215     }
216 
217     /** */
218     @Provides
219     @StatusBarComponent.StatusBarScope
getTapAgainView(NotificationPanelView npv)220     public static TapAgainView getTapAgainView(NotificationPanelView npv) {
221         return npv.getTapAgainView();
222     }
223 
224     /** */
225     @Provides
226     @StatusBarComponent.StatusBarScope
getNotificationsQuickSettingsContainer( NotificationShadeWindowView notificationShadeWindowView)227     public static NotificationsQuickSettingsContainer getNotificationsQuickSettingsContainer(
228             NotificationShadeWindowView notificationShadeWindowView) {
229         return notificationShadeWindowView.findViewById(R.id.notification_container_parent);
230     }
231 
232     /**
233      * Creates a new {@link CollapsedStatusBarFragment}.
234      *
235      * **IMPORTANT**: This method intentionally does not have
236      * {@link StatusBarComponent.StatusBarScope}, which means a new fragment *will* be created each
237      * time this method is called. This is intentional because we need fragments to re-created in
238      * certain lifecycle scenarios.
239      *
240      * **IMPORTANT**: This method also intentionally does not have a {@link Provides} annotation. If
241      * you need to get access to a {@link CollapsedStatusBarFragment}, go through
242      * {@link StatusBarFragmentComponent} instead.
243      */
createCollapsedStatusBarFragment( StatusBarFragmentComponent.Factory statusBarFragmentComponentFactory, OngoingCallController ongoingCallController, SystemStatusAnimationScheduler animationScheduler, StatusBarLocationPublisher locationPublisher, NotificationIconAreaController notificationIconAreaController, PanelExpansionStateManager panelExpansionStateManager, FeatureFlags featureFlags, StatusBarIconController statusBarIconController, StatusBarHideIconsForBouncerManager statusBarHideIconsForBouncerManager, KeyguardStateController keyguardStateController, NotificationPanelViewController notificationPanelViewController, NetworkController networkController, StatusBarStateController statusBarStateController, CommandQueue commandQueue, CollapsedStatusBarFragmentLogger collapsedStatusBarFragmentLogger, OperatorNameViewController.Factory operatorNameViewControllerFactory )244     public static CollapsedStatusBarFragment createCollapsedStatusBarFragment(
245             StatusBarFragmentComponent.Factory statusBarFragmentComponentFactory,
246             OngoingCallController ongoingCallController,
247             SystemStatusAnimationScheduler animationScheduler,
248             StatusBarLocationPublisher locationPublisher,
249             NotificationIconAreaController notificationIconAreaController,
250             PanelExpansionStateManager panelExpansionStateManager,
251             FeatureFlags featureFlags,
252             StatusBarIconController statusBarIconController,
253             StatusBarHideIconsForBouncerManager statusBarHideIconsForBouncerManager,
254             KeyguardStateController keyguardStateController,
255             NotificationPanelViewController notificationPanelViewController,
256             NetworkController networkController,
257             StatusBarStateController statusBarStateController,
258             CommandQueue commandQueue,
259             CollapsedStatusBarFragmentLogger collapsedStatusBarFragmentLogger,
260             OperatorNameViewController.Factory operatorNameViewControllerFactory
261     ) {
262         return new CollapsedStatusBarFragment(statusBarFragmentComponentFactory,
263                 ongoingCallController,
264                 animationScheduler,
265                 locationPublisher,
266                 notificationIconAreaController,
267                 panelExpansionStateManager,
268                 featureFlags,
269                 statusBarIconController,
270                 statusBarHideIconsForBouncerManager,
271                 keyguardStateController,
272                 notificationPanelViewController,
273                 networkController,
274                 statusBarStateController,
275                 commandQueue,
276                 collapsedStatusBarFragmentLogger,
277                 operatorNameViewControllerFactory);
278     }
279 }
280