Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 android.app; |
| 18 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 19 | import android.accounts.AccountManager; |
| 20 | import android.accounts.IAccountManager; |
Makoto Onuki | d67070e | 2018-03-30 12:39:14 -0700 | [diff] [blame] | 21 | import android.app.ContextImpl.ServiceInitializationState; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 22 | import android.app.admin.DevicePolicyManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 23 | import android.app.admin.IDevicePolicyManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 24 | import android.app.job.IJobScheduler; |
| 25 | import android.app.job.JobScheduler; |
Hai Zhang | 4ef21d0 | 2018-11-09 14:43:51 -0800 | [diff] [blame] | 26 | import android.app.role.RoleManager; |
Jason Monk | 8f5f7ff | 2017-10-17 14:12:42 -0400 | [diff] [blame] | 27 | import android.app.slice.SliceManager; |
Neil Fuller | feeee68 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 28 | import android.app.timedetector.TimeDetector; |
Neil Fuller | 328532a | 2017-03-16 18:32:21 +0000 | [diff] [blame] | 29 | import android.app.timezone.RulesManager; |
Neil Fuller | 7fb88c3 | 2018-06-19 12:53:47 +0100 | [diff] [blame] | 30 | import android.app.timezonedetector.TimeZoneDetector; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 31 | import android.app.trust.TrustManager; |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 32 | import android.app.usage.IStorageStatsManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 33 | import android.app.usage.IUsageStatsManager; |
Zoltan Szatmary-Ban | 9c5dfa5 | 2015-02-23 17:20:20 +0000 | [diff] [blame] | 34 | import android.app.usage.NetworkStatsManager; |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 35 | import android.app.usage.StorageStatsManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 36 | import android.app.usage.UsageStatsManager; |
| 37 | import android.appwidget.AppWidgetManager; |
| 38 | import android.bluetooth.BluetoothManager; |
Eugene Susla | 6ed45d8 | 2017-01-22 13:52:51 -0800 | [diff] [blame] | 39 | import android.companion.CompanionDeviceManager; |
| 40 | import android.companion.ICompanionDeviceManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 41 | import android.content.ClipboardManager; |
| 42 | import android.content.Context; |
| 43 | import android.content.IRestrictionsManager; |
| 44 | import android.content.RestrictionsManager; |
Tony Mak | b0d2262 | 2018-01-18 12:49:49 +0000 | [diff] [blame] | 45 | import android.content.pm.CrossProfileApps; |
| 46 | import android.content.pm.ICrossProfileApps; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 47 | import android.content.pm.IShortcutService; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 48 | import android.content.pm.LauncherApps; |
Svet Ganov | ec7daa5 | 2017-06-30 12:02:59 -0700 | [diff] [blame] | 49 | import android.content.pm.PackageManager; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 50 | import android.content.pm.ShortcutManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 51 | import android.content.res.Resources; |
Kenny Root | f74bfde | 2018-01-18 15:42:48 -0800 | [diff] [blame] | 52 | import android.debug.AdbManager; |
| 53 | import android.debug.IAdbManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 54 | import android.hardware.ConsumerIrManager; |
| 55 | import android.hardware.ISerialManager; |
| 56 | import android.hardware.SensorManager; |
| 57 | import android.hardware.SerialManager; |
| 58 | import android.hardware.SystemSensorManager; |
Kevin Chyn | 05c2150 | 2018-09-18 13:07:19 -0700 | [diff] [blame] | 59 | import android.hardware.biometrics.BiometricManager; |
| 60 | import android.hardware.biometrics.IBiometricService; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 61 | import android.hardware.camera2.CameraManager; |
Christine Franks | 39b0311 | 2018-07-03 14:46:07 -0700 | [diff] [blame] | 62 | import android.hardware.display.ColorDisplayManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 63 | import android.hardware.display.DisplayManager; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 64 | import android.hardware.face.FaceManager; |
| 65 | import android.hardware.face.IFaceService; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 66 | import android.hardware.fingerprint.FingerprintManager; |
| 67 | import android.hardware.fingerprint.IFingerprintService; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 68 | import android.hardware.hdmi.HdmiControlManager; |
| 69 | import android.hardware.hdmi.IHdmiControlService; |
| 70 | import android.hardware.input.InputManager; |
Kevin Chyn | 51676d2 | 2018-11-05 18:00:43 -0800 | [diff] [blame] | 71 | import android.hardware.iris.IIrisService; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 72 | import android.hardware.iris.IrisManager; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 73 | import android.hardware.location.ContextHubManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 74 | import android.hardware.radio.RadioManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 75 | import android.hardware.usb.IUsbManager; |
| 76 | import android.hardware.usb.UsbManager; |
| 77 | import android.location.CountryDetector; |
| 78 | import android.location.ICountryDetector; |
| 79 | import android.location.ILocationManager; |
| 80 | import android.location.LocationManager; |
| 81 | import android.media.AudioManager; |
| 82 | import android.media.MediaRouter; |
| 83 | import android.media.midi.IMidiManager; |
| 84 | import android.media.midi.MidiManager; |
| 85 | import android.media.projection.MediaProjectionManager; |
| 86 | import android.media.session.MediaSessionManager; |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 87 | import android.media.soundtrigger.SoundTriggerManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 88 | import android.media.tv.ITvInputManager; |
| 89 | import android.media.tv.TvInputManager; |
| 90 | import android.net.ConnectivityManager; |
Paul Stewart | bf8cbb05 | 2016-03-17 10:11:54 -0700 | [diff] [blame] | 91 | import android.net.ConnectivityThread; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 92 | import android.net.EthernetManager; |
| 93 | import android.net.IConnectivityManager; |
| 94 | import android.net.IEthernetManager; |
Nathan Harold | 28084d8 | 2017-03-01 18:55:06 -0800 | [diff] [blame] | 95 | import android.net.IIpSecService; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 96 | import android.net.INetworkPolicyManager; |
Nathan Harold | 28084d8 | 2017-03-01 18:55:06 -0800 | [diff] [blame] | 97 | import android.net.IpSecManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 98 | import android.net.NetworkPolicyManager; |
| 99 | import android.net.NetworkScoreManager; |
Ricky Wai | 1a6e667 | 2017-10-27 14:46:01 +0100 | [diff] [blame] | 100 | import android.net.NetworkWatchlistManager; |
Robert Quattlebaum | 87a7104 | 2017-05-15 15:45:20 -0700 | [diff] [blame] | 101 | import android.net.lowpan.ILowpanManager; |
| 102 | import android.net.lowpan.LowpanManager; |
Etan Cohen | 17ba472 | 2017-08-21 10:52:17 -0700 | [diff] [blame] | 103 | import android.net.nsd.INsdManager; |
| 104 | import android.net.nsd.NsdManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 105 | import android.net.wifi.IWifiManager; |
| 106 | import android.net.wifi.IWifiScanner; |
| 107 | import android.net.wifi.RttManager; |
| 108 | import android.net.wifi.WifiManager; |
| 109 | import android.net.wifi.WifiScanner; |
Etan Cohen | 0413327 | 2016-10-26 11:22:06 -0700 | [diff] [blame] | 110 | import android.net.wifi.aware.IWifiAwareManager; |
| 111 | import android.net.wifi.aware.WifiAwareManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 112 | import android.net.wifi.p2p.IWifiP2pManager; |
| 113 | import android.net.wifi.p2p.WifiP2pManager; |
Etan Cohen | 17ba472 | 2017-08-21 10:52:17 -0700 | [diff] [blame] | 114 | import android.net.wifi.rtt.IWifiRttManager; |
| 115 | import android.net.wifi.rtt.WifiRttManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 116 | import android.nfc.NfcManager; |
| 117 | import android.os.BatteryManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 118 | import android.os.BatteryStats; |
Jeff Sharkey | 351c2c2 | 2017-03-18 16:48:02 -0600 | [diff] [blame] | 119 | import android.os.Build; |
Philip P. Moltmann | f80809f | 2018-04-04 11:20:44 -0700 | [diff] [blame] | 120 | import android.os.DeviceIdleManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 121 | import android.os.DropBoxManager; |
Polina Bondarenko | 965ecbb | 2015-11-13 15:34:28 +0100 | [diff] [blame] | 122 | import android.os.HardwarePropertiesManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 123 | import android.os.IBatteryPropertiesRegistrar; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 124 | import android.os.IBinder; |
Philip P. Moltmann | f80809f | 2018-04-04 11:20:44 -0700 | [diff] [blame] | 125 | import android.os.IDeviceIdleController; |
Polina Bondarenko | f8754ac | 2016-02-12 20:38:23 +0100 | [diff] [blame] | 126 | import android.os.IHardwarePropertiesManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 127 | import android.os.IPowerManager; |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 128 | import android.os.IRecoverySystem; |
Tao Bao | 07342dc | 2017-01-24 15:08:21 -0800 | [diff] [blame] | 129 | import android.os.ISystemUpdateManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 130 | import android.os.IUserManager; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 131 | import android.os.IncidentManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 132 | import android.os.PowerManager; |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 133 | import android.os.RecoverySystem; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 134 | import android.os.ServiceManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 135 | import android.os.ServiceManager.ServiceNotFoundException; |
Tao Bao | 07342dc | 2017-01-24 15:08:21 -0800 | [diff] [blame] | 136 | import android.os.SystemUpdateManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 137 | import android.os.SystemVibrator; |
| 138 | import android.os.UserHandle; |
| 139 | import android.os.UserManager; |
| 140 | import android.os.Vibrator; |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 141 | import android.os.health.SystemHealthManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 142 | import android.os.storage.StorageManager; |
Philip P. Moltmann | 039678e | 2018-09-18 13:04:38 -0700 | [diff] [blame] | 143 | import android.permission.PermissionManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 144 | import android.print.IPrintManager; |
| 145 | import android.print.PrintManager; |
Andrew Scull | 3b8b46f | 2017-02-13 18:12:15 +0000 | [diff] [blame] | 146 | import android.service.oemlock.IOemLockService; |
| 147 | import android.service.oemlock.OemLockManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 148 | import android.service.persistentdata.IPersistentDataBlockService; |
| 149 | import android.service.persistentdata.PersistentDataBlockManager; |
Zak Cohen | 56345f4 | 2017-01-26 13:54:28 -0800 | [diff] [blame] | 150 | import android.service.vr.IVrManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 151 | import android.telecom.TelecomManager; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 152 | import android.telephony.CarrierConfigManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 153 | import android.telephony.SubscriptionManager; |
| 154 | import android.telephony.TelephonyManager; |
Holly Jiuyu Sun | 5c11024 | 2017-12-21 18:44:59 -0800 | [diff] [blame] | 155 | import android.telephony.euicc.EuiccCardManager; |
Neil Fuller | 009e77a | 2017-05-04 16:53:41 +0100 | [diff] [blame] | 156 | import android.telephony.euicc.EuiccManager; |
Sahin Caliskan | 9458ebc | 2018-10-31 13:23:29 -0700 | [diff] [blame] | 157 | import android.telephony.rcs.RcsManager; |
Robert Benea | 1901a5b | 2018-05-15 16:36:07 -0700 | [diff] [blame] | 158 | import android.util.ArrayMap; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 159 | import android.util.Log; |
| 160 | import android.view.ContextThemeWrapper; |
| 161 | import android.view.LayoutInflater; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 162 | import android.view.WindowManager; |
| 163 | import android.view.WindowManagerImpl; |
| 164 | import android.view.accessibility.AccessibilityManager; |
| 165 | import android.view.accessibility.CaptioningManager; |
Neil Fuller | 009e77a | 2017-05-04 16:53:41 +0100 | [diff] [blame] | 166 | import android.view.autofill.AutofillManager; |
| 167 | import android.view.autofill.IAutoFillManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 168 | import android.view.inputmethod.InputMethodManager; |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 169 | import android.view.intelligence.ContentCaptureManager; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 170 | import android.view.intelligence.IIntelligenceManager; |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 171 | import android.view.textclassifier.TextClassificationManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 172 | import android.view.textservice.TextServicesManager; |
| 173 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 174 | import com.android.internal.app.IAppOpsService; |
| 175 | import com.android.internal.app.IBatteryStats; |
| 176 | import com.android.internal.app.ISoundTriggerService; |
| 177 | import com.android.internal.appwidget.IAppWidgetService; |
Ricky Wai | 1a6e667 | 2017-10-27 14:46:01 +0100 | [diff] [blame] | 178 | import com.android.internal.net.INetworkWatchlistManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 179 | import com.android.internal.os.IDropBoxManagerService; |
| 180 | import com.android.internal.policy.PhoneLayoutInflater; |
| 181 | |
Robert Benea | 1901a5b | 2018-05-15 16:36:07 -0700 | [diff] [blame] | 182 | import java.util.Map; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * Manages all of the system services that can be returned by {@link Context#getSystemService}. |
| 186 | * Used by {@link ContextImpl}. |
| 187 | */ |
| 188 | final class SystemServiceRegistry { |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 189 | private static final String TAG = "SystemServiceRegistry"; |
| 190 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 191 | // Service registry information. |
| 192 | // This information is never changed once static initialization has completed. |
Robert Benea | 1901a5b | 2018-05-15 16:36:07 -0700 | [diff] [blame] | 193 | private static final Map<Class<?>, String> SYSTEM_SERVICE_NAMES = |
| 194 | new ArrayMap<Class<?>, String>(); |
| 195 | private static final Map<String, ServiceFetcher<?>> SYSTEM_SERVICE_FETCHERS = |
| 196 | new ArrayMap<String, ServiceFetcher<?>>(); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 197 | private static int sServiceCacheSize; |
| 198 | |
| 199 | // Not instantiable. |
| 200 | private SystemServiceRegistry() { } |
| 201 | |
| 202 | static { |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 203 | //CHECKSTYLE:OFF IndentationCheck |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 204 | registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class, |
| 205 | new CachedServiceFetcher<AccessibilityManager>() { |
| 206 | @Override |
| 207 | public AccessibilityManager createService(ContextImpl ctx) { |
| 208 | return AccessibilityManager.getInstance(ctx); |
| 209 | }}); |
| 210 | |
| 211 | registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class, |
| 212 | new CachedServiceFetcher<CaptioningManager>() { |
| 213 | @Override |
| 214 | public CaptioningManager createService(ContextImpl ctx) { |
| 215 | return new CaptioningManager(ctx); |
| 216 | }}); |
| 217 | |
| 218 | registerService(Context.ACCOUNT_SERVICE, AccountManager.class, |
| 219 | new CachedServiceFetcher<AccountManager>() { |
| 220 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 221 | public AccountManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 222 | IBinder b = ServiceManager.getServiceOrThrow(Context.ACCOUNT_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 223 | IAccountManager service = IAccountManager.Stub.asInterface(b); |
| 224 | return new AccountManager(ctx, service); |
| 225 | }}); |
| 226 | |
| 227 | registerService(Context.ACTIVITY_SERVICE, ActivityManager.class, |
| 228 | new CachedServiceFetcher<ActivityManager>() { |
| 229 | @Override |
| 230 | public ActivityManager createService(ContextImpl ctx) { |
| 231 | return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); |
| 232 | }}); |
| 233 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 234 | registerService(Context.ACTIVITY_TASK_SERVICE, ActivityTaskManager.class, |
| 235 | new CachedServiceFetcher<ActivityTaskManager>() { |
| 236 | @Override |
| 237 | public ActivityTaskManager createService(ContextImpl ctx) { |
| 238 | return new ActivityTaskManager( |
| 239 | ctx.getOuterContext(), ctx.mMainThread.getHandler()); |
| 240 | }}); |
| 241 | |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 242 | registerService(Context.URI_GRANTS_SERVICE, UriGrantsManager.class, |
| 243 | new CachedServiceFetcher<UriGrantsManager>() { |
| 244 | @Override |
| 245 | public UriGrantsManager createService(ContextImpl ctx) { |
| 246 | return new UriGrantsManager( |
| 247 | ctx.getOuterContext(), ctx.mMainThread.getHandler()); |
| 248 | }}); |
| 249 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 250 | registerService(Context.ALARM_SERVICE, AlarmManager.class, |
| 251 | new CachedServiceFetcher<AlarmManager>() { |
| 252 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 253 | public AlarmManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 254 | IBinder b = ServiceManager.getServiceOrThrow(Context.ALARM_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 255 | IAlarmManager service = IAlarmManager.Stub.asInterface(b); |
| 256 | return new AlarmManager(service, ctx); |
| 257 | }}); |
| 258 | |
| 259 | registerService(Context.AUDIO_SERVICE, AudioManager.class, |
| 260 | new CachedServiceFetcher<AudioManager>() { |
| 261 | @Override |
| 262 | public AudioManager createService(ContextImpl ctx) { |
| 263 | return new AudioManager(ctx); |
| 264 | }}); |
| 265 | |
| 266 | registerService(Context.MEDIA_ROUTER_SERVICE, MediaRouter.class, |
| 267 | new CachedServiceFetcher<MediaRouter>() { |
| 268 | @Override |
| 269 | public MediaRouter createService(ContextImpl ctx) { |
| 270 | return new MediaRouter(ctx); |
| 271 | }}); |
| 272 | |
| 273 | registerService(Context.BLUETOOTH_SERVICE, BluetoothManager.class, |
| 274 | new CachedServiceFetcher<BluetoothManager>() { |
| 275 | @Override |
| 276 | public BluetoothManager createService(ContextImpl ctx) { |
| 277 | return new BluetoothManager(ctx); |
| 278 | }}); |
| 279 | |
| 280 | registerService(Context.HDMI_CONTROL_SERVICE, HdmiControlManager.class, |
| 281 | new StaticServiceFetcher<HdmiControlManager>() { |
| 282 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 283 | public HdmiControlManager createService() throws ServiceNotFoundException { |
| 284 | IBinder b = ServiceManager.getServiceOrThrow(Context.HDMI_CONTROL_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 285 | return new HdmiControlManager(IHdmiControlService.Stub.asInterface(b)); |
| 286 | }}); |
| 287 | |
Abodunrinwa Toki | 8158af5 | 2016-11-23 20:41:09 +0000 | [diff] [blame] | 288 | registerService(Context.TEXT_CLASSIFICATION_SERVICE, TextClassificationManager.class, |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 289 | new CachedServiceFetcher<TextClassificationManager>() { |
Abodunrinwa Toki | 8158af5 | 2016-11-23 20:41:09 +0000 | [diff] [blame] | 290 | @Override |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 291 | public TextClassificationManager createService(ContextImpl ctx) { |
| 292 | return new TextClassificationManager(ctx); |
Abodunrinwa Toki | 8158af5 | 2016-11-23 20:41:09 +0000 | [diff] [blame] | 293 | }}); |
| 294 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 295 | registerService(Context.CLIPBOARD_SERVICE, ClipboardManager.class, |
| 296 | new CachedServiceFetcher<ClipboardManager>() { |
| 297 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 298 | public ClipboardManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 299 | return new ClipboardManager(ctx.getOuterContext(), |
| 300 | ctx.mMainThread.getHandler()); |
| 301 | }}); |
| 302 | |
| 303 | // The clipboard service moved to a new package. If someone asks for the old |
| 304 | // interface by class then we want to redirect over to the new interface instead |
| 305 | // (which extends it). |
| 306 | SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE); |
| 307 | |
| 308 | registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class, |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 309 | new StaticApplicationContextServiceFetcher<ConnectivityManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 310 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 311 | public ConnectivityManager createService(Context context) throws ServiceNotFoundException { |
| 312 | IBinder b = ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE); |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 313 | IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
| 314 | return new ConnectivityManager(context, service); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 315 | }}); |
| 316 | |
Nathan Harold | 28084d8 | 2017-03-01 18:55:06 -0800 | [diff] [blame] | 317 | registerService(Context.IPSEC_SERVICE, IpSecManager.class, |
Nathan Harold | 592dadb | 2018-03-15 18:06:06 -0700 | [diff] [blame] | 318 | new CachedServiceFetcher<IpSecManager>() { |
Nathan Harold | 28084d8 | 2017-03-01 18:55:06 -0800 | [diff] [blame] | 319 | @Override |
Nathan Harold | 592dadb | 2018-03-15 18:06:06 -0700 | [diff] [blame] | 320 | public IpSecManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Nathan Harold | 28084d8 | 2017-03-01 18:55:06 -0800 | [diff] [blame] | 321 | IBinder b = ServiceManager.getService(Context.IPSEC_SERVICE); |
| 322 | IIpSecService service = IIpSecService.Stub.asInterface(b); |
Nathan Harold | 592dadb | 2018-03-15 18:06:06 -0700 | [diff] [blame] | 323 | return new IpSecManager(ctx, service); |
Nathan Harold | 28084d8 | 2017-03-01 18:55:06 -0800 | [diff] [blame] | 324 | }}); |
| 325 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 326 | registerService(Context.COUNTRY_DETECTOR, CountryDetector.class, |
| 327 | new StaticServiceFetcher<CountryDetector>() { |
| 328 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 329 | public CountryDetector createService() throws ServiceNotFoundException { |
| 330 | IBinder b = ServiceManager.getServiceOrThrow(Context.COUNTRY_DETECTOR); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 331 | return new CountryDetector(ICountryDetector.Stub.asInterface(b)); |
| 332 | }}); |
| 333 | |
| 334 | registerService(Context.DEVICE_POLICY_SERVICE, DevicePolicyManager.class, |
| 335 | new CachedServiceFetcher<DevicePolicyManager>() { |
| 336 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 337 | public DevicePolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 338 | IBinder b = ServiceManager.getServiceOrThrow(Context.DEVICE_POLICY_SERVICE); |
| 339 | return new DevicePolicyManager(ctx, IDevicePolicyManager.Stub.asInterface(b)); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 340 | }}); |
| 341 | |
| 342 | registerService(Context.DOWNLOAD_SERVICE, DownloadManager.class, |
| 343 | new CachedServiceFetcher<DownloadManager>() { |
| 344 | @Override |
| 345 | public DownloadManager createService(ContextImpl ctx) { |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 346 | return new DownloadManager(ctx); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 347 | }}); |
| 348 | |
| 349 | registerService(Context.BATTERY_SERVICE, BatteryManager.class, |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 350 | new CachedServiceFetcher<BatteryManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 351 | @Override |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 352 | public BatteryManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 353 | IBatteryStats stats = IBatteryStats.Stub.asInterface( |
| 354 | ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME)); |
| 355 | IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub |
| 356 | .asInterface(ServiceManager.getServiceOrThrow("batteryproperties")); |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 357 | return new BatteryManager(ctx, stats, registrar); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 358 | }}); |
| 359 | |
| 360 | registerService(Context.NFC_SERVICE, NfcManager.class, |
| 361 | new CachedServiceFetcher<NfcManager>() { |
| 362 | @Override |
| 363 | public NfcManager createService(ContextImpl ctx) { |
| 364 | return new NfcManager(ctx); |
| 365 | }}); |
| 366 | |
| 367 | registerService(Context.DROPBOX_SERVICE, DropBoxManager.class, |
Jeff Sharkey | b8e8a91 | 2016-03-09 16:27:40 -0700 | [diff] [blame] | 368 | new CachedServiceFetcher<DropBoxManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 369 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 370 | public DropBoxManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 371 | IBinder b = ServiceManager.getServiceOrThrow(Context.DROPBOX_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 372 | IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b); |
Jeff Sharkey | b8e8a91 | 2016-03-09 16:27:40 -0700 | [diff] [blame] | 373 | return new DropBoxManager(ctx, service); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 374 | }}); |
| 375 | |
| 376 | registerService(Context.INPUT_SERVICE, InputManager.class, |
| 377 | new StaticServiceFetcher<InputManager>() { |
| 378 | @Override |
| 379 | public InputManager createService() { |
| 380 | return InputManager.getInstance(); |
| 381 | }}); |
| 382 | |
| 383 | registerService(Context.DISPLAY_SERVICE, DisplayManager.class, |
| 384 | new CachedServiceFetcher<DisplayManager>() { |
| 385 | @Override |
| 386 | public DisplayManager createService(ContextImpl ctx) { |
| 387 | return new DisplayManager(ctx.getOuterContext()); |
| 388 | }}); |
| 389 | |
Christine Franks | 39b0311 | 2018-07-03 14:46:07 -0700 | [diff] [blame] | 390 | registerService(Context.COLOR_DISPLAY_SERVICE, ColorDisplayManager.class, |
| 391 | new CachedServiceFetcher<ColorDisplayManager>() { |
| 392 | @Override |
| 393 | public ColorDisplayManager createService(ContextImpl ctx) { |
| 394 | return new ColorDisplayManager(); |
| 395 | } |
| 396 | }); |
| 397 | |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 398 | // InputMethodManager has its own cache strategy based on display id to support apps that |
| 399 | // still assume InputMethodManager is a per-process singleton and it's safe to directly |
| 400 | // access internal fields via reflection. Hence directly use ServiceFetcher instead of |
| 401 | // StaticServiceFetcher/CachedServiceFetcher. |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 402 | registerService(Context.INPUT_METHOD_SERVICE, InputMethodManager.class, |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 403 | new ServiceFetcher<InputMethodManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 404 | @Override |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 405 | public InputMethodManager getService(ContextImpl ctx) { |
| 406 | return InputMethodManager.forContext(ctx.getOuterContext()); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 407 | }}); |
| 408 | |
| 409 | registerService(Context.TEXT_SERVICES_MANAGER_SERVICE, TextServicesManager.class, |
| 410 | new StaticServiceFetcher<TextServicesManager>() { |
| 411 | @Override |
| 412 | public TextServicesManager createService() { |
| 413 | return TextServicesManager.getInstance(); |
| 414 | }}); |
| 415 | |
| 416 | registerService(Context.KEYGUARD_SERVICE, KeyguardManager.class, |
Nancy Zheng | 43f166d | 2016-11-18 18:15:09 -0800 | [diff] [blame] | 417 | new CachedServiceFetcher<KeyguardManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 418 | @Override |
Nancy Zheng | 40cd8e4 | 2016-11-21 12:58:16 -0800 | [diff] [blame] | 419 | public KeyguardManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Nancy Zheng | 43f166d | 2016-11-18 18:15:09 -0800 | [diff] [blame] | 420 | return new KeyguardManager(ctx); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 421 | }}); |
| 422 | |
| 423 | registerService(Context.LAYOUT_INFLATER_SERVICE, LayoutInflater.class, |
| 424 | new CachedServiceFetcher<LayoutInflater>() { |
| 425 | @Override |
| 426 | public LayoutInflater createService(ContextImpl ctx) { |
| 427 | return new PhoneLayoutInflater(ctx.getOuterContext()); |
| 428 | }}); |
| 429 | |
| 430 | registerService(Context.LOCATION_SERVICE, LocationManager.class, |
| 431 | new CachedServiceFetcher<LocationManager>() { |
| 432 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 433 | public LocationManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 434 | IBinder b = ServiceManager.getServiceOrThrow(Context.LOCATION_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 435 | return new LocationManager(ctx, ILocationManager.Stub.asInterface(b)); |
| 436 | }}); |
| 437 | |
| 438 | registerService(Context.NETWORK_POLICY_SERVICE, NetworkPolicyManager.class, |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 439 | new CachedServiceFetcher<NetworkPolicyManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 440 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 441 | public NetworkPolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 442 | return new NetworkPolicyManager(ctx, INetworkPolicyManager.Stub.asInterface( |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 443 | ServiceManager.getServiceOrThrow(Context.NETWORK_POLICY_SERVICE))); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 444 | }}); |
| 445 | |
| 446 | registerService(Context.NOTIFICATION_SERVICE, NotificationManager.class, |
| 447 | new CachedServiceFetcher<NotificationManager>() { |
| 448 | @Override |
| 449 | public NotificationManager createService(ContextImpl ctx) { |
| 450 | final Context outerContext = ctx.getOuterContext(); |
| 451 | return new NotificationManager( |
| 452 | new ContextThemeWrapper(outerContext, |
| 453 | Resources.selectSystemTheme(0, |
| 454 | outerContext.getApplicationInfo().targetSdkVersion, |
| 455 | com.android.internal.R.style.Theme_Dialog, |
| 456 | com.android.internal.R.style.Theme_Holo_Dialog, |
| 457 | com.android.internal.R.style.Theme_DeviceDefault_Dialog, |
| 458 | com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog)), |
| 459 | ctx.mMainThread.getHandler()); |
| 460 | }}); |
| 461 | |
| 462 | registerService(Context.NSD_SERVICE, NsdManager.class, |
| 463 | new CachedServiceFetcher<NsdManager>() { |
| 464 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 465 | public NsdManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 466 | IBinder b = ServiceManager.getServiceOrThrow(Context.NSD_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 467 | INsdManager service = INsdManager.Stub.asInterface(b); |
| 468 | return new NsdManager(ctx.getOuterContext(), service); |
| 469 | }}); |
| 470 | |
| 471 | registerService(Context.POWER_SERVICE, PowerManager.class, |
| 472 | new CachedServiceFetcher<PowerManager>() { |
| 473 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 474 | public PowerManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 475 | IBinder b = ServiceManager.getServiceOrThrow(Context.POWER_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 476 | IPowerManager service = IPowerManager.Stub.asInterface(b); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 477 | return new PowerManager(ctx.getOuterContext(), |
| 478 | service, ctx.mMainThread.getHandler()); |
| 479 | }}); |
| 480 | |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 481 | registerService(Context.RECOVERY_SERVICE, RecoverySystem.class, |
| 482 | new CachedServiceFetcher<RecoverySystem>() { |
| 483 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 484 | public RecoverySystem createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 485 | IBinder b = ServiceManager.getServiceOrThrow(Context.RECOVERY_SERVICE); |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 486 | IRecoverySystem service = IRecoverySystem.Stub.asInterface(b); |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 487 | return new RecoverySystem(service); |
| 488 | }}); |
| 489 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 490 | registerService(Context.SEARCH_SERVICE, SearchManager.class, |
| 491 | new CachedServiceFetcher<SearchManager>() { |
| 492 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 493 | public SearchManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 494 | return new SearchManager(ctx.getOuterContext(), |
| 495 | ctx.mMainThread.getHandler()); |
| 496 | }}); |
| 497 | |
| 498 | registerService(Context.SENSOR_SERVICE, SensorManager.class, |
| 499 | new CachedServiceFetcher<SensorManager>() { |
| 500 | @Override |
| 501 | public SensorManager createService(ContextImpl ctx) { |
| 502 | return new SystemSensorManager(ctx.getOuterContext(), |
| 503 | ctx.mMainThread.getHandler().getLooper()); |
| 504 | }}); |
| 505 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 506 | registerService(Context.STATS_MANAGER, StatsManager.class, |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 507 | new CachedServiceFetcher<StatsManager>() { |
| 508 | @Override |
| 509 | public StatsManager createService(ContextImpl ctx) { |
| 510 | return new StatsManager(ctx.getOuterContext()); |
| 511 | }}); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 512 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 513 | registerService(Context.STATUS_BAR_SERVICE, StatusBarManager.class, |
| 514 | new CachedServiceFetcher<StatusBarManager>() { |
| 515 | @Override |
| 516 | public StatusBarManager createService(ContextImpl ctx) { |
| 517 | return new StatusBarManager(ctx.getOuterContext()); |
| 518 | }}); |
| 519 | |
| 520 | registerService(Context.STORAGE_SERVICE, StorageManager.class, |
| 521 | new CachedServiceFetcher<StorageManager>() { |
| 522 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 523 | public StorageManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 524 | return new StorageManager(ctx, ctx.mMainThread.getHandler().getLooper()); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 525 | }}); |
| 526 | |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 527 | registerService(Context.STORAGE_STATS_SERVICE, StorageStatsManager.class, |
| 528 | new CachedServiceFetcher<StorageStatsManager>() { |
| 529 | @Override |
| 530 | public StorageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 531 | IStorageStatsManager service = IStorageStatsManager.Stub.asInterface( |
| 532 | ServiceManager.getServiceOrThrow(Context.STORAGE_STATS_SERVICE)); |
| 533 | return new StorageStatsManager(ctx, service); |
| 534 | }}); |
| 535 | |
Tao Bao | 07342dc | 2017-01-24 15:08:21 -0800 | [diff] [blame] | 536 | registerService(Context.SYSTEM_UPDATE_SERVICE, SystemUpdateManager.class, |
| 537 | new CachedServiceFetcher<SystemUpdateManager>() { |
| 538 | @Override |
| 539 | public SystemUpdateManager createService(ContextImpl ctx) |
| 540 | throws ServiceNotFoundException { |
| 541 | IBinder b = ServiceManager.getServiceOrThrow( |
| 542 | Context.SYSTEM_UPDATE_SERVICE); |
| 543 | ISystemUpdateManager service = ISystemUpdateManager.Stub.asInterface(b); |
| 544 | return new SystemUpdateManager(service); |
| 545 | }}); |
| 546 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 547 | registerService(Context.TELEPHONY_SERVICE, TelephonyManager.class, |
| 548 | new CachedServiceFetcher<TelephonyManager>() { |
| 549 | @Override |
| 550 | public TelephonyManager createService(ContextImpl ctx) { |
| 551 | return new TelephonyManager(ctx.getOuterContext()); |
| 552 | }}); |
| 553 | |
| 554 | registerService(Context.TELEPHONY_SUBSCRIPTION_SERVICE, SubscriptionManager.class, |
| 555 | new CachedServiceFetcher<SubscriptionManager>() { |
| 556 | @Override |
Jeff Sharkey | 717f52f | 2018-01-04 16:04:11 -0700 | [diff] [blame] | 557 | public SubscriptionManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 558 | return new SubscriptionManager(ctx.getOuterContext()); |
| 559 | }}); |
| 560 | |
Sahin Caliskan | 9458ebc | 2018-10-31 13:23:29 -0700 | [diff] [blame] | 561 | registerService(Context.TELEPHONY_RCS_SERVICE, RcsManager.class, |
| 562 | new CachedServiceFetcher<RcsManager>() { |
| 563 | @Override |
| 564 | public RcsManager createService(ContextImpl ctx) { |
| 565 | return new RcsManager(); |
| 566 | } |
| 567 | }); |
| 568 | |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 569 | registerService(Context.CARRIER_CONFIG_SERVICE, CarrierConfigManager.class, |
| 570 | new CachedServiceFetcher<CarrierConfigManager>() { |
| 571 | @Override |
| 572 | public CarrierConfigManager createService(ContextImpl ctx) { |
Malcolm Chen | d1272d1 | 2018-02-28 15:20:45 -0800 | [diff] [blame] | 573 | return new CarrierConfigManager(ctx.getOuterContext()); |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 574 | }}); |
| 575 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 576 | registerService(Context.TELECOM_SERVICE, TelecomManager.class, |
| 577 | new CachedServiceFetcher<TelecomManager>() { |
| 578 | @Override |
| 579 | public TelecomManager createService(ContextImpl ctx) { |
| 580 | return new TelecomManager(ctx.getOuterContext()); |
| 581 | }}); |
| 582 | |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 583 | registerService(Context.EUICC_SERVICE, EuiccManager.class, |
| 584 | new CachedServiceFetcher<EuiccManager>() { |
| 585 | @Override |
| 586 | public EuiccManager createService(ContextImpl ctx) { |
| 587 | return new EuiccManager(ctx.getOuterContext()); |
| 588 | }}); |
| 589 | |
Holly Jiuyu Sun | 5c11024 | 2017-12-21 18:44:59 -0800 | [diff] [blame] | 590 | registerService(Context.EUICC_CARD_SERVICE, EuiccCardManager.class, |
| 591 | new CachedServiceFetcher<EuiccCardManager>() { |
| 592 | @Override |
| 593 | public EuiccCardManager createService(ContextImpl ctx) { |
| 594 | return new EuiccCardManager(ctx.getOuterContext()); |
| 595 | }}); |
| 596 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 597 | registerService(Context.UI_MODE_SERVICE, UiModeManager.class, |
| 598 | new CachedServiceFetcher<UiModeManager>() { |
| 599 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 600 | public UiModeManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 601 | return new UiModeManager(); |
| 602 | }}); |
| 603 | |
| 604 | registerService(Context.USB_SERVICE, UsbManager.class, |
| 605 | new CachedServiceFetcher<UsbManager>() { |
| 606 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 607 | public UsbManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 608 | IBinder b = ServiceManager.getServiceOrThrow(Context.USB_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 609 | return new UsbManager(ctx, IUsbManager.Stub.asInterface(b)); |
| 610 | }}); |
| 611 | |
Kenny Root | f74bfde | 2018-01-18 15:42:48 -0800 | [diff] [blame] | 612 | registerService(Context.ADB_SERVICE, AdbManager.class, |
| 613 | new CachedServiceFetcher<AdbManager>() { |
| 614 | @Override |
| 615 | public AdbManager createService(ContextImpl ctx) |
| 616 | throws ServiceNotFoundException { |
| 617 | IBinder b = ServiceManager.getServiceOrThrow(Context.ADB_SERVICE); |
| 618 | return new AdbManager(ctx, IAdbManager.Stub.asInterface(b)); |
| 619 | }}); |
| 620 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 621 | registerService(Context.SERIAL_SERVICE, SerialManager.class, |
| 622 | new CachedServiceFetcher<SerialManager>() { |
| 623 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 624 | public SerialManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 625 | IBinder b = ServiceManager.getServiceOrThrow(Context.SERIAL_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 626 | return new SerialManager(ctx, ISerialManager.Stub.asInterface(b)); |
| 627 | }}); |
| 628 | |
| 629 | registerService(Context.VIBRATOR_SERVICE, Vibrator.class, |
| 630 | new CachedServiceFetcher<Vibrator>() { |
| 631 | @Override |
| 632 | public Vibrator createService(ContextImpl ctx) { |
| 633 | return new SystemVibrator(ctx); |
| 634 | }}); |
| 635 | |
| 636 | registerService(Context.WALLPAPER_SERVICE, WallpaperManager.class, |
| 637 | new CachedServiceFetcher<WallpaperManager>() { |
| 638 | @Override |
Svet Ganov | 8f90bcc | 2017-12-22 23:29:24 -0800 | [diff] [blame] | 639 | public WallpaperManager createService(ContextImpl ctx) |
| 640 | throws ServiceNotFoundException { |
| 641 | final IBinder b; |
| 642 | if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) { |
| 643 | b = ServiceManager.getServiceOrThrow(Context.WALLPAPER_SERVICE); |
| 644 | } else { |
| 645 | b = ServiceManager.getService(Context.WALLPAPER_SERVICE); |
| 646 | } |
| 647 | IWallpaperManager service = IWallpaperManager.Stub.asInterface(b); |
| 648 | return new WallpaperManager(service, ctx.getOuterContext(), |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 649 | ctx.mMainThread.getHandler()); |
| 650 | }}); |
| 651 | |
Robert Quattlebaum | 87a7104 | 2017-05-15 15:45:20 -0700 | [diff] [blame] | 652 | registerService(Context.LOWPAN_SERVICE, LowpanManager.class, |
| 653 | new CachedServiceFetcher<LowpanManager>() { |
| 654 | @Override |
| 655 | public LowpanManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 656 | IBinder b = ServiceManager.getServiceOrThrow(Context.LOWPAN_SERVICE); |
| 657 | ILowpanManager service = ILowpanManager.Stub.asInterface(b); |
| 658 | return new LowpanManager(ctx.getOuterContext(), service, |
| 659 | ConnectivityThread.getInstanceLooper()); |
| 660 | }}); |
| 661 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 662 | registerService(Context.WIFI_SERVICE, WifiManager.class, |
| 663 | new CachedServiceFetcher<WifiManager>() { |
| 664 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 665 | public WifiManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 666 | IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 667 | IWifiManager service = IWifiManager.Stub.asInterface(b); |
Paul Stewart | bf8cbb05 | 2016-03-17 10:11:54 -0700 | [diff] [blame] | 668 | return new WifiManager(ctx.getOuterContext(), service, |
| 669 | ConnectivityThread.getInstanceLooper()); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 670 | }}); |
| 671 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 672 | registerService(Context.WIFI_P2P_SERVICE, WifiP2pManager.class, |
| 673 | new StaticServiceFetcher<WifiP2pManager>() { |
| 674 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 675 | public WifiP2pManager createService() throws ServiceNotFoundException { |
| 676 | IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_P2P_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 677 | IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b); |
| 678 | return new WifiP2pManager(service); |
| 679 | }}); |
| 680 | |
Etan Cohen | 0413327 | 2016-10-26 11:22:06 -0700 | [diff] [blame] | 681 | registerService(Context.WIFI_AWARE_SERVICE, WifiAwareManager.class, |
| 682 | new CachedServiceFetcher<WifiAwareManager>() { |
Etan Cohen | 20d329b | 2015-09-29 13:49:02 -0700 | [diff] [blame] | 683 | @Override |
Etan Cohen | 0413327 | 2016-10-26 11:22:06 -0700 | [diff] [blame] | 684 | public WifiAwareManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Sharkey | 589f309 | 2016-11-29 12:54:39 -0700 | [diff] [blame] | 685 | IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_AWARE_SERVICE); |
Etan Cohen | 0413327 | 2016-10-26 11:22:06 -0700 | [diff] [blame] | 686 | IWifiAwareManager service = IWifiAwareManager.Stub.asInterface(b); |
Etan Cohen | 20d329b | 2015-09-29 13:49:02 -0700 | [diff] [blame] | 687 | if (service == null) { |
| 688 | return null; |
| 689 | } |
Etan Cohen | 0413327 | 2016-10-26 11:22:06 -0700 | [diff] [blame] | 690 | return new WifiAwareManager(ctx.getOuterContext(), service); |
Etan Cohen | 20d329b | 2015-09-29 13:49:02 -0700 | [diff] [blame] | 691 | }}); |
| 692 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 693 | registerService(Context.WIFI_SCANNING_SERVICE, WifiScanner.class, |
| 694 | new CachedServiceFetcher<WifiScanner>() { |
| 695 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 696 | public WifiScanner createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 697 | IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SCANNING_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 698 | IWifiScanner service = IWifiScanner.Stub.asInterface(b); |
Mitchell Wills | 91312c7 | 2016-04-06 17:03:35 -0700 | [diff] [blame] | 699 | return new WifiScanner(ctx.getOuterContext(), service, |
| 700 | ConnectivityThread.getInstanceLooper()); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 701 | }}); |
| 702 | |
| 703 | registerService(Context.WIFI_RTT_SERVICE, RttManager.class, |
| 704 | new CachedServiceFetcher<RttManager>() { |
Etan Cohen | 9accbba | 2018-01-30 16:41:00 -0800 | [diff] [blame] | 705 | @Override |
| 706 | public RttManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 707 | IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_RTT_RANGING_SERVICE); |
| 708 | IWifiRttManager service = IWifiRttManager.Stub.asInterface(b); |
| 709 | return new RttManager(ctx.getOuterContext(), |
| 710 | new WifiRttManager(ctx.getOuterContext(), service)); |
| 711 | }}); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 712 | |
Etan Cohen | 46efb48 | 2017-12-07 13:50:57 -0800 | [diff] [blame] | 713 | registerService(Context.WIFI_RTT_RANGING_SERVICE, WifiRttManager.class, |
Etan Cohen | 17ba472 | 2017-08-21 10:52:17 -0700 | [diff] [blame] | 714 | new CachedServiceFetcher<WifiRttManager>() { |
| 715 | @Override |
| 716 | public WifiRttManager createService(ContextImpl ctx) |
| 717 | throws ServiceNotFoundException { |
Etan Cohen | 46efb48 | 2017-12-07 13:50:57 -0800 | [diff] [blame] | 718 | IBinder b = ServiceManager.getServiceOrThrow( |
| 719 | Context.WIFI_RTT_RANGING_SERVICE); |
Etan Cohen | 17ba472 | 2017-08-21 10:52:17 -0700 | [diff] [blame] | 720 | IWifiRttManager service = IWifiRttManager.Stub.asInterface(b); |
| 721 | return new WifiRttManager(ctx.getOuterContext(), service); |
| 722 | }}); |
| 723 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 724 | registerService(Context.ETHERNET_SERVICE, EthernetManager.class, |
| 725 | new CachedServiceFetcher<EthernetManager>() { |
| 726 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 727 | public EthernetManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 728 | IBinder b = ServiceManager.getServiceOrThrow(Context.ETHERNET_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 729 | IEthernetManager service = IEthernetManager.Stub.asInterface(b); |
| 730 | return new EthernetManager(ctx.getOuterContext(), service); |
| 731 | }}); |
| 732 | |
| 733 | registerService(Context.WINDOW_SERVICE, WindowManager.class, |
| 734 | new CachedServiceFetcher<WindowManager>() { |
| 735 | @Override |
| 736 | public WindowManager createService(ContextImpl ctx) { |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 737 | return new WindowManagerImpl(ctx); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 738 | }}); |
| 739 | |
| 740 | registerService(Context.USER_SERVICE, UserManager.class, |
| 741 | new CachedServiceFetcher<UserManager>() { |
| 742 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 743 | public UserManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 744 | IBinder b = ServiceManager.getServiceOrThrow(Context.USER_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 745 | IUserManager service = IUserManager.Stub.asInterface(b); |
| 746 | return new UserManager(ctx, service); |
| 747 | }}); |
| 748 | |
| 749 | registerService(Context.APP_OPS_SERVICE, AppOpsManager.class, |
| 750 | new CachedServiceFetcher<AppOpsManager>() { |
| 751 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 752 | public AppOpsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 753 | IBinder b = ServiceManager.getServiceOrThrow(Context.APP_OPS_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 754 | IAppOpsService service = IAppOpsService.Stub.asInterface(b); |
| 755 | return new AppOpsManager(ctx, service); |
| 756 | }}); |
| 757 | |
| 758 | registerService(Context.CAMERA_SERVICE, CameraManager.class, |
| 759 | new CachedServiceFetcher<CameraManager>() { |
| 760 | @Override |
| 761 | public CameraManager createService(ContextImpl ctx) { |
| 762 | return new CameraManager(ctx); |
| 763 | }}); |
| 764 | |
| 765 | registerService(Context.LAUNCHER_APPS_SERVICE, LauncherApps.class, |
| 766 | new CachedServiceFetcher<LauncherApps>() { |
| 767 | @Override |
| 768 | public LauncherApps createService(ContextImpl ctx) { |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 769 | return new LauncherApps(ctx); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 770 | }}); |
| 771 | |
| 772 | registerService(Context.RESTRICTIONS_SERVICE, RestrictionsManager.class, |
| 773 | new CachedServiceFetcher<RestrictionsManager>() { |
| 774 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 775 | public RestrictionsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 776 | IBinder b = ServiceManager.getServiceOrThrow(Context.RESTRICTIONS_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 777 | IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b); |
| 778 | return new RestrictionsManager(ctx, service); |
| 779 | }}); |
| 780 | |
| 781 | registerService(Context.PRINT_SERVICE, PrintManager.class, |
| 782 | new CachedServiceFetcher<PrintManager>() { |
| 783 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 784 | public PrintManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Svet Ganov | ec7daa5 | 2017-06-30 12:02:59 -0700 | [diff] [blame] | 785 | IPrintManager service = null; |
| 786 | // If the feature not present, don't try to look up every time |
| 787 | if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PRINTING)) { |
| 788 | service = IPrintManager.Stub.asInterface(ServiceManager |
| 789 | .getServiceOrThrow(Context.PRINT_SERVICE)); |
| 790 | } |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 791 | final int userId = ctx.getUserId(); |
| 792 | final int appId = UserHandle.getAppId(ctx.getApplicationInfo().uid); |
| 793 | return new PrintManager(ctx.getOuterContext(), service, userId, appId); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 794 | }}); |
| 795 | |
Eugene Susla | 6ed45d8 | 2017-01-22 13:52:51 -0800 | [diff] [blame] | 796 | registerService(Context.COMPANION_DEVICE_SERVICE, CompanionDeviceManager.class, |
| 797 | new CachedServiceFetcher<CompanionDeviceManager>() { |
Svet Ganov | ec7daa5 | 2017-06-30 12:02:59 -0700 | [diff] [blame] | 798 | @Override |
| 799 | public CompanionDeviceManager createService(ContextImpl ctx) |
| 800 | throws ServiceNotFoundException { |
| 801 | ICompanionDeviceManager service = null; |
| 802 | // If the feature not present, don't try to look up every time |
| 803 | if (ctx.getPackageManager().hasSystemFeature( |
| 804 | PackageManager.FEATURE_COMPANION_DEVICE_SETUP)) { |
| 805 | service = ICompanionDeviceManager.Stub.asInterface( |
| 806 | ServiceManager.getServiceOrThrow(Context.COMPANION_DEVICE_SERVICE)); |
| 807 | } |
| 808 | return new CompanionDeviceManager(service, ctx.getOuterContext()); |
| 809 | }}); |
Eugene Susla | 6ed45d8 | 2017-01-22 13:52:51 -0800 | [diff] [blame] | 810 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 811 | registerService(Context.CONSUMER_IR_SERVICE, ConsumerIrManager.class, |
| 812 | new CachedServiceFetcher<ConsumerIrManager>() { |
| 813 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 814 | public ConsumerIrManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 815 | return new ConsumerIrManager(ctx); |
| 816 | }}); |
| 817 | |
| 818 | registerService(Context.MEDIA_SESSION_SERVICE, MediaSessionManager.class, |
| 819 | new CachedServiceFetcher<MediaSessionManager>() { |
| 820 | @Override |
| 821 | public MediaSessionManager createService(ContextImpl ctx) { |
| 822 | return new MediaSessionManager(ctx); |
| 823 | }}); |
| 824 | |
| 825 | registerService(Context.TRUST_SERVICE, TrustManager.class, |
| 826 | new StaticServiceFetcher<TrustManager>() { |
| 827 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 828 | public TrustManager createService() throws ServiceNotFoundException { |
| 829 | IBinder b = ServiceManager.getServiceOrThrow(Context.TRUST_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 830 | return new TrustManager(b); |
| 831 | }}); |
| 832 | |
| 833 | registerService(Context.FINGERPRINT_SERVICE, FingerprintManager.class, |
| 834 | new CachedServiceFetcher<FingerprintManager>() { |
| 835 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 836 | public FingerprintManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Sharkey | 351c2c2 | 2017-03-18 16:48:02 -0600 | [diff] [blame] | 837 | final IBinder binder; |
| 838 | if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { |
| 839 | binder = ServiceManager.getServiceOrThrow(Context.FINGERPRINT_SERVICE); |
| 840 | } else { |
| 841 | binder = ServiceManager.getService(Context.FINGERPRINT_SERVICE); |
| 842 | } |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 843 | IFingerprintService service = IFingerprintService.Stub.asInterface(binder); |
| 844 | return new FingerprintManager(ctx.getOuterContext(), service); |
| 845 | }}); |
| 846 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 847 | registerService(Context.FACE_SERVICE, FaceManager.class, |
| 848 | new CachedServiceFetcher<FaceManager>() { |
| 849 | @Override |
| 850 | public FaceManager createService(ContextImpl ctx) |
| 851 | throws ServiceNotFoundException { |
| 852 | final IBinder binder; |
| 853 | if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { |
| 854 | binder = ServiceManager.getServiceOrThrow(Context.FACE_SERVICE); |
| 855 | } else { |
| 856 | binder = ServiceManager.getService(Context.FACE_SERVICE); |
| 857 | } |
| 858 | IFaceService service = IFaceService.Stub.asInterface(binder); |
| 859 | return new FaceManager(ctx.getOuterContext(), service); |
| 860 | } |
| 861 | }); |
| 862 | |
Kevin Chyn | 51676d2 | 2018-11-05 18:00:43 -0800 | [diff] [blame] | 863 | registerService(Context.IRIS_SERVICE, IrisManager.class, |
| 864 | new CachedServiceFetcher<IrisManager>() { |
| 865 | @Override |
| 866 | public IrisManager createService(ContextImpl ctx) |
| 867 | throws ServiceNotFoundException { |
| 868 | final IBinder binder = |
| 869 | ServiceManager.getServiceOrThrow(Context.IRIS_SERVICE); |
| 870 | IIrisService service = IIrisService.Stub.asInterface(binder); |
| 871 | return new IrisManager(ctx.getOuterContext(), service); |
| 872 | } |
| 873 | }); |
| 874 | |
Kevin Chyn | 05c2150 | 2018-09-18 13:07:19 -0700 | [diff] [blame] | 875 | registerService(Context.BIOMETRIC_SERVICE, BiometricManager.class, |
| 876 | new CachedServiceFetcher<BiometricManager>() { |
| 877 | @Override |
| 878 | public BiometricManager createService(ContextImpl ctx) |
| 879 | throws ServiceNotFoundException { |
Kevin Chyn | e739daf | 2018-11-06 17:11:06 -0800 | [diff] [blame] | 880 | if (BiometricManager.hasBiometrics(ctx)) { |
| 881 | final IBinder binder = |
| 882 | ServiceManager.getServiceOrThrow(Context.BIOMETRIC_SERVICE); |
| 883 | final IBiometricService service = |
| 884 | IBiometricService.Stub.asInterface(binder); |
| 885 | return new BiometricManager(ctx.getOuterContext(), service); |
| 886 | } else { |
| 887 | // Allow access to the manager when service is null. This saves memory |
| 888 | // on devices without biometric hardware. |
| 889 | return new BiometricManager(ctx.getOuterContext(), null); |
| 890 | } |
Kevin Chyn | 05c2150 | 2018-09-18 13:07:19 -0700 | [diff] [blame] | 891 | } |
| 892 | }); |
| 893 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 894 | registerService(Context.TV_INPUT_SERVICE, TvInputManager.class, |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 895 | new CachedServiceFetcher<TvInputManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 896 | @Override |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 897 | public TvInputManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 898 | IBinder iBinder = ServiceManager.getServiceOrThrow(Context.TV_INPUT_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 899 | ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder); |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 900 | return new TvInputManager(service, ctx.getUserId()); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 901 | }}); |
| 902 | |
| 903 | registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class, |
| 904 | new CachedServiceFetcher<NetworkScoreManager>() { |
| 905 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 906 | public NetworkScoreManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 907 | return new NetworkScoreManager(ctx); |
| 908 | }}); |
| 909 | |
| 910 | registerService(Context.USAGE_STATS_SERVICE, UsageStatsManager.class, |
| 911 | new CachedServiceFetcher<UsageStatsManager>() { |
| 912 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 913 | public UsageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 914 | IBinder iBinder = ServiceManager.getServiceOrThrow(Context.USAGE_STATS_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 915 | IUsageStatsManager service = IUsageStatsManager.Stub.asInterface(iBinder); |
| 916 | return new UsageStatsManager(ctx.getOuterContext(), service); |
| 917 | }}); |
| 918 | |
Zoltan Szatmary-Ban | 9c5dfa5 | 2015-02-23 17:20:20 +0000 | [diff] [blame] | 919 | registerService(Context.NETWORK_STATS_SERVICE, NetworkStatsManager.class, |
| 920 | new CachedServiceFetcher<NetworkStatsManager>() { |
| 921 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 922 | public NetworkStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Zoltan Szatmary-Ban | 9c5dfa5 | 2015-02-23 17:20:20 +0000 | [diff] [blame] | 923 | return new NetworkStatsManager(ctx.getOuterContext()); |
| 924 | }}); |
| 925 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 926 | registerService(Context.JOB_SCHEDULER_SERVICE, JobScheduler.class, |
| 927 | new StaticServiceFetcher<JobScheduler>() { |
| 928 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 929 | public JobScheduler createService() throws ServiceNotFoundException { |
| 930 | IBinder b = ServiceManager.getServiceOrThrow(Context.JOB_SCHEDULER_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 931 | return new JobSchedulerImpl(IJobScheduler.Stub.asInterface(b)); |
| 932 | }}); |
| 933 | |
| 934 | registerService(Context.PERSISTENT_DATA_BLOCK_SERVICE, PersistentDataBlockManager.class, |
| 935 | new StaticServiceFetcher<PersistentDataBlockManager>() { |
| 936 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 937 | public PersistentDataBlockManager createService() throws ServiceNotFoundException { |
| 938 | IBinder b = ServiceManager.getServiceOrThrow(Context.PERSISTENT_DATA_BLOCK_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 939 | IPersistentDataBlockService persistentDataBlockService = |
| 940 | IPersistentDataBlockService.Stub.asInterface(b); |
| 941 | if (persistentDataBlockService != null) { |
| 942 | return new PersistentDataBlockManager(persistentDataBlockService); |
| 943 | } else { |
| 944 | // not supported |
| 945 | return null; |
| 946 | } |
| 947 | }}); |
| 948 | |
Andrew Scull | 3b8b46f | 2017-02-13 18:12:15 +0000 | [diff] [blame] | 949 | registerService(Context.OEM_LOCK_SERVICE, OemLockManager.class, |
| 950 | new StaticServiceFetcher<OemLockManager>() { |
| 951 | @Override |
| 952 | public OemLockManager createService() throws ServiceNotFoundException { |
| 953 | IBinder b = ServiceManager.getServiceOrThrow(Context.OEM_LOCK_SERVICE); |
| 954 | IOemLockService oemLockService = IOemLockService.Stub.asInterface(b); |
| 955 | if (oemLockService != null) { |
| 956 | return new OemLockManager(oemLockService); |
| 957 | } else { |
| 958 | // not supported |
| 959 | return null; |
| 960 | } |
| 961 | }}); |
| 962 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 963 | registerService(Context.MEDIA_PROJECTION_SERVICE, MediaProjectionManager.class, |
| 964 | new CachedServiceFetcher<MediaProjectionManager>() { |
| 965 | @Override |
| 966 | public MediaProjectionManager createService(ContextImpl ctx) { |
| 967 | return new MediaProjectionManager(ctx); |
| 968 | }}); |
| 969 | |
| 970 | registerService(Context.APPWIDGET_SERVICE, AppWidgetManager.class, |
| 971 | new CachedServiceFetcher<AppWidgetManager>() { |
| 972 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 973 | public AppWidgetManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 974 | IBinder b = ServiceManager.getServiceOrThrow(Context.APPWIDGET_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 975 | return new AppWidgetManager(ctx, IAppWidgetService.Stub.asInterface(b)); |
| 976 | }}); |
| 977 | |
| 978 | registerService(Context.MIDI_SERVICE, MidiManager.class, |
| 979 | new CachedServiceFetcher<MidiManager>() { |
| 980 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 981 | public MidiManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 982 | IBinder b = ServiceManager.getServiceOrThrow(Context.MIDI_SERVICE); |
Mike Lockwood | e0a6ca6 | 2015-06-04 13:43:56 -0700 | [diff] [blame] | 983 | return new MidiManager(IMidiManager.Stub.asInterface(b)); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 984 | }}); |
Eric Laurent | 2035ac8 | 2015-03-05 15:18:44 -0800 | [diff] [blame] | 985 | |
| 986 | registerService(Context.RADIO_SERVICE, RadioManager.class, |
| 987 | new CachedServiceFetcher<RadioManager>() { |
| 988 | @Override |
Tomasz Wasilczyk | 347192e | 2017-04-04 11:13:44 -0700 | [diff] [blame] | 989 | public RadioManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Eric Laurent | 2035ac8 | 2015-03-05 15:18:44 -0800 | [diff] [blame] | 990 | return new RadioManager(ctx); |
| 991 | }}); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 992 | |
Polina Bondarenko | 965ecbb | 2015-11-13 15:34:28 +0100 | [diff] [blame] | 993 | registerService(Context.HARDWARE_PROPERTIES_SERVICE, HardwarePropertiesManager.class, |
| 994 | new CachedServiceFetcher<HardwarePropertiesManager>() { |
| 995 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 996 | public HardwarePropertiesManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 997 | IBinder b = ServiceManager.getServiceOrThrow(Context.HARDWARE_PROPERTIES_SERVICE); |
| 998 | IHardwarePropertiesManager service = |
| 999 | IHardwarePropertiesManager.Stub.asInterface(b); |
| 1000 | return new HardwarePropertiesManager(ctx, service); |
Polina Bondarenko | 965ecbb | 2015-11-13 15:34:28 +0100 | [diff] [blame] | 1001 | }}); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1002 | |
| 1003 | registerService(Context.SOUND_TRIGGER_SERVICE, SoundTriggerManager.class, |
| 1004 | new CachedServiceFetcher<SoundTriggerManager>() { |
| 1005 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1006 | public SoundTriggerManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1007 | IBinder b = ServiceManager.getServiceOrThrow(Context.SOUND_TRIGGER_SERVICE); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1008 | return new SoundTriggerManager(ctx, ISoundTriggerService.Stub.asInterface(b)); |
| 1009 | }}); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1010 | |
| 1011 | registerService(Context.SHORTCUT_SERVICE, ShortcutManager.class, |
| 1012 | new CachedServiceFetcher<ShortcutManager>() { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1013 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1014 | public ShortcutManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1015 | IBinder b = ServiceManager.getServiceOrThrow(Context.SHORTCUT_SERVICE); |
| 1016 | return new ShortcutManager(ctx, IShortcutService.Stub.asInterface(b)); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1017 | }}); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 1018 | |
Ricky Wai | 1a6e667 | 2017-10-27 14:46:01 +0100 | [diff] [blame] | 1019 | registerService(Context.NETWORK_WATCHLIST_SERVICE, NetworkWatchlistManager.class, |
| 1020 | new CachedServiceFetcher<NetworkWatchlistManager>() { |
| 1021 | @Override |
| 1022 | public NetworkWatchlistManager createService(ContextImpl ctx) |
| 1023 | throws ServiceNotFoundException { |
| 1024 | IBinder b = |
| 1025 | ServiceManager.getServiceOrThrow(Context.NETWORK_WATCHLIST_SERVICE); |
| 1026 | return new NetworkWatchlistManager(ctx, |
| 1027 | INetworkWatchlistManager.Stub.asInterface(b)); |
| 1028 | }}); |
| 1029 | |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 1030 | registerService(Context.SYSTEM_HEALTH_SERVICE, SystemHealthManager.class, |
| 1031 | new CachedServiceFetcher<SystemHealthManager>() { |
| 1032 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1033 | public SystemHealthManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1034 | IBinder b = ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME); |
| 1035 | return new SystemHealthManager(IBatteryStats.Stub.asInterface(b)); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 1036 | }}); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 1037 | |
| 1038 | registerService(Context.CONTEXTHUB_SERVICE, ContextHubManager.class, |
| 1039 | new CachedServiceFetcher<ContextHubManager>() { |
| 1040 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1041 | public ContextHubManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 1042 | return new ContextHubManager(ctx.getOuterContext(), |
| 1043 | ctx.mMainThread.getHandler().getLooper()); |
| 1044 | }}); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 1045 | |
| 1046 | registerService(Context.INCIDENT_SERVICE, IncidentManager.class, |
| 1047 | new CachedServiceFetcher<IncidentManager>() { |
| 1048 | @Override |
| 1049 | public IncidentManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1050 | return new IncidentManager(ctx); |
| 1051 | }}); |
Clara Bayarri | 04d72ab | 2017-01-10 09:31:51 -0800 | [diff] [blame] | 1052 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1053 | registerService(Context.AUTOFILL_MANAGER_SERVICE, AutofillManager.class, |
| 1054 | new CachedServiceFetcher<AutofillManager>() { |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 1055 | @Override |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1056 | public AutofillManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 1057 | // Get the services without throwing as this is an optional feature |
| 1058 | IBinder b = ServiceManager.getService(Context.AUTOFILL_MANAGER_SERVICE); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1059 | IAutoFillManager service = IAutoFillManager.Stub.asInterface(b); |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1060 | return new AutofillManager(ctx.getOuterContext(), service); |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 1061 | }}); |
Zak Cohen | 56345f4 | 2017-01-26 13:54:28 -0800 | [diff] [blame] | 1062 | |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1063 | registerService(Context.CONTENT_CAPTURE_MANAGER_SERVICE, ContentCaptureManager.class, |
| 1064 | new CachedServiceFetcher<ContentCaptureManager>() { |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1065 | @Override |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1066 | public ContentCaptureManager createService(ContextImpl ctx) |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1067 | throws ServiceNotFoundException { |
| 1068 | // Get the services without throwing as this is an optional feature |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1069 | Context outerContext = ctx.getOuterContext(); |
| 1070 | if (outerContext.isContentCaptureSupported()) { |
| 1071 | IBinder b = ServiceManager |
| 1072 | .getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE); |
| 1073 | IIntelligenceManager service = IIntelligenceManager.Stub.asInterface(b); |
| 1074 | return new ContentCaptureManager(outerContext, service); |
| 1075 | } |
| 1076 | return null; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1077 | }}); |
| 1078 | |
Zak Cohen | 56345f4 | 2017-01-26 13:54:28 -0800 | [diff] [blame] | 1079 | registerService(Context.VR_SERVICE, VrManager.class, new CachedServiceFetcher<VrManager>() { |
| 1080 | @Override |
| 1081 | public VrManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 1082 | IBinder b = ServiceManager.getServiceOrThrow(Context.VR_SERVICE); |
| 1083 | return new VrManager(IVrManager.Stub.asInterface(b)); |
| 1084 | } |
| 1085 | }); |
Neil Fuller | 328532a | 2017-03-16 18:32:21 +0000 | [diff] [blame] | 1086 | |
| 1087 | registerService(Context.TIME_ZONE_RULES_MANAGER_SERVICE, RulesManager.class, |
| 1088 | new CachedServiceFetcher<RulesManager>() { |
| 1089 | @Override |
| 1090 | public RulesManager createService(ContextImpl ctx) { |
| 1091 | return new RulesManager(ctx.getOuterContext()); |
| 1092 | }}); |
Tony Mak | 1b708e6 | 2017-10-12 10:59:11 +0100 | [diff] [blame] | 1093 | |
| 1094 | registerService(Context.CROSS_PROFILE_APPS_SERVICE, CrossProfileApps.class, |
| 1095 | new CachedServiceFetcher<CrossProfileApps>() { |
| 1096 | @Override |
| 1097 | public CrossProfileApps createService(ContextImpl ctx) |
| 1098 | throws ServiceNotFoundException { |
| 1099 | IBinder b = ServiceManager.getServiceOrThrow( |
| 1100 | Context.CROSS_PROFILE_APPS_SERVICE); |
| 1101 | return new CrossProfileApps(ctx.getOuterContext(), |
| 1102 | ICrossProfileApps.Stub.asInterface(b)); |
| 1103 | } |
| 1104 | }); |
Jason Monk | 8f5f7ff | 2017-10-17 14:12:42 -0400 | [diff] [blame] | 1105 | |
| 1106 | registerService(Context.SLICE_SERVICE, SliceManager.class, |
| 1107 | new CachedServiceFetcher<SliceManager>() { |
| 1108 | @Override |
| 1109 | public SliceManager createService(ContextImpl ctx) |
| 1110 | throws ServiceNotFoundException { |
| 1111 | return new SliceManager(ctx.getOuterContext(), |
| 1112 | ctx.mMainThread.getHandler()); |
| 1113 | } |
| 1114 | }); |
Philip P. Moltmann | f80809f | 2018-04-04 11:20:44 -0700 | [diff] [blame] | 1115 | |
| 1116 | registerService(Context.DEVICE_IDLE_CONTROLLER, DeviceIdleManager.class, |
| 1117 | new CachedServiceFetcher<DeviceIdleManager>() { |
| 1118 | @Override |
| 1119 | public DeviceIdleManager createService(ContextImpl ctx) |
| 1120 | throws ServiceNotFoundException { |
| 1121 | IDeviceIdleController service = IDeviceIdleController.Stub.asInterface( |
| 1122 | ServiceManager.getServiceOrThrow( |
| 1123 | Context.DEVICE_IDLE_CONTROLLER)); |
| 1124 | return new DeviceIdleManager(ctx.getOuterContext(), service); |
| 1125 | }}); |
Neil Fuller | feeee68 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 1126 | |
| 1127 | registerService(Context.TIME_DETECTOR_SERVICE, TimeDetector.class, |
| 1128 | new CachedServiceFetcher<TimeDetector>() { |
| 1129 | @Override |
| 1130 | public TimeDetector createService(ContextImpl ctx) |
| 1131 | throws ServiceNotFoundException { |
| 1132 | return new TimeDetector(); |
| 1133 | }}); |
Neil Fuller | 7fb88c3 | 2018-06-19 12:53:47 +0100 | [diff] [blame] | 1134 | registerService(Context.TIME_ZONE_DETECTOR_SERVICE, TimeZoneDetector.class, |
| 1135 | new CachedServiceFetcher<TimeZoneDetector>() { |
| 1136 | @Override |
| 1137 | public TimeZoneDetector createService(ContextImpl ctx) |
| 1138 | throws ServiceNotFoundException { |
| 1139 | return new TimeZoneDetector(); |
| 1140 | }}); |
Philip P. Moltmann | 039678e | 2018-09-18 13:04:38 -0700 | [diff] [blame] | 1141 | |
| 1142 | registerService(Context.PERMISSION_SERVICE, PermissionManager.class, |
| 1143 | new CachedServiceFetcher<PermissionManager>() { |
| 1144 | @Override |
| 1145 | public PermissionManager createService(ContextImpl ctx) { |
| 1146 | return new PermissionManager(ctx.getOuterContext()); |
| 1147 | }}); |
Hai Zhang | 4ef21d0 | 2018-11-09 14:43:51 -0800 | [diff] [blame] | 1148 | |
| 1149 | registerService(Context.ROLE_SERVICE, RoleManager.class, |
| 1150 | new CachedServiceFetcher<RoleManager>() { |
| 1151 | @Override |
| 1152 | public RoleManager createService(ContextImpl ctx) |
| 1153 | throws ServiceNotFoundException { |
| 1154 | return new RoleManager(ctx.getOuterContext()); |
| 1155 | }}); |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 1156 | //CHECKSTYLE:ON IndentationCheck |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * Creates an array which is used to cache per-Context service instances. |
| 1161 | */ |
| 1162 | public static Object[] createServiceCache() { |
| 1163 | return new Object[sServiceCacheSize]; |
| 1164 | } |
| 1165 | |
| 1166 | /** |
| 1167 | * Gets a system service from a given context. |
| 1168 | */ |
| 1169 | public static Object getSystemService(ContextImpl ctx, String name) { |
| 1170 | ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name); |
| 1171 | return fetcher != null ? fetcher.getService(ctx) : null; |
| 1172 | } |
| 1173 | |
| 1174 | /** |
Paul McLean | e3383cc | 2015-05-08 11:41:20 -0700 | [diff] [blame] | 1175 | * Gets the name of the system-level service that is represented by the specified class. |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1176 | */ |
| 1177 | public static String getSystemServiceName(Class<?> serviceClass) { |
| 1178 | return SYSTEM_SERVICE_NAMES.get(serviceClass); |
| 1179 | } |
| 1180 | |
| 1181 | /** |
| 1182 | * Statically registers a system service with the context. |
| 1183 | * This method must be called during static initialization only. |
| 1184 | */ |
| 1185 | private static <T> void registerService(String serviceName, Class<T> serviceClass, |
| 1186 | ServiceFetcher<T> serviceFetcher) { |
| 1187 | SYSTEM_SERVICE_NAMES.put(serviceClass, serviceName); |
| 1188 | SYSTEM_SERVICE_FETCHERS.put(serviceName, serviceFetcher); |
| 1189 | } |
| 1190 | |
| 1191 | /** |
| 1192 | * Base interface for classes that fetch services. |
| 1193 | * These objects must only be created during static initialization. |
| 1194 | */ |
| 1195 | static abstract interface ServiceFetcher<T> { |
| 1196 | T getService(ContextImpl ctx); |
| 1197 | } |
| 1198 | |
| 1199 | /** |
| 1200 | * Override this class when the system service constructor needs a |
| 1201 | * ContextImpl and should be cached and retained by that context. |
| 1202 | */ |
| 1203 | static abstract class CachedServiceFetcher<T> implements ServiceFetcher<T> { |
| 1204 | private final int mCacheIndex; |
| 1205 | |
Makoto Onuki | d67070e | 2018-03-30 12:39:14 -0700 | [diff] [blame] | 1206 | CachedServiceFetcher() { |
| 1207 | // Note this class must be instantiated only by the static initializer of the |
| 1208 | // outer class (SystemServiceRegistry), which already does the synchronization, |
| 1209 | // so bare access to sServiceCacheSize is okay here. |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1210 | mCacheIndex = sServiceCacheSize++; |
| 1211 | } |
| 1212 | |
| 1213 | @Override |
| 1214 | @SuppressWarnings("unchecked") |
| 1215 | public final T getService(ContextImpl ctx) { |
| 1216 | final Object[] cache = ctx.mServiceCache; |
Makoto Onuki | d67070e | 2018-03-30 12:39:14 -0700 | [diff] [blame] | 1217 | final int[] gates = ctx.mServiceInitializationStateArray; |
Makoto Onuki | f896f12 | 2018-01-25 09:50:24 -0800 | [diff] [blame] | 1218 | |
Makoto Onuki | d67070e | 2018-03-30 12:39:14 -0700 | [diff] [blame] | 1219 | for (;;) { |
| 1220 | boolean doInitialize = false; |
| 1221 | synchronized (cache) { |
| 1222 | // Return it if we already have a cached instance. |
| 1223 | T service = (T) cache[mCacheIndex]; |
| 1224 | if (service != null || gates[mCacheIndex] == ContextImpl.STATE_NOT_FOUND) { |
| 1225 | return service; |
| 1226 | } |
Makoto Onuki | f896f12 | 2018-01-25 09:50:24 -0800 | [diff] [blame] | 1227 | |
Makoto Onuki | d67070e | 2018-03-30 12:39:14 -0700 | [diff] [blame] | 1228 | // If we get here, there's no cached instance. |
Makoto Onuki | f896f12 | 2018-01-25 09:50:24 -0800 | [diff] [blame] | 1229 | |
Makoto Onuki | d67070e | 2018-03-30 12:39:14 -0700 | [diff] [blame] | 1230 | // Grr... if gate is STATE_READY, then this means we initialized the service |
| 1231 | // once but someone cleared it. |
| 1232 | // We start over from STATE_UNINITIALIZED. |
| 1233 | if (gates[mCacheIndex] == ContextImpl.STATE_READY) { |
| 1234 | gates[mCacheIndex] = ContextImpl.STATE_UNINITIALIZED; |
| 1235 | } |
| 1236 | |
| 1237 | // It's possible for multiple threads to get here at the same time, so |
| 1238 | // use the "gate" to make sure only the first thread will call createService(). |
| 1239 | |
| 1240 | // At this point, the gate must be either UNINITIALIZED or INITIALIZING. |
| 1241 | if (gates[mCacheIndex] == ContextImpl.STATE_UNINITIALIZED) { |
| 1242 | doInitialize = true; |
| 1243 | gates[mCacheIndex] = ContextImpl.STATE_INITIALIZING; |
| 1244 | } |
Makoto Onuki | f896f12 | 2018-01-25 09:50:24 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
Makoto Onuki | d67070e | 2018-03-30 12:39:14 -0700 | [diff] [blame] | 1247 | if (doInitialize) { |
| 1248 | // Only the first thread gets here. |
Makoto Onuki | f896f12 | 2018-01-25 09:50:24 -0800 | [diff] [blame] | 1249 | |
Makoto Onuki | d67070e | 2018-03-30 12:39:14 -0700 | [diff] [blame] | 1250 | T service = null; |
| 1251 | @ServiceInitializationState int newState = ContextImpl.STATE_NOT_FOUND; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1252 | try { |
Makoto Onuki | d67070e | 2018-03-30 12:39:14 -0700 | [diff] [blame] | 1253 | // This thread is the first one to get here. Instantiate the service |
| 1254 | // *without* the cache lock held. |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1255 | service = createService(ctx); |
Makoto Onuki | d67070e | 2018-03-30 12:39:14 -0700 | [diff] [blame] | 1256 | newState = ContextImpl.STATE_READY; |
Makoto Onuki | f896f12 | 2018-01-25 09:50:24 -0800 | [diff] [blame] | 1257 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1258 | } catch (ServiceNotFoundException e) { |
Jeff Sharkey | 589f309 | 2016-11-29 12:54:39 -0700 | [diff] [blame] | 1259 | onServiceNotFound(e); |
Makoto Onuki | f896f12 | 2018-01-25 09:50:24 -0800 | [diff] [blame] | 1260 | |
Makoto Onuki | d67070e | 2018-03-30 12:39:14 -0700 | [diff] [blame] | 1261 | } finally { |
| 1262 | synchronized (cache) { |
| 1263 | cache[mCacheIndex] = service; |
| 1264 | gates[mCacheIndex] = newState; |
| 1265 | cache.notifyAll(); |
| 1266 | } |
| 1267 | } |
| 1268 | return service; |
| 1269 | } |
| 1270 | // The other threads will wait for the first thread to call notifyAll(), |
| 1271 | // and go back to the top and retry. |
| 1272 | synchronized (cache) { |
| 1273 | while (gates[mCacheIndex] < ContextImpl.STATE_READY) { |
| 1274 | try { |
| 1275 | cache.wait(); |
| 1276 | } catch (InterruptedException e) { |
| 1277 | Log.w(TAG, "getService() interrupted"); |
| 1278 | Thread.currentThread().interrupt(); |
| 1279 | return null; |
| 1280 | } |
Makoto Onuki | f896f12 | 2018-01-25 09:50:24 -0800 | [diff] [blame] | 1281 | } |
| 1282 | } |
Makoto Onuki | f896f12 | 2018-01-25 09:50:24 -0800 | [diff] [blame] | 1283 | } |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1284 | } |
| 1285 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1286 | public abstract T createService(ContextImpl ctx) throws ServiceNotFoundException; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | /** |
| 1290 | * Override this class when the system service does not need a ContextImpl |
| 1291 | * and should be cached and retained process-wide. |
| 1292 | */ |
| 1293 | static abstract class StaticServiceFetcher<T> implements ServiceFetcher<T> { |
| 1294 | private T mCachedInstance; |
| 1295 | |
| 1296 | @Override |
Jeff Sharkey | 589f309 | 2016-11-29 12:54:39 -0700 | [diff] [blame] | 1297 | public final T getService(ContextImpl ctx) { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1298 | synchronized (StaticServiceFetcher.this) { |
| 1299 | if (mCachedInstance == null) { |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1300 | try { |
| 1301 | mCachedInstance = createService(); |
| 1302 | } catch (ServiceNotFoundException e) { |
Jeff Sharkey | 589f309 | 2016-11-29 12:54:39 -0700 | [diff] [blame] | 1303 | onServiceNotFound(e); |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1304 | } |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1305 | } |
| 1306 | return mCachedInstance; |
| 1307 | } |
| 1308 | } |
| 1309 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1310 | public abstract T createService() throws ServiceNotFoundException; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1311 | } |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 1312 | |
| 1313 | /** |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 1314 | * Like StaticServiceFetcher, creates only one instance of the service per application, but when |
| 1315 | * creating the service for the first time, passes it the application context of the creating |
| 1316 | * application. |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 1317 | * |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 1318 | * TODO: Delete this once its only user (ConnectivityManager) is known to work well in the |
| 1319 | * case where multiple application components each have their own ConnectivityManager object. |
| 1320 | */ |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 1321 | static abstract class StaticApplicationContextServiceFetcher<T> implements ServiceFetcher<T> { |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 1322 | private T mCachedInstance; |
| 1323 | |
| 1324 | @Override |
| 1325 | public final T getService(ContextImpl ctx) { |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 1326 | synchronized (StaticApplicationContextServiceFetcher.this) { |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 1327 | if (mCachedInstance == null) { |
Lorenzo Colitti | 0ad9ab0 | 2016-03-25 17:40:11 +0900 | [diff] [blame] | 1328 | Context appContext = ctx.getApplicationContext(); |
| 1329 | // If the application context is null, we're either in the system process or |
| 1330 | // it's the application context very early in app initialization. In both these |
| 1331 | // cases, the passed-in ContextImpl will not be freed, so it's safe to pass it |
| 1332 | // to the service. http://b/27532714 . |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1333 | try { |
| 1334 | mCachedInstance = createService(appContext != null ? appContext : ctx); |
| 1335 | } catch (ServiceNotFoundException e) { |
Jeff Sharkey | 589f309 | 2016-11-29 12:54:39 -0700 | [diff] [blame] | 1336 | onServiceNotFound(e); |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1337 | } |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 1338 | } |
| 1339 | return mCachedInstance; |
| 1340 | } |
| 1341 | } |
| 1342 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 1343 | public abstract T createService(Context applicationContext) throws ServiceNotFoundException; |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 1344 | } |
Jeff Sharkey | 589f309 | 2016-11-29 12:54:39 -0700 | [diff] [blame] | 1345 | |
| 1346 | public static void onServiceNotFound(ServiceNotFoundException e) { |
| 1347 | // We're mostly interested in tracking down long-lived core system |
| 1348 | // components that might stumble if they obtain bad references; just |
| 1349 | // emit a tidy log message for normal apps |
| 1350 | if (android.os.Process.myUid() < android.os.Process.FIRST_APPLICATION_UID) { |
| 1351 | Log.wtf(TAG, e.getMessage(), e); |
| 1352 | } else { |
| 1353 | Log.w(TAG, e.getMessage()); |
| 1354 | } |
| 1355 | } |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1356 | } |