Dave Mankoff | f473681 | 2019-10-18 17:25:50 -0400 | [diff] [blame^] | 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.AlarmManager; |
| 23 | import android.app.IActivityManager; |
| 24 | import android.app.IWallpaperManager; |
| 25 | import android.app.WallpaperManager; |
| 26 | import android.content.Context; |
| 27 | import android.content.res.Resources; |
| 28 | import android.hardware.SensorPrivacyManager; |
| 29 | import android.os.Handler; |
| 30 | import android.os.PowerManager; |
| 31 | import android.os.ServiceManager; |
| 32 | import android.os.UserHandle; |
| 33 | import android.view.IWindowManager; |
| 34 | import android.view.WindowManager; |
| 35 | import android.view.WindowManagerGlobal; |
| 36 | |
| 37 | import com.android.settingslib.bluetooth.LocalBluetoothManager; |
| 38 | import com.android.systemui.dagger.qualifiers.BgHandler; |
| 39 | import com.android.systemui.dagger.qualifiers.MainResources; |
| 40 | import com.android.systemui.shared.system.PackageManagerWrapper; |
| 41 | |
| 42 | import javax.inject.Singleton; |
| 43 | |
| 44 | import dagger.Module; |
| 45 | import dagger.Provides; |
| 46 | |
| 47 | /** |
| 48 | * Provides Non-SystemUI, Framework-Owned instances to the dependency graph. |
| 49 | */ |
| 50 | @Module |
| 51 | public class SystemServicesModule { |
| 52 | |
| 53 | @Singleton |
| 54 | @Provides |
| 55 | static AlarmManager provideAlarmManager(Context context) { |
| 56 | return context.getSystemService(AlarmManager.class); |
| 57 | } |
| 58 | |
| 59 | @Singleton |
| 60 | @Provides |
| 61 | static IActivityManager providesIActivityManager() { |
| 62 | return ActivityManager.getService(); |
| 63 | } |
| 64 | |
| 65 | @Provides |
| 66 | static IWallpaperManager provideWallPaperManager() { |
| 67 | return IWallpaperManager.Stub.asInterface( |
| 68 | ServiceManager.getService(Context.WALLPAPER_SERVICE)); |
| 69 | } |
| 70 | |
| 71 | @Singleton |
| 72 | @Provides |
| 73 | static IWindowManager provideIWindowManager() { |
| 74 | return WindowManagerGlobal.getWindowManagerService(); |
| 75 | } |
| 76 | |
| 77 | @SuppressLint("MissingPermission") |
| 78 | @Singleton |
| 79 | @Provides |
| 80 | @Nullable |
| 81 | static LocalBluetoothManager provideLocalBluetoothController(Context context, |
| 82 | @BgHandler Handler bgHandler) { |
| 83 | return LocalBluetoothManager.create(context, bgHandler, UserHandle.ALL); |
| 84 | } |
| 85 | |
| 86 | @Singleton |
| 87 | @Provides |
| 88 | static PackageManagerWrapper providePackageManagerWrapper() { |
| 89 | return PackageManagerWrapper.getInstance(); |
| 90 | } |
| 91 | |
| 92 | /** */ |
| 93 | @Singleton |
| 94 | @Provides |
| 95 | static PowerManager providePowerManager(Context context) { |
| 96 | return context.getSystemService(PowerManager.class); |
| 97 | } |
| 98 | |
| 99 | @Provides |
| 100 | @MainResources |
| 101 | static Resources provideResources(Context context) { |
| 102 | return context.getResources(); |
| 103 | } |
| 104 | |
| 105 | @Singleton |
| 106 | @Provides |
| 107 | static SensorPrivacyManager provideSensorPrivacyManager(Context context) { |
| 108 | return context.getSystemService(SensorPrivacyManager.class); |
| 109 | } |
| 110 | |
| 111 | @Provides |
| 112 | static WallpaperManager providesWallpaperManager(Context context) { |
| 113 | return (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE); |
| 114 | } |
| 115 | |
| 116 | @Singleton |
| 117 | @Provides |
| 118 | static WindowManager providesWindowManager(Context context) { |
| 119 | return context.getSystemService(WindowManager.class); |
| 120 | } |
| 121 | |
| 122 | } |