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