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