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.app.ActivityManager;
21 import android.app.ActivityTaskManager;
22 import android.app.AlarmManager;
23 import android.app.IActivityManager;
24 import android.app.IActivityTaskManager;
25 import android.app.IWallpaperManager;
26 import android.app.KeyguardManager;
27 import android.app.NotificationManager;
28 import android.app.StatsManager;
29 import android.app.WallpaperManager;
30 import android.app.admin.DevicePolicyManager;
31 import android.app.role.RoleManager;
32 import android.app.smartspace.SmartspaceManager;
33 import android.app.trust.TrustManager;
34 import android.content.ContentResolver;
35 import android.content.Context;
36 import android.content.om.OverlayManager;
37 import android.content.pm.IPackageManager;
38 import android.content.pm.LauncherApps;
39 import android.content.pm.PackageManager;
40 import android.content.pm.ShortcutManager;
41 import android.content.res.Resources;
42 import android.hardware.SensorManager;
43 import android.hardware.SensorPrivacyManager;
44 import android.hardware.devicestate.DeviceStateManager;
45 import android.hardware.display.ColorDisplayManager;
46 import android.hardware.display.DisplayManager;
47 import android.hardware.face.FaceManager;
48 import android.hardware.fingerprint.FingerprintManager;
49 import android.media.AudioManager;
50 import android.media.IAudioService;
51 import android.media.MediaRouter2Manager;
52 import android.media.session.MediaSessionManager;
53 import android.net.ConnectivityManager;
54 import android.net.NetworkScoreManager;
55 import android.net.wifi.WifiManager;
56 import android.os.BatteryStats;
57 import android.os.PowerManager;
58 import android.os.ServiceManager;
59 import android.os.UserManager;
60 import android.os.Vibrator;
61 import android.permission.PermissionManager;
62 import android.service.dreams.DreamService;
63 import android.service.dreams.IDreamManager;
64 import android.telecom.TelecomManager;
65 import android.telephony.SubscriptionManager;
66 import android.telephony.TelephonyManager;
67 import android.view.CrossWindowBlurListeners;
68 import android.view.IWindowManager;
69 import android.view.ViewConfiguration;
70 import android.view.WindowManager;
71 import android.view.WindowManagerGlobal;
72 import android.view.accessibility.AccessibilityManager;
73 import android.view.inputmethod.InputMethodManager;
74 
75 import com.android.internal.app.IBatteryStats;
76 import com.android.internal.appwidget.IAppWidgetService;
77 import com.android.internal.jank.InteractionJankMonitor;
78 import com.android.internal.statusbar.IStatusBarService;
79 import com.android.internal.util.LatencyTracker;
80 import com.android.systemui.dagger.qualifiers.DisplayId;
81 import com.android.systemui.dagger.qualifiers.Main;
82 import com.android.systemui.shared.system.PackageManagerWrapper;
83 
84 import java.util.Optional;
85 
86 import javax.inject.Singleton;
87 
88 import dagger.Module;
89 import dagger.Provides;
90 
91 /**
92  * Provides Non-SystemUI, Framework-Owned instances to the dependency graph.
93  */
94 @Module
95 public class FrameworkServicesModule {
96     @Provides
97     @Singleton
provideAccessibilityManager(Context context)98     static AccessibilityManager provideAccessibilityManager(Context context) {
99         return context.getSystemService(AccessibilityManager.class);
100     }
101 
102     @Provides
103     @Singleton
provideActivityManager(Context context)104     static ActivityManager provideActivityManager(Context context) {
105         return context.getSystemService(ActivityManager.class);
106     }
107 
108     @Provides
109     @Singleton
provideAlarmManager(Context context)110     static AlarmManager provideAlarmManager(Context context) {
111         return context.getSystemService(AlarmManager.class);
112     }
113 
114     @Provides
115     @Singleton
provideAudioManager(Context context)116     static AudioManager provideAudioManager(Context context) {
117         return context.getSystemService(AudioManager.class);
118     }
119 
120     @Provides
121     @Singleton
provideColorDisplayManager(Context context)122     static ColorDisplayManager provideColorDisplayManager(Context context) {
123         return context.getSystemService(ColorDisplayManager.class);
124     }
125 
126     @Provides
127     @Singleton
provideConnectivityManagager(Context context)128     static ConnectivityManager provideConnectivityManagager(Context context) {
129         return context.getSystemService(ConnectivityManager.class);
130     }
131 
132     @Provides
133     @Singleton
provideContentResolver(Context context)134     static ContentResolver provideContentResolver(Context context) {
135         return context.getContentResolver();
136     }
137 
138     @Provides
139     @Singleton
provideDevicePolicyManager(Context context)140     static DevicePolicyManager provideDevicePolicyManager(Context context) {
141         return context.getSystemService(DevicePolicyManager.class);
142     }
143 
144     @Provides
145     @Singleton
provideCrossWindowBlurListeners()146     static CrossWindowBlurListeners provideCrossWindowBlurListeners() {
147         return CrossWindowBlurListeners.getInstance();
148     }
149 
150     @Provides
151     @DisplayId
provideDisplayId(Context context)152     static int provideDisplayId(Context context) {
153         return context.getDisplayId();
154     }
155 
156     @Provides
157     @Singleton
provideDisplayManager(Context context)158     static DisplayManager provideDisplayManager(Context context) {
159         return context.getSystemService(DisplayManager.class);
160     }
161 
162     @Provides
163     @Singleton
provideDeviceStateManager(Context context)164     static DeviceStateManager provideDeviceStateManager(Context context) {
165         return context.getSystemService(DeviceStateManager.class);
166     }
167 
168     @Provides
169     @Singleton
provideIActivityManager()170     static IActivityManager provideIActivityManager() {
171         return ActivityManager.getService();
172     }
173 
174     @Provides
175     @Singleton
provideActivityTaskManager()176     static ActivityTaskManager provideActivityTaskManager() {
177         return ActivityTaskManager.getInstance();
178     }
179 
180     @Provides
181     @Singleton
provideIActivityTaskManager()182     static IActivityTaskManager provideIActivityTaskManager() {
183         return ActivityTaskManager.getService();
184     }
185 
186     @Provides
187     @Singleton
provideIAudioService()188     static IAudioService provideIAudioService() {
189         return IAudioService.Stub.asInterface(ServiceManager.getService(Context.AUDIO_SERVICE));
190     }
191 
192 
193     @Provides
194     @Singleton
provideIBatteryStats()195     static IBatteryStats provideIBatteryStats() {
196         return IBatteryStats.Stub.asInterface(
197                 ServiceManager.getService(BatteryStats.SERVICE_NAME));
198     }
199 
200     @Provides
201     @Singleton
provideIDreamManager()202     static IDreamManager provideIDreamManager() {
203         return IDreamManager.Stub.asInterface(
204                 ServiceManager.checkService(DreamService.DREAM_SERVICE));
205     }
206 
207     @Provides
208     @Singleton
209     @Nullable
provideFaceManager(Context context)210     static FaceManager provideFaceManager(Context context) {
211         return context.getSystemService(FaceManager.class);
212 
213     }
214 
215     @Provides
216     @Singleton
217     @Nullable
providesFingerprintManager(Context context)218     static FingerprintManager providesFingerprintManager(Context context) {
219         return context.getSystemService(FingerprintManager.class);
220     }
221 
222     @Provides
223     @Singleton
provideInteractionJankMonitor()224     static InteractionJankMonitor provideInteractionJankMonitor() {
225         return InteractionJankMonitor.getInstance();
226     }
227 
228     @Provides
229     @Singleton
provideInputMethodManager(Context context)230     static InputMethodManager provideInputMethodManager(Context context) {
231         return context.getSystemService(InputMethodManager.class);
232     }
233 
234     @Provides
235     @Singleton
provideIAppWidgetService()236     static IAppWidgetService provideIAppWidgetService() {
237         return IAppWidgetService.Stub.asInterface(
238                 ServiceManager.getService(Context.APPWIDGET_SERVICE));
239     }
240 
241     @Provides
242     @Singleton
provideIPackageManager()243     static IPackageManager provideIPackageManager() {
244         return IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
245     }
246 
247     @Provides
248     @Singleton
provideIStatusBarService()249     static IStatusBarService provideIStatusBarService() {
250         return IStatusBarService.Stub.asInterface(
251                 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
252     }
253 
254     @Provides
255     @Nullable
provideIWallPaperManager()256     static IWallpaperManager provideIWallPaperManager() {
257         return IWallpaperManager.Stub.asInterface(
258                 ServiceManager.getService(Context.WALLPAPER_SERVICE));
259     }
260 
261     @Provides
262     @Singleton
provideIWindowManager()263     static IWindowManager provideIWindowManager() {
264         return WindowManagerGlobal.getWindowManagerService();
265     }
266 
267     @Provides
268     @Singleton
provideKeyguardManager(Context context)269     static KeyguardManager provideKeyguardManager(Context context) {
270         return context.getSystemService(KeyguardManager.class);
271     }
272 
273     @Provides
274     @Singleton
provideLatencyTracker(Context context)275     static LatencyTracker provideLatencyTracker(Context context) {
276         return LatencyTracker.getInstance(context);
277     }
278 
279     @Provides
280     @Singleton
provideLauncherApps(Context context)281     static LauncherApps provideLauncherApps(Context context) {
282         return context.getSystemService(LauncherApps.class);
283     }
284 
285     @Provides
provideMediaRouter2Manager(Context context)286     static MediaRouter2Manager provideMediaRouter2Manager(Context context) {
287         return MediaRouter2Manager.getInstance(context);
288     }
289 
290     @Provides
provideMediaSessionManager(Context context)291     static MediaSessionManager provideMediaSessionManager(Context context) {
292         return context.getSystemService(MediaSessionManager.class);
293     }
294 
295     @Provides
296     @Singleton
provideNetworkScoreManager(Context context)297     static NetworkScoreManager provideNetworkScoreManager(Context context) {
298         return context.getSystemService(NetworkScoreManager.class);
299     }
300 
301     @Provides
302     @Singleton
provideNotificationManager(Context context)303     static NotificationManager provideNotificationManager(Context context) {
304         return context.getSystemService(NotificationManager.class);
305     }
306 
307     @Provides
308     @Singleton
providePackageManager(Context context)309     static PackageManager providePackageManager(Context context) {
310         return context.getPackageManager();
311     }
312 
313     @Provides
314     @Singleton
providePackageManagerWrapper()315     static PackageManagerWrapper providePackageManagerWrapper() {
316         return PackageManagerWrapper.getInstance();
317     }
318 
319     /** */
320     @Provides
321     @Singleton
providePowerManager(Context context)322     static PowerManager providePowerManager(Context context) {
323         return context.getSystemService(PowerManager.class);
324     }
325 
326     @Provides
327     @Main
provideResources(Context context)328     static Resources provideResources(Context context) {
329         return context.getResources();
330     }
331 
332     @Provides
333     @Singleton
provideRoleManager(Context context)334     static RoleManager provideRoleManager(Context context) {
335         return context.getSystemService(RoleManager.class);
336     }
337 
338     @Provides
339     @Singleton
providesSensorManager(Context context)340     static SensorManager providesSensorManager(Context context) {
341         return context.getSystemService(SensorManager.class);
342     }
343 
344     @Provides
345     @Singleton
provideSensorPrivacyManager(Context context)346     static SensorPrivacyManager provideSensorPrivacyManager(Context context) {
347         return context.getSystemService(SensorPrivacyManager.class);
348     }
349 
350     @Provides
351     @Singleton
provideShortcutManager(Context context)352     static ShortcutManager provideShortcutManager(Context context) {
353         return context.getSystemService(ShortcutManager.class);
354     }
355 
356     @Provides
357     @Singleton
provideStatsManager(Context context)358     static StatsManager provideStatsManager(Context context) {
359         return context.getSystemService(StatsManager.class);
360     }
361 
362     @Provides
363     @Singleton
provideSubcriptionManager(Context context)364     static SubscriptionManager provideSubcriptionManager(Context context) {
365         return context.getSystemService(SubscriptionManager.class);
366     }
367 
368     @Provides
369     @Singleton
370     @Nullable
provideTelecomManager(Context context)371     static TelecomManager provideTelecomManager(Context context) {
372         return context.getSystemService(TelecomManager.class);
373     }
374 
375     @Provides
376     @Singleton
provideOptionalTelecomManager(Context context)377     static Optional<TelecomManager> provideOptionalTelecomManager(Context context) {
378         return Optional.ofNullable(context.getSystemService(TelecomManager.class));
379     }
380 
381     @Provides
382     @Singleton
provideTelephonyManager(Context context)383     static TelephonyManager provideTelephonyManager(Context context) {
384         return context.getSystemService(TelephonyManager.class);
385     }
386 
387     @Provides
388     @Singleton
provideTrustManager(Context context)389     static TrustManager provideTrustManager(Context context) {
390         return context.getSystemService(TrustManager.class);
391     }
392 
393     @Provides
394     @Singleton
395     @Nullable
provideVibrator(Context context)396     static Vibrator provideVibrator(Context context) {
397         return context.getSystemService(Vibrator.class);
398     }
399 
400     @Provides
401     @Singleton
provideOptionalVibrator(Context context)402     static Optional<Vibrator> provideOptionalVibrator(Context context) {
403         return Optional.ofNullable(context.getSystemService(Vibrator.class));
404     }
405 
406     @Provides
407     @Singleton
provideViewConfiguration(Context context)408     static ViewConfiguration provideViewConfiguration(Context context) {
409         return ViewConfiguration.get(context);
410     }
411 
412     @Provides
413     @Singleton
provideUserManager(Context context)414     static UserManager provideUserManager(Context context) {
415         return context.getSystemService(UserManager.class);
416     }
417 
418     @Provides
provideWallpaperManager(Context context)419     static WallpaperManager provideWallpaperManager(Context context) {
420         return context.getSystemService(WallpaperManager.class);
421     }
422 
423     @Provides
424     @Singleton
425     @Nullable
provideWifiManager(Context context)426     static WifiManager provideWifiManager(Context context) {
427         return context.getSystemService(WifiManager.class);
428     }
429 
430     @Provides
431     @Singleton
provideOverlayManager(Context context)432     static OverlayManager provideOverlayManager(Context context) {
433         return context.getSystemService(OverlayManager.class);
434     }
435 
436     @Provides
437     @Singleton
provideWindowManager(Context context)438     static WindowManager provideWindowManager(Context context) {
439         return context.getSystemService(WindowManager.class);
440     }
441 
442     @Provides
443     @Singleton
providePermissionManager(Context context)444     static PermissionManager providePermissionManager(Context context) {
445         PermissionManager pm = context.getSystemService(PermissionManager.class);
446         if (pm != null) {
447             pm.initializeUsageHelper();
448         }
449         return pm;
450     }
451 
452     @Provides
453     @Singleton
provideSmartspaceManager(Context context)454     static SmartspaceManager provideSmartspaceManager(Context context) {
455         return context.getSystemService(SmartspaceManager.class);
456     }
457 }
458