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