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