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