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