• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.annotation.SuppressLint;
21 import android.app.ActivityManager;
22 import android.app.ActivityTaskManager;
23 import android.app.AlarmManager;
24 import android.app.IActivityManager;
25 import android.app.IActivityTaskManager;
26 import android.app.IWallpaperManager;
27 import android.app.KeyguardManager;
28 import android.app.NotificationManager;
29 import android.app.WallpaperManager;
30 import android.app.admin.DevicePolicyManager;
31 import android.app.role.RoleManager;
32 import android.app.trust.TrustManager;
33 import android.content.ContentResolver;
34 import android.content.Context;
35 import android.content.pm.IPackageManager;
36 import android.content.pm.LauncherApps;
37 import android.content.pm.PackageManager;
38 import android.content.pm.ShortcutManager;
39 import android.content.res.Resources;
40 import android.hardware.SensorManager;
41 import android.hardware.SensorPrivacyManager;
42 import android.hardware.display.DisplayManager;
43 import android.media.AudioManager;
44 import android.media.MediaRouter2Manager;
45 import android.media.session.MediaSessionManager;
46 import android.net.ConnectivityManager;
47 import android.net.NetworkScoreManager;
48 import android.net.wifi.WifiManager;
49 import android.os.BatteryStats;
50 import android.os.Handler;
51 import android.os.PowerManager;
52 import android.os.ServiceManager;
53 import android.os.UserHandle;
54 import android.os.UserManager;
55 import android.os.Vibrator;
56 import android.service.dreams.DreamService;
57 import android.service.dreams.IDreamManager;
58 import android.telecom.TelecomManager;
59 import android.telephony.TelephonyManager;
60 import android.view.IWindowManager;
61 import android.view.WindowManager;
62 import android.view.WindowManagerGlobal;
63 import android.view.accessibility.AccessibilityManager;
64 
65 import com.android.internal.app.IBatteryStats;
66 import com.android.internal.statusbar.IStatusBarService;
67 import com.android.internal.util.LatencyTracker;
68 import com.android.settingslib.bluetooth.LocalBluetoothManager;
69 import com.android.systemui.dagger.qualifiers.Background;
70 import com.android.systemui.dagger.qualifiers.DisplayId;
71 import com.android.systemui.dagger.qualifiers.Main;
72 import com.android.systemui.shared.system.PackageManagerWrapper;
73 
74 import javax.inject.Singleton;
75 
76 import dagger.Module;
77 import dagger.Provides;
78 
79 /**
80  * Provides Non-SystemUI, Framework-Owned instances to the dependency graph.
81  */
82 @Module
83 public class SystemServicesModule {
84     @Provides
85     @Singleton
provideAccessibilityManager(Context context)86     static AccessibilityManager provideAccessibilityManager(Context context) {
87         return context.getSystemService(AccessibilityManager.class);
88     }
89 
90     @Provides
91     @Singleton
provideActivityManager(Context context)92     static ActivityManager provideActivityManager(Context context) {
93         return context.getSystemService(ActivityManager.class);
94     }
95 
96     @Singleton
97     @Provides
provideAlarmManager(Context context)98     static AlarmManager provideAlarmManager(Context context) {
99         return context.getSystemService(AlarmManager.class);
100     }
101 
102     @Provides
103     @Singleton
provideAudioManager(Context context)104     static AudioManager provideAudioManager(Context context) {
105         return context.getSystemService(AudioManager.class);
106     }
107 
108     @Provides
109     @Singleton
provideConnectivityManagager(Context context)110     static ConnectivityManager provideConnectivityManagager(Context context) {
111         return context.getSystemService(ConnectivityManager.class);
112     }
113 
114     @Provides
115     @Singleton
provideContentResolver(Context context)116     static ContentResolver provideContentResolver(Context context) {
117         return context.getContentResolver();
118     }
119 
120     @Provides
121     @Singleton
provideDevicePolicyManager(Context context)122     static DevicePolicyManager provideDevicePolicyManager(Context context) {
123         return context.getSystemService(DevicePolicyManager.class);
124     }
125 
126     @Provides
127     @DisplayId
provideDisplayId(Context context)128     static int provideDisplayId(Context context) {
129         return context.getDisplayId();
130     }
131 
132     @Provides
133     @Singleton
provideDisplayManager(Context context)134     static DisplayManager provideDisplayManager(Context context) {
135         return context.getSystemService(DisplayManager.class);
136     }
137 
138     @Singleton
139     @Provides
provideIActivityManager()140     static IActivityManager provideIActivityManager() {
141         return ActivityManager.getService();
142     }
143 
144     @Singleton
145     @Provides
provideIActivityTaskManager()146     static IActivityTaskManager provideIActivityTaskManager() {
147         return ActivityTaskManager.getService();
148     }
149 
150     @Provides
151     @Singleton
provideIBatteryStats()152     static IBatteryStats provideIBatteryStats() {
153         return IBatteryStats.Stub.asInterface(
154                 ServiceManager.getService(BatteryStats.SERVICE_NAME));
155     }
156 
157     @Provides
158     @Singleton
provideIDreamManager()159     static IDreamManager provideIDreamManager() {
160         return IDreamManager.Stub.asInterface(
161                 ServiceManager.checkService(DreamService.DREAM_SERVICE));
162     }
163 
164     @Provides
165     @Singleton
provideIPackageManager()166     static IPackageManager provideIPackageManager() {
167         return IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
168     }
169 
170     @Singleton
171     @Provides
provideIStatusBarService()172     static IStatusBarService provideIStatusBarService() {
173         return IStatusBarService.Stub.asInterface(
174                 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
175     }
176 
177     @Provides
178     @Nullable
provideIWallPaperManager()179     static IWallpaperManager provideIWallPaperManager() {
180         return IWallpaperManager.Stub.asInterface(
181                 ServiceManager.getService(Context.WALLPAPER_SERVICE));
182     }
183 
184     @Singleton
185     @Provides
provideIWindowManager()186     static IWindowManager provideIWindowManager() {
187         return WindowManagerGlobal.getWindowManagerService();
188     }
189 
190     @Singleton
191     @Provides
provideKeyguardManager(Context context)192     static KeyguardManager provideKeyguardManager(Context context) {
193         return context.getSystemService(KeyguardManager.class);
194     }
195 
196     @Singleton
197     @Provides
provideLatencyTracker(Context context)198     static LatencyTracker provideLatencyTracker(Context context) {
199         return LatencyTracker.getInstance(context);
200     }
201 
202     @Singleton
203     @Provides
provideLauncherApps(Context context)204     static LauncherApps provideLauncherApps(Context context) {
205         return context.getSystemService(LauncherApps.class);
206     }
207 
208     @SuppressLint("MissingPermission")
209     @Singleton
210     @Provides
211     @Nullable
provideLocalBluetoothController(Context context, @Background Handler bgHandler)212     static LocalBluetoothManager provideLocalBluetoothController(Context context,
213             @Background Handler bgHandler) {
214         return LocalBluetoothManager.create(context, bgHandler, UserHandle.ALL);
215     }
216 
217     @Provides
provideMediaRouter2Manager(Context context)218     static MediaRouter2Manager provideMediaRouter2Manager(Context context) {
219         return MediaRouter2Manager.getInstance(context);
220     }
221 
222     @Provides
provideMediaSessionManager(Context context)223     static MediaSessionManager provideMediaSessionManager(Context context) {
224         return context.getSystemService(MediaSessionManager.class);
225     }
226 
227     @Provides
228     @Singleton
provideNetworkScoreManager(Context context)229     static NetworkScoreManager provideNetworkScoreManager(Context context) {
230         return context.getSystemService(NetworkScoreManager.class);
231     }
232 
233     @Singleton
234     @Provides
provideNotificationManager(Context context)235     static NotificationManager provideNotificationManager(Context context) {
236         return context.getSystemService(NotificationManager.class);
237     }
238 
239     @Singleton
240     @Provides
providePackageManager(Context context)241     static PackageManager providePackageManager(Context context) {
242         return context.getPackageManager();
243     }
244 
245     @Singleton
246     @Provides
providePackageManagerWrapper()247     static PackageManagerWrapper providePackageManagerWrapper() {
248         return PackageManagerWrapper.getInstance();
249     }
250 
251     /** */
252     @Singleton
253     @Provides
providePowerManager(Context context)254     static PowerManager providePowerManager(Context context) {
255         return context.getSystemService(PowerManager.class);
256     }
257 
258     @Provides
259     @Main
provideResources(Context context)260     static Resources provideResources(Context context) {
261         return context.getResources();
262     }
263 
264     @Provides
265     @Singleton
providesSensorManager(Context context)266     static SensorManager providesSensorManager(Context context) {
267         return context.getSystemService(SensorManager.class);
268     }
269 
270     @Singleton
271     @Provides
provideSensorPrivacyManager(Context context)272     static SensorPrivacyManager provideSensorPrivacyManager(Context context) {
273         return context.getSystemService(SensorPrivacyManager.class);
274     }
275 
276     @Singleton
277     @Provides
provideShortcutManager(Context context)278     static ShortcutManager provideShortcutManager(Context context) {
279         return context.getSystemService(ShortcutManager.class);
280     }
281 
282     @Provides
283     @Singleton
284     @Nullable
provideTelecomManager(Context context)285     static TelecomManager provideTelecomManager(Context context) {
286         return context.getSystemService(TelecomManager.class);
287     }
288 
289     @Provides
290     @Singleton
provideTelephonyManager(Context context)291     static TelephonyManager provideTelephonyManager(Context context) {
292         return context.getSystemService(TelephonyManager.class);
293     }
294 
295     @Provides
296     @Singleton
provideTrustManager(Context context)297     static TrustManager provideTrustManager(Context context) {
298         return context.getSystemService(TrustManager.class);
299     }
300 
301     @Provides
302     @Singleton
303     @Nullable
provideVibrator(Context context)304     static Vibrator provideVibrator(Context context) {
305         return context.getSystemService(Vibrator.class);
306     }
307 
308     @Provides
309     @Singleton
provideUserManager(Context context)310     static UserManager provideUserManager(Context context) {
311         return context.getSystemService(UserManager.class);
312     }
313 
314     @Provides
provideWallpaperManager(Context context)315     static WallpaperManager provideWallpaperManager(Context context) {
316         return (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
317     }
318 
319     @Provides
320     @Singleton
provideWifiManager(Context context)321     static WifiManager provideWifiManager(Context context) {
322         return context.getSystemService(WifiManager.class);
323     }
324 
325     @Singleton
326     @Provides
provideWindowManager(Context context)327     static WindowManager provideWindowManager(Context context) {
328         return context.getSystemService(WindowManager.class);
329     }
330 
331     @Provides
332     @Singleton
provideRoleManager(Context context)333     static RoleManager provideRoleManager(Context context) {
334         return context.getSystemService(RoleManager.class);
335     }
336 }
337