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 19 import android.accounts.AccountManager; 20 import android.accounts.IAccountManager; 21 import android.app.ContextImpl.ServiceInitializationState; 22 import android.app.admin.DevicePolicyManager; 23 import android.app.admin.IDevicePolicyManager; 24 import android.app.contentsuggestions.ContentSuggestionsManager; 25 import android.app.contentsuggestions.IContentSuggestionsManager; 26 import android.app.job.IJobScheduler; 27 import android.app.job.JobScheduler; 28 import android.app.prediction.AppPredictionManager; 29 import android.app.role.RoleControllerManager; 30 import android.app.role.RoleManager; 31 import android.app.slice.SliceManager; 32 import android.app.timedetector.TimeDetector; 33 import android.app.timezone.RulesManager; 34 import android.app.trust.TrustManager; 35 import android.app.usage.IStorageStatsManager; 36 import android.app.usage.IUsageStatsManager; 37 import android.app.usage.NetworkStatsManager; 38 import android.app.usage.StorageStatsManager; 39 import android.app.usage.UsageStatsManager; 40 import android.appwidget.AppWidgetManager; 41 import android.bluetooth.BluetoothManager; 42 import android.companion.CompanionDeviceManager; 43 import android.companion.ICompanionDeviceManager; 44 import android.content.ClipboardManager; 45 import android.content.ContentCaptureOptions; 46 import android.content.Context; 47 import android.content.IRestrictionsManager; 48 import android.content.RestrictionsManager; 49 import android.content.om.IOverlayManager; 50 import android.content.om.OverlayManager; 51 import android.content.pm.CrossProfileApps; 52 import android.content.pm.ICrossProfileApps; 53 import android.content.pm.IPackageManager; 54 import android.content.pm.IShortcutService; 55 import android.content.pm.LauncherApps; 56 import android.content.pm.PackageManager; 57 import android.content.pm.ShortcutManager; 58 import android.content.res.Resources; 59 import android.content.rollback.IRollbackManager; 60 import android.content.rollback.RollbackManager; 61 import android.debug.AdbManager; 62 import android.debug.IAdbManager; 63 import android.hardware.ConsumerIrManager; 64 import android.hardware.ISerialManager; 65 import android.hardware.SensorManager; 66 import android.hardware.SensorPrivacyManager; 67 import android.hardware.SerialManager; 68 import android.hardware.SystemSensorManager; 69 import android.hardware.biometrics.BiometricManager; 70 import android.hardware.biometrics.IBiometricService; 71 import android.hardware.camera2.CameraManager; 72 import android.hardware.display.ColorDisplayManager; 73 import android.hardware.display.DisplayManager; 74 import android.hardware.face.FaceManager; 75 import android.hardware.face.IFaceService; 76 import android.hardware.fingerprint.FingerprintManager; 77 import android.hardware.fingerprint.IFingerprintService; 78 import android.hardware.hdmi.HdmiControlManager; 79 import android.hardware.hdmi.IHdmiControlService; 80 import android.hardware.input.InputManager; 81 import android.hardware.iris.IIrisService; 82 import android.hardware.iris.IrisManager; 83 import android.hardware.location.ContextHubManager; 84 import android.hardware.radio.RadioManager; 85 import android.hardware.usb.IUsbManager; 86 import android.hardware.usb.UsbManager; 87 import android.location.CountryDetector; 88 import android.location.ICountryDetector; 89 import android.location.ILocationManager; 90 import android.location.LocationManager; 91 import android.media.AudioManager; 92 import android.media.MediaRouter; 93 import android.media.midi.IMidiManager; 94 import android.media.midi.MidiManager; 95 import android.media.projection.MediaProjectionManager; 96 import android.media.session.MediaSessionManager; 97 import android.media.soundtrigger.SoundTriggerManager; 98 import android.media.tv.ITvInputManager; 99 import android.media.tv.TvInputManager; 100 import android.net.ConnectivityManager; 101 import android.net.ConnectivityThread; 102 import android.net.EthernetManager; 103 import android.net.IConnectivityManager; 104 import android.net.IEthernetManager; 105 import android.net.IIpSecService; 106 import android.net.INetworkPolicyManager; 107 import android.net.ITestNetworkManager; 108 import android.net.IpSecManager; 109 import android.net.NetworkPolicyManager; 110 import android.net.NetworkScoreManager; 111 import android.net.NetworkWatchlistManager; 112 import android.net.TestNetworkManager; 113 import android.net.lowpan.ILowpanManager; 114 import android.net.lowpan.LowpanManager; 115 import android.net.nsd.INsdManager; 116 import android.net.nsd.NsdManager; 117 import android.net.wifi.IWifiManager; 118 import android.net.wifi.IWifiScanner; 119 import android.net.wifi.RttManager; 120 import android.net.wifi.WifiManager; 121 import android.net.wifi.WifiScanner; 122 import android.net.wifi.aware.IWifiAwareManager; 123 import android.net.wifi.aware.WifiAwareManager; 124 import android.net.wifi.p2p.IWifiP2pManager; 125 import android.net.wifi.p2p.WifiP2pManager; 126 import android.net.wifi.rtt.IWifiRttManager; 127 import android.net.wifi.rtt.WifiRttManager; 128 import android.nfc.NfcManager; 129 import android.os.BatteryManager; 130 import android.os.BatteryStats; 131 import android.os.BugreportManager; 132 import android.os.Build; 133 import android.os.DeviceIdleManager; 134 import android.os.DropBoxManager; 135 import android.os.HardwarePropertiesManager; 136 import android.os.IBatteryPropertiesRegistrar; 137 import android.os.IBinder; 138 import android.os.IDeviceIdleController; 139 import android.os.IDumpstate; 140 import android.os.IHardwarePropertiesManager; 141 import android.os.IPowerManager; 142 import android.os.IRecoverySystem; 143 import android.os.ISystemUpdateManager; 144 import android.os.IUserManager; 145 import android.os.IncidentManager; 146 import android.os.PowerManager; 147 import android.os.RecoverySystem; 148 import android.os.RemoteException; 149 import android.os.ServiceManager; 150 import android.os.ServiceManager.ServiceNotFoundException; 151 import android.os.SystemUpdateManager; 152 import android.os.SystemVibrator; 153 import android.os.UserHandle; 154 import android.os.UserManager; 155 import android.os.Vibrator; 156 import android.os.health.SystemHealthManager; 157 import android.os.image.DynamicSystemManager; 158 import android.os.image.IDynamicSystemService; 159 import android.os.storage.StorageManager; 160 import android.permission.PermissionControllerManager; 161 import android.permission.PermissionManager; 162 import android.print.IPrintManager; 163 import android.print.PrintManager; 164 import android.service.oemlock.IOemLockService; 165 import android.service.oemlock.OemLockManager; 166 import android.service.persistentdata.IPersistentDataBlockService; 167 import android.service.persistentdata.PersistentDataBlockManager; 168 import android.service.vr.IVrManager; 169 import android.telecom.TelecomManager; 170 import android.telephony.CarrierConfigManager; 171 import android.telephony.SubscriptionManager; 172 import android.telephony.TelephonyManager; 173 import android.telephony.euicc.EuiccCardManager; 174 import android.telephony.euicc.EuiccManager; 175 import android.telephony.ims.RcsManager; 176 import android.util.ArrayMap; 177 import android.util.Log; 178 import android.view.ContextThemeWrapper; 179 import android.view.LayoutInflater; 180 import android.view.WindowManager; 181 import android.view.WindowManagerImpl; 182 import android.view.accessibility.AccessibilityManager; 183 import android.view.accessibility.CaptioningManager; 184 import android.view.autofill.AutofillManager; 185 import android.view.autofill.IAutoFillManager; 186 import android.view.contentcapture.ContentCaptureManager; 187 import android.view.contentcapture.IContentCaptureManager; 188 import android.view.inputmethod.InputMethodManager; 189 import android.view.textclassifier.TextClassificationManager; 190 import android.view.textservice.TextServicesManager; 191 192 import com.android.internal.app.IAppOpsService; 193 import com.android.internal.app.IBatteryStats; 194 import com.android.internal.app.ISoundTriggerService; 195 import com.android.internal.appwidget.IAppWidgetService; 196 import com.android.internal.net.INetworkWatchlistManager; 197 import com.android.internal.os.IDropBoxManagerService; 198 import com.android.internal.policy.PhoneLayoutInflater; 199 200 import java.util.Map; 201 202 /** 203 * Manages all of the system services that can be returned by {@link Context#getSystemService}. 204 * Used by {@link ContextImpl}. 205 */ 206 final class SystemServiceRegistry { 207 private static final String TAG = "SystemServiceRegistry"; 208 209 // Service registry information. 210 // This information is never changed once static initialization has completed. 211 private static final Map<Class<?>, String> SYSTEM_SERVICE_NAMES = 212 new ArrayMap<Class<?>, String>(); 213 private static final Map<String, ServiceFetcher<?>> SYSTEM_SERVICE_FETCHERS = 214 new ArrayMap<String, ServiceFetcher<?>>(); 215 private static int sServiceCacheSize; 216 217 // Not instantiable. SystemServiceRegistry()218 private SystemServiceRegistry() { } 219 220 static { 221 //CHECKSTYLE:OFF IndentationCheck registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class, new CachedServiceFetcher<AccessibilityManager>() { @Override public AccessibilityManager createService(ContextImpl ctx) { return AccessibilityManager.getInstance(ctx); }})222 registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class, 223 new CachedServiceFetcher<AccessibilityManager>() { 224 @Override 225 public AccessibilityManager createService(ContextImpl ctx) { 226 return AccessibilityManager.getInstance(ctx); 227 }}); 228 registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class, new CachedServiceFetcher<CaptioningManager>() { @Override public CaptioningManager createService(ContextImpl ctx) { return new CaptioningManager(ctx); }})229 registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class, 230 new CachedServiceFetcher<CaptioningManager>() { 231 @Override 232 public CaptioningManager createService(ContextImpl ctx) { 233 return new CaptioningManager(ctx); 234 }}); 235 registerService(Context.ACCOUNT_SERVICE, AccountManager.class, new CachedServiceFetcher<AccountManager>() { @Override public AccountManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.ACCOUNT_SERVICE); IAccountManager service = IAccountManager.Stub.asInterface(b); return new AccountManager(ctx, service); }})236 registerService(Context.ACCOUNT_SERVICE, AccountManager.class, 237 new CachedServiceFetcher<AccountManager>() { 238 @Override 239 public AccountManager createService(ContextImpl ctx) throws ServiceNotFoundException { 240 IBinder b = ServiceManager.getServiceOrThrow(Context.ACCOUNT_SERVICE); 241 IAccountManager service = IAccountManager.Stub.asInterface(b); 242 return new AccountManager(ctx, service); 243 }}); 244 registerService(Context.ACTIVITY_SERVICE, ActivityManager.class, new CachedServiceFetcher<ActivityManager>() { @Override public ActivityManager createService(ContextImpl ctx) { return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); }})245 registerService(Context.ACTIVITY_SERVICE, ActivityManager.class, 246 new CachedServiceFetcher<ActivityManager>() { 247 @Override 248 public ActivityManager createService(ContextImpl ctx) { 249 return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); 250 }}); 251 registerService(Context.ACTIVITY_TASK_SERVICE, ActivityTaskManager.class, new CachedServiceFetcher<ActivityTaskManager>() { @Override public ActivityTaskManager createService(ContextImpl ctx) { return new ActivityTaskManager( ctx.getOuterContext(), ctx.mMainThread.getHandler()); }})252 registerService(Context.ACTIVITY_TASK_SERVICE, ActivityTaskManager.class, 253 new CachedServiceFetcher<ActivityTaskManager>() { 254 @Override 255 public ActivityTaskManager createService(ContextImpl ctx) { 256 return new ActivityTaskManager( 257 ctx.getOuterContext(), ctx.mMainThread.getHandler()); 258 }}); 259 registerService(Context.URI_GRANTS_SERVICE, UriGrantsManager.class, new CachedServiceFetcher<UriGrantsManager>() { @Override public UriGrantsManager createService(ContextImpl ctx) { return new UriGrantsManager( ctx.getOuterContext(), ctx.mMainThread.getHandler()); }})260 registerService(Context.URI_GRANTS_SERVICE, UriGrantsManager.class, 261 new CachedServiceFetcher<UriGrantsManager>() { 262 @Override 263 public UriGrantsManager createService(ContextImpl ctx) { 264 return new UriGrantsManager( 265 ctx.getOuterContext(), ctx.mMainThread.getHandler()); 266 }}); 267 registerService(Context.ALARM_SERVICE, AlarmManager.class, new CachedServiceFetcher<AlarmManager>() { @Override public AlarmManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.ALARM_SERVICE); IAlarmManager service = IAlarmManager.Stub.asInterface(b); return new AlarmManager(service, ctx); }})268 registerService(Context.ALARM_SERVICE, AlarmManager.class, 269 new CachedServiceFetcher<AlarmManager>() { 270 @Override 271 public AlarmManager createService(ContextImpl ctx) throws ServiceNotFoundException { 272 IBinder b = ServiceManager.getServiceOrThrow(Context.ALARM_SERVICE); 273 IAlarmManager service = IAlarmManager.Stub.asInterface(b); 274 return new AlarmManager(service, ctx); 275 }}); 276 registerService(Context.AUDIO_SERVICE, AudioManager.class, new CachedServiceFetcher<AudioManager>() { @Override public AudioManager createService(ContextImpl ctx) { return new AudioManager(ctx); }})277 registerService(Context.AUDIO_SERVICE, AudioManager.class, 278 new CachedServiceFetcher<AudioManager>() { 279 @Override 280 public AudioManager createService(ContextImpl ctx) { 281 return new AudioManager(ctx); 282 }}); 283 registerService(Context.MEDIA_ROUTER_SERVICE, MediaRouter.class, new CachedServiceFetcher<MediaRouter>() { @Override public MediaRouter createService(ContextImpl ctx) { return new MediaRouter(ctx); }})284 registerService(Context.MEDIA_ROUTER_SERVICE, MediaRouter.class, 285 new CachedServiceFetcher<MediaRouter>() { 286 @Override 287 public MediaRouter createService(ContextImpl ctx) { 288 return new MediaRouter(ctx); 289 }}); 290 registerService(Context.BLUETOOTH_SERVICE, BluetoothManager.class, new CachedServiceFetcher<BluetoothManager>() { @Override public BluetoothManager createService(ContextImpl ctx) { return new BluetoothManager(ctx); }})291 registerService(Context.BLUETOOTH_SERVICE, BluetoothManager.class, 292 new CachedServiceFetcher<BluetoothManager>() { 293 @Override 294 public BluetoothManager createService(ContextImpl ctx) { 295 return new BluetoothManager(ctx); 296 }}); 297 registerService(Context.HDMI_CONTROL_SERVICE, HdmiControlManager.class, new StaticServiceFetcher<HdmiControlManager>() { @Override public HdmiControlManager createService() throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.HDMI_CONTROL_SERVICE); return new HdmiControlManager(IHdmiControlService.Stub.asInterface(b)); }})298 registerService(Context.HDMI_CONTROL_SERVICE, HdmiControlManager.class, 299 new StaticServiceFetcher<HdmiControlManager>() { 300 @Override 301 public HdmiControlManager createService() throws ServiceNotFoundException { 302 IBinder b = ServiceManager.getServiceOrThrow(Context.HDMI_CONTROL_SERVICE); 303 return new HdmiControlManager(IHdmiControlService.Stub.asInterface(b)); 304 }}); 305 registerService(Context.TEXT_CLASSIFICATION_SERVICE, TextClassificationManager.class, new CachedServiceFetcher<TextClassificationManager>() { @Override public TextClassificationManager createService(ContextImpl ctx) { return new TextClassificationManager(ctx); }})306 registerService(Context.TEXT_CLASSIFICATION_SERVICE, TextClassificationManager.class, 307 new CachedServiceFetcher<TextClassificationManager>() { 308 @Override 309 public TextClassificationManager createService(ContextImpl ctx) { 310 return new TextClassificationManager(ctx); 311 }}); 312 registerService(Context.CLIPBOARD_SERVICE, ClipboardManager.class, new CachedServiceFetcher<ClipboardManager>() { @Override public ClipboardManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new ClipboardManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); }})313 registerService(Context.CLIPBOARD_SERVICE, ClipboardManager.class, 314 new CachedServiceFetcher<ClipboardManager>() { 315 @Override 316 public ClipboardManager createService(ContextImpl ctx) throws ServiceNotFoundException { 317 return new ClipboardManager(ctx.getOuterContext(), 318 ctx.mMainThread.getHandler()); 319 }}); 320 321 // The clipboard service moved to a new package. If someone asks for the old 322 // interface by class then we want to redirect over to the new interface instead 323 // (which extends it). SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE)324 SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE); 325 registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class, new StaticApplicationContextServiceFetcher<ConnectivityManager>() { @Override public ConnectivityManager createService(Context context) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE); IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); return new ConnectivityManager(context, service); }})326 registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class, 327 new StaticApplicationContextServiceFetcher<ConnectivityManager>() { 328 @Override 329 public ConnectivityManager createService(Context context) throws ServiceNotFoundException { 330 IBinder b = ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE); 331 IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); 332 return new ConnectivityManager(context, service); 333 }}); 334 registerService(Context.NETD_SERVICE, IBinder.class, new StaticServiceFetcher<IBinder>() { @Override public IBinder createService() throws ServiceNotFoundException { return ServiceManager.getServiceOrThrow(Context.NETD_SERVICE); } })335 registerService(Context.NETD_SERVICE, IBinder.class, new StaticServiceFetcher<IBinder>() { 336 @Override 337 public IBinder createService() throws ServiceNotFoundException { 338 return ServiceManager.getServiceOrThrow(Context.NETD_SERVICE); 339 } 340 }); 341 registerService(Context.IPSEC_SERVICE, IpSecManager.class, new CachedServiceFetcher<IpSecManager>() { @Override public IpSecManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getService(Context.IPSEC_SERVICE); IIpSecService service = IIpSecService.Stub.asInterface(b); return new IpSecManager(ctx, service); }})342 registerService(Context.IPSEC_SERVICE, IpSecManager.class, 343 new CachedServiceFetcher<IpSecManager>() { 344 @Override 345 public IpSecManager createService(ContextImpl ctx) throws ServiceNotFoundException { 346 IBinder b = ServiceManager.getService(Context.IPSEC_SERVICE); 347 IIpSecService service = IIpSecService.Stub.asInterface(b); 348 return new IpSecManager(ctx, service); 349 }}); 350 registerService( Context.TEST_NETWORK_SERVICE, TestNetworkManager.class, new StaticApplicationContextServiceFetcher<TestNetworkManager>() { @Override public TestNetworkManager createService(Context context) throws ServiceNotFoundException { IBinder csBinder = ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE); IConnectivityManager csMgr = IConnectivityManager.Stub.asInterface(csBinder); final IBinder tnBinder; try { tnBinder = csMgr.startOrGetTestNetworkService(); } catch (RemoteException e) { throw new ServiceNotFoundException(Context.TEST_NETWORK_SERVICE); } ITestNetworkManager tnMgr = ITestNetworkManager.Stub.asInterface(tnBinder); return new TestNetworkManager(tnMgr); } })351 registerService( 352 Context.TEST_NETWORK_SERVICE, 353 TestNetworkManager.class, 354 new StaticApplicationContextServiceFetcher<TestNetworkManager>() { 355 @Override 356 public TestNetworkManager createService(Context context) 357 throws ServiceNotFoundException { 358 IBinder csBinder = 359 ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE); 360 IConnectivityManager csMgr = 361 IConnectivityManager.Stub.asInterface(csBinder); 362 363 final IBinder tnBinder; 364 try { 365 tnBinder = csMgr.startOrGetTestNetworkService(); 366 } catch (RemoteException e) { 367 throw new ServiceNotFoundException(Context.TEST_NETWORK_SERVICE); 368 } 369 ITestNetworkManager tnMgr = ITestNetworkManager.Stub.asInterface(tnBinder); 370 return new TestNetworkManager(tnMgr); 371 } 372 }); 373 registerService(Context.COUNTRY_DETECTOR, CountryDetector.class, new StaticServiceFetcher<CountryDetector>() { @Override public CountryDetector createService() throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.COUNTRY_DETECTOR); return new CountryDetector(ICountryDetector.Stub.asInterface(b)); }})374 registerService(Context.COUNTRY_DETECTOR, CountryDetector.class, 375 new StaticServiceFetcher<CountryDetector>() { 376 @Override 377 public CountryDetector createService() throws ServiceNotFoundException { 378 IBinder b = ServiceManager.getServiceOrThrow(Context.COUNTRY_DETECTOR); 379 return new CountryDetector(ICountryDetector.Stub.asInterface(b)); 380 }}); 381 registerService(Context.DEVICE_POLICY_SERVICE, DevicePolicyManager.class, new CachedServiceFetcher<DevicePolicyManager>() { @Override public DevicePolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.DEVICE_POLICY_SERVICE); return new DevicePolicyManager(ctx, IDevicePolicyManager.Stub.asInterface(b)); }})382 registerService(Context.DEVICE_POLICY_SERVICE, DevicePolicyManager.class, 383 new CachedServiceFetcher<DevicePolicyManager>() { 384 @Override 385 public DevicePolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { 386 IBinder b = ServiceManager.getServiceOrThrow(Context.DEVICE_POLICY_SERVICE); 387 return new DevicePolicyManager(ctx, IDevicePolicyManager.Stub.asInterface(b)); 388 }}); 389 registerService(Context.DOWNLOAD_SERVICE, DownloadManager.class, new CachedServiceFetcher<DownloadManager>() { @Override public DownloadManager createService(ContextImpl ctx) { return new DownloadManager(ctx); }})390 registerService(Context.DOWNLOAD_SERVICE, DownloadManager.class, 391 new CachedServiceFetcher<DownloadManager>() { 392 @Override 393 public DownloadManager createService(ContextImpl ctx) { 394 return new DownloadManager(ctx); 395 }}); 396 registerService(Context.BATTERY_SERVICE, BatteryManager.class, new CachedServiceFetcher<BatteryManager>() { @Override public BatteryManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBatteryStats stats = IBatteryStats.Stub.asInterface( ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME)); IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub .asInterface(ServiceManager.getServiceOrThrow("batteryproperties")); return new BatteryManager(ctx, stats, registrar); }})397 registerService(Context.BATTERY_SERVICE, BatteryManager.class, 398 new CachedServiceFetcher<BatteryManager>() { 399 @Override 400 public BatteryManager createService(ContextImpl ctx) throws ServiceNotFoundException { 401 IBatteryStats stats = IBatteryStats.Stub.asInterface( 402 ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME)); 403 IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub 404 .asInterface(ServiceManager.getServiceOrThrow("batteryproperties")); 405 return new BatteryManager(ctx, stats, registrar); 406 }}); 407 registerService(Context.NFC_SERVICE, NfcManager.class, new CachedServiceFetcher<NfcManager>() { @Override public NfcManager createService(ContextImpl ctx) { return new NfcManager(ctx); }})408 registerService(Context.NFC_SERVICE, NfcManager.class, 409 new CachedServiceFetcher<NfcManager>() { 410 @Override 411 public NfcManager createService(ContextImpl ctx) { 412 return new NfcManager(ctx); 413 }}); 414 registerService(Context.DROPBOX_SERVICE, DropBoxManager.class, new CachedServiceFetcher<DropBoxManager>() { @Override public DropBoxManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.DROPBOX_SERVICE); IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b); return new DropBoxManager(ctx, service); }})415 registerService(Context.DROPBOX_SERVICE, DropBoxManager.class, 416 new CachedServiceFetcher<DropBoxManager>() { 417 @Override 418 public DropBoxManager createService(ContextImpl ctx) throws ServiceNotFoundException { 419 IBinder b = ServiceManager.getServiceOrThrow(Context.DROPBOX_SERVICE); 420 IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b); 421 return new DropBoxManager(ctx, service); 422 }}); 423 registerService(Context.INPUT_SERVICE, InputManager.class, new StaticServiceFetcher<InputManager>() { @Override public InputManager createService() { return InputManager.getInstance(); }})424 registerService(Context.INPUT_SERVICE, InputManager.class, 425 new StaticServiceFetcher<InputManager>() { 426 @Override 427 public InputManager createService() { 428 return InputManager.getInstance(); 429 }}); 430 registerService(Context.DISPLAY_SERVICE, DisplayManager.class, new CachedServiceFetcher<DisplayManager>() { @Override public DisplayManager createService(ContextImpl ctx) { return new DisplayManager(ctx.getOuterContext()); }})431 registerService(Context.DISPLAY_SERVICE, DisplayManager.class, 432 new CachedServiceFetcher<DisplayManager>() { 433 @Override 434 public DisplayManager createService(ContextImpl ctx) { 435 return new DisplayManager(ctx.getOuterContext()); 436 }}); 437 registerService(Context.COLOR_DISPLAY_SERVICE, ColorDisplayManager.class, new CachedServiceFetcher<ColorDisplayManager>() { @Override public ColorDisplayManager createService(ContextImpl ctx) { return new ColorDisplayManager(); } })438 registerService(Context.COLOR_DISPLAY_SERVICE, ColorDisplayManager.class, 439 new CachedServiceFetcher<ColorDisplayManager>() { 440 @Override 441 public ColorDisplayManager createService(ContextImpl ctx) { 442 return new ColorDisplayManager(); 443 } 444 }); 445 446 // InputMethodManager has its own cache strategy based on display id to support apps that 447 // still assume InputMethodManager is a per-process singleton and it's safe to directly 448 // access internal fields via reflection. Hence directly use ServiceFetcher instead of 449 // StaticServiceFetcher/CachedServiceFetcher. registerService(Context.INPUT_METHOD_SERVICE, InputMethodManager.class, new ServiceFetcher<InputMethodManager>() { @Override public InputMethodManager getService(ContextImpl ctx) { return InputMethodManager.forContext(ctx.getOuterContext()); }})450 registerService(Context.INPUT_METHOD_SERVICE, InputMethodManager.class, 451 new ServiceFetcher<InputMethodManager>() { 452 @Override 453 public InputMethodManager getService(ContextImpl ctx) { 454 return InputMethodManager.forContext(ctx.getOuterContext()); 455 }}); 456 registerService(Context.TEXT_SERVICES_MANAGER_SERVICE, TextServicesManager.class, new CachedServiceFetcher<TextServicesManager>() { @Override public TextServicesManager createService(ContextImpl ctx) throws ServiceNotFoundException { return TextServicesManager.createInstance(ctx); }})457 registerService(Context.TEXT_SERVICES_MANAGER_SERVICE, TextServicesManager.class, 458 new CachedServiceFetcher<TextServicesManager>() { 459 @Override 460 public TextServicesManager createService(ContextImpl ctx) 461 throws ServiceNotFoundException { 462 return TextServicesManager.createInstance(ctx); 463 }}); 464 registerService(Context.KEYGUARD_SERVICE, KeyguardManager.class, new CachedServiceFetcher<KeyguardManager>() { @Override public KeyguardManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new KeyguardManager(ctx); }})465 registerService(Context.KEYGUARD_SERVICE, KeyguardManager.class, 466 new CachedServiceFetcher<KeyguardManager>() { 467 @Override 468 public KeyguardManager createService(ContextImpl ctx) throws ServiceNotFoundException { 469 return new KeyguardManager(ctx); 470 }}); 471 registerService(Context.LAYOUT_INFLATER_SERVICE, LayoutInflater.class, new CachedServiceFetcher<LayoutInflater>() { @Override public LayoutInflater createService(ContextImpl ctx) { return new PhoneLayoutInflater(ctx.getOuterContext()); }})472 registerService(Context.LAYOUT_INFLATER_SERVICE, LayoutInflater.class, 473 new CachedServiceFetcher<LayoutInflater>() { 474 @Override 475 public LayoutInflater createService(ContextImpl ctx) { 476 return new PhoneLayoutInflater(ctx.getOuterContext()); 477 }}); 478 registerService(Context.LOCATION_SERVICE, LocationManager.class, new CachedServiceFetcher<LocationManager>() { @Override public LocationManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.LOCATION_SERVICE); return new LocationManager(ctx, ILocationManager.Stub.asInterface(b)); }})479 registerService(Context.LOCATION_SERVICE, LocationManager.class, 480 new CachedServiceFetcher<LocationManager>() { 481 @Override 482 public LocationManager createService(ContextImpl ctx) throws ServiceNotFoundException { 483 IBinder b = ServiceManager.getServiceOrThrow(Context.LOCATION_SERVICE); 484 return new LocationManager(ctx, ILocationManager.Stub.asInterface(b)); 485 }}); 486 registerService(Context.NETWORK_POLICY_SERVICE, NetworkPolicyManager.class, new CachedServiceFetcher<NetworkPolicyManager>() { @Override public NetworkPolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new NetworkPolicyManager(ctx, INetworkPolicyManager.Stub.asInterface( ServiceManager.getServiceOrThrow(Context.NETWORK_POLICY_SERVICE))); }})487 registerService(Context.NETWORK_POLICY_SERVICE, NetworkPolicyManager.class, 488 new CachedServiceFetcher<NetworkPolicyManager>() { 489 @Override 490 public NetworkPolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { 491 return new NetworkPolicyManager(ctx, INetworkPolicyManager.Stub.asInterface( 492 ServiceManager.getServiceOrThrow(Context.NETWORK_POLICY_SERVICE))); 493 }}); 494 registerService(Context.NOTIFICATION_SERVICE, NotificationManager.class, new CachedServiceFetcher<NotificationManager>() { @Override public NotificationManager createService(ContextImpl ctx) { final Context outerContext = ctx.getOuterContext(); return new NotificationManager( new ContextThemeWrapper(outerContext, Resources.selectSystemTheme(0, outerContext.getApplicationInfo().targetSdkVersion, com.android.internal.R.style.Theme_Dialog, com.android.internal.R.style.Theme_Holo_Dialog, com.android.internal.R.style.Theme_DeviceDefault_Dialog, com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog)), ctx.mMainThread.getHandler()); }})495 registerService(Context.NOTIFICATION_SERVICE, NotificationManager.class, 496 new CachedServiceFetcher<NotificationManager>() { 497 @Override 498 public NotificationManager createService(ContextImpl ctx) { 499 final Context outerContext = ctx.getOuterContext(); 500 return new NotificationManager( 501 new ContextThemeWrapper(outerContext, 502 Resources.selectSystemTheme(0, 503 outerContext.getApplicationInfo().targetSdkVersion, 504 com.android.internal.R.style.Theme_Dialog, 505 com.android.internal.R.style.Theme_Holo_Dialog, 506 com.android.internal.R.style.Theme_DeviceDefault_Dialog, 507 com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog)), 508 ctx.mMainThread.getHandler()); 509 }}); 510 registerService(Context.NSD_SERVICE, NsdManager.class, new CachedServiceFetcher<NsdManager>() { @Override public NsdManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.NSD_SERVICE); INsdManager service = INsdManager.Stub.asInterface(b); return new NsdManager(ctx.getOuterContext(), service); }})511 registerService(Context.NSD_SERVICE, NsdManager.class, 512 new CachedServiceFetcher<NsdManager>() { 513 @Override 514 public NsdManager createService(ContextImpl ctx) throws ServiceNotFoundException { 515 IBinder b = ServiceManager.getServiceOrThrow(Context.NSD_SERVICE); 516 INsdManager service = INsdManager.Stub.asInterface(b); 517 return new NsdManager(ctx.getOuterContext(), service); 518 }}); 519 registerService(Context.POWER_SERVICE, PowerManager.class, new CachedServiceFetcher<PowerManager>() { @Override public PowerManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.POWER_SERVICE); IPowerManager service = IPowerManager.Stub.asInterface(b); return new PowerManager(ctx.getOuterContext(), service, ctx.mMainThread.getHandler()); }})520 registerService(Context.POWER_SERVICE, PowerManager.class, 521 new CachedServiceFetcher<PowerManager>() { 522 @Override 523 public PowerManager createService(ContextImpl ctx) throws ServiceNotFoundException { 524 IBinder b = ServiceManager.getServiceOrThrow(Context.POWER_SERVICE); 525 IPowerManager service = IPowerManager.Stub.asInterface(b); 526 return new PowerManager(ctx.getOuterContext(), 527 service, ctx.mMainThread.getHandler()); 528 }}); 529 registerService(Context.RECOVERY_SERVICE, RecoverySystem.class, new CachedServiceFetcher<RecoverySystem>() { @Override public RecoverySystem createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.RECOVERY_SERVICE); IRecoverySystem service = IRecoverySystem.Stub.asInterface(b); return new RecoverySystem(service); }})530 registerService(Context.RECOVERY_SERVICE, RecoverySystem.class, 531 new CachedServiceFetcher<RecoverySystem>() { 532 @Override 533 public RecoverySystem createService(ContextImpl ctx) throws ServiceNotFoundException { 534 IBinder b = ServiceManager.getServiceOrThrow(Context.RECOVERY_SERVICE); 535 IRecoverySystem service = IRecoverySystem.Stub.asInterface(b); 536 return new RecoverySystem(service); 537 }}); 538 registerService(Context.SEARCH_SERVICE, SearchManager.class, new CachedServiceFetcher<SearchManager>() { @Override public SearchManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new SearchManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); }})539 registerService(Context.SEARCH_SERVICE, SearchManager.class, 540 new CachedServiceFetcher<SearchManager>() { 541 @Override 542 public SearchManager createService(ContextImpl ctx) throws ServiceNotFoundException { 543 return new SearchManager(ctx.getOuterContext(), 544 ctx.mMainThread.getHandler()); 545 }}); 546 registerService(Context.SENSOR_SERVICE, SensorManager.class, new CachedServiceFetcher<SensorManager>() { @Override public SensorManager createService(ContextImpl ctx) { return new SystemSensorManager(ctx.getOuterContext(), ctx.mMainThread.getHandler().getLooper()); }})547 registerService(Context.SENSOR_SERVICE, SensorManager.class, 548 new CachedServiceFetcher<SensorManager>() { 549 @Override 550 public SensorManager createService(ContextImpl ctx) { 551 return new SystemSensorManager(ctx.getOuterContext(), 552 ctx.mMainThread.getHandler().getLooper()); 553 }}); 554 registerService(Context.SENSOR_PRIVACY_SERVICE, SensorPrivacyManager.class, new CachedServiceFetcher<SensorPrivacyManager>() { @Override public SensorPrivacyManager createService(ContextImpl ctx) { return SensorPrivacyManager.getInstance(ctx); }})555 registerService(Context.SENSOR_PRIVACY_SERVICE, SensorPrivacyManager.class, 556 new CachedServiceFetcher<SensorPrivacyManager>() { 557 @Override 558 public SensorPrivacyManager createService(ContextImpl ctx) { 559 return SensorPrivacyManager.getInstance(ctx); 560 }}); 561 registerService(Context.STATS_MANAGER, StatsManager.class, new CachedServiceFetcher<StatsManager>() { @Override public StatsManager createService(ContextImpl ctx) { return new StatsManager(ctx.getOuterContext()); }})562 registerService(Context.STATS_MANAGER, StatsManager.class, 563 new CachedServiceFetcher<StatsManager>() { 564 @Override 565 public StatsManager createService(ContextImpl ctx) { 566 return new StatsManager(ctx.getOuterContext()); 567 }}); 568 registerService(Context.STATUS_BAR_SERVICE, StatusBarManager.class, new CachedServiceFetcher<StatusBarManager>() { @Override public StatusBarManager createService(ContextImpl ctx) { return new StatusBarManager(ctx.getOuterContext()); }})569 registerService(Context.STATUS_BAR_SERVICE, StatusBarManager.class, 570 new CachedServiceFetcher<StatusBarManager>() { 571 @Override 572 public StatusBarManager createService(ContextImpl ctx) { 573 return new StatusBarManager(ctx.getOuterContext()); 574 }}); 575 registerService(Context.STORAGE_SERVICE, StorageManager.class, new CachedServiceFetcher<StorageManager>() { @Override public StorageManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new StorageManager(ctx, ctx.mMainThread.getHandler().getLooper()); }})576 registerService(Context.STORAGE_SERVICE, StorageManager.class, 577 new CachedServiceFetcher<StorageManager>() { 578 @Override 579 public StorageManager createService(ContextImpl ctx) throws ServiceNotFoundException { 580 return new StorageManager(ctx, ctx.mMainThread.getHandler().getLooper()); 581 }}); 582 registerService(Context.STORAGE_STATS_SERVICE, StorageStatsManager.class, new CachedServiceFetcher<StorageStatsManager>() { @Override public StorageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { IStorageStatsManager service = IStorageStatsManager.Stub.asInterface( ServiceManager.getServiceOrThrow(Context.STORAGE_STATS_SERVICE)); return new StorageStatsManager(ctx, service); }})583 registerService(Context.STORAGE_STATS_SERVICE, StorageStatsManager.class, 584 new CachedServiceFetcher<StorageStatsManager>() { 585 @Override 586 public StorageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { 587 IStorageStatsManager service = IStorageStatsManager.Stub.asInterface( 588 ServiceManager.getServiceOrThrow(Context.STORAGE_STATS_SERVICE)); 589 return new StorageStatsManager(ctx, service); 590 }}); 591 registerService(Context.SYSTEM_UPDATE_SERVICE, SystemUpdateManager.class, new CachedServiceFetcher<SystemUpdateManager>() { @Override public SystemUpdateManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow( Context.SYSTEM_UPDATE_SERVICE); ISystemUpdateManager service = ISystemUpdateManager.Stub.asInterface(b); return new SystemUpdateManager(service); }})592 registerService(Context.SYSTEM_UPDATE_SERVICE, SystemUpdateManager.class, 593 new CachedServiceFetcher<SystemUpdateManager>() { 594 @Override 595 public SystemUpdateManager createService(ContextImpl ctx) 596 throws ServiceNotFoundException { 597 IBinder b = ServiceManager.getServiceOrThrow( 598 Context.SYSTEM_UPDATE_SERVICE); 599 ISystemUpdateManager service = ISystemUpdateManager.Stub.asInterface(b); 600 return new SystemUpdateManager(service); 601 }}); 602 registerService(Context.TELEPHONY_SERVICE, TelephonyManager.class, new CachedServiceFetcher<TelephonyManager>() { @Override public TelephonyManager createService(ContextImpl ctx) { return new TelephonyManager(ctx.getOuterContext()); }})603 registerService(Context.TELEPHONY_SERVICE, TelephonyManager.class, 604 new CachedServiceFetcher<TelephonyManager>() { 605 @Override 606 public TelephonyManager createService(ContextImpl ctx) { 607 return new TelephonyManager(ctx.getOuterContext()); 608 }}); 609 registerService(Context.TELEPHONY_SUBSCRIPTION_SERVICE, SubscriptionManager.class, new CachedServiceFetcher<SubscriptionManager>() { @Override public SubscriptionManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new SubscriptionManager(ctx.getOuterContext()); }})610 registerService(Context.TELEPHONY_SUBSCRIPTION_SERVICE, SubscriptionManager.class, 611 new CachedServiceFetcher<SubscriptionManager>() { 612 @Override 613 public SubscriptionManager createService(ContextImpl ctx) throws ServiceNotFoundException { 614 return new SubscriptionManager(ctx.getOuterContext()); 615 }}); 616 registerService(Context.TELEPHONY_RCS_SERVICE, RcsManager.class, new CachedServiceFetcher<RcsManager>() { @Override public RcsManager createService(ContextImpl ctx) { return new RcsManager(ctx.getOuterContext()); } })617 registerService(Context.TELEPHONY_RCS_SERVICE, RcsManager.class, 618 new CachedServiceFetcher<RcsManager>() { 619 @Override 620 public RcsManager createService(ContextImpl ctx) { 621 return new RcsManager(ctx.getOuterContext()); 622 } 623 }); 624 registerService(Context.CARRIER_CONFIG_SERVICE, CarrierConfigManager.class, new CachedServiceFetcher<CarrierConfigManager>() { @Override public CarrierConfigManager createService(ContextImpl ctx) { return new CarrierConfigManager(ctx.getOuterContext()); }})625 registerService(Context.CARRIER_CONFIG_SERVICE, CarrierConfigManager.class, 626 new CachedServiceFetcher<CarrierConfigManager>() { 627 @Override 628 public CarrierConfigManager createService(ContextImpl ctx) { 629 return new CarrierConfigManager(ctx.getOuterContext()); 630 }}); 631 registerService(Context.TELECOM_SERVICE, TelecomManager.class, new CachedServiceFetcher<TelecomManager>() { @Override public TelecomManager createService(ContextImpl ctx) { return new TelecomManager(ctx.getOuterContext()); }})632 registerService(Context.TELECOM_SERVICE, TelecomManager.class, 633 new CachedServiceFetcher<TelecomManager>() { 634 @Override 635 public TelecomManager createService(ContextImpl ctx) { 636 return new TelecomManager(ctx.getOuterContext()); 637 }}); 638 registerService(Context.EUICC_SERVICE, EuiccManager.class, new CachedServiceFetcher<EuiccManager>() { @Override public EuiccManager createService(ContextImpl ctx) { return new EuiccManager(ctx.getOuterContext()); }})639 registerService(Context.EUICC_SERVICE, EuiccManager.class, 640 new CachedServiceFetcher<EuiccManager>() { 641 @Override 642 public EuiccManager createService(ContextImpl ctx) { 643 return new EuiccManager(ctx.getOuterContext()); 644 }}); 645 registerService(Context.EUICC_CARD_SERVICE, EuiccCardManager.class, new CachedServiceFetcher<EuiccCardManager>() { @Override public EuiccCardManager createService(ContextImpl ctx) { return new EuiccCardManager(ctx.getOuterContext()); }})646 registerService(Context.EUICC_CARD_SERVICE, EuiccCardManager.class, 647 new CachedServiceFetcher<EuiccCardManager>() { 648 @Override 649 public EuiccCardManager createService(ContextImpl ctx) { 650 return new EuiccCardManager(ctx.getOuterContext()); 651 }}); 652 registerService(Context.UI_MODE_SERVICE, UiModeManager.class, new CachedServiceFetcher<UiModeManager>() { @Override public UiModeManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new UiModeManager(); }})653 registerService(Context.UI_MODE_SERVICE, UiModeManager.class, 654 new CachedServiceFetcher<UiModeManager>() { 655 @Override 656 public UiModeManager createService(ContextImpl ctx) throws ServiceNotFoundException { 657 return new UiModeManager(); 658 }}); 659 registerService(Context.USB_SERVICE, UsbManager.class, new CachedServiceFetcher<UsbManager>() { @Override public UsbManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.USB_SERVICE); return new UsbManager(ctx, IUsbManager.Stub.asInterface(b)); }})660 registerService(Context.USB_SERVICE, UsbManager.class, 661 new CachedServiceFetcher<UsbManager>() { 662 @Override 663 public UsbManager createService(ContextImpl ctx) throws ServiceNotFoundException { 664 IBinder b = ServiceManager.getServiceOrThrow(Context.USB_SERVICE); 665 return new UsbManager(ctx, IUsbManager.Stub.asInterface(b)); 666 }}); 667 registerService(Context.ADB_SERVICE, AdbManager.class, new CachedServiceFetcher<AdbManager>() { @Override public AdbManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.ADB_SERVICE); return new AdbManager(ctx, IAdbManager.Stub.asInterface(b)); }})668 registerService(Context.ADB_SERVICE, AdbManager.class, 669 new CachedServiceFetcher<AdbManager>() { 670 @Override 671 public AdbManager createService(ContextImpl ctx) 672 throws ServiceNotFoundException { 673 IBinder b = ServiceManager.getServiceOrThrow(Context.ADB_SERVICE); 674 return new AdbManager(ctx, IAdbManager.Stub.asInterface(b)); 675 }}); 676 registerService(Context.SERIAL_SERVICE, SerialManager.class, new CachedServiceFetcher<SerialManager>() { @Override public SerialManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.SERIAL_SERVICE); return new SerialManager(ctx, ISerialManager.Stub.asInterface(b)); }})677 registerService(Context.SERIAL_SERVICE, SerialManager.class, 678 new CachedServiceFetcher<SerialManager>() { 679 @Override 680 public SerialManager createService(ContextImpl ctx) throws ServiceNotFoundException { 681 IBinder b = ServiceManager.getServiceOrThrow(Context.SERIAL_SERVICE); 682 return new SerialManager(ctx, ISerialManager.Stub.asInterface(b)); 683 }}); 684 registerService(Context.VIBRATOR_SERVICE, Vibrator.class, new CachedServiceFetcher<Vibrator>() { @Override public Vibrator createService(ContextImpl ctx) { return new SystemVibrator(ctx); }})685 registerService(Context.VIBRATOR_SERVICE, Vibrator.class, 686 new CachedServiceFetcher<Vibrator>() { 687 @Override 688 public Vibrator createService(ContextImpl ctx) { 689 return new SystemVibrator(ctx); 690 }}); 691 registerService(Context.WALLPAPER_SERVICE, WallpaperManager.class, new CachedServiceFetcher<WallpaperManager>() { @Override public WallpaperManager createService(ContextImpl ctx) throws ServiceNotFoundException { final IBinder b; if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) { b = ServiceManager.getServiceOrThrow(Context.WALLPAPER_SERVICE); } else { b = ServiceManager.getService(Context.WALLPAPER_SERVICE); } IWallpaperManager service = IWallpaperManager.Stub.asInterface(b); return new WallpaperManager(service, ctx.getOuterContext(), ctx.mMainThread.getHandler()); }})692 registerService(Context.WALLPAPER_SERVICE, WallpaperManager.class, 693 new CachedServiceFetcher<WallpaperManager>() { 694 @Override 695 public WallpaperManager createService(ContextImpl ctx) 696 throws ServiceNotFoundException { 697 final IBinder b; 698 if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) { 699 b = ServiceManager.getServiceOrThrow(Context.WALLPAPER_SERVICE); 700 } else { 701 b = ServiceManager.getService(Context.WALLPAPER_SERVICE); 702 } 703 IWallpaperManager service = IWallpaperManager.Stub.asInterface(b); 704 return new WallpaperManager(service, ctx.getOuterContext(), 705 ctx.mMainThread.getHandler()); 706 }}); 707 registerService(Context.LOWPAN_SERVICE, LowpanManager.class, new CachedServiceFetcher<LowpanManager>() { @Override public LowpanManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.LOWPAN_SERVICE); ILowpanManager service = ILowpanManager.Stub.asInterface(b); return new LowpanManager(ctx.getOuterContext(), service, ConnectivityThread.getInstanceLooper()); }})708 registerService(Context.LOWPAN_SERVICE, LowpanManager.class, 709 new CachedServiceFetcher<LowpanManager>() { 710 @Override 711 public LowpanManager createService(ContextImpl ctx) throws ServiceNotFoundException { 712 IBinder b = ServiceManager.getServiceOrThrow(Context.LOWPAN_SERVICE); 713 ILowpanManager service = ILowpanManager.Stub.asInterface(b); 714 return new LowpanManager(ctx.getOuterContext(), service, 715 ConnectivityThread.getInstanceLooper()); 716 }}); 717 registerService(Context.WIFI_SERVICE, WifiManager.class, new CachedServiceFetcher<WifiManager>() { @Override public WifiManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SERVICE); IWifiManager service = IWifiManager.Stub.asInterface(b); return new WifiManager(ctx.getOuterContext(), service, ConnectivityThread.getInstanceLooper()); }})718 registerService(Context.WIFI_SERVICE, WifiManager.class, 719 new CachedServiceFetcher<WifiManager>() { 720 @Override 721 public WifiManager createService(ContextImpl ctx) throws ServiceNotFoundException { 722 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SERVICE); 723 IWifiManager service = IWifiManager.Stub.asInterface(b); 724 return new WifiManager(ctx.getOuterContext(), service, 725 ConnectivityThread.getInstanceLooper()); 726 }}); 727 registerService(Context.WIFI_P2P_SERVICE, WifiP2pManager.class, new StaticServiceFetcher<WifiP2pManager>() { @Override public WifiP2pManager createService() throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_P2P_SERVICE); IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b); return new WifiP2pManager(service); }})728 registerService(Context.WIFI_P2P_SERVICE, WifiP2pManager.class, 729 new StaticServiceFetcher<WifiP2pManager>() { 730 @Override 731 public WifiP2pManager createService() throws ServiceNotFoundException { 732 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_P2P_SERVICE); 733 IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b); 734 return new WifiP2pManager(service); 735 }}); 736 registerService(Context.WIFI_AWARE_SERVICE, WifiAwareManager.class, new CachedServiceFetcher<WifiAwareManager>() { @Override public WifiAwareManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_AWARE_SERVICE); IWifiAwareManager service = IWifiAwareManager.Stub.asInterface(b); if (service == null) { return null; } return new WifiAwareManager(ctx.getOuterContext(), service); }})737 registerService(Context.WIFI_AWARE_SERVICE, WifiAwareManager.class, 738 new CachedServiceFetcher<WifiAwareManager>() { 739 @Override 740 public WifiAwareManager createService(ContextImpl ctx) throws ServiceNotFoundException { 741 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_AWARE_SERVICE); 742 IWifiAwareManager service = IWifiAwareManager.Stub.asInterface(b); 743 if (service == null) { 744 return null; 745 } 746 return new WifiAwareManager(ctx.getOuterContext(), service); 747 }}); 748 registerService(Context.WIFI_SCANNING_SERVICE, WifiScanner.class, new CachedServiceFetcher<WifiScanner>() { @Override public WifiScanner createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SCANNING_SERVICE); IWifiScanner service = IWifiScanner.Stub.asInterface(b); return new WifiScanner(ctx.getOuterContext(), service, ConnectivityThread.getInstanceLooper()); }})749 registerService(Context.WIFI_SCANNING_SERVICE, WifiScanner.class, 750 new CachedServiceFetcher<WifiScanner>() { 751 @Override 752 public WifiScanner createService(ContextImpl ctx) throws ServiceNotFoundException { 753 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SCANNING_SERVICE); 754 IWifiScanner service = IWifiScanner.Stub.asInterface(b); 755 return new WifiScanner(ctx.getOuterContext(), service, 756 ConnectivityThread.getInstanceLooper()); 757 }}); 758 registerService(Context.WIFI_RTT_SERVICE, RttManager.class, new CachedServiceFetcher<RttManager>() { @Override public RttManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_RTT_RANGING_SERVICE); IWifiRttManager service = IWifiRttManager.Stub.asInterface(b); return new RttManager(ctx.getOuterContext(), new WifiRttManager(ctx.getOuterContext(), service)); }})759 registerService(Context.WIFI_RTT_SERVICE, RttManager.class, 760 new CachedServiceFetcher<RttManager>() { 761 @Override 762 public RttManager createService(ContextImpl ctx) throws ServiceNotFoundException { 763 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_RTT_RANGING_SERVICE); 764 IWifiRttManager service = IWifiRttManager.Stub.asInterface(b); 765 return new RttManager(ctx.getOuterContext(), 766 new WifiRttManager(ctx.getOuterContext(), service)); 767 }}); 768 registerService(Context.WIFI_RTT_RANGING_SERVICE, WifiRttManager.class, new CachedServiceFetcher<WifiRttManager>() { @Override public WifiRttManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow( Context.WIFI_RTT_RANGING_SERVICE); IWifiRttManager service = IWifiRttManager.Stub.asInterface(b); return new WifiRttManager(ctx.getOuterContext(), service); }})769 registerService(Context.WIFI_RTT_RANGING_SERVICE, WifiRttManager.class, 770 new CachedServiceFetcher<WifiRttManager>() { 771 @Override 772 public WifiRttManager createService(ContextImpl ctx) 773 throws ServiceNotFoundException { 774 IBinder b = ServiceManager.getServiceOrThrow( 775 Context.WIFI_RTT_RANGING_SERVICE); 776 IWifiRttManager service = IWifiRttManager.Stub.asInterface(b); 777 return new WifiRttManager(ctx.getOuterContext(), service); 778 }}); 779 registerService(Context.ETHERNET_SERVICE, EthernetManager.class, new CachedServiceFetcher<EthernetManager>() { @Override public EthernetManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.ETHERNET_SERVICE); IEthernetManager service = IEthernetManager.Stub.asInterface(b); return new EthernetManager(ctx.getOuterContext(), service); }})780 registerService(Context.ETHERNET_SERVICE, EthernetManager.class, 781 new CachedServiceFetcher<EthernetManager>() { 782 @Override 783 public EthernetManager createService(ContextImpl ctx) throws ServiceNotFoundException { 784 IBinder b = ServiceManager.getServiceOrThrow(Context.ETHERNET_SERVICE); 785 IEthernetManager service = IEthernetManager.Stub.asInterface(b); 786 return new EthernetManager(ctx.getOuterContext(), service); 787 }}); 788 registerService(Context.WINDOW_SERVICE, WindowManager.class, new CachedServiceFetcher<WindowManager>() { @Override public WindowManager createService(ContextImpl ctx) { return new WindowManagerImpl(ctx); }})789 registerService(Context.WINDOW_SERVICE, WindowManager.class, 790 new CachedServiceFetcher<WindowManager>() { 791 @Override 792 public WindowManager createService(ContextImpl ctx) { 793 return new WindowManagerImpl(ctx); 794 }}); 795 registerService(Context.USER_SERVICE, UserManager.class, new CachedServiceFetcher<UserManager>() { @Override public UserManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.USER_SERVICE); IUserManager service = IUserManager.Stub.asInterface(b); return new UserManager(ctx, service); }})796 registerService(Context.USER_SERVICE, UserManager.class, 797 new CachedServiceFetcher<UserManager>() { 798 @Override 799 public UserManager createService(ContextImpl ctx) throws ServiceNotFoundException { 800 IBinder b = ServiceManager.getServiceOrThrow(Context.USER_SERVICE); 801 IUserManager service = IUserManager.Stub.asInterface(b); 802 return new UserManager(ctx, service); 803 }}); 804 registerService(Context.APP_OPS_SERVICE, AppOpsManager.class, new CachedServiceFetcher<AppOpsManager>() { @Override public AppOpsManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.APP_OPS_SERVICE); IAppOpsService service = IAppOpsService.Stub.asInterface(b); return new AppOpsManager(ctx, service); }})805 registerService(Context.APP_OPS_SERVICE, AppOpsManager.class, 806 new CachedServiceFetcher<AppOpsManager>() { 807 @Override 808 public AppOpsManager createService(ContextImpl ctx) throws ServiceNotFoundException { 809 IBinder b = ServiceManager.getServiceOrThrow(Context.APP_OPS_SERVICE); 810 IAppOpsService service = IAppOpsService.Stub.asInterface(b); 811 return new AppOpsManager(ctx, service); 812 }}); 813 registerService(Context.CAMERA_SERVICE, CameraManager.class, new CachedServiceFetcher<CameraManager>() { @Override public CameraManager createService(ContextImpl ctx) { return new CameraManager(ctx); }})814 registerService(Context.CAMERA_SERVICE, CameraManager.class, 815 new CachedServiceFetcher<CameraManager>() { 816 @Override 817 public CameraManager createService(ContextImpl ctx) { 818 return new CameraManager(ctx); 819 }}); 820 registerService(Context.LAUNCHER_APPS_SERVICE, LauncherApps.class, new CachedServiceFetcher<LauncherApps>() { @Override public LauncherApps createService(ContextImpl ctx) { return new LauncherApps(ctx); }})821 registerService(Context.LAUNCHER_APPS_SERVICE, LauncherApps.class, 822 new CachedServiceFetcher<LauncherApps>() { 823 @Override 824 public LauncherApps createService(ContextImpl ctx) { 825 return new LauncherApps(ctx); 826 }}); 827 registerService(Context.RESTRICTIONS_SERVICE, RestrictionsManager.class, new CachedServiceFetcher<RestrictionsManager>() { @Override public RestrictionsManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.RESTRICTIONS_SERVICE); IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b); return new RestrictionsManager(ctx, service); }})828 registerService(Context.RESTRICTIONS_SERVICE, RestrictionsManager.class, 829 new CachedServiceFetcher<RestrictionsManager>() { 830 @Override 831 public RestrictionsManager createService(ContextImpl ctx) throws ServiceNotFoundException { 832 IBinder b = ServiceManager.getServiceOrThrow(Context.RESTRICTIONS_SERVICE); 833 IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b); 834 return new RestrictionsManager(ctx, service); 835 }}); 836 registerService(Context.PRINT_SERVICE, PrintManager.class, new CachedServiceFetcher<PrintManager>() { @Override public PrintManager createService(ContextImpl ctx) throws ServiceNotFoundException { IPrintManager service = null; if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PRINTING)) { service = IPrintManager.Stub.asInterface(ServiceManager .getServiceOrThrow(Context.PRINT_SERVICE)); } final int userId = ctx.getUserId(); final int appId = UserHandle.getAppId(ctx.getApplicationInfo().uid); return new PrintManager(ctx.getOuterContext(), service, userId, appId); }})837 registerService(Context.PRINT_SERVICE, PrintManager.class, 838 new CachedServiceFetcher<PrintManager>() { 839 @Override 840 public PrintManager createService(ContextImpl ctx) throws ServiceNotFoundException { 841 IPrintManager service = null; 842 // If the feature not present, don't try to look up every time 843 if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PRINTING)) { 844 service = IPrintManager.Stub.asInterface(ServiceManager 845 .getServiceOrThrow(Context.PRINT_SERVICE)); 846 } 847 final int userId = ctx.getUserId(); 848 final int appId = UserHandle.getAppId(ctx.getApplicationInfo().uid); 849 return new PrintManager(ctx.getOuterContext(), service, userId, appId); 850 }}); 851 registerService(Context.COMPANION_DEVICE_SERVICE, CompanionDeviceManager.class, new CachedServiceFetcher<CompanionDeviceManager>() { @Override public CompanionDeviceManager createService(ContextImpl ctx) throws ServiceNotFoundException { ICompanionDeviceManager service = null; if (ctx.getPackageManager().hasSystemFeature( PackageManager.FEATURE_COMPANION_DEVICE_SETUP)) { service = ICompanionDeviceManager.Stub.asInterface( ServiceManager.getServiceOrThrow(Context.COMPANION_DEVICE_SERVICE)); } return new CompanionDeviceManager(service, ctx.getOuterContext()); }})852 registerService(Context.COMPANION_DEVICE_SERVICE, CompanionDeviceManager.class, 853 new CachedServiceFetcher<CompanionDeviceManager>() { 854 @Override 855 public CompanionDeviceManager createService(ContextImpl ctx) 856 throws ServiceNotFoundException { 857 ICompanionDeviceManager service = null; 858 // If the feature not present, don't try to look up every time 859 if (ctx.getPackageManager().hasSystemFeature( 860 PackageManager.FEATURE_COMPANION_DEVICE_SETUP)) { 861 service = ICompanionDeviceManager.Stub.asInterface( 862 ServiceManager.getServiceOrThrow(Context.COMPANION_DEVICE_SERVICE)); 863 } 864 return new CompanionDeviceManager(service, ctx.getOuterContext()); 865 }}); 866 registerService(Context.CONSUMER_IR_SERVICE, ConsumerIrManager.class, new CachedServiceFetcher<ConsumerIrManager>() { @Override public ConsumerIrManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new ConsumerIrManager(ctx); }})867 registerService(Context.CONSUMER_IR_SERVICE, ConsumerIrManager.class, 868 new CachedServiceFetcher<ConsumerIrManager>() { 869 @Override 870 public ConsumerIrManager createService(ContextImpl ctx) throws ServiceNotFoundException { 871 return new ConsumerIrManager(ctx); 872 }}); 873 registerService(Context.MEDIA_SESSION_SERVICE, MediaSessionManager.class, new CachedServiceFetcher<MediaSessionManager>() { @Override public MediaSessionManager createService(ContextImpl ctx) { return new MediaSessionManager(ctx); }})874 registerService(Context.MEDIA_SESSION_SERVICE, MediaSessionManager.class, 875 new CachedServiceFetcher<MediaSessionManager>() { 876 @Override 877 public MediaSessionManager createService(ContextImpl ctx) { 878 return new MediaSessionManager(ctx); 879 }}); 880 registerService(Context.TRUST_SERVICE, TrustManager.class, new StaticServiceFetcher<TrustManager>() { @Override public TrustManager createService() throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.TRUST_SERVICE); return new TrustManager(b); }})881 registerService(Context.TRUST_SERVICE, TrustManager.class, 882 new StaticServiceFetcher<TrustManager>() { 883 @Override 884 public TrustManager createService() throws ServiceNotFoundException { 885 IBinder b = ServiceManager.getServiceOrThrow(Context.TRUST_SERVICE); 886 return new TrustManager(b); 887 }}); 888 registerService(Context.FINGERPRINT_SERVICE, FingerprintManager.class, new CachedServiceFetcher<FingerprintManager>() { @Override public FingerprintManager createService(ContextImpl ctx) throws ServiceNotFoundException { final IBinder binder; if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { binder = ServiceManager.getServiceOrThrow(Context.FINGERPRINT_SERVICE); } else { binder = ServiceManager.getService(Context.FINGERPRINT_SERVICE); } IFingerprintService service = IFingerprintService.Stub.asInterface(binder); return new FingerprintManager(ctx.getOuterContext(), service); }})889 registerService(Context.FINGERPRINT_SERVICE, FingerprintManager.class, 890 new CachedServiceFetcher<FingerprintManager>() { 891 @Override 892 public FingerprintManager createService(ContextImpl ctx) throws ServiceNotFoundException { 893 final IBinder binder; 894 if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { 895 binder = ServiceManager.getServiceOrThrow(Context.FINGERPRINT_SERVICE); 896 } else { 897 binder = ServiceManager.getService(Context.FINGERPRINT_SERVICE); 898 } 899 IFingerprintService service = IFingerprintService.Stub.asInterface(binder); 900 return new FingerprintManager(ctx.getOuterContext(), service); 901 }}); 902 registerService(Context.FACE_SERVICE, FaceManager.class, new CachedServiceFetcher<FaceManager>() { @Override public FaceManager createService(ContextImpl ctx) throws ServiceNotFoundException { final IBinder binder; if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { binder = ServiceManager.getServiceOrThrow(Context.FACE_SERVICE); } else { binder = ServiceManager.getService(Context.FACE_SERVICE); } IFaceService service = IFaceService.Stub.asInterface(binder); return new FaceManager(ctx.getOuterContext(), service); } })903 registerService(Context.FACE_SERVICE, FaceManager.class, 904 new CachedServiceFetcher<FaceManager>() { 905 @Override 906 public FaceManager createService(ContextImpl ctx) 907 throws ServiceNotFoundException { 908 final IBinder binder; 909 if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { 910 binder = ServiceManager.getServiceOrThrow(Context.FACE_SERVICE); 911 } else { 912 binder = ServiceManager.getService(Context.FACE_SERVICE); 913 } 914 IFaceService service = IFaceService.Stub.asInterface(binder); 915 return new FaceManager(ctx.getOuterContext(), service); 916 } 917 }); 918 registerService(Context.IRIS_SERVICE, IrisManager.class, new CachedServiceFetcher<IrisManager>() { @Override public IrisManager createService(ContextImpl ctx) throws ServiceNotFoundException { final IBinder binder = ServiceManager.getServiceOrThrow(Context.IRIS_SERVICE); IIrisService service = IIrisService.Stub.asInterface(binder); return new IrisManager(ctx.getOuterContext(), service); } })919 registerService(Context.IRIS_SERVICE, IrisManager.class, 920 new CachedServiceFetcher<IrisManager>() { 921 @Override 922 public IrisManager createService(ContextImpl ctx) 923 throws ServiceNotFoundException { 924 final IBinder binder = 925 ServiceManager.getServiceOrThrow(Context.IRIS_SERVICE); 926 IIrisService service = IIrisService.Stub.asInterface(binder); 927 return new IrisManager(ctx.getOuterContext(), service); 928 } 929 }); 930 registerService(Context.BIOMETRIC_SERVICE, BiometricManager.class, new CachedServiceFetcher<BiometricManager>() { @Override public BiometricManager createService(ContextImpl ctx) throws ServiceNotFoundException { if (BiometricManager.hasBiometrics(ctx)) { final IBinder binder = ServiceManager.getServiceOrThrow(Context.BIOMETRIC_SERVICE); final IBiometricService service = IBiometricService.Stub.asInterface(binder); return new BiometricManager(ctx.getOuterContext(), service); } else { return new BiometricManager(ctx.getOuterContext(), null); } } })931 registerService(Context.BIOMETRIC_SERVICE, BiometricManager.class, 932 new CachedServiceFetcher<BiometricManager>() { 933 @Override 934 public BiometricManager createService(ContextImpl ctx) 935 throws ServiceNotFoundException { 936 if (BiometricManager.hasBiometrics(ctx)) { 937 final IBinder binder = 938 ServiceManager.getServiceOrThrow(Context.BIOMETRIC_SERVICE); 939 final IBiometricService service = 940 IBiometricService.Stub.asInterface(binder); 941 return new BiometricManager(ctx.getOuterContext(), service); 942 } else { 943 // Allow access to the manager when service is null. This saves memory 944 // on devices without biometric hardware. 945 return new BiometricManager(ctx.getOuterContext(), null); 946 } 947 } 948 }); 949 registerService(Context.TV_INPUT_SERVICE, TvInputManager.class, new CachedServiceFetcher<TvInputManager>() { @Override public TvInputManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder iBinder = ServiceManager.getServiceOrThrow(Context.TV_INPUT_SERVICE); ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder); return new TvInputManager(service, ctx.getUserId()); }})950 registerService(Context.TV_INPUT_SERVICE, TvInputManager.class, 951 new CachedServiceFetcher<TvInputManager>() { 952 @Override 953 public TvInputManager createService(ContextImpl ctx) throws ServiceNotFoundException { 954 IBinder iBinder = ServiceManager.getServiceOrThrow(Context.TV_INPUT_SERVICE); 955 ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder); 956 return new TvInputManager(service, ctx.getUserId()); 957 }}); 958 registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class, new CachedServiceFetcher<NetworkScoreManager>() { @Override public NetworkScoreManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new NetworkScoreManager(ctx); }})959 registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class, 960 new CachedServiceFetcher<NetworkScoreManager>() { 961 @Override 962 public NetworkScoreManager createService(ContextImpl ctx) throws ServiceNotFoundException { 963 return new NetworkScoreManager(ctx); 964 }}); 965 registerService(Context.USAGE_STATS_SERVICE, UsageStatsManager.class, new CachedServiceFetcher<UsageStatsManager>() { @Override public UsageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder iBinder = ServiceManager.getServiceOrThrow(Context.USAGE_STATS_SERVICE); IUsageStatsManager service = IUsageStatsManager.Stub.asInterface(iBinder); return new UsageStatsManager(ctx.getOuterContext(), service); }})966 registerService(Context.USAGE_STATS_SERVICE, UsageStatsManager.class, 967 new CachedServiceFetcher<UsageStatsManager>() { 968 @Override 969 public UsageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { 970 IBinder iBinder = ServiceManager.getServiceOrThrow(Context.USAGE_STATS_SERVICE); 971 IUsageStatsManager service = IUsageStatsManager.Stub.asInterface(iBinder); 972 return new UsageStatsManager(ctx.getOuterContext(), service); 973 }}); 974 registerService(Context.NETWORK_STATS_SERVICE, NetworkStatsManager.class, new CachedServiceFetcher<NetworkStatsManager>() { @Override public NetworkStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new NetworkStatsManager(ctx.getOuterContext()); }})975 registerService(Context.NETWORK_STATS_SERVICE, NetworkStatsManager.class, 976 new CachedServiceFetcher<NetworkStatsManager>() { 977 @Override 978 public NetworkStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { 979 return new NetworkStatsManager(ctx.getOuterContext()); 980 }}); 981 registerService(Context.JOB_SCHEDULER_SERVICE, JobScheduler.class, new StaticServiceFetcher<JobScheduler>() { @Override public JobScheduler createService() throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.JOB_SCHEDULER_SERVICE); return new JobSchedulerImpl(IJobScheduler.Stub.asInterface(b)); }})982 registerService(Context.JOB_SCHEDULER_SERVICE, JobScheduler.class, 983 new StaticServiceFetcher<JobScheduler>() { 984 @Override 985 public JobScheduler createService() throws ServiceNotFoundException { 986 IBinder b = ServiceManager.getServiceOrThrow(Context.JOB_SCHEDULER_SERVICE); 987 return new JobSchedulerImpl(IJobScheduler.Stub.asInterface(b)); 988 }}); 989 registerService(Context.PERSISTENT_DATA_BLOCK_SERVICE, PersistentDataBlockManager.class, new StaticServiceFetcher<PersistentDataBlockManager>() { @Override public PersistentDataBlockManager createService() throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.PERSISTENT_DATA_BLOCK_SERVICE); IPersistentDataBlockService persistentDataBlockService = IPersistentDataBlockService.Stub.asInterface(b); if (persistentDataBlockService != null) { return new PersistentDataBlockManager(persistentDataBlockService); } else { return null; } }})990 registerService(Context.PERSISTENT_DATA_BLOCK_SERVICE, PersistentDataBlockManager.class, 991 new StaticServiceFetcher<PersistentDataBlockManager>() { 992 @Override 993 public PersistentDataBlockManager createService() throws ServiceNotFoundException { 994 IBinder b = ServiceManager.getServiceOrThrow(Context.PERSISTENT_DATA_BLOCK_SERVICE); 995 IPersistentDataBlockService persistentDataBlockService = 996 IPersistentDataBlockService.Stub.asInterface(b); 997 if (persistentDataBlockService != null) { 998 return new PersistentDataBlockManager(persistentDataBlockService); 999 } else { 1000 // not supported 1001 return null; 1002 } 1003 }}); 1004 registerService(Context.OEM_LOCK_SERVICE, OemLockManager.class, new StaticServiceFetcher<OemLockManager>() { @Override public OemLockManager createService() throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.OEM_LOCK_SERVICE); IOemLockService oemLockService = IOemLockService.Stub.asInterface(b); if (oemLockService != null) { return new OemLockManager(oemLockService); } else { return null; } }})1005 registerService(Context.OEM_LOCK_SERVICE, OemLockManager.class, 1006 new StaticServiceFetcher<OemLockManager>() { 1007 @Override 1008 public OemLockManager createService() throws ServiceNotFoundException { 1009 IBinder b = ServiceManager.getServiceOrThrow(Context.OEM_LOCK_SERVICE); 1010 IOemLockService oemLockService = IOemLockService.Stub.asInterface(b); 1011 if (oemLockService != null) { 1012 return new OemLockManager(oemLockService); 1013 } else { 1014 // not supported 1015 return null; 1016 } 1017 }}); 1018 registerService(Context.MEDIA_PROJECTION_SERVICE, MediaProjectionManager.class, new CachedServiceFetcher<MediaProjectionManager>() { @Override public MediaProjectionManager createService(ContextImpl ctx) { return new MediaProjectionManager(ctx); }})1019 registerService(Context.MEDIA_PROJECTION_SERVICE, MediaProjectionManager.class, 1020 new CachedServiceFetcher<MediaProjectionManager>() { 1021 @Override 1022 public MediaProjectionManager createService(ContextImpl ctx) { 1023 return new MediaProjectionManager(ctx); 1024 }}); 1025 registerService(Context.APPWIDGET_SERVICE, AppWidgetManager.class, new CachedServiceFetcher<AppWidgetManager>() { @Override public AppWidgetManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.APPWIDGET_SERVICE); return new AppWidgetManager(ctx, IAppWidgetService.Stub.asInterface(b)); }})1026 registerService(Context.APPWIDGET_SERVICE, AppWidgetManager.class, 1027 new CachedServiceFetcher<AppWidgetManager>() { 1028 @Override 1029 public AppWidgetManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1030 IBinder b = ServiceManager.getServiceOrThrow(Context.APPWIDGET_SERVICE); 1031 return new AppWidgetManager(ctx, IAppWidgetService.Stub.asInterface(b)); 1032 }}); 1033 registerService(Context.MIDI_SERVICE, MidiManager.class, new CachedServiceFetcher<MidiManager>() { @Override public MidiManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.MIDI_SERVICE); return new MidiManager(IMidiManager.Stub.asInterface(b)); }})1034 registerService(Context.MIDI_SERVICE, MidiManager.class, 1035 new CachedServiceFetcher<MidiManager>() { 1036 @Override 1037 public MidiManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1038 IBinder b = ServiceManager.getServiceOrThrow(Context.MIDI_SERVICE); 1039 return new MidiManager(IMidiManager.Stub.asInterface(b)); 1040 }}); 1041 registerService(Context.RADIO_SERVICE, RadioManager.class, new CachedServiceFetcher<RadioManager>() { @Override public RadioManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new RadioManager(ctx); }})1042 registerService(Context.RADIO_SERVICE, RadioManager.class, 1043 new CachedServiceFetcher<RadioManager>() { 1044 @Override 1045 public RadioManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1046 return new RadioManager(ctx); 1047 }}); 1048 registerService(Context.HARDWARE_PROPERTIES_SERVICE, HardwarePropertiesManager.class, new CachedServiceFetcher<HardwarePropertiesManager>() { @Override public HardwarePropertiesManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.HARDWARE_PROPERTIES_SERVICE); IHardwarePropertiesManager service = IHardwarePropertiesManager.Stub.asInterface(b); return new HardwarePropertiesManager(ctx, service); }})1049 registerService(Context.HARDWARE_PROPERTIES_SERVICE, HardwarePropertiesManager.class, 1050 new CachedServiceFetcher<HardwarePropertiesManager>() { 1051 @Override 1052 public HardwarePropertiesManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1053 IBinder b = ServiceManager.getServiceOrThrow(Context.HARDWARE_PROPERTIES_SERVICE); 1054 IHardwarePropertiesManager service = 1055 IHardwarePropertiesManager.Stub.asInterface(b); 1056 return new HardwarePropertiesManager(ctx, service); 1057 }}); 1058 registerService(Context.SOUND_TRIGGER_SERVICE, SoundTriggerManager.class, new CachedServiceFetcher<SoundTriggerManager>() { @Override public SoundTriggerManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.SOUND_TRIGGER_SERVICE); return new SoundTriggerManager(ctx, ISoundTriggerService.Stub.asInterface(b)); }})1059 registerService(Context.SOUND_TRIGGER_SERVICE, SoundTriggerManager.class, 1060 new CachedServiceFetcher<SoundTriggerManager>() { 1061 @Override 1062 public SoundTriggerManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1063 IBinder b = ServiceManager.getServiceOrThrow(Context.SOUND_TRIGGER_SERVICE); 1064 return new SoundTriggerManager(ctx, ISoundTriggerService.Stub.asInterface(b)); 1065 }}); 1066 registerService(Context.SHORTCUT_SERVICE, ShortcutManager.class, new CachedServiceFetcher<ShortcutManager>() { @Override public ShortcutManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.SHORTCUT_SERVICE); return new ShortcutManager(ctx, IShortcutService.Stub.asInterface(b)); }})1067 registerService(Context.SHORTCUT_SERVICE, ShortcutManager.class, 1068 new CachedServiceFetcher<ShortcutManager>() { 1069 @Override 1070 public ShortcutManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1071 IBinder b = ServiceManager.getServiceOrThrow(Context.SHORTCUT_SERVICE); 1072 return new ShortcutManager(ctx, IShortcutService.Stub.asInterface(b)); 1073 }}); 1074 registerService(Context.OVERLAY_SERVICE, OverlayManager.class, new CachedServiceFetcher<OverlayManager>() { @Override public OverlayManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.OVERLAY_SERVICE); return new OverlayManager(ctx, IOverlayManager.Stub.asInterface(b)); }})1075 registerService(Context.OVERLAY_SERVICE, OverlayManager.class, 1076 new CachedServiceFetcher<OverlayManager>() { 1077 @Override 1078 public OverlayManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1079 IBinder b = ServiceManager.getServiceOrThrow(Context.OVERLAY_SERVICE); 1080 return new OverlayManager(ctx, IOverlayManager.Stub.asInterface(b)); 1081 }}); 1082 registerService(Context.NETWORK_WATCHLIST_SERVICE, NetworkWatchlistManager.class, new CachedServiceFetcher<NetworkWatchlistManager>() { @Override public NetworkWatchlistManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.NETWORK_WATCHLIST_SERVICE); return new NetworkWatchlistManager(ctx, INetworkWatchlistManager.Stub.asInterface(b)); }})1083 registerService(Context.NETWORK_WATCHLIST_SERVICE, NetworkWatchlistManager.class, 1084 new CachedServiceFetcher<NetworkWatchlistManager>() { 1085 @Override 1086 public NetworkWatchlistManager createService(ContextImpl ctx) 1087 throws ServiceNotFoundException { 1088 IBinder b = 1089 ServiceManager.getServiceOrThrow(Context.NETWORK_WATCHLIST_SERVICE); 1090 return new NetworkWatchlistManager(ctx, 1091 INetworkWatchlistManager.Stub.asInterface(b)); 1092 }}); 1093 registerService(Context.SYSTEM_HEALTH_SERVICE, SystemHealthManager.class, new CachedServiceFetcher<SystemHealthManager>() { @Override public SystemHealthManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME); return new SystemHealthManager(IBatteryStats.Stub.asInterface(b)); }})1094 registerService(Context.SYSTEM_HEALTH_SERVICE, SystemHealthManager.class, 1095 new CachedServiceFetcher<SystemHealthManager>() { 1096 @Override 1097 public SystemHealthManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1098 IBinder b = ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME); 1099 return new SystemHealthManager(IBatteryStats.Stub.asInterface(b)); 1100 }}); 1101 registerService(Context.CONTEXTHUB_SERVICE, ContextHubManager.class, new CachedServiceFetcher<ContextHubManager>() { @Override public ContextHubManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new ContextHubManager(ctx.getOuterContext(), ctx.mMainThread.getHandler().getLooper()); }})1102 registerService(Context.CONTEXTHUB_SERVICE, ContextHubManager.class, 1103 new CachedServiceFetcher<ContextHubManager>() { 1104 @Override 1105 public ContextHubManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1106 return new ContextHubManager(ctx.getOuterContext(), 1107 ctx.mMainThread.getHandler().getLooper()); 1108 }}); 1109 registerService(Context.INCIDENT_SERVICE, IncidentManager.class, new CachedServiceFetcher<IncidentManager>() { @Override public IncidentManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new IncidentManager(ctx); }})1110 registerService(Context.INCIDENT_SERVICE, IncidentManager.class, 1111 new CachedServiceFetcher<IncidentManager>() { 1112 @Override 1113 public IncidentManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1114 return new IncidentManager(ctx); 1115 }}); 1116 registerService(Context.BUGREPORT_SERVICE, BugreportManager.class, new CachedServiceFetcher<BugreportManager>() { @Override public BugreportManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.BUGREPORT_SERVICE); return new BugreportManager(ctx.getOuterContext(), IDumpstate.Stub.asInterface(b)); }})1117 registerService(Context.BUGREPORT_SERVICE, BugreportManager.class, 1118 new CachedServiceFetcher<BugreportManager>() { 1119 @Override 1120 public BugreportManager createService(ContextImpl ctx) 1121 throws ServiceNotFoundException { 1122 IBinder b = ServiceManager.getServiceOrThrow(Context.BUGREPORT_SERVICE); 1123 return new BugreportManager(ctx.getOuterContext(), 1124 IDumpstate.Stub.asInterface(b)); 1125 }}); 1126 registerService(Context.AUTOFILL_MANAGER_SERVICE, AutofillManager.class, new CachedServiceFetcher<AutofillManager>() { @Override public AutofillManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getService(Context.AUTOFILL_MANAGER_SERVICE); IAutoFillManager service = IAutoFillManager.Stub.asInterface(b); return new AutofillManager(ctx.getOuterContext(), service); }})1127 registerService(Context.AUTOFILL_MANAGER_SERVICE, AutofillManager.class, 1128 new CachedServiceFetcher<AutofillManager>() { 1129 @Override 1130 public AutofillManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1131 // Get the services without throwing as this is an optional feature 1132 IBinder b = ServiceManager.getService(Context.AUTOFILL_MANAGER_SERVICE); 1133 IAutoFillManager service = IAutoFillManager.Stub.asInterface(b); 1134 return new AutofillManager(ctx.getOuterContext(), service); 1135 }}); 1136 registerService(Context.CONTENT_CAPTURE_MANAGER_SERVICE, ContentCaptureManager.class, new CachedServiceFetcher<ContentCaptureManager>() { @Override public ContentCaptureManager createService(ContextImpl ctx) throws ServiceNotFoundException { Context outerContext = ctx.getOuterContext(); ContentCaptureOptions options = outerContext.getContentCaptureOptions(); if (options != null && (options.lite || options.isWhitelisted(outerContext))) { IBinder b = ServiceManager .getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE); IContentCaptureManager service = IContentCaptureManager.Stub.asInterface(b); if (service != null) { return new ContentCaptureManager(outerContext, service, options); } } return null; }})1137 registerService(Context.CONTENT_CAPTURE_MANAGER_SERVICE, ContentCaptureManager.class, 1138 new CachedServiceFetcher<ContentCaptureManager>() { 1139 @Override 1140 public ContentCaptureManager createService(ContextImpl ctx) 1141 throws ServiceNotFoundException { 1142 // Get the services without throwing as this is an optional feature 1143 Context outerContext = ctx.getOuterContext(); 1144 ContentCaptureOptions options = outerContext.getContentCaptureOptions(); 1145 // Options is null when the service didn't whitelist the activity or package 1146 if (options != null && (options.lite || options.isWhitelisted(outerContext))) { 1147 IBinder b = ServiceManager 1148 .getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE); 1149 IContentCaptureManager service = IContentCaptureManager.Stub.asInterface(b); 1150 // Service is null when not provided by OEM or disabled by kill-switch. 1151 if (service != null) { 1152 return new ContentCaptureManager(outerContext, service, options); 1153 } 1154 } 1155 // When feature is disabled or app / package not whitelisted, we return a null 1156 // manager to apps so the performance impact is practically zero 1157 return null; 1158 }}); 1159 registerService(Context.APP_PREDICTION_SERVICE, AppPredictionManager.class, new CachedServiceFetcher<AppPredictionManager>() { @Override public AppPredictionManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new AppPredictionManager(ctx); } })1160 registerService(Context.APP_PREDICTION_SERVICE, AppPredictionManager.class, 1161 new CachedServiceFetcher<AppPredictionManager>() { 1162 @Override 1163 public AppPredictionManager createService(ContextImpl ctx) 1164 throws ServiceNotFoundException { 1165 return new AppPredictionManager(ctx); 1166 } 1167 }); 1168 registerService(Context.CONTENT_SUGGESTIONS_SERVICE, ContentSuggestionsManager.class, new CachedServiceFetcher<ContentSuggestionsManager>() { @Override public ContentSuggestionsManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService( Context.CONTENT_SUGGESTIONS_SERVICE); IContentSuggestionsManager service = IContentSuggestionsManager.Stub.asInterface(b); return new ContentSuggestionsManager(ctx.getUserId(), service); } })1169 registerService(Context.CONTENT_SUGGESTIONS_SERVICE, 1170 ContentSuggestionsManager.class, 1171 new CachedServiceFetcher<ContentSuggestionsManager>() { 1172 @Override 1173 public ContentSuggestionsManager createService(ContextImpl ctx) { 1174 // No throw as this is an optional service 1175 IBinder b = ServiceManager.getService( 1176 Context.CONTENT_SUGGESTIONS_SERVICE); 1177 IContentSuggestionsManager service = 1178 IContentSuggestionsManager.Stub.asInterface(b); 1179 return new ContentSuggestionsManager(ctx.getUserId(), service); 1180 } 1181 }); 1182 registerService(Context.VR_SERVICE, VrManager.class, new CachedServiceFetcher<VrManager>() { @Override public VrManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.VR_SERVICE); return new VrManager(IVrManager.Stub.asInterface(b)); } })1183 registerService(Context.VR_SERVICE, VrManager.class, new CachedServiceFetcher<VrManager>() { 1184 @Override 1185 public VrManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1186 IBinder b = ServiceManager.getServiceOrThrow(Context.VR_SERVICE); 1187 return new VrManager(IVrManager.Stub.asInterface(b)); 1188 } 1189 }); 1190 registerService(Context.TIME_ZONE_RULES_MANAGER_SERVICE, RulesManager.class, new CachedServiceFetcher<RulesManager>() { @Override public RulesManager createService(ContextImpl ctx) { return new RulesManager(ctx.getOuterContext()); }})1191 registerService(Context.TIME_ZONE_RULES_MANAGER_SERVICE, RulesManager.class, 1192 new CachedServiceFetcher<RulesManager>() { 1193 @Override 1194 public RulesManager createService(ContextImpl ctx) { 1195 return new RulesManager(ctx.getOuterContext()); 1196 }}); 1197 registerService(Context.CROSS_PROFILE_APPS_SERVICE, CrossProfileApps.class, new CachedServiceFetcher<CrossProfileApps>() { @Override public CrossProfileApps createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow( Context.CROSS_PROFILE_APPS_SERVICE); return new CrossProfileApps(ctx.getOuterContext(), ICrossProfileApps.Stub.asInterface(b)); } })1198 registerService(Context.CROSS_PROFILE_APPS_SERVICE, CrossProfileApps.class, 1199 new CachedServiceFetcher<CrossProfileApps>() { 1200 @Override 1201 public CrossProfileApps createService(ContextImpl ctx) 1202 throws ServiceNotFoundException { 1203 IBinder b = ServiceManager.getServiceOrThrow( 1204 Context.CROSS_PROFILE_APPS_SERVICE); 1205 return new CrossProfileApps(ctx.getOuterContext(), 1206 ICrossProfileApps.Stub.asInterface(b)); 1207 } 1208 }); 1209 registerService(Context.SLICE_SERVICE, SliceManager.class, new CachedServiceFetcher<SliceManager>() { @Override public SliceManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new SliceManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); } })1210 registerService(Context.SLICE_SERVICE, SliceManager.class, 1211 new CachedServiceFetcher<SliceManager>() { 1212 @Override 1213 public SliceManager createService(ContextImpl ctx) 1214 throws ServiceNotFoundException { 1215 return new SliceManager(ctx.getOuterContext(), 1216 ctx.mMainThread.getHandler()); 1217 } 1218 }); 1219 registerService(Context.DEVICE_IDLE_CONTROLLER, DeviceIdleManager.class, new CachedServiceFetcher<DeviceIdleManager>() { @Override public DeviceIdleManager createService(ContextImpl ctx) throws ServiceNotFoundException { IDeviceIdleController service = IDeviceIdleController.Stub.asInterface( ServiceManager.getServiceOrThrow( Context.DEVICE_IDLE_CONTROLLER)); return new DeviceIdleManager(ctx.getOuterContext(), service); }})1220 registerService(Context.DEVICE_IDLE_CONTROLLER, DeviceIdleManager.class, 1221 new CachedServiceFetcher<DeviceIdleManager>() { 1222 @Override 1223 public DeviceIdleManager createService(ContextImpl ctx) 1224 throws ServiceNotFoundException { 1225 IDeviceIdleController service = IDeviceIdleController.Stub.asInterface( 1226 ServiceManager.getServiceOrThrow( 1227 Context.DEVICE_IDLE_CONTROLLER)); 1228 return new DeviceIdleManager(ctx.getOuterContext(), service); 1229 }}); 1230 registerService(Context.TIME_DETECTOR_SERVICE, TimeDetector.class, new CachedServiceFetcher<TimeDetector>() { @Override public TimeDetector createService(ContextImpl ctx) throws ServiceNotFoundException { return new TimeDetector(); }})1231 registerService(Context.TIME_DETECTOR_SERVICE, TimeDetector.class, 1232 new CachedServiceFetcher<TimeDetector>() { 1233 @Override 1234 public TimeDetector createService(ContextImpl ctx) 1235 throws ServiceNotFoundException { 1236 return new TimeDetector(); 1237 }}); 1238 registerService(Context.PERMISSION_SERVICE, PermissionManager.class, new CachedServiceFetcher<PermissionManager>() { @Override public PermissionManager createService(ContextImpl ctx) { IPackageManager packageManager = AppGlobals.getPackageManager(); return new PermissionManager(ctx.getOuterContext(), packageManager); }})1239 registerService(Context.PERMISSION_SERVICE, PermissionManager.class, 1240 new CachedServiceFetcher<PermissionManager>() { 1241 @Override 1242 public PermissionManager createService(ContextImpl ctx) { 1243 IPackageManager packageManager = AppGlobals.getPackageManager(); 1244 return new PermissionManager(ctx.getOuterContext(), packageManager); 1245 }}); 1246 registerService(Context.PERMISSION_CONTROLLER_SERVICE, PermissionControllerManager.class, new CachedServiceFetcher<PermissionControllerManager>() { @Override public PermissionControllerManager createService(ContextImpl ctx) { return new PermissionControllerManager(ctx.getOuterContext(), ctx.getMainThreadHandler()); }})1247 registerService(Context.PERMISSION_CONTROLLER_SERVICE, PermissionControllerManager.class, 1248 new CachedServiceFetcher<PermissionControllerManager>() { 1249 @Override 1250 public PermissionControllerManager createService(ContextImpl ctx) { 1251 return new PermissionControllerManager(ctx.getOuterContext(), 1252 ctx.getMainThreadHandler()); 1253 }}); 1254 registerService(Context.ROLE_SERVICE, RoleManager.class, new CachedServiceFetcher<RoleManager>() { @Override public RoleManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new RoleManager(ctx.getOuterContext()); }})1255 registerService(Context.ROLE_SERVICE, RoleManager.class, 1256 new CachedServiceFetcher<RoleManager>() { 1257 @Override 1258 public RoleManager createService(ContextImpl ctx) 1259 throws ServiceNotFoundException { 1260 return new RoleManager(ctx.getOuterContext()); 1261 }}); 1262 registerService(Context.ROLE_CONTROLLER_SERVICE, RoleControllerManager.class, new CachedServiceFetcher<RoleControllerManager>() { @Override public RoleControllerManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new RoleControllerManager(ctx.getOuterContext()); }})1263 registerService(Context.ROLE_CONTROLLER_SERVICE, RoleControllerManager.class, 1264 new CachedServiceFetcher<RoleControllerManager>() { 1265 @Override 1266 public RoleControllerManager createService(ContextImpl ctx) 1267 throws ServiceNotFoundException { 1268 return new RoleControllerManager(ctx.getOuterContext()); 1269 }}); 1270 registerService(Context.ROLLBACK_SERVICE, RollbackManager.class, new CachedServiceFetcher<RollbackManager>() { @Override public RollbackManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.ROLLBACK_SERVICE); return new RollbackManager(ctx.getOuterContext(), IRollbackManager.Stub.asInterface(b)); }})1271 registerService(Context.ROLLBACK_SERVICE, RollbackManager.class, 1272 new CachedServiceFetcher<RollbackManager>() { 1273 @Override 1274 public RollbackManager createService(ContextImpl ctx) 1275 throws ServiceNotFoundException { 1276 IBinder b = ServiceManager.getServiceOrThrow(Context.ROLLBACK_SERVICE); 1277 return new RollbackManager(ctx.getOuterContext(), 1278 IRollbackManager.Stub.asInterface(b)); 1279 }}); 1280 registerService(Context.DYNAMIC_SYSTEM_SERVICE, DynamicSystemManager.class, new CachedServiceFetcher<DynamicSystemManager>() { @Override public DynamicSystemManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow( Context.DYNAMIC_SYSTEM_SERVICE); return new DynamicSystemManager( IDynamicSystemService.Stub.asInterface(b)); }})1281 registerService(Context.DYNAMIC_SYSTEM_SERVICE, DynamicSystemManager.class, 1282 new CachedServiceFetcher<DynamicSystemManager>() { 1283 @Override 1284 public DynamicSystemManager createService(ContextImpl ctx) 1285 throws ServiceNotFoundException { 1286 IBinder b = ServiceManager.getServiceOrThrow( 1287 Context.DYNAMIC_SYSTEM_SERVICE); 1288 return new DynamicSystemManager( 1289 IDynamicSystemService.Stub.asInterface(b)); 1290 }}); 1291 //CHECKSTYLE:ON IndentationCheck 1292 } 1293 1294 /** 1295 * Creates an array which is used to cache per-Context service instances. 1296 */ createServiceCache()1297 public static Object[] createServiceCache() { 1298 return new Object[sServiceCacheSize]; 1299 } 1300 1301 /** 1302 * Gets a system service from a given context. 1303 */ getSystemService(ContextImpl ctx, String name)1304 public static Object getSystemService(ContextImpl ctx, String name) { 1305 ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name); 1306 return fetcher != null ? fetcher.getService(ctx) : null; 1307 } 1308 1309 /** 1310 * Gets the name of the system-level service that is represented by the specified class. 1311 */ getSystemServiceName(Class<?> serviceClass)1312 public static String getSystemServiceName(Class<?> serviceClass) { 1313 return SYSTEM_SERVICE_NAMES.get(serviceClass); 1314 } 1315 1316 /** 1317 * Statically registers a system service with the context. 1318 * This method must be called during static initialization only. 1319 */ registerService(String serviceName, Class<T> serviceClass, ServiceFetcher<T> serviceFetcher)1320 private static <T> void registerService(String serviceName, Class<T> serviceClass, 1321 ServiceFetcher<T> serviceFetcher) { 1322 SYSTEM_SERVICE_NAMES.put(serviceClass, serviceName); 1323 SYSTEM_SERVICE_FETCHERS.put(serviceName, serviceFetcher); 1324 } 1325 1326 /** 1327 * Base interface for classes that fetch services. 1328 * These objects must only be created during static initialization. 1329 */ 1330 static abstract interface ServiceFetcher<T> { getService(ContextImpl ctx)1331 T getService(ContextImpl ctx); 1332 } 1333 1334 /** 1335 * Override this class when the system service constructor needs a 1336 * ContextImpl and should be cached and retained by that context. 1337 */ 1338 static abstract class CachedServiceFetcher<T> implements ServiceFetcher<T> { 1339 private final int mCacheIndex; 1340 CachedServiceFetcher()1341 CachedServiceFetcher() { 1342 // Note this class must be instantiated only by the static initializer of the 1343 // outer class (SystemServiceRegistry), which already does the synchronization, 1344 // so bare access to sServiceCacheSize is okay here. 1345 mCacheIndex = sServiceCacheSize++; 1346 } 1347 1348 @Override 1349 @SuppressWarnings("unchecked") getService(ContextImpl ctx)1350 public final T getService(ContextImpl ctx) { 1351 final Object[] cache = ctx.mServiceCache; 1352 final int[] gates = ctx.mServiceInitializationStateArray; 1353 1354 for (;;) { 1355 boolean doInitialize = false; 1356 synchronized (cache) { 1357 // Return it if we already have a cached instance. 1358 T service = (T) cache[mCacheIndex]; 1359 if (service != null || gates[mCacheIndex] == ContextImpl.STATE_NOT_FOUND) { 1360 return service; 1361 } 1362 1363 // If we get here, there's no cached instance. 1364 1365 // Grr... if gate is STATE_READY, then this means we initialized the service 1366 // once but someone cleared it. 1367 // We start over from STATE_UNINITIALIZED. 1368 if (gates[mCacheIndex] == ContextImpl.STATE_READY) { 1369 gates[mCacheIndex] = ContextImpl.STATE_UNINITIALIZED; 1370 } 1371 1372 // It's possible for multiple threads to get here at the same time, so 1373 // use the "gate" to make sure only the first thread will call createService(). 1374 1375 // At this point, the gate must be either UNINITIALIZED or INITIALIZING. 1376 if (gates[mCacheIndex] == ContextImpl.STATE_UNINITIALIZED) { 1377 doInitialize = true; 1378 gates[mCacheIndex] = ContextImpl.STATE_INITIALIZING; 1379 } 1380 } 1381 1382 if (doInitialize) { 1383 // Only the first thread gets here. 1384 1385 T service = null; 1386 @ServiceInitializationState int newState = ContextImpl.STATE_NOT_FOUND; 1387 try { 1388 // This thread is the first one to get here. Instantiate the service 1389 // *without* the cache lock held. 1390 service = createService(ctx); 1391 newState = ContextImpl.STATE_READY; 1392 1393 } catch (ServiceNotFoundException e) { 1394 onServiceNotFound(e); 1395 1396 } finally { 1397 synchronized (cache) { 1398 cache[mCacheIndex] = service; 1399 gates[mCacheIndex] = newState; 1400 cache.notifyAll(); 1401 } 1402 } 1403 return service; 1404 } 1405 // The other threads will wait for the first thread to call notifyAll(), 1406 // and go back to the top and retry. 1407 synchronized (cache) { 1408 while (gates[mCacheIndex] < ContextImpl.STATE_READY) { 1409 try { 1410 cache.wait(); 1411 } catch (InterruptedException e) { 1412 Log.w(TAG, "getService() interrupted"); 1413 Thread.currentThread().interrupt(); 1414 return null; 1415 } 1416 } 1417 } 1418 } 1419 } 1420 createService(ContextImpl ctx)1421 public abstract T createService(ContextImpl ctx) throws ServiceNotFoundException; 1422 } 1423 1424 /** 1425 * Override this class when the system service does not need a ContextImpl 1426 * and should be cached and retained process-wide. 1427 */ 1428 static abstract class StaticServiceFetcher<T> implements ServiceFetcher<T> { 1429 private T mCachedInstance; 1430 1431 @Override getService(ContextImpl ctx)1432 public final T getService(ContextImpl ctx) { 1433 synchronized (StaticServiceFetcher.this) { 1434 if (mCachedInstance == null) { 1435 try { 1436 mCachedInstance = createService(); 1437 } catch (ServiceNotFoundException e) { 1438 onServiceNotFound(e); 1439 } 1440 } 1441 return mCachedInstance; 1442 } 1443 } 1444 createService()1445 public abstract T createService() throws ServiceNotFoundException; 1446 } 1447 1448 /** 1449 * Like StaticServiceFetcher, creates only one instance of the service per application, but when 1450 * creating the service for the first time, passes it the application context of the creating 1451 * application. 1452 * 1453 * TODO: Delete this once its only user (ConnectivityManager) is known to work well in the 1454 * case where multiple application components each have their own ConnectivityManager object. 1455 */ 1456 static abstract class StaticApplicationContextServiceFetcher<T> implements ServiceFetcher<T> { 1457 private T mCachedInstance; 1458 1459 @Override getService(ContextImpl ctx)1460 public final T getService(ContextImpl ctx) { 1461 synchronized (StaticApplicationContextServiceFetcher.this) { 1462 if (mCachedInstance == null) { 1463 Context appContext = ctx.getApplicationContext(); 1464 // If the application context is null, we're either in the system process or 1465 // it's the application context very early in app initialization. In both these 1466 // cases, the passed-in ContextImpl will not be freed, so it's safe to pass it 1467 // to the service. http://b/27532714 . 1468 try { 1469 mCachedInstance = createService(appContext != null ? appContext : ctx); 1470 } catch (ServiceNotFoundException e) { 1471 onServiceNotFound(e); 1472 } 1473 } 1474 return mCachedInstance; 1475 } 1476 } 1477 createService(Context applicationContext)1478 public abstract T createService(Context applicationContext) throws ServiceNotFoundException; 1479 } 1480 onServiceNotFound(ServiceNotFoundException e)1481 public static void onServiceNotFound(ServiceNotFoundException e) { 1482 // We're mostly interested in tracking down long-lived core system 1483 // components that might stumble if they obtain bad references; just 1484 // emit a tidy log message for normal apps 1485 if (android.os.Process.myUid() < android.os.Process.FIRST_APPLICATION_UID) { 1486 Log.wtf(TAG, e.getMessage(), e); 1487 } else { 1488 Log.w(TAG, e.getMessage()); 1489 } 1490 } 1491 } 1492