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.dagger;
18 
19 import android.annotation.Nullable;
20 import android.content.Context;
21 import android.content.pm.PackageManager;
22 
23 import com.android.keyguard.KeyguardUpdateMonitor;
24 import com.android.systemui.BootCompleteCache;
25 import com.android.systemui.BootCompleteCacheImpl;
26 import com.android.systemui.assist.AssistModule;
27 import com.android.systemui.dump.DumpManager;
28 import com.android.systemui.log.dagger.LogModule;
29 import com.android.systemui.model.SysUiState;
30 import com.android.systemui.plugins.statusbar.StatusBarStateController;
31 import com.android.systemui.recents.Recents;
32 import com.android.systemui.settings.dagger.SettingsModule;
33 import com.android.systemui.stackdivider.Divider;
34 import com.android.systemui.statusbar.CommandQueue;
35 import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinder;
36 import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinderImpl;
37 import com.android.systemui.statusbar.notification.people.PeopleHubModule;
38 import com.android.systemui.statusbar.notification.row.dagger.ExpandableNotificationRowComponent;
39 import com.android.systemui.statusbar.notification.row.dagger.NotificationRowComponent;
40 import com.android.systemui.statusbar.phone.KeyguardLiftController;
41 import com.android.systemui.statusbar.phone.StatusBar;
42 import com.android.systemui.statusbar.phone.dagger.StatusBarComponent;
43 import com.android.systemui.statusbar.policy.HeadsUpManager;
44 import com.android.systemui.util.concurrency.ConcurrencyModule;
45 import com.android.systemui.util.sensors.AsyncSensorManager;
46 import com.android.systemui.util.time.SystemClock;
47 import com.android.systemui.util.time.SystemClockImpl;
48 
49 import javax.inject.Singleton;
50 
51 import dagger.Binds;
52 import dagger.BindsOptionalOf;
53 import dagger.Module;
54 import dagger.Provides;
55 
56 /**
57  * A dagger module for injecting components of System UI that are not overridden by the System UI
58  * implementation.
59  */
60 @Module(includes = {
61             AssistModule.class,
62             ConcurrencyModule.class,
63             LogModule.class,
64             PeopleHubModule.class,
65             SettingsModule.class
66         },
67         subcomponents = {StatusBarComponent.class,
68                 NotificationRowComponent.class,
69                 ExpandableNotificationRowComponent.class})
70 public abstract class SystemUIModule {
71 
72     @Binds
bindBootCompleteCache(BootCompleteCacheImpl bootCompleteCache)73     abstract BootCompleteCache bindBootCompleteCache(BootCompleteCacheImpl bootCompleteCache);
74 
75     /** */
76     @Binds
bindComponentHelper( ContextComponentResolver componentHelper)77     public abstract ContextComponentHelper bindComponentHelper(
78             ContextComponentResolver componentHelper);
79 
80     @Singleton
81     @Provides
82     @Nullable
provideKeyguardLiftController( Context context, StatusBarStateController statusBarStateController, AsyncSensorManager asyncSensorManager, KeyguardUpdateMonitor keyguardUpdateMonitor, DumpManager dumpManager)83     static KeyguardLiftController provideKeyguardLiftController(
84             Context context,
85             StatusBarStateController statusBarStateController,
86             AsyncSensorManager asyncSensorManager,
87             KeyguardUpdateMonitor keyguardUpdateMonitor,
88             DumpManager dumpManager) {
89         if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE)) {
90             return null;
91         }
92         return new KeyguardLiftController(statusBarStateController, asyncSensorManager,
93                 keyguardUpdateMonitor, dumpManager);
94     }
95 
96     /** */
97     @Binds
bindNotificationRowBinder( NotificationRowBinderImpl notificationRowBinder)98     public abstract NotificationRowBinder bindNotificationRowBinder(
99             NotificationRowBinderImpl notificationRowBinder);
100 
101     @Singleton
102     @Provides
provideSysUiState()103     static SysUiState provideSysUiState() {
104         return new SysUiState();
105     }
106 
107     @BindsOptionalOf
optionalCommandQueue()108     abstract CommandQueue optionalCommandQueue();
109 
110     @BindsOptionalOf
optionalDivider()111     abstract Divider optionalDivider();
112 
113     @BindsOptionalOf
optionalHeadsUpManager()114     abstract HeadsUpManager optionalHeadsUpManager();
115 
116     @BindsOptionalOf
optionalRecents()117     abstract Recents optionalRecents();
118 
119     @BindsOptionalOf
optionalStatusBar()120     abstract StatusBar optionalStatusBar();
121 
122     @Singleton
123     @Binds
bindSystemClock(SystemClockImpl systemClock)124     abstract SystemClock bindSystemClock(SystemClockImpl systemClock);
125 }
126