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; |
| 25 | import android.app.trust.TrustManager; |
| 26 | import android.app.usage.IUsageStatsManager; |
Zoltan Szatmary-Ban | 9c5dfa5 | 2015-02-23 17:20:20 +0000 | [diff] [blame] | 27 | import android.app.usage.NetworkStatsManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 28 | import android.app.usage.UsageStatsManager; |
| 29 | import android.appwidget.AppWidgetManager; |
| 30 | import android.bluetooth.BluetoothManager; |
| 31 | import android.content.ClipboardManager; |
| 32 | import android.content.Context; |
| 33 | import android.content.IRestrictionsManager; |
| 34 | import android.content.RestrictionsManager; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 35 | import android.content.pm.IShortcutService; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 36 | import android.content.pm.LauncherApps; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 37 | import android.content.pm.ShortcutManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 38 | import android.content.res.Resources; |
| 39 | import android.hardware.ConsumerIrManager; |
| 40 | import android.hardware.ISerialManager; |
| 41 | import android.hardware.SensorManager; |
| 42 | import android.hardware.SerialManager; |
| 43 | import android.hardware.SystemSensorManager; |
| 44 | import android.hardware.camera2.CameraManager; |
| 45 | import android.hardware.display.DisplayManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 46 | import android.hardware.fingerprint.FingerprintManager; |
| 47 | import android.hardware.fingerprint.IFingerprintService; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 48 | import android.hardware.hdmi.HdmiControlManager; |
| 49 | import android.hardware.hdmi.IHdmiControlService; |
| 50 | import android.hardware.input.InputManager; |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 51 | import android.hardware.location.ContextHubManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 52 | import android.hardware.radio.RadioManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 53 | import android.hardware.usb.IUsbManager; |
| 54 | import android.hardware.usb.UsbManager; |
| 55 | import android.location.CountryDetector; |
| 56 | import android.location.ICountryDetector; |
| 57 | import android.location.ILocationManager; |
| 58 | import android.location.LocationManager; |
| 59 | import android.media.AudioManager; |
| 60 | import android.media.MediaRouter; |
| 61 | import android.media.midi.IMidiManager; |
| 62 | import android.media.midi.MidiManager; |
| 63 | import android.media.projection.MediaProjectionManager; |
| 64 | import android.media.session.MediaSessionManager; |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 65 | import android.media.soundtrigger.SoundTriggerManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 66 | import android.media.tv.ITvInputManager; |
| 67 | import android.media.tv.TvInputManager; |
| 68 | import android.net.ConnectivityManager; |
Paul Stewart | bf8cbb05 | 2016-03-17 10:11:54 -0700 | [diff] [blame] | 69 | import android.net.ConnectivityThread; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 70 | import android.net.EthernetManager; |
| 71 | import android.net.IConnectivityManager; |
| 72 | import android.net.IEthernetManager; |
| 73 | import android.net.INetworkPolicyManager; |
| 74 | import android.net.NetworkPolicyManager; |
| 75 | import android.net.NetworkScoreManager; |
| 76 | import android.net.nsd.INsdManager; |
| 77 | import android.net.nsd.NsdManager; |
| 78 | import android.net.wifi.IRttManager; |
| 79 | import android.net.wifi.IWifiManager; |
| 80 | import android.net.wifi.IWifiScanner; |
| 81 | import android.net.wifi.RttManager; |
| 82 | import android.net.wifi.WifiManager; |
| 83 | import android.net.wifi.WifiScanner; |
Etan Cohen | 20d329b | 2015-09-29 13:49:02 -0700 | [diff] [blame] | 84 | import android.net.wifi.nan.IWifiNanManager; |
| 85 | import android.net.wifi.nan.WifiNanManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 86 | import android.net.wifi.p2p.IWifiP2pManager; |
| 87 | import android.net.wifi.p2p.WifiP2pManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 88 | import android.nfc.NfcManager; |
| 89 | import android.os.BatteryManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 90 | import android.os.BatteryStats; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 91 | import android.os.DropBoxManager; |
Polina Bondarenko | 965ecbb | 2015-11-13 15:34:28 +0100 | [diff] [blame] | 92 | import android.os.HardwarePropertiesManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 93 | import android.os.IBatteryPropertiesRegistrar; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 94 | import android.os.IBinder; |
Polina Bondarenko | f8754ac | 2016-02-12 20:38:23 +0100 | [diff] [blame] | 95 | import android.os.IHardwarePropertiesManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 96 | import android.os.IPowerManager; |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 97 | import android.os.IRecoverySystem; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 98 | import android.os.IUserManager; |
| 99 | import android.os.PowerManager; |
| 100 | import android.os.Process; |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 101 | import android.os.RecoverySystem; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 102 | import android.os.ServiceManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 103 | import android.os.ServiceManager.ServiceNotFoundException; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 104 | import android.os.SystemVibrator; |
| 105 | import android.os.UserHandle; |
| 106 | import android.os.UserManager; |
| 107 | import android.os.Vibrator; |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 108 | import android.os.health.SystemHealthManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 109 | import android.os.storage.StorageManager; |
| 110 | import android.print.IPrintManager; |
| 111 | import android.print.PrintManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 112 | import android.service.persistentdata.IPersistentDataBlockService; |
| 113 | import android.service.persistentdata.PersistentDataBlockManager; |
| 114 | import android.telecom.TelecomManager; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 115 | import android.telephony.CarrierConfigManager; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 116 | import android.telephony.SubscriptionManager; |
| 117 | import android.telephony.TelephonyManager; |
| 118 | import android.util.Log; |
| 119 | import android.view.ContextThemeWrapper; |
| 120 | import android.view.LayoutInflater; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 121 | import android.view.WindowManager; |
| 122 | import android.view.WindowManagerImpl; |
| 123 | import android.view.accessibility.AccessibilityManager; |
| 124 | import android.view.accessibility.CaptioningManager; |
| 125 | import android.view.inputmethod.InputMethodManager; |
| 126 | import android.view.textservice.TextServicesManager; |
| 127 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 128 | import com.android.internal.app.IAppOpsService; |
| 129 | import com.android.internal.app.IBatteryStats; |
| 130 | import com.android.internal.app.ISoundTriggerService; |
| 131 | import com.android.internal.appwidget.IAppWidgetService; |
| 132 | import com.android.internal.os.IDropBoxManagerService; |
| 133 | import com.android.internal.policy.PhoneLayoutInflater; |
| 134 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 135 | import java.util.HashMap; |
| 136 | |
| 137 | /** |
| 138 | * Manages all of the system services that can be returned by {@link Context#getSystemService}. |
| 139 | * Used by {@link ContextImpl}. |
| 140 | */ |
| 141 | final class SystemServiceRegistry { |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 142 | private static final String TAG = "SystemServiceRegistry"; |
| 143 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 144 | // Service registry information. |
| 145 | // This information is never changed once static initialization has completed. |
| 146 | private static final HashMap<Class<?>, String> SYSTEM_SERVICE_NAMES = |
| 147 | new HashMap<Class<?>, String>(); |
| 148 | private static final HashMap<String, ServiceFetcher<?>> SYSTEM_SERVICE_FETCHERS = |
| 149 | new HashMap<String, ServiceFetcher<?>>(); |
| 150 | private static int sServiceCacheSize; |
| 151 | |
| 152 | // Not instantiable. |
| 153 | private SystemServiceRegistry() { } |
| 154 | |
| 155 | static { |
| 156 | registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class, |
| 157 | new CachedServiceFetcher<AccessibilityManager>() { |
| 158 | @Override |
| 159 | public AccessibilityManager createService(ContextImpl ctx) { |
| 160 | return AccessibilityManager.getInstance(ctx); |
| 161 | }}); |
| 162 | |
| 163 | registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class, |
| 164 | new CachedServiceFetcher<CaptioningManager>() { |
| 165 | @Override |
| 166 | public CaptioningManager createService(ContextImpl ctx) { |
| 167 | return new CaptioningManager(ctx); |
| 168 | }}); |
| 169 | |
| 170 | registerService(Context.ACCOUNT_SERVICE, AccountManager.class, |
| 171 | new CachedServiceFetcher<AccountManager>() { |
| 172 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 173 | public AccountManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 174 | IBinder b = ServiceManager.getServiceOrThrow(Context.ACCOUNT_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 175 | IAccountManager service = IAccountManager.Stub.asInterface(b); |
| 176 | return new AccountManager(ctx, service); |
| 177 | }}); |
| 178 | |
| 179 | registerService(Context.ACTIVITY_SERVICE, ActivityManager.class, |
| 180 | new CachedServiceFetcher<ActivityManager>() { |
| 181 | @Override |
| 182 | public ActivityManager createService(ContextImpl ctx) { |
| 183 | return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); |
| 184 | }}); |
| 185 | |
| 186 | registerService(Context.ALARM_SERVICE, AlarmManager.class, |
| 187 | new CachedServiceFetcher<AlarmManager>() { |
| 188 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 189 | public AlarmManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 190 | IBinder b = ServiceManager.getServiceOrThrow(Context.ALARM_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 191 | IAlarmManager service = IAlarmManager.Stub.asInterface(b); |
| 192 | return new AlarmManager(service, ctx); |
| 193 | }}); |
| 194 | |
| 195 | registerService(Context.AUDIO_SERVICE, AudioManager.class, |
| 196 | new CachedServiceFetcher<AudioManager>() { |
| 197 | @Override |
| 198 | public AudioManager createService(ContextImpl ctx) { |
| 199 | return new AudioManager(ctx); |
| 200 | }}); |
| 201 | |
| 202 | registerService(Context.MEDIA_ROUTER_SERVICE, MediaRouter.class, |
| 203 | new CachedServiceFetcher<MediaRouter>() { |
| 204 | @Override |
| 205 | public MediaRouter createService(ContextImpl ctx) { |
| 206 | return new MediaRouter(ctx); |
| 207 | }}); |
| 208 | |
| 209 | registerService(Context.BLUETOOTH_SERVICE, BluetoothManager.class, |
| 210 | new CachedServiceFetcher<BluetoothManager>() { |
| 211 | @Override |
| 212 | public BluetoothManager createService(ContextImpl ctx) { |
| 213 | return new BluetoothManager(ctx); |
| 214 | }}); |
| 215 | |
| 216 | registerService(Context.HDMI_CONTROL_SERVICE, HdmiControlManager.class, |
| 217 | new StaticServiceFetcher<HdmiControlManager>() { |
| 218 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 219 | public HdmiControlManager createService() throws ServiceNotFoundException { |
| 220 | IBinder b = ServiceManager.getServiceOrThrow(Context.HDMI_CONTROL_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 221 | return new HdmiControlManager(IHdmiControlService.Stub.asInterface(b)); |
| 222 | }}); |
| 223 | |
| 224 | registerService(Context.CLIPBOARD_SERVICE, ClipboardManager.class, |
| 225 | new CachedServiceFetcher<ClipboardManager>() { |
| 226 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 227 | public ClipboardManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 228 | return new ClipboardManager(ctx.getOuterContext(), |
| 229 | ctx.mMainThread.getHandler()); |
| 230 | }}); |
| 231 | |
| 232 | // The clipboard service moved to a new package. If someone asks for the old |
| 233 | // interface by class then we want to redirect over to the new interface instead |
| 234 | // (which extends it). |
| 235 | SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE); |
| 236 | |
| 237 | registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class, |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 238 | new StaticApplicationContextServiceFetcher<ConnectivityManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 239 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 240 | public ConnectivityManager createService(Context context) throws ServiceNotFoundException { |
| 241 | IBinder b = ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE); |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 242 | IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
| 243 | return new ConnectivityManager(context, service); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 244 | }}); |
| 245 | |
| 246 | registerService(Context.COUNTRY_DETECTOR, CountryDetector.class, |
| 247 | new StaticServiceFetcher<CountryDetector>() { |
| 248 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 249 | public CountryDetector createService() throws ServiceNotFoundException { |
| 250 | IBinder b = ServiceManager.getServiceOrThrow(Context.COUNTRY_DETECTOR); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 251 | return new CountryDetector(ICountryDetector.Stub.asInterface(b)); |
| 252 | }}); |
| 253 | |
| 254 | registerService(Context.DEVICE_POLICY_SERVICE, DevicePolicyManager.class, |
| 255 | new CachedServiceFetcher<DevicePolicyManager>() { |
| 256 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 257 | public DevicePolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 258 | IBinder b = ServiceManager.getServiceOrThrow(Context.DEVICE_POLICY_SERVICE); |
| 259 | return new DevicePolicyManager(ctx, IDevicePolicyManager.Stub.asInterface(b)); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 260 | }}); |
| 261 | |
| 262 | registerService(Context.DOWNLOAD_SERVICE, DownloadManager.class, |
| 263 | new CachedServiceFetcher<DownloadManager>() { |
| 264 | @Override |
| 265 | public DownloadManager createService(ContextImpl ctx) { |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 266 | return new DownloadManager(ctx); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 267 | }}); |
| 268 | |
| 269 | registerService(Context.BATTERY_SERVICE, BatteryManager.class, |
| 270 | new StaticServiceFetcher<BatteryManager>() { |
| 271 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 272 | public BatteryManager createService() throws ServiceNotFoundException { |
| 273 | IBatteryStats stats = IBatteryStats.Stub.asInterface( |
| 274 | ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME)); |
| 275 | IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub |
| 276 | .asInterface(ServiceManager.getServiceOrThrow("batteryproperties")); |
| 277 | return new BatteryManager(stats, registrar); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 278 | }}); |
| 279 | |
| 280 | registerService(Context.NFC_SERVICE, NfcManager.class, |
| 281 | new CachedServiceFetcher<NfcManager>() { |
| 282 | @Override |
| 283 | public NfcManager createService(ContextImpl ctx) { |
| 284 | return new NfcManager(ctx); |
| 285 | }}); |
| 286 | |
| 287 | registerService(Context.DROPBOX_SERVICE, DropBoxManager.class, |
Jeff Sharkey | b8e8a91 | 2016-03-09 16:27:40 -0700 | [diff] [blame] | 288 | new CachedServiceFetcher<DropBoxManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 289 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 290 | public DropBoxManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 291 | IBinder b = ServiceManager.getServiceOrThrow(Context.DROPBOX_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 292 | IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b); |
Jeff Sharkey | b8e8a91 | 2016-03-09 16:27:40 -0700 | [diff] [blame] | 293 | return new DropBoxManager(ctx, service); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 294 | }}); |
| 295 | |
| 296 | registerService(Context.INPUT_SERVICE, InputManager.class, |
| 297 | new StaticServiceFetcher<InputManager>() { |
| 298 | @Override |
| 299 | public InputManager createService() { |
| 300 | return InputManager.getInstance(); |
| 301 | }}); |
| 302 | |
| 303 | registerService(Context.DISPLAY_SERVICE, DisplayManager.class, |
| 304 | new CachedServiceFetcher<DisplayManager>() { |
| 305 | @Override |
| 306 | public DisplayManager createService(ContextImpl ctx) { |
| 307 | return new DisplayManager(ctx.getOuterContext()); |
| 308 | }}); |
| 309 | |
| 310 | registerService(Context.INPUT_METHOD_SERVICE, InputMethodManager.class, |
| 311 | new StaticServiceFetcher<InputMethodManager>() { |
| 312 | @Override |
| 313 | public InputMethodManager createService() { |
| 314 | return InputMethodManager.getInstance(); |
| 315 | }}); |
| 316 | |
| 317 | registerService(Context.TEXT_SERVICES_MANAGER_SERVICE, TextServicesManager.class, |
| 318 | new StaticServiceFetcher<TextServicesManager>() { |
| 319 | @Override |
| 320 | public TextServicesManager createService() { |
| 321 | return TextServicesManager.getInstance(); |
| 322 | }}); |
| 323 | |
| 324 | registerService(Context.KEYGUARD_SERVICE, KeyguardManager.class, |
| 325 | new StaticServiceFetcher<KeyguardManager>() { |
| 326 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 327 | public KeyguardManager createService() throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 328 | return new KeyguardManager(); |
| 329 | }}); |
| 330 | |
| 331 | registerService(Context.LAYOUT_INFLATER_SERVICE, LayoutInflater.class, |
| 332 | new CachedServiceFetcher<LayoutInflater>() { |
| 333 | @Override |
| 334 | public LayoutInflater createService(ContextImpl ctx) { |
| 335 | return new PhoneLayoutInflater(ctx.getOuterContext()); |
| 336 | }}); |
| 337 | |
| 338 | registerService(Context.LOCATION_SERVICE, LocationManager.class, |
| 339 | new CachedServiceFetcher<LocationManager>() { |
| 340 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 341 | public LocationManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 342 | IBinder b = ServiceManager.getServiceOrThrow(Context.LOCATION_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 343 | return new LocationManager(ctx, ILocationManager.Stub.asInterface(b)); |
| 344 | }}); |
| 345 | |
| 346 | registerService(Context.NETWORK_POLICY_SERVICE, NetworkPolicyManager.class, |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 347 | new CachedServiceFetcher<NetworkPolicyManager>() { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 348 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 349 | public NetworkPolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 350 | return new NetworkPolicyManager(ctx, INetworkPolicyManager.Stub.asInterface( |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 351 | ServiceManager.getServiceOrThrow(Context.NETWORK_POLICY_SERVICE))); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 352 | }}); |
| 353 | |
| 354 | registerService(Context.NOTIFICATION_SERVICE, NotificationManager.class, |
| 355 | new CachedServiceFetcher<NotificationManager>() { |
| 356 | @Override |
| 357 | public NotificationManager createService(ContextImpl ctx) { |
| 358 | final Context outerContext = ctx.getOuterContext(); |
| 359 | return new NotificationManager( |
| 360 | new ContextThemeWrapper(outerContext, |
| 361 | Resources.selectSystemTheme(0, |
| 362 | outerContext.getApplicationInfo().targetSdkVersion, |
| 363 | com.android.internal.R.style.Theme_Dialog, |
| 364 | com.android.internal.R.style.Theme_Holo_Dialog, |
| 365 | com.android.internal.R.style.Theme_DeviceDefault_Dialog, |
| 366 | com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog)), |
| 367 | ctx.mMainThread.getHandler()); |
| 368 | }}); |
| 369 | |
| 370 | registerService(Context.NSD_SERVICE, NsdManager.class, |
| 371 | new CachedServiceFetcher<NsdManager>() { |
| 372 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 373 | public NsdManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 374 | IBinder b = ServiceManager.getServiceOrThrow(Context.NSD_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 375 | INsdManager service = INsdManager.Stub.asInterface(b); |
| 376 | return new NsdManager(ctx.getOuterContext(), service); |
| 377 | }}); |
| 378 | |
| 379 | registerService(Context.POWER_SERVICE, PowerManager.class, |
| 380 | new CachedServiceFetcher<PowerManager>() { |
| 381 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 382 | public PowerManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 383 | IBinder b = ServiceManager.getServiceOrThrow(Context.POWER_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 384 | IPowerManager service = IPowerManager.Stub.asInterface(b); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 385 | return new PowerManager(ctx.getOuterContext(), |
| 386 | service, ctx.mMainThread.getHandler()); |
| 387 | }}); |
| 388 | |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 389 | registerService(Context.RECOVERY_SERVICE, RecoverySystem.class, |
| 390 | new CachedServiceFetcher<RecoverySystem>() { |
| 391 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 392 | public RecoverySystem createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 393 | IBinder b = ServiceManager.getServiceOrThrow(Context.RECOVERY_SERVICE); |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 394 | IRecoverySystem service = IRecoverySystem.Stub.asInterface(b); |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 395 | return new RecoverySystem(service); |
| 396 | }}); |
| 397 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 398 | registerService(Context.SEARCH_SERVICE, SearchManager.class, |
| 399 | new CachedServiceFetcher<SearchManager>() { |
| 400 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 401 | public SearchManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 402 | return new SearchManager(ctx.getOuterContext(), |
| 403 | ctx.mMainThread.getHandler()); |
| 404 | }}); |
| 405 | |
| 406 | registerService(Context.SENSOR_SERVICE, SensorManager.class, |
| 407 | new CachedServiceFetcher<SensorManager>() { |
| 408 | @Override |
| 409 | public SensorManager createService(ContextImpl ctx) { |
| 410 | return new SystemSensorManager(ctx.getOuterContext(), |
| 411 | ctx.mMainThread.getHandler().getLooper()); |
| 412 | }}); |
| 413 | |
| 414 | registerService(Context.STATUS_BAR_SERVICE, StatusBarManager.class, |
| 415 | new CachedServiceFetcher<StatusBarManager>() { |
| 416 | @Override |
| 417 | public StatusBarManager createService(ContextImpl ctx) { |
| 418 | return new StatusBarManager(ctx.getOuterContext()); |
| 419 | }}); |
| 420 | |
| 421 | registerService(Context.STORAGE_SERVICE, StorageManager.class, |
| 422 | new CachedServiceFetcher<StorageManager>() { |
| 423 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 424 | public StorageManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 425 | return new StorageManager(ctx, ctx.mMainThread.getHandler().getLooper()); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 426 | }}); |
| 427 | |
| 428 | registerService(Context.TELEPHONY_SERVICE, TelephonyManager.class, |
| 429 | new CachedServiceFetcher<TelephonyManager>() { |
| 430 | @Override |
| 431 | public TelephonyManager createService(ContextImpl ctx) { |
| 432 | return new TelephonyManager(ctx.getOuterContext()); |
| 433 | }}); |
| 434 | |
| 435 | registerService(Context.TELEPHONY_SUBSCRIPTION_SERVICE, SubscriptionManager.class, |
| 436 | new CachedServiceFetcher<SubscriptionManager>() { |
| 437 | @Override |
| 438 | public SubscriptionManager createService(ContextImpl ctx) { |
| 439 | return new SubscriptionManager(ctx.getOuterContext()); |
| 440 | }}); |
| 441 | |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 442 | registerService(Context.CARRIER_CONFIG_SERVICE, CarrierConfigManager.class, |
| 443 | new CachedServiceFetcher<CarrierConfigManager>() { |
| 444 | @Override |
| 445 | public CarrierConfigManager createService(ContextImpl ctx) { |
| 446 | return new CarrierConfigManager(); |
| 447 | }}); |
| 448 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 449 | registerService(Context.TELECOM_SERVICE, TelecomManager.class, |
| 450 | new CachedServiceFetcher<TelecomManager>() { |
| 451 | @Override |
| 452 | public TelecomManager createService(ContextImpl ctx) { |
| 453 | return new TelecomManager(ctx.getOuterContext()); |
| 454 | }}); |
| 455 | |
| 456 | registerService(Context.UI_MODE_SERVICE, UiModeManager.class, |
| 457 | new CachedServiceFetcher<UiModeManager>() { |
| 458 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 459 | public UiModeManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 460 | return new UiModeManager(); |
| 461 | }}); |
| 462 | |
| 463 | registerService(Context.USB_SERVICE, UsbManager.class, |
| 464 | new CachedServiceFetcher<UsbManager>() { |
| 465 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 466 | public UsbManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 467 | IBinder b = ServiceManager.getServiceOrThrow(Context.USB_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 468 | return new UsbManager(ctx, IUsbManager.Stub.asInterface(b)); |
| 469 | }}); |
| 470 | |
| 471 | registerService(Context.SERIAL_SERVICE, SerialManager.class, |
| 472 | new CachedServiceFetcher<SerialManager>() { |
| 473 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 474 | public SerialManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 475 | IBinder b = ServiceManager.getServiceOrThrow(Context.SERIAL_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 476 | return new SerialManager(ctx, ISerialManager.Stub.asInterface(b)); |
| 477 | }}); |
| 478 | |
| 479 | registerService(Context.VIBRATOR_SERVICE, Vibrator.class, |
| 480 | new CachedServiceFetcher<Vibrator>() { |
| 481 | @Override |
| 482 | public Vibrator createService(ContextImpl ctx) { |
| 483 | return new SystemVibrator(ctx); |
| 484 | }}); |
| 485 | |
| 486 | registerService(Context.WALLPAPER_SERVICE, WallpaperManager.class, |
| 487 | new CachedServiceFetcher<WallpaperManager>() { |
| 488 | @Override |
| 489 | public WallpaperManager createService(ContextImpl ctx) { |
| 490 | return new WallpaperManager(ctx.getOuterContext(), |
| 491 | ctx.mMainThread.getHandler()); |
| 492 | }}); |
| 493 | |
| 494 | registerService(Context.WIFI_SERVICE, WifiManager.class, |
| 495 | new CachedServiceFetcher<WifiManager>() { |
| 496 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 497 | public WifiManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 498 | IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 499 | IWifiManager service = IWifiManager.Stub.asInterface(b); |
Paul Stewart | bf8cbb05 | 2016-03-17 10:11:54 -0700 | [diff] [blame] | 500 | return new WifiManager(ctx.getOuterContext(), service, |
| 501 | ConnectivityThread.getInstanceLooper()); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 502 | }}); |
| 503 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 504 | registerService(Context.WIFI_P2P_SERVICE, WifiP2pManager.class, |
| 505 | new StaticServiceFetcher<WifiP2pManager>() { |
| 506 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 507 | public WifiP2pManager createService() throws ServiceNotFoundException { |
| 508 | IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_P2P_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 509 | IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b); |
| 510 | return new WifiP2pManager(service); |
| 511 | }}); |
| 512 | |
Etan Cohen | 20d329b | 2015-09-29 13:49:02 -0700 | [diff] [blame] | 513 | registerService(Context.WIFI_NAN_SERVICE, WifiNanManager.class, |
Etan Cohen | 7531a28 | 2016-08-11 09:31:21 -0700 | [diff] [blame] | 514 | new CachedServiceFetcher<WifiNanManager>() { |
Etan Cohen | 20d329b | 2015-09-29 13:49:02 -0700 | [diff] [blame] | 515 | @Override |
Etan Cohen | ccb0b65 | 2016-08-19 11:22:06 -0700 | [diff] [blame] | 516 | public WifiNanManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Etan Cohen | 20d329b | 2015-09-29 13:49:02 -0700 | [diff] [blame] | 517 | IBinder b = ServiceManager.getService(Context.WIFI_NAN_SERVICE); |
| 518 | IWifiNanManager service = IWifiNanManager.Stub.asInterface(b); |
| 519 | if (service == null) { |
| 520 | return null; |
| 521 | } |
Etan Cohen | 7531a28 | 2016-08-11 09:31:21 -0700 | [diff] [blame] | 522 | return new WifiNanManager(ctx.getOuterContext(), service); |
Etan Cohen | 20d329b | 2015-09-29 13:49:02 -0700 | [diff] [blame] | 523 | }}); |
| 524 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 525 | registerService(Context.WIFI_SCANNING_SERVICE, WifiScanner.class, |
| 526 | new CachedServiceFetcher<WifiScanner>() { |
| 527 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 528 | public WifiScanner createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 529 | IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SCANNING_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 530 | IWifiScanner service = IWifiScanner.Stub.asInterface(b); |
Mitchell Wills | 91312c7 | 2016-04-06 17:03:35 -0700 | [diff] [blame] | 531 | return new WifiScanner(ctx.getOuterContext(), service, |
| 532 | ConnectivityThread.getInstanceLooper()); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 533 | }}); |
| 534 | |
| 535 | registerService(Context.WIFI_RTT_SERVICE, RttManager.class, |
| 536 | new CachedServiceFetcher<RttManager>() { |
| 537 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 538 | public RttManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 539 | IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_RTT_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 540 | IRttManager service = IRttManager.Stub.asInterface(b); |
Wei Wang | bd3353a | 2016-04-08 14:24:09 -0700 | [diff] [blame] | 541 | return new RttManager(ctx.getOuterContext(), service, |
| 542 | ConnectivityThread.getInstanceLooper()); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 543 | }}); |
| 544 | |
| 545 | registerService(Context.ETHERNET_SERVICE, EthernetManager.class, |
| 546 | new CachedServiceFetcher<EthernetManager>() { |
| 547 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 548 | public EthernetManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 549 | IBinder b = ServiceManager.getServiceOrThrow(Context.ETHERNET_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 550 | IEthernetManager service = IEthernetManager.Stub.asInterface(b); |
| 551 | return new EthernetManager(ctx.getOuterContext(), service); |
| 552 | }}); |
| 553 | |
| 554 | registerService(Context.WINDOW_SERVICE, WindowManager.class, |
| 555 | new CachedServiceFetcher<WindowManager>() { |
| 556 | @Override |
| 557 | public WindowManager createService(ContextImpl ctx) { |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 558 | return new WindowManagerImpl(ctx); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 559 | }}); |
| 560 | |
| 561 | registerService(Context.USER_SERVICE, UserManager.class, |
| 562 | new CachedServiceFetcher<UserManager>() { |
| 563 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 564 | public UserManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 565 | IBinder b = ServiceManager.getServiceOrThrow(Context.USER_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 566 | IUserManager service = IUserManager.Stub.asInterface(b); |
| 567 | return new UserManager(ctx, service); |
| 568 | }}); |
| 569 | |
| 570 | registerService(Context.APP_OPS_SERVICE, AppOpsManager.class, |
| 571 | new CachedServiceFetcher<AppOpsManager>() { |
| 572 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 573 | public AppOpsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 574 | IBinder b = ServiceManager.getServiceOrThrow(Context.APP_OPS_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 575 | IAppOpsService service = IAppOpsService.Stub.asInterface(b); |
| 576 | return new AppOpsManager(ctx, service); |
| 577 | }}); |
| 578 | |
| 579 | registerService(Context.CAMERA_SERVICE, CameraManager.class, |
| 580 | new CachedServiceFetcher<CameraManager>() { |
| 581 | @Override |
| 582 | public CameraManager createService(ContextImpl ctx) { |
| 583 | return new CameraManager(ctx); |
| 584 | }}); |
| 585 | |
| 586 | registerService(Context.LAUNCHER_APPS_SERVICE, LauncherApps.class, |
| 587 | new CachedServiceFetcher<LauncherApps>() { |
| 588 | @Override |
| 589 | public LauncherApps createService(ContextImpl ctx) { |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 590 | return new LauncherApps(ctx); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 591 | }}); |
| 592 | |
| 593 | registerService(Context.RESTRICTIONS_SERVICE, RestrictionsManager.class, |
| 594 | new CachedServiceFetcher<RestrictionsManager>() { |
| 595 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 596 | public RestrictionsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 597 | IBinder b = ServiceManager.getServiceOrThrow(Context.RESTRICTIONS_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 598 | IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b); |
| 599 | return new RestrictionsManager(ctx, service); |
| 600 | }}); |
| 601 | |
| 602 | registerService(Context.PRINT_SERVICE, PrintManager.class, |
| 603 | new CachedServiceFetcher<PrintManager>() { |
| 604 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 605 | public PrintManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 606 | IBinder iBinder = ServiceManager.getServiceOrThrow(Context.PRINT_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 607 | IPrintManager service = IPrintManager.Stub.asInterface(iBinder); |
| 608 | return new PrintManager(ctx.getOuterContext(), service, UserHandle.myUserId(), |
| 609 | UserHandle.getAppId(Process.myUid())); |
| 610 | }}); |
| 611 | |
| 612 | registerService(Context.CONSUMER_IR_SERVICE, ConsumerIrManager.class, |
| 613 | new CachedServiceFetcher<ConsumerIrManager>() { |
| 614 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 615 | public ConsumerIrManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 616 | return new ConsumerIrManager(ctx); |
| 617 | }}); |
| 618 | |
| 619 | registerService(Context.MEDIA_SESSION_SERVICE, MediaSessionManager.class, |
| 620 | new CachedServiceFetcher<MediaSessionManager>() { |
| 621 | @Override |
| 622 | public MediaSessionManager createService(ContextImpl ctx) { |
| 623 | return new MediaSessionManager(ctx); |
| 624 | }}); |
| 625 | |
| 626 | registerService(Context.TRUST_SERVICE, TrustManager.class, |
| 627 | new StaticServiceFetcher<TrustManager>() { |
| 628 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 629 | public TrustManager createService() throws ServiceNotFoundException { |
| 630 | IBinder b = ServiceManager.getServiceOrThrow(Context.TRUST_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 631 | return new TrustManager(b); |
| 632 | }}); |
| 633 | |
| 634 | registerService(Context.FINGERPRINT_SERVICE, FingerprintManager.class, |
| 635 | new CachedServiceFetcher<FingerprintManager>() { |
| 636 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 637 | public FingerprintManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 638 | IBinder binder = ServiceManager.getServiceOrThrow(Context.FINGERPRINT_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 639 | IFingerprintService service = IFingerprintService.Stub.asInterface(binder); |
| 640 | return new FingerprintManager(ctx.getOuterContext(), service); |
| 641 | }}); |
| 642 | |
| 643 | registerService(Context.TV_INPUT_SERVICE, TvInputManager.class, |
| 644 | new StaticServiceFetcher<TvInputManager>() { |
| 645 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 646 | public TvInputManager createService() throws ServiceNotFoundException { |
| 647 | IBinder iBinder = ServiceManager.getServiceOrThrow(Context.TV_INPUT_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 648 | ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder); |
| 649 | return new TvInputManager(service, UserHandle.myUserId()); |
| 650 | }}); |
| 651 | |
| 652 | registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class, |
| 653 | new CachedServiceFetcher<NetworkScoreManager>() { |
| 654 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 655 | public NetworkScoreManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 656 | return new NetworkScoreManager(ctx); |
| 657 | }}); |
| 658 | |
| 659 | registerService(Context.USAGE_STATS_SERVICE, UsageStatsManager.class, |
| 660 | new CachedServiceFetcher<UsageStatsManager>() { |
| 661 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 662 | public UsageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 663 | IBinder iBinder = ServiceManager.getServiceOrThrow(Context.USAGE_STATS_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 664 | IUsageStatsManager service = IUsageStatsManager.Stub.asInterface(iBinder); |
| 665 | return new UsageStatsManager(ctx.getOuterContext(), service); |
| 666 | }}); |
| 667 | |
Zoltan Szatmary-Ban | 9c5dfa5 | 2015-02-23 17:20:20 +0000 | [diff] [blame] | 668 | registerService(Context.NETWORK_STATS_SERVICE, NetworkStatsManager.class, |
| 669 | new CachedServiceFetcher<NetworkStatsManager>() { |
| 670 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 671 | public NetworkStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Zoltan Szatmary-Ban | 9c5dfa5 | 2015-02-23 17:20:20 +0000 | [diff] [blame] | 672 | return new NetworkStatsManager(ctx.getOuterContext()); |
| 673 | }}); |
| 674 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 675 | registerService(Context.JOB_SCHEDULER_SERVICE, JobScheduler.class, |
| 676 | new StaticServiceFetcher<JobScheduler>() { |
| 677 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 678 | public JobScheduler createService() throws ServiceNotFoundException { |
| 679 | IBinder b = ServiceManager.getServiceOrThrow(Context.JOB_SCHEDULER_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 680 | return new JobSchedulerImpl(IJobScheduler.Stub.asInterface(b)); |
| 681 | }}); |
| 682 | |
| 683 | registerService(Context.PERSISTENT_DATA_BLOCK_SERVICE, PersistentDataBlockManager.class, |
| 684 | new StaticServiceFetcher<PersistentDataBlockManager>() { |
| 685 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 686 | public PersistentDataBlockManager createService() throws ServiceNotFoundException { |
| 687 | IBinder b = ServiceManager.getServiceOrThrow(Context.PERSISTENT_DATA_BLOCK_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 688 | IPersistentDataBlockService persistentDataBlockService = |
| 689 | IPersistentDataBlockService.Stub.asInterface(b); |
| 690 | if (persistentDataBlockService != null) { |
| 691 | return new PersistentDataBlockManager(persistentDataBlockService); |
| 692 | } else { |
| 693 | // not supported |
| 694 | return null; |
| 695 | } |
| 696 | }}); |
| 697 | |
| 698 | registerService(Context.MEDIA_PROJECTION_SERVICE, MediaProjectionManager.class, |
| 699 | new CachedServiceFetcher<MediaProjectionManager>() { |
| 700 | @Override |
| 701 | public MediaProjectionManager createService(ContextImpl ctx) { |
| 702 | return new MediaProjectionManager(ctx); |
| 703 | }}); |
| 704 | |
| 705 | registerService(Context.APPWIDGET_SERVICE, AppWidgetManager.class, |
| 706 | new CachedServiceFetcher<AppWidgetManager>() { |
| 707 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 708 | public AppWidgetManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 709 | IBinder b = ServiceManager.getServiceOrThrow(Context.APPWIDGET_SERVICE); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 710 | return new AppWidgetManager(ctx, IAppWidgetService.Stub.asInterface(b)); |
| 711 | }}); |
| 712 | |
| 713 | registerService(Context.MIDI_SERVICE, MidiManager.class, |
| 714 | new CachedServiceFetcher<MidiManager>() { |
| 715 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 716 | public MidiManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 717 | IBinder b = ServiceManager.getServiceOrThrow(Context.MIDI_SERVICE); |
Mike Lockwood | e0a6ca6 | 2015-06-04 13:43:56 -0700 | [diff] [blame] | 718 | return new MidiManager(IMidiManager.Stub.asInterface(b)); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 719 | }}); |
Eric Laurent | 2035ac8 | 2015-03-05 15:18:44 -0800 | [diff] [blame] | 720 | |
| 721 | registerService(Context.RADIO_SERVICE, RadioManager.class, |
| 722 | new CachedServiceFetcher<RadioManager>() { |
| 723 | @Override |
| 724 | public RadioManager createService(ContextImpl ctx) { |
| 725 | return new RadioManager(ctx); |
| 726 | }}); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 727 | |
Polina Bondarenko | 965ecbb | 2015-11-13 15:34:28 +0100 | [diff] [blame] | 728 | registerService(Context.HARDWARE_PROPERTIES_SERVICE, HardwarePropertiesManager.class, |
| 729 | new CachedServiceFetcher<HardwarePropertiesManager>() { |
| 730 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 731 | public HardwarePropertiesManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 732 | IBinder b = ServiceManager.getServiceOrThrow(Context.HARDWARE_PROPERTIES_SERVICE); |
| 733 | IHardwarePropertiesManager service = |
| 734 | IHardwarePropertiesManager.Stub.asInterface(b); |
| 735 | return new HardwarePropertiesManager(ctx, service); |
Polina Bondarenko | 965ecbb | 2015-11-13 15:34:28 +0100 | [diff] [blame] | 736 | }}); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 737 | |
| 738 | registerService(Context.SOUND_TRIGGER_SERVICE, SoundTriggerManager.class, |
| 739 | new CachedServiceFetcher<SoundTriggerManager>() { |
| 740 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 741 | public SoundTriggerManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 742 | IBinder b = ServiceManager.getServiceOrThrow(Context.SOUND_TRIGGER_SERVICE); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 743 | return new SoundTriggerManager(ctx, ISoundTriggerService.Stub.asInterface(b)); |
| 744 | }}); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 745 | |
| 746 | registerService(Context.SHORTCUT_SERVICE, ShortcutManager.class, |
| 747 | new CachedServiceFetcher<ShortcutManager>() { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 748 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 749 | public ShortcutManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 750 | IBinder b = ServiceManager.getServiceOrThrow(Context.SHORTCUT_SERVICE); |
| 751 | return new ShortcutManager(ctx, IShortcutService.Stub.asInterface(b)); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 752 | }}); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 753 | |
| 754 | registerService(Context.SYSTEM_HEALTH_SERVICE, SystemHealthManager.class, |
| 755 | new CachedServiceFetcher<SystemHealthManager>() { |
| 756 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 757 | public SystemHealthManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
| 758 | IBinder b = ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME); |
| 759 | return new SystemHealthManager(IBatteryStats.Stub.asInterface(b)); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 760 | }}); |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 761 | |
| 762 | registerService(Context.CONTEXTHUB_SERVICE, ContextHubManager.class, |
| 763 | new CachedServiceFetcher<ContextHubManager>() { |
| 764 | @Override |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 765 | public ContextHubManager createService(ContextImpl ctx) throws ServiceNotFoundException { |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 766 | return new ContextHubManager(ctx.getOuterContext(), |
| 767 | ctx.mMainThread.getHandler().getLooper()); |
| 768 | }}); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | /** |
| 772 | * Creates an array which is used to cache per-Context service instances. |
| 773 | */ |
| 774 | public static Object[] createServiceCache() { |
| 775 | return new Object[sServiceCacheSize]; |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * Gets a system service from a given context. |
| 780 | */ |
| 781 | public static Object getSystemService(ContextImpl ctx, String name) { |
| 782 | ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name); |
| 783 | return fetcher != null ? fetcher.getService(ctx) : null; |
| 784 | } |
| 785 | |
| 786 | /** |
Paul McLean | e3383cc | 2015-05-08 11:41:20 -0700 | [diff] [blame] | 787 | * 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] | 788 | */ |
| 789 | public static String getSystemServiceName(Class<?> serviceClass) { |
| 790 | return SYSTEM_SERVICE_NAMES.get(serviceClass); |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * Statically registers a system service with the context. |
| 795 | * This method must be called during static initialization only. |
| 796 | */ |
| 797 | private static <T> void registerService(String serviceName, Class<T> serviceClass, |
| 798 | ServiceFetcher<T> serviceFetcher) { |
| 799 | SYSTEM_SERVICE_NAMES.put(serviceClass, serviceName); |
| 800 | SYSTEM_SERVICE_FETCHERS.put(serviceName, serviceFetcher); |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * Base interface for classes that fetch services. |
| 805 | * These objects must only be created during static initialization. |
| 806 | */ |
| 807 | static abstract interface ServiceFetcher<T> { |
| 808 | T getService(ContextImpl ctx); |
| 809 | } |
| 810 | |
| 811 | /** |
| 812 | * Override this class when the system service constructor needs a |
| 813 | * ContextImpl and should be cached and retained by that context. |
| 814 | */ |
| 815 | static abstract class CachedServiceFetcher<T> implements ServiceFetcher<T> { |
| 816 | private final int mCacheIndex; |
| 817 | |
| 818 | public CachedServiceFetcher() { |
| 819 | mCacheIndex = sServiceCacheSize++; |
| 820 | } |
| 821 | |
| 822 | @Override |
| 823 | @SuppressWarnings("unchecked") |
| 824 | public final T getService(ContextImpl ctx) { |
| 825 | final Object[] cache = ctx.mServiceCache; |
| 826 | synchronized (cache) { |
| 827 | // Fetch or create the service. |
| 828 | Object service = cache[mCacheIndex]; |
| 829 | if (service == null) { |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 830 | try { |
| 831 | service = createService(ctx); |
| 832 | cache[mCacheIndex] = service; |
| 833 | } catch (ServiceNotFoundException e) { |
Jeff Sharkey | d79d203 | 2016-08-23 13:39:07 -0600 | [diff] [blame] | 834 | Log.wtf(TAG, e.getMessage(), e); |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 835 | } |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 836 | } |
| 837 | return (T)service; |
| 838 | } |
| 839 | } |
| 840 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 841 | public abstract T createService(ContextImpl ctx) throws ServiceNotFoundException; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | /** |
| 845 | * Override this class when the system service does not need a ContextImpl |
| 846 | * and should be cached and retained process-wide. |
| 847 | */ |
| 848 | static abstract class StaticServiceFetcher<T> implements ServiceFetcher<T> { |
| 849 | private T mCachedInstance; |
| 850 | |
| 851 | @Override |
| 852 | public final T getService(ContextImpl unused) { |
| 853 | synchronized (StaticServiceFetcher.this) { |
| 854 | if (mCachedInstance == null) { |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 855 | try { |
| 856 | mCachedInstance = createService(); |
| 857 | } catch (ServiceNotFoundException e) { |
Jeff Sharkey | d79d203 | 2016-08-23 13:39:07 -0600 | [diff] [blame] | 858 | Log.wtf(TAG, e.getMessage(), e); |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 859 | } |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 860 | } |
| 861 | return mCachedInstance; |
| 862 | } |
| 863 | } |
| 864 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 865 | public abstract T createService() throws ServiceNotFoundException; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 866 | } |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 867 | |
| 868 | /** |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 869 | * Like StaticServiceFetcher, creates only one instance of the service per application, but when |
| 870 | * creating the service for the first time, passes it the application context of the creating |
| 871 | * application. |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 872 | * |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 873 | * TODO: Delete this once its only user (ConnectivityManager) is known to work well in the |
| 874 | * case where multiple application components each have their own ConnectivityManager object. |
| 875 | */ |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 876 | static abstract class StaticApplicationContextServiceFetcher<T> implements ServiceFetcher<T> { |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 877 | private T mCachedInstance; |
| 878 | |
| 879 | @Override |
| 880 | public final T getService(ContextImpl ctx) { |
Lorenzo Colitti | cf95977 | 2016-02-29 16:07:37 +0900 | [diff] [blame] | 881 | synchronized (StaticApplicationContextServiceFetcher.this) { |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 882 | if (mCachedInstance == null) { |
Lorenzo Colitti | 0ad9ab0 | 2016-03-25 17:40:11 +0900 | [diff] [blame] | 883 | Context appContext = ctx.getApplicationContext(); |
| 884 | // If the application context is null, we're either in the system process or |
| 885 | // it's the application context very early in app initialization. In both these |
| 886 | // cases, the passed-in ContextImpl will not be freed, so it's safe to pass it |
| 887 | // to the service. http://b/27532714 . |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 888 | try { |
| 889 | mCachedInstance = createService(appContext != null ? appContext : ctx); |
| 890 | } catch (ServiceNotFoundException e) { |
Jeff Sharkey | d79d203 | 2016-08-23 13:39:07 -0600 | [diff] [blame] | 891 | Log.wtf(TAG, e.getMessage(), e); |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 892 | } |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 893 | } |
| 894 | return mCachedInstance; |
| 895 | } |
| 896 | } |
| 897 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 898 | public abstract T createService(Context applicationContext) throws ServiceNotFoundException; |
Lorenzo Colitti | ffc42b0 | 2015-07-29 11:41:21 +0900 | [diff] [blame] | 899 | } |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 900 | } |