• 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.INotificationManager;
27 import android.app.IWallpaperManager;
28 import android.app.KeyguardManager;
29 import android.app.NotificationManager;
30 import android.app.StatsManager;
31 import android.app.UiModeManager;
32 import android.app.WallpaperManager;
33 import android.app.admin.DevicePolicyManager;
34 import android.app.ambientcontext.AmbientContextManager;
35 import android.app.job.JobScheduler;
36 import android.app.role.RoleManager;
37 import android.app.smartspace.SmartspaceManager;
38 import android.app.trust.TrustManager;
39 import android.bluetooth.BluetoothAdapter;
40 import android.bluetooth.BluetoothManager;
41 import android.content.ClipboardManager;
42 import android.content.ContentResolver;
43 import android.content.Context;
44 import android.content.SharedPreferences;
45 import android.content.om.OverlayManager;
46 import android.content.pm.IPackageManager;
47 import android.content.pm.LauncherApps;
48 import android.content.pm.PackageManager;
49 import android.content.pm.ShortcutManager;
50 import android.content.res.AssetManager;
51 import android.content.res.Resources;
52 import android.hardware.SensorManager;
53 import android.hardware.SensorPrivacyManager;
54 import android.hardware.biometrics.BiometricManager;
55 import android.hardware.camera2.CameraManager;
56 import android.hardware.devicestate.DeviceStateManager;
57 import android.hardware.display.AmbientDisplayConfiguration;
58 import android.hardware.display.ColorDisplayManager;
59 import android.hardware.display.DisplayManager;
60 import android.hardware.face.FaceManager;
61 import android.hardware.fingerprint.FingerprintManager;
62 import android.hardware.input.InputManager;
63 import android.media.AudioManager;
64 import android.media.IAudioService;
65 import android.media.MediaRouter2Manager;
66 import android.media.projection.MediaProjectionManager;
67 import android.media.session.MediaSessionManager;
68 import android.net.ConnectivityManager;
69 import android.net.NetworkScoreManager;
70 import android.net.wifi.WifiManager;
71 import android.os.BatteryStats;
72 import android.os.PowerExemptionManager;
73 import android.os.PowerManager;
74 import android.os.ServiceManager;
75 import android.os.SystemUpdateManager;
76 import android.os.UserManager;
77 import android.os.Vibrator;
78 import android.os.storage.StorageManager;
79 import android.permission.PermissionManager;
80 import android.safetycenter.SafetyCenterManager;
81 import android.service.dreams.DreamService;
82 import android.service.dreams.IDreamManager;
83 import android.service.vr.IVrManager;
84 import android.telecom.TelecomManager;
85 import android.telephony.CarrierConfigManager;
86 import android.telephony.SubscriptionManager;
87 import android.telephony.TelephonyManager;
88 import android.view.Choreographer;
89 import android.view.CrossWindowBlurListeners;
90 import android.view.IWindowManager;
91 import android.view.LayoutInflater;
92 import android.view.ViewConfiguration;
93 import android.view.WindowManager;
94 import android.view.WindowManagerGlobal;
95 import android.view.accessibility.AccessibilityManager;
96 import android.view.accessibility.CaptioningManager;
97 import android.view.inputmethod.InputMethodManager;
98 import android.view.textclassifier.TextClassificationManager;
99 
100 import androidx.asynclayoutinflater.view.AsyncLayoutInflater;
101 import androidx.core.app.NotificationManagerCompat;
102 
103 import com.android.internal.app.IBatteryStats;
104 import com.android.internal.appwidget.IAppWidgetService;
105 import com.android.internal.jank.InteractionJankMonitor;
106 import com.android.internal.statusbar.IStatusBarService;
107 import com.android.internal.util.LatencyTracker;
108 import com.android.systemui.Prefs;
109 import com.android.systemui.dagger.qualifiers.Application;
110 import com.android.systemui.dagger.qualifiers.DisplayId;
111 import com.android.systemui.dagger.qualifiers.Main;
112 import com.android.systemui.dagger.qualifiers.TestHarness;
113 import com.android.systemui.shared.system.PackageManagerWrapper;
114 
115 import java.util.Optional;
116 
117 import javax.inject.Singleton;
118 
119 import dagger.Module;
120 import dagger.Provides;
121 
122 /**
123  * Provides Non-SystemUI, Framework-Owned instances to the dependency graph.
124  */
125 @SuppressLint("NonInjectedService")
126 @Module
127 public class FrameworkServicesModule {
128     @Provides
129     @Singleton
provideAccessibilityManager(Context context)130     static AccessibilityManager provideAccessibilityManager(Context context) {
131         return context.getSystemService(AccessibilityManager.class);
132     }
133 
134     @Provides
135     @Singleton
provideActivityManager(Context context)136     static ActivityManager provideActivityManager(Context context) {
137         return context.getSystemService(ActivityManager.class);
138     }
139 
140     @Provides
141     @Singleton
provideAlarmManager(Context context)142     static AlarmManager provideAlarmManager(Context context) {
143         return context.getSystemService(AlarmManager.class);
144     }
145 
146     @Provides
147     @Singleton
provideSystemUpdateManager(Context context)148     static Optional<SystemUpdateManager> provideSystemUpdateManager(Context context) {
149         return Optional.ofNullable(context.getSystemService(SystemUpdateManager.class));
150     }
151 
152     @Provides
153     @Nullable
154     @Singleton
provideAmbientContextManager(Context context)155     static AmbientContextManager provideAmbientContextManager(Context context) {
156         return context.getSystemService(AmbientContextManager.class);
157     }
158 
159     /** */
160     @Provides
provideAmbientDisplayConfiguration(Context context)161     public AmbientDisplayConfiguration provideAmbientDisplayConfiguration(Context context) {
162         return new AmbientDisplayConfiguration(context);
163     }
164 
165     @Provides
166     @Singleton
provideAudioManager(Context context)167     static AudioManager provideAudioManager(Context context) {
168         return context.getSystemService(AudioManager.class);
169     }
170 
171     @Provides
172     @Singleton
provideCaptioningManager(Context context)173     static CaptioningManager provideCaptioningManager(Context context) {
174         return context.getSystemService(CaptioningManager.class);
175     }
176 
177     /** */
178     @Provides
179     @Singleton
providesChoreographer()180     public Choreographer providesChoreographer() {
181         return Choreographer.getInstance();
182     }
183 
184     @Provides
185     @Singleton
provideColorDisplayManager(Context context)186     static ColorDisplayManager provideColorDisplayManager(Context context) {
187         return context.getSystemService(ColorDisplayManager.class);
188     }
189 
190     @Provides
191     @Singleton
provideConnectivityManagager(Context context)192     static ConnectivityManager provideConnectivityManagager(Context context) {
193         return context.getSystemService(ConnectivityManager.class);
194     }
195 
196     @Provides
197     @Singleton
provideContentResolver(Context context)198     static ContentResolver provideContentResolver(Context context) {
199         return context.getContentResolver();
200     }
201 
202     @Provides
203     @Singleton
provideDevicePolicyManager(Context context)204     static DevicePolicyManager provideDevicePolicyManager(Context context) {
205         return context.getSystemService(DevicePolicyManager.class);
206     }
207 
208     @Provides
209     @Singleton
provideCrossWindowBlurListeners()210     static CrossWindowBlurListeners provideCrossWindowBlurListeners() {
211         return CrossWindowBlurListeners.getInstance();
212     }
213 
214     @Provides
215     @DisplayId
provideDisplayId(Context context)216     static int provideDisplayId(Context context) {
217         return context.getDisplayId();
218     }
219 
220     @Provides
221     @Singleton
provideDisplayManager(Context context)222     static DisplayManager provideDisplayManager(Context context) {
223         return context.getSystemService(DisplayManager.class);
224     }
225 
226     @Provides
227     @Singleton
provideDeviceStateManager(Context context)228     static DeviceStateManager provideDeviceStateManager(Context context) {
229         return context.getSystemService(DeviceStateManager.class);
230     }
231 
232     @Provides
233     @Singleton
provideIActivityManager()234     static IActivityManager provideIActivityManager() {
235         return ActivityManager.getService();
236     }
237 
238     @Provides
239     @Singleton
provideActivityTaskManager()240     static ActivityTaskManager provideActivityTaskManager() {
241         return ActivityTaskManager.getInstance();
242     }
243 
244     @Provides
245     @Singleton
provideIActivityTaskManager()246     static IActivityTaskManager provideIActivityTaskManager() {
247         return ActivityTaskManager.getService();
248     }
249 
250     @Provides
251     @Singleton
provideIAudioService()252     static IAudioService provideIAudioService() {
253         return IAudioService.Stub.asInterface(ServiceManager.getService(Context.AUDIO_SERVICE));
254     }
255 
256 
257     @Provides
258     @Singleton
provideIBatteryStats()259     static IBatteryStats provideIBatteryStats() {
260         return IBatteryStats.Stub.asInterface(
261                 ServiceManager.getService(BatteryStats.SERVICE_NAME));
262     }
263 
264     @Provides
265     @Singleton
provideIDreamManager()266     static IDreamManager provideIDreamManager() {
267         return IDreamManager.Stub.asInterface(
268                 ServiceManager.getService(DreamService.DREAM_SERVICE));
269     }
270 
271     @Provides
272     @Singleton
273     @Nullable
provideIVrManager()274     static IVrManager provideIVrManager() {
275         return IVrManager.Stub.asInterface(ServiceManager.getService(Context.VR_SERVICE));
276     }
277 
278     @Provides
279     @Singleton
280     @Nullable
provideFaceManager(Context context)281     static FaceManager provideFaceManager(Context context) {
282         if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE)) {
283             return context.getSystemService(FaceManager.class);
284         }
285         return null;
286     }
287 
288     @Provides
289     @Singleton
290     @Nullable
providesFingerprintManager(Context context)291     static FingerprintManager providesFingerprintManager(Context context) {
292         if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
293             return context.getSystemService(FingerprintManager.class);
294         }
295         return null;
296     }
297 
298     /**
299      * @return null if both faceManager and fingerprintManager are null.
300      */
301     @Provides
302     @Singleton
303     @Nullable
providesBiometricManager(Context context, @Nullable FaceManager faceManager, @Nullable FingerprintManager fingerprintManager)304     static BiometricManager providesBiometricManager(Context context,
305             @Nullable FaceManager faceManager, @Nullable FingerprintManager fingerprintManager) {
306         return faceManager == null && fingerprintManager == null ? null :
307                 context.getSystemService(BiometricManager.class);
308     }
309 
310     @Provides
311     @Singleton
provideJobScheduler(Context context)312     static JobScheduler provideJobScheduler(Context context) {
313         return context.getSystemService(JobScheduler.class);
314     }
315 
316     @Provides
317     @Singleton
provideInteractionJankMonitor()318     static InteractionJankMonitor provideInteractionJankMonitor() {
319         return InteractionJankMonitor.getInstance();
320     }
321 
322     @Provides
323     @Singleton
provideInputManager(Context context)324     static InputManager provideInputManager(Context context) {
325         return context.getSystemService(InputManager.class);
326     }
327 
328     @Provides
329     @Singleton
provideInputMethodManager(Context context)330     static InputMethodManager provideInputMethodManager(Context context) {
331         return context.getSystemService(InputMethodManager.class);
332     }
333 
334     @Provides
335     @Singleton
provideIAppWidgetService()336     static IAppWidgetService provideIAppWidgetService() {
337         return IAppWidgetService.Stub.asInterface(
338                 ServiceManager.getService(Context.APPWIDGET_SERVICE));
339     }
340 
341     @Provides
342     @Singleton
provideIPackageManager()343     static IPackageManager provideIPackageManager() {
344         return IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
345     }
346 
347     @Provides
348     @Singleton
provideIStatusBarService()349     static IStatusBarService provideIStatusBarService() {
350         return IStatusBarService.Stub.asInterface(
351                 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
352     }
353 
354     @Provides
355     @Nullable
provideIWallPaperManager()356     static IWallpaperManager provideIWallPaperManager() {
357         return IWallpaperManager.Stub.asInterface(
358                 ServiceManager.getService(Context.WALLPAPER_SERVICE));
359     }
360 
361     @Provides
362     @Singleton
provideIWindowManager()363     static IWindowManager provideIWindowManager() {
364         return WindowManagerGlobal.getWindowManagerService();
365     }
366 
367     @Provides
368     @Singleton
provideKeyguardManager(Context context)369     static KeyguardManager provideKeyguardManager(Context context) {
370         return context.getSystemService(KeyguardManager.class);
371     }
372 
373     @Provides
374     @Singleton
provideLatencyTracker(Context context)375     static LatencyTracker provideLatencyTracker(Context context) {
376         return LatencyTracker.getInstance(context);
377     }
378 
379     @Provides
380     @Singleton
provideLauncherApps(Context context)381     static LauncherApps provideLauncherApps(Context context) {
382         return context.getSystemService(LauncherApps.class);
383     }
384 
385     /** */
386     @Provides
387     @Singleton
providerLayoutInflater(Context context)388     public LayoutInflater providerLayoutInflater(Context context) {
389         return LayoutInflater.from(context);
390     }
391 
392     /** */
393     @Provides
394     @Singleton
provideAsyncLayoutInflater(Context context)395     public AsyncLayoutInflater provideAsyncLayoutInflater(Context context) {
396         return new AsyncLayoutInflater(context);
397     }
398 
399     @Provides
provideMediaProjectionManager(Context context)400     static MediaProjectionManager provideMediaProjectionManager(Context context) {
401         return context.getSystemService(MediaProjectionManager.class);
402     }
403 
404     @Provides
provideMediaRouter2Manager(Context context)405     static MediaRouter2Manager provideMediaRouter2Manager(Context context) {
406         return MediaRouter2Manager.getInstance(context);
407     }
408 
409     @Provides
provideMediaSessionManager(Context context)410     static MediaSessionManager provideMediaSessionManager(Context context) {
411         return context.getSystemService(MediaSessionManager.class);
412     }
413 
414     @Provides
415     @Singleton
provideNetworkScoreManager(Context context)416     static NetworkScoreManager provideNetworkScoreManager(Context context) {
417         return context.getSystemService(NetworkScoreManager.class);
418     }
419 
420     @Provides
421     @Singleton
provideNotificationManager(Context context)422     static NotificationManager provideNotificationManager(Context context) {
423         return context.getSystemService(NotificationManager.class);
424     }
425 
426     @Provides
427     @Singleton
provideNotificationManagerCompat(Context context)428     static NotificationManagerCompat provideNotificationManagerCompat(Context context) {
429         return NotificationManagerCompat.from(context);
430     }
431 
432     /** */
433     @Provides
434     @Singleton
provideINotificationManager()435     public INotificationManager provideINotificationManager() {
436         return INotificationManager.Stub.asInterface(
437                 ServiceManager.getService(Context.NOTIFICATION_SERVICE));
438     }
439 
440     @Provides
441     @Singleton
providePackageManager(Context context)442     static PackageManager providePackageManager(Context context) {
443         return context.getPackageManager();
444     }
445 
446     @Provides
447     @Singleton
providePackageManagerWrapper()448     static PackageManagerWrapper providePackageManagerWrapper() {
449         return PackageManagerWrapper.getInstance();
450     }
451 
452     /** */
453     @Provides
454     @Singleton
providePowerManager(Context context)455     static PowerManager providePowerManager(Context context) {
456         return context.getSystemService(PowerManager.class);
457     }
458 
459     /** */
460     @Provides
461     @Singleton
providePowerExemptionManager(Context context)462     static PowerExemptionManager providePowerExemptionManager(Context context) {
463         return context.getSystemService(PowerExemptionManager.class);
464     }
465 
466     /** */
467     @Provides
468     @Main
provideSharePreferences(Context context)469     public SharedPreferences provideSharePreferences(Context context) {
470         return Prefs.get(context);
471     }
472 
473     /** */
474     @Provides
475     @Singleton
provideUiModeManager(Context context)476     static UiModeManager provideUiModeManager(Context context) {
477         return context.getSystemService(UiModeManager.class);
478     }
479 
480     @Provides
481     @Main
provideResources(Context context)482     static Resources provideResources(Context context) {
483         return context.getResources();
484     }
485 
486     @Provides
487     @Application
provideAssetManager(@pplication Context context)488     static AssetManager provideAssetManager(@Application Context context) {
489         return context.getAssets();
490     }
491 
492     @Provides
493     @Singleton
provideRoleManager(Context context)494     static RoleManager provideRoleManager(Context context) {
495         return context.getSystemService(RoleManager.class);
496     }
497 
498     @Provides
499     @Singleton
providesSensorManager(Context context)500     static SensorManager providesSensorManager(Context context) {
501         return context.getSystemService(SensorManager.class);
502     }
503 
504     @Provides
505     @Singleton
provideSensorPrivacyManager(Context context)506     static SensorPrivacyManager provideSensorPrivacyManager(Context context) {
507         return context.getSystemService(SensorPrivacyManager.class);
508     }
509 
510     @Provides
511     @Singleton
provideShortcutManager(Context context)512     static ShortcutManager provideShortcutManager(Context context) {
513         return context.getSystemService(ShortcutManager.class);
514     }
515 
516     @Provides
517     @Singleton
provideStatsManager(Context context)518     static StatsManager provideStatsManager(Context context) {
519         return context.getSystemService(StatsManager.class);
520     }
521 
522     @Provides
523     @Singleton
provideStorageManager(Context context)524     static StorageManager provideStorageManager(Context context) {
525         return context.getSystemService(StorageManager.class);
526     }
527 
528     @Provides
529     @Singleton
provideSubscriptionManager(Context context)530     static SubscriptionManager provideSubscriptionManager(Context context) {
531         return context.getSystemService(SubscriptionManager.class);
532     }
533 
534     @Provides
535     @Singleton
536     @Nullable
provideTelecomManager(Context context)537     static TelecomManager provideTelecomManager(Context context) {
538         return context.getSystemService(TelecomManager.class);
539     }
540 
541     @Provides
542     @Singleton
provideOptionalTelecomManager(Context context)543     static Optional<TelecomManager> provideOptionalTelecomManager(Context context) {
544         return Optional.ofNullable(context.getSystemService(TelecomManager.class));
545     }
546 
547     @Provides
548     @Singleton
provideTelephonyManager(Context context)549     static TelephonyManager provideTelephonyManager(Context context) {
550         return context.getSystemService(TelephonyManager.class);
551     }
552 
553     @Provides
554     @Singleton
555     @TestHarness
provideIsTestHarness()556     static boolean provideIsTestHarness() {
557         return ActivityManager.isRunningInUserTestHarness();
558     }
559 
560     @Provides
561     @Singleton
provideTrustManager(Context context)562     static TrustManager provideTrustManager(Context context) {
563         return context.getSystemService(TrustManager.class);
564     }
565 
566     @Provides
567     @Singleton
568     @Nullable
provideVibrator(Context context)569     static Vibrator provideVibrator(Context context) {
570         return context.getSystemService(Vibrator.class);
571     }
572 
573     @Provides
574     @Singleton
provideOptionalVibrator(Context context)575     static Optional<Vibrator> provideOptionalVibrator(Context context) {
576         return Optional.ofNullable(context.getSystemService(Vibrator.class));
577     }
578 
579     @Provides
580     @Singleton
provideViewConfiguration(Context context)581     static ViewConfiguration provideViewConfiguration(Context context) {
582         return ViewConfiguration.get(context);
583     }
584 
585     @Provides
586     @Singleton
provideUserManager(Context context)587     static UserManager provideUserManager(Context context) {
588         return context.getSystemService(UserManager.class);
589     }
590 
591     @Provides
provideWallpaperManager(Context context)592     static WallpaperManager provideWallpaperManager(Context context) {
593         return context.getSystemService(WallpaperManager.class);
594     }
595 
596     @Provides
597     @Singleton
598     @Nullable
provideWifiManager(Context context)599     static WifiManager provideWifiManager(Context context) {
600         return context.getSystemService(WifiManager.class);
601     }
602 
603     @Provides
604     @Singleton
provideOverlayManager(Context context)605     static OverlayManager provideOverlayManager(Context context) {
606         return context.getSystemService(OverlayManager.class);
607     }
608 
609     @Provides
610     @Singleton
provideCarrierConfigManager(Context context)611     static CarrierConfigManager provideCarrierConfigManager(Context context) {
612         return context.getSystemService(CarrierConfigManager.class);
613     }
614 
615     @Provides
616     @Singleton
provideWindowManager(Context context)617     static WindowManager provideWindowManager(Context context) {
618         return context.getSystemService(WindowManager.class);
619     }
620 
621     @Provides
622     @Singleton
providePermissionManager(Context context)623     static PermissionManager providePermissionManager(Context context) {
624         PermissionManager pm = context.getSystemService(PermissionManager.class);
625         if (pm != null) {
626             pm.initializeUsageHelper();
627         }
628         return pm;
629     }
630 
631     @Provides
632     @Singleton
provideClipboardManager(Context context)633     static ClipboardManager provideClipboardManager(Context context) {
634         return context.getSystemService(ClipboardManager.class);
635     }
636 
637     @Provides
638     @Singleton
provideSmartspaceManager(Context context)639     static SmartspaceManager provideSmartspaceManager(Context context) {
640         return context.getSystemService(SmartspaceManager.class);
641     }
642 
643     @Provides
644     @Singleton
provideSafetyCenterManager(Context context)645     static SafetyCenterManager provideSafetyCenterManager(Context context) {
646         return context.getSystemService(SafetyCenterManager.class);
647     }
648 
649     @Provides
650     @Singleton
provideCameraManager(Context context)651     static CameraManager provideCameraManager(Context context) {
652         return context.getSystemService(CameraManager.class);
653     }
654 
655     @Provides
656     @Singleton
provideBluetoothManager(Context context)657     static BluetoothManager provideBluetoothManager(Context context) {
658         return context.getSystemService(BluetoothManager.class);
659     }
660 
661     @Provides
662     @Singleton
663     @Nullable
provideBluetoothAdapter(BluetoothManager bluetoothManager)664     static BluetoothAdapter provideBluetoothAdapter(BluetoothManager bluetoothManager) {
665         return bluetoothManager.getAdapter();
666     }
667 
668     @Provides
669     @Singleton
provideTextClassificationManager(Context context)670     static TextClassificationManager provideTextClassificationManager(Context context) {
671         return context.getSystemService(TextClassificationManager.class);
672     }
673 }
674