blob: a517d7ce8e0e8d221cd7bd8b90e5b37ac65b0c37 [file] [log] [blame]
Jason Monk27d01a622018-12-10 15:57:09 -05001/*
2 * Copyright (C) 2018 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
17package com.android.systemui;
18
19import static com.android.systemui.Dependency.BG_HANDLER_NAME;
20import static com.android.systemui.Dependency.BG_LOOPER_NAME;
Jason Monk27d01a622018-12-10 15:57:09 -050021import static com.android.systemui.Dependency.MAIN_HANDLER_NAME;
22import static com.android.systemui.Dependency.TIME_TICK_HANDLER_NAME;
23
24import android.annotation.Nullable;
25import android.content.Context;
Jason Monk27d01a622018-12-10 15:57:09 -050026import android.hardware.SensorPrivacyManager;
Christine Franks71e003e2019-01-24 14:40:20 -080027import android.hardware.display.NightDisplayListener;
Jason Monk27d01a622018-12-10 15:57:09 -050028import android.os.Handler;
29import android.os.HandlerThread;
30import android.os.Looper;
31import android.os.Process;
32import android.os.ServiceManager;
33import android.os.UserHandle;
34import android.util.DisplayMetrics;
Jason Monk27d01a622018-12-10 15:57:09 -050035import android.view.IWindowManager;
36import android.view.WindowManagerGlobal;
37
Jason Monk27d01a622018-12-10 15:57:09 -050038import com.android.internal.logging.MetricsLogger;
39import com.android.internal.statusbar.IStatusBarService;
40import com.android.settingslib.bluetooth.LocalBluetoothManager;
Jason Monk27d01a622018-12-10 15:57:09 -050041import com.android.systemui.plugins.PluginInitializerImpl;
Jason Monk27d01a622018-12-10 15:57:09 -050042import com.android.systemui.shared.plugins.PluginManager;
43import com.android.systemui.shared.plugins.PluginManagerImpl;
Charles Chen10ca70b2018-11-28 00:03:38 +080044import com.android.systemui.statusbar.NavigationBarController;
Charles Chen8c9a83f2018-12-18 17:44:10 +080045import com.android.systemui.statusbar.phone.AutoHideController;
Jason Monk27d01a622018-12-10 15:57:09 -050046import com.android.systemui.statusbar.phone.ConfigurationControllerImpl;
Jason Monk27d01a622018-12-10 15:57:09 -050047import com.android.systemui.statusbar.policy.ConfigurationController;
Jason Monk27d01a622018-12-10 15:57:09 -050048import com.android.systemui.statusbar.policy.DataSaverController;
Jason Monk27d01a622018-12-10 15:57:09 -050049import com.android.systemui.statusbar.policy.NetworkController;
Jason Monk27d01a622018-12-10 15:57:09 -050050import com.android.systemui.util.leak.LeakDetector;
Jason Monk27d01a622018-12-10 15:57:09 -050051
52import javax.inject.Named;
53import javax.inject.Singleton;
54
55import dagger.Module;
56import dagger.Provides;
57
58/**
59 * Provides dependencies for the root component of sysui injection.
60 * See SystemUI/docs/dagger.md
61 */
62@Module
63public class DependencyProvider {
64
65 @Singleton
66 @Provides
67 @Named(TIME_TICK_HANDLER_NAME)
68 public Handler provideHandler() {
69 HandlerThread thread = new HandlerThread("TimeTick");
70 thread.start();
71 return new Handler(thread.getLooper());
72 }
73
74 @Singleton
75 @Provides
76 @Named(BG_LOOPER_NAME)
77 public Looper provideBgLooper() {
78 HandlerThread thread = new HandlerThread("SysUiBg",
79 Process.THREAD_PRIORITY_BACKGROUND);
80 thread.start();
81 return thread.getLooper();
82 }
83
84 @Singleton
85 @Provides
86 @Named(BG_HANDLER_NAME)
87 public Handler provideBgHandler(@Named(BG_LOOPER_NAME) Looper bgLooper) {
88 return new Handler(bgLooper);
89 }
90
91 @Singleton
92 @Provides
93 @Named(MAIN_HANDLER_NAME)
94 public Handler provideMainHandler() {
95 return new Handler(Looper.getMainLooper());
96 }
97
98 @Singleton
99 @Provides
Jason Monk27d01a622018-12-10 15:57:09 -0500100 public DataSaverController provideDataSaverController(NetworkController networkController) {
101 return networkController.getDataSaverController();
102 }
103
104 @Singleton
105 @Provides
Brad Stenning32cedc12018-12-20 11:25:06 -0800106 @Nullable
Jason Monk27d01a622018-12-10 15:57:09 -0500107 public LocalBluetoothManager provideLocalBluetoothController(Context context,
108 @Named(BG_HANDLER_NAME) Handler bgHandler) {
109 return LocalBluetoothManager.create(context, bgHandler,
110 UserHandle.ALL);
111 }
112
113 @Singleton
114 @Provides
Jason Monk27d01a622018-12-10 15:57:09 -0500115 public MetricsLogger provideMetricsLogger() {
116 return new MetricsLogger();
Jason Monk27d01a622018-12-10 15:57:09 -0500117 }
118
119 @Singleton
120 @Provides
121 public IWindowManager provideIWindowManager() {
122 return WindowManagerGlobal.getWindowManagerService();
123 }
124
125 @Singleton
126 @Provides
Jason Monk27d01a622018-12-10 15:57:09 -0500127 public IStatusBarService provideIStatusBarService() {
128 return IStatusBarService.Stub.asInterface(
129 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
130 }
131
132 @Singleton
133 @Provides
134 // Single instance of DisplayMetrics, gets updated by StatusBar, but can be used
Jason Monk196d6392018-12-20 13:25:34 -0500135 // anywhere it is needed.
Jason Monk27d01a622018-12-10 15:57:09 -0500136 public DisplayMetrics provideDisplayMetrics() {
137 return new DisplayMetrics();
Jason Monk27d01a622018-12-10 15:57:09 -0500138 }
139
140 @Singleton
141 @Provides
Jason Monk27d01a622018-12-10 15:57:09 -0500142 public SensorPrivacyManager provideSensorPrivacyManager(Context context) {
143 return context.getSystemService(SensorPrivacyManager.class);
144 }
Jason Monk196d6392018-12-20 13:25:34 -0500145
146 @Singleton
147 @Provides
148 public LeakDetector provideLeakDetector() {
149 return LeakDetector.create();
150
151 }
152
153 @Singleton
154 @Provides
Christine Franks71e003e2019-01-24 14:40:20 -0800155 public NightDisplayListener provideNightDisplayListener(Context context) {
156 return new NightDisplayListener(context);
Jason Monk196d6392018-12-20 13:25:34 -0500157 }
158
159 @Singleton
160 @Provides
161 public PluginManager providePluginManager(Context context) {
162 return new PluginManagerImpl(context, new PluginInitializerImpl());
163 }
164
165 @Singleton
166 @Provides
Charles Chen10ca70b2018-11-28 00:03:38 +0800167 public NavigationBarController provideNavigationBarController(Context context,
168 @Named(MAIN_HANDLER_NAME) Handler mainHandler) {
169 return new NavigationBarController(context, mainHandler);
170 }
171
172 @Singleton
173 @Provides
Jason Monk196d6392018-12-20 13:25:34 -0500174 public ConfigurationController provideConfigurationController(Context context) {
175 return new ConfigurationControllerImpl(context);
176 }
Charles Chen8c9a83f2018-12-18 17:44:10 +0800177
178 @Singleton
179 @Provides
180 public AutoHideController provideAutoHideController(Context context,
181 @Named(MAIN_HANDLER_NAME) Handler mainHandler) {
182 return new AutoHideController(context, mainHandler);
183 }
Jason Monk27d01a622018-12-10 15:57:09 -0500184}