1 /*
2  * Copyright (C) 2021 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.fragment.dagger;
18 
19 import com.android.systemui.battery.BatteryMeterViewController;
20 import com.android.systemui.dagger.qualifiers.RootView;
21 import com.android.systemui.statusbar.notification.shared.NotificationsLiveDataStoreRefactor;
22 import com.android.systemui.statusbar.phone.HeadsUpAppearanceController;
23 import com.android.systemui.statusbar.phone.LegacyLightsOutNotifController;
24 import com.android.systemui.statusbar.phone.PhoneStatusBarTransitions;
25 import com.android.systemui.statusbar.phone.PhoneStatusBarView;
26 import com.android.systemui.statusbar.phone.PhoneStatusBarViewController;
27 import com.android.systemui.statusbar.phone.StatusBarBoundsProvider;
28 import com.android.systemui.statusbar.phone.StatusBarDemoMode;
29 import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment;
30 
31 import dagger.BindsInstance;
32 import dagger.Subcomponent;
33 
34 import java.util.Set;
35 
36 /**
37  * A subcomponent that gets re-created each time we create a new {@link CollapsedStatusBarFragment}.
38  *
39  * This component will also re-create all classes that depend on {@link CollapsedStatusBarFragment}
40  * and friends. Specifically, the fragment creates a new {@link PhoneStatusBarView} and multiple
41  * controllers need access to that view, so those controllers will be re-created whenever the
42  * fragment is recreated.
43  *
44  * Anything that depends on {@link CollapsedStatusBarFragment} or {@link PhoneStatusBarView}
45  * should be included here or in {@link StatusBarFragmentModule}.
46  */
47 
48 @Subcomponent(modules = {
49         StatusBarFragmentModule.class,
50         StatusBarStartablesModule.class
51 })
52 @StatusBarFragmentScope
53 public interface StatusBarFragmentComponent {
54     /** Simple factory. */
55     @Subcomponent.Factory
56     interface Factory {
create( @indsInstance @ootView PhoneStatusBarView phoneStatusBarView)57         StatusBarFragmentComponent create(
58                 @BindsInstance @RootView PhoneStatusBarView phoneStatusBarView);
59     }
60 
61     /**
62      * Performs initialization logic after {@link StatusBarFragmentComponent} has been constructed.
63      */
64     interface Startable {
start()65         void start();
stop()66         void stop();
67 
68         enum State {
69             NONE, STARTING, STARTED, STOPPING, STOPPED
70         }
71     }
72 
73     /**
74      * Initialize anything extra for the component. Must be called after the component is created.
75      */
init()76     default void init() {
77         // No one accesses these controllers, so we need to make sure we reference them here so they
78         // do get initialized.
79         getBatteryMeterViewController().init();
80         getHeadsUpAppearanceController().init();
81         getPhoneStatusBarViewController().init();
82         if (!NotificationsLiveDataStoreRefactor.isEnabled()) {
83             getLegacyLightsOutNotifController().init();
84         }
85         getStatusBarDemoMode().init();
86     }
87 
88     /** */
89     @StatusBarFragmentScope
getBatteryMeterViewController()90     BatteryMeterViewController getBatteryMeterViewController();
91 
92     /** */
93     @StatusBarFragmentScope
94     @RootView
getPhoneStatusBarView()95     PhoneStatusBarView getPhoneStatusBarView();
96 
97     /** */
98     @StatusBarFragmentScope
getPhoneStatusBarViewController()99     PhoneStatusBarViewController getPhoneStatusBarViewController();
100 
101     /** */
102     @StatusBarFragmentScope
getHeadsUpAppearanceController()103     HeadsUpAppearanceController getHeadsUpAppearanceController();
104 
105     /** */
106     @StatusBarFragmentScope
getLegacyLightsOutNotifController()107     LegacyLightsOutNotifController getLegacyLightsOutNotifController();
108 
109     /** */
110     @StatusBarFragmentScope
getStatusBarDemoMode()111     StatusBarDemoMode getStatusBarDemoMode();
112 
113     /** */
114     @StatusBarFragmentScope
getPhoneStatusBarTransitions()115     PhoneStatusBarTransitions getPhoneStatusBarTransitions();
116 
117     /** */
getStartables()118     Set<Startable> getStartables();
119 
120     /** */
getBoundsProvider()121     StatusBarBoundsProvider getBoundsProvider();
122 }
123