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