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.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.annotation.SystemApi; 24 import android.app.ContextImpl.ServiceInitializationState; 25 import android.app.admin.DevicePolicyManager; 26 import android.app.admin.IDevicePolicyManager; 27 import android.app.appsearch.AppSearchManagerFrameworkInitializer; 28 import android.app.blob.BlobStoreManagerFrameworkInitializer; 29 import android.app.contentsuggestions.ContentSuggestionsManager; 30 import android.app.contentsuggestions.IContentSuggestionsManager; 31 import android.app.job.JobSchedulerFrameworkInitializer; 32 import android.app.people.PeopleManager; 33 import android.app.prediction.AppPredictionManager; 34 import android.app.role.RoleFrameworkInitializer; 35 import android.app.search.SearchUiManager; 36 import android.app.slice.SliceManager; 37 import android.app.smartspace.SmartspaceManager; 38 import android.app.time.TimeManager; 39 import android.app.timedetector.TimeDetector; 40 import android.app.timedetector.TimeDetectorImpl; 41 import android.app.timezone.RulesManager; 42 import android.app.timezonedetector.TimeZoneDetector; 43 import android.app.timezonedetector.TimeZoneDetectorImpl; 44 import android.app.trust.TrustManager; 45 import android.app.usage.IStorageStatsManager; 46 import android.app.usage.IUsageStatsManager; 47 import android.app.usage.NetworkStatsManager; 48 import android.app.usage.StorageStatsManager; 49 import android.app.usage.UsageStatsManager; 50 import android.apphibernation.AppHibernationManager; 51 import android.appwidget.AppWidgetManager; 52 import android.bluetooth.BluetoothManager; 53 import android.companion.CompanionDeviceManager; 54 import android.companion.ICompanionDeviceManager; 55 import android.content.ClipboardManager; 56 import android.content.ContentCaptureOptions; 57 import android.content.Context; 58 import android.content.IRestrictionsManager; 59 import android.content.RestrictionsManager; 60 import android.content.integrity.AppIntegrityManager; 61 import android.content.integrity.IAppIntegrityManager; 62 import android.content.om.IOverlayManager; 63 import android.content.om.OverlayManager; 64 import android.content.pm.ApplicationInfo; 65 import android.content.pm.CrossProfileApps; 66 import android.content.pm.DataLoaderManager; 67 import android.content.pm.ICrossProfileApps; 68 import android.content.pm.IDataLoaderManager; 69 import android.content.pm.IShortcutService; 70 import android.content.pm.LauncherApps; 71 import android.content.pm.PackageManager; 72 import android.content.pm.ShortcutManager; 73 import android.content.pm.verify.domain.DomainVerificationManager; 74 import android.content.pm.verify.domain.IDomainVerificationManager; 75 import android.content.res.Resources; 76 import android.content.rollback.RollbackManagerFrameworkInitializer; 77 import android.debug.AdbManager; 78 import android.debug.IAdbManager; 79 import android.graphics.fonts.FontManager; 80 import android.hardware.ConsumerIrManager; 81 import android.hardware.ISerialManager; 82 import android.hardware.SensorManager; 83 import android.hardware.SensorPrivacyManager; 84 import android.hardware.SerialManager; 85 import android.hardware.SystemSensorManager; 86 import android.hardware.biometrics.BiometricManager; 87 import android.hardware.biometrics.IAuthService; 88 import android.hardware.camera2.CameraManager; 89 import android.hardware.devicestate.DeviceStateManager; 90 import android.hardware.display.ColorDisplayManager; 91 import android.hardware.display.DisplayManager; 92 import android.hardware.face.FaceManager; 93 import android.hardware.face.IFaceService; 94 import android.hardware.fingerprint.FingerprintManager; 95 import android.hardware.fingerprint.IFingerprintService; 96 import android.hardware.hdmi.HdmiControlManager; 97 import android.hardware.hdmi.IHdmiControlService; 98 import android.hardware.input.InputManager; 99 import android.hardware.iris.IIrisService; 100 import android.hardware.iris.IrisManager; 101 import android.hardware.lights.LightsManager; 102 import android.hardware.lights.SystemLightsManager; 103 import android.hardware.location.ContextHubManager; 104 import android.hardware.radio.RadioManager; 105 import android.hardware.usb.IUsbManager; 106 import android.hardware.usb.UsbManager; 107 import android.location.CountryDetector; 108 import android.location.ICountryDetector; 109 import android.location.ILocationManager; 110 import android.location.LocationManager; 111 import android.media.AudioManager; 112 import android.media.MediaFrameworkInitializer; 113 import android.media.MediaFrameworkPlatformInitializer; 114 import android.media.MediaRouter; 115 import android.media.metrics.IMediaMetricsManager; 116 import android.media.metrics.MediaMetricsManager; 117 import android.media.midi.IMidiManager; 118 import android.media.midi.MidiManager; 119 import android.media.musicrecognition.IMusicRecognitionManager; 120 import android.media.musicrecognition.MusicRecognitionManager; 121 import android.media.projection.MediaProjectionManager; 122 import android.media.soundtrigger.SoundTriggerManager; 123 import android.media.tv.ITvInputManager; 124 import android.media.tv.TvInputManager; 125 import android.media.tv.tunerresourcemanager.ITunerResourceManager; 126 import android.media.tv.tunerresourcemanager.TunerResourceManager; 127 import android.net.ConnectivityFrameworkInitializer; 128 import android.net.EthernetManager; 129 import android.net.IEthernetManager; 130 import android.net.IIpSecService; 131 import android.net.INetworkPolicyManager; 132 import android.net.IPacProxyManager; 133 import android.net.IVpnManager; 134 import android.net.IpSecManager; 135 import android.net.NetworkPolicyManager; 136 import android.net.NetworkScoreManager; 137 import android.net.NetworkWatchlistManager; 138 import android.net.PacProxyManager; 139 import android.net.TetheringManager; 140 import android.net.VpnManager; 141 import android.net.lowpan.ILowpanManager; 142 import android.net.lowpan.LowpanManager; 143 import android.net.nsd.INsdManager; 144 import android.net.nsd.NsdManager; 145 import android.net.vcn.IVcnManagementService; 146 import android.net.vcn.VcnManager; 147 import android.net.wifi.WifiFrameworkInitializer; 148 import android.net.wifi.nl80211.WifiNl80211Manager; 149 import android.nfc.NfcManager; 150 import android.os.BatteryManager; 151 import android.os.BatteryStats; 152 import android.os.BatteryStatsManager; 153 import android.os.BugreportManager; 154 import android.os.Build; 155 import android.os.DropBoxManager; 156 import android.os.HardwarePropertiesManager; 157 import android.os.IBatteryPropertiesRegistrar; 158 import android.os.IBinder; 159 import android.os.IDumpstate; 160 import android.os.IHardwarePropertiesManager; 161 import android.os.IPowerManager; 162 import android.os.IRecoverySystem; 163 import android.os.ISystemUpdateManager; 164 import android.os.IThermalService; 165 import android.os.IUserManager; 166 import android.os.IncidentManager; 167 import android.os.PerformanceHintManager; 168 import android.os.PowerManager; 169 import android.os.RecoverySystem; 170 import android.os.ServiceManager; 171 import android.os.ServiceManager.ServiceNotFoundException; 172 import android.os.StatsFrameworkInitializer; 173 import android.os.SystemConfigManager; 174 import android.os.SystemUpdateManager; 175 import android.os.SystemVibrator; 176 import android.os.SystemVibratorManager; 177 import android.os.UserHandle; 178 import android.os.UserManager; 179 import android.os.Vibrator; 180 import android.os.VibratorManager; 181 import android.os.health.SystemHealthManager; 182 import android.os.image.DynamicSystemManager; 183 import android.os.image.IDynamicSystemService; 184 import android.os.incremental.IIncrementalService; 185 import android.os.incremental.IncrementalManager; 186 import android.os.storage.StorageManager; 187 import android.permission.LegacyPermissionManager; 188 import android.permission.PermissionCheckerManager; 189 import android.permission.PermissionControllerManager; 190 import android.permission.PermissionManager; 191 import android.print.IPrintManager; 192 import android.print.PrintManager; 193 import android.scheduling.SchedulingFrameworkInitializer; 194 import android.security.FileIntegrityManager; 195 import android.security.IFileIntegrityService; 196 import android.service.oemlock.IOemLockService; 197 import android.service.oemlock.OemLockManager; 198 import android.service.persistentdata.IPersistentDataBlockService; 199 import android.service.persistentdata.PersistentDataBlockManager; 200 import android.service.vr.IVrManager; 201 import android.telecom.TelecomManager; 202 import android.telephony.MmsManager; 203 import android.telephony.TelephonyFrameworkInitializer; 204 import android.telephony.TelephonyRegistryManager; 205 import android.util.ArrayMap; 206 import android.util.Log; 207 import android.util.Slog; 208 import android.uwb.UwbManager; 209 import android.view.ContextThemeWrapper; 210 import android.view.LayoutInflater; 211 import android.view.WindowManager; 212 import android.view.WindowManagerImpl; 213 import android.view.accessibility.AccessibilityManager; 214 import android.view.accessibility.CaptioningManager; 215 import android.view.autofill.AutofillManager; 216 import android.view.autofill.IAutoFillManager; 217 import android.view.contentcapture.ContentCaptureManager; 218 import android.view.contentcapture.IContentCaptureManager; 219 import android.view.displayhash.DisplayHashManager; 220 import android.view.inputmethod.InputMethodManager; 221 import android.view.textclassifier.TextClassificationManager; 222 import android.view.textservice.TextServicesManager; 223 import android.view.translation.ITranslationManager; 224 import android.view.translation.TranslationManager; 225 import android.view.translation.UiTranslationManager; 226 227 import com.android.internal.app.IAppOpsService; 228 import com.android.internal.app.IBatteryStats; 229 import com.android.internal.app.ISoundTriggerService; 230 import com.android.internal.appwidget.IAppWidgetService; 231 import com.android.internal.graphics.fonts.IFontManager; 232 import com.android.internal.net.INetworkWatchlistManager; 233 import com.android.internal.os.IDropBoxManagerService; 234 import com.android.internal.policy.PhoneLayoutInflater; 235 import com.android.internal.util.Preconditions; 236 237 import java.util.Map; 238 import java.util.Objects; 239 240 /** 241 * Manages all of the system services that can be returned by {@link Context#getSystemService}. 242 * Used by {@link ContextImpl}. 243 * 244 * @hide 245 */ 246 @SystemApi 247 public final class SystemServiceRegistry { 248 private static final String TAG = "SystemServiceRegistry"; 249 250 /** @hide */ 251 public static boolean sEnableServiceNotFoundWtf = false; 252 253 // Service registry information. 254 // This information is never changed once static initialization has completed. 255 private static final Map<Class<?>, String> SYSTEM_SERVICE_NAMES = 256 new ArrayMap<Class<?>, String>(); 257 private static final Map<String, ServiceFetcher<?>> SYSTEM_SERVICE_FETCHERS = 258 new ArrayMap<String, ServiceFetcher<?>>(); 259 private static final Map<String, String> SYSTEM_SERVICE_CLASS_NAMES = new ArrayMap<>(); 260 261 private static int sServiceCacheSize; 262 263 private static volatile boolean sInitializing; 264 265 // Not instantiable. SystemServiceRegistry()266 private SystemServiceRegistry() { } 267 268 static { 269 //CHECKSTYLE:OFF IndentationCheck registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class, new CachedServiceFetcher<AccessibilityManager>() { @Override public AccessibilityManager createService(ContextImpl ctx) { return AccessibilityManager.getInstance(ctx); }})270 registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class, 271 new CachedServiceFetcher<AccessibilityManager>() { 272 @Override 273 public AccessibilityManager createService(ContextImpl ctx) { 274 return AccessibilityManager.getInstance(ctx); 275 }}); 276 registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class, new CachedServiceFetcher<CaptioningManager>() { @Override public CaptioningManager createService(ContextImpl ctx) { return new CaptioningManager(ctx); }})277 registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class, 278 new CachedServiceFetcher<CaptioningManager>() { 279 @Override 280 public CaptioningManager createService(ContextImpl ctx) { 281 return new CaptioningManager(ctx); 282 }}); 283 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); }})284 registerService(Context.ACCOUNT_SERVICE, AccountManager.class, 285 new CachedServiceFetcher<AccountManager>() { 286 @Override 287 public AccountManager createService(ContextImpl ctx) throws ServiceNotFoundException { 288 IBinder b = ServiceManager.getServiceOrThrow(Context.ACCOUNT_SERVICE); 289 IAccountManager service = IAccountManager.Stub.asInterface(b); 290 return new AccountManager(ctx, service); 291 }}); 292 registerService(Context.ACTIVITY_SERVICE, ActivityManager.class, new CachedServiceFetcher<ActivityManager>() { @Override public ActivityManager createService(ContextImpl ctx) { return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); }})293 registerService(Context.ACTIVITY_SERVICE, ActivityManager.class, 294 new CachedServiceFetcher<ActivityManager>() { 295 @Override 296 public ActivityManager createService(ContextImpl ctx) { 297 return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); 298 }}); 299 registerService(Context.ACTIVITY_TASK_SERVICE, ActivityTaskManager.class, new CachedServiceFetcher<ActivityTaskManager>() { @Override public ActivityTaskManager createService(ContextImpl ctx) { return ActivityTaskManager.getInstance(); }})300 registerService(Context.ACTIVITY_TASK_SERVICE, ActivityTaskManager.class, 301 new CachedServiceFetcher<ActivityTaskManager>() { 302 @Override 303 public ActivityTaskManager createService(ContextImpl ctx) { 304 return ActivityTaskManager.getInstance(); 305 }}); 306 registerService(Context.URI_GRANTS_SERVICE, UriGrantsManager.class, new CachedServiceFetcher<UriGrantsManager>() { @Override public UriGrantsManager createService(ContextImpl ctx) { return new UriGrantsManager( ctx.getOuterContext(), ctx.mMainThread.getHandler()); }})307 registerService(Context.URI_GRANTS_SERVICE, UriGrantsManager.class, 308 new CachedServiceFetcher<UriGrantsManager>() { 309 @Override 310 public UriGrantsManager createService(ContextImpl ctx) { 311 return new UriGrantsManager( 312 ctx.getOuterContext(), ctx.mMainThread.getHandler()); 313 }}); 314 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); }})315 registerService(Context.ALARM_SERVICE, AlarmManager.class, 316 new CachedServiceFetcher<AlarmManager>() { 317 @Override 318 public AlarmManager createService(ContextImpl ctx) throws ServiceNotFoundException { 319 IBinder b = ServiceManager.getServiceOrThrow(Context.ALARM_SERVICE); 320 IAlarmManager service = IAlarmManager.Stub.asInterface(b); 321 return new AlarmManager(service, ctx); 322 }}); 323 registerService(Context.AUDIO_SERVICE, AudioManager.class, new CachedServiceFetcher<AudioManager>() { @Override public AudioManager createService(ContextImpl ctx) { return new AudioManager(ctx); }})324 registerService(Context.AUDIO_SERVICE, AudioManager.class, 325 new CachedServiceFetcher<AudioManager>() { 326 @Override 327 public AudioManager createService(ContextImpl ctx) { 328 return new AudioManager(ctx); 329 }}); 330 registerService(Context.MEDIA_ROUTER_SERVICE, MediaRouter.class, new CachedServiceFetcher<MediaRouter>() { @Override public MediaRouter createService(ContextImpl ctx) { return new MediaRouter(ctx); }})331 registerService(Context.MEDIA_ROUTER_SERVICE, MediaRouter.class, 332 new CachedServiceFetcher<MediaRouter>() { 333 @Override 334 public MediaRouter createService(ContextImpl ctx) { 335 return new MediaRouter(ctx); 336 }}); 337 registerService(Context.BLUETOOTH_SERVICE, BluetoothManager.class, new CachedServiceFetcher<BluetoothManager>() { @Override public BluetoothManager createService(ContextImpl ctx) { return new BluetoothManager(ctx); }})338 registerService(Context.BLUETOOTH_SERVICE, BluetoothManager.class, 339 new CachedServiceFetcher<BluetoothManager>() { 340 @Override 341 public BluetoothManager createService(ContextImpl ctx) { 342 return new BluetoothManager(ctx); 343 }}); 344 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)); }})345 registerService(Context.HDMI_CONTROL_SERVICE, HdmiControlManager.class, 346 new StaticServiceFetcher<HdmiControlManager>() { 347 @Override 348 public HdmiControlManager createService() throws ServiceNotFoundException { 349 IBinder b = ServiceManager.getServiceOrThrow(Context.HDMI_CONTROL_SERVICE); 350 return new HdmiControlManager(IHdmiControlService.Stub.asInterface(b)); 351 }}); 352 registerService(Context.TEXT_CLASSIFICATION_SERVICE, TextClassificationManager.class, new CachedServiceFetcher<TextClassificationManager>() { @Override public TextClassificationManager createService(ContextImpl ctx) { return new TextClassificationManager(ctx); }})353 registerService(Context.TEXT_CLASSIFICATION_SERVICE, TextClassificationManager.class, 354 new CachedServiceFetcher<TextClassificationManager>() { 355 @Override 356 public TextClassificationManager createService(ContextImpl ctx) { 357 return new TextClassificationManager(ctx); 358 }}); 359 registerService(Context.FONT_SERVICE, FontManager.class, new CachedServiceFetcher<FontManager>() { @Override public FontManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.FONT_SERVICE); return FontManager.create(IFontManager.Stub.asInterface(b)); }})360 registerService(Context.FONT_SERVICE, FontManager.class, 361 new CachedServiceFetcher<FontManager>() { 362 @Override 363 public FontManager createService(ContextImpl ctx) throws ServiceNotFoundException { 364 IBinder b = ServiceManager.getServiceOrThrow(Context.FONT_SERVICE); 365 return FontManager.create(IFontManager.Stub.asInterface(b)); 366 }}); 367 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()); }})368 registerService(Context.CLIPBOARD_SERVICE, ClipboardManager.class, 369 new CachedServiceFetcher<ClipboardManager>() { 370 @Override 371 public ClipboardManager createService(ContextImpl ctx) throws ServiceNotFoundException { 372 return new ClipboardManager(ctx.getOuterContext(), 373 ctx.mMainThread.getHandler()); 374 }}); 375 376 // The clipboard service moved to a new package. If someone asks for the old 377 // interface by class then we want to redirect over to the new interface instead 378 // (which extends it). SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE)379 SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE); 380 registerService(Context.PAC_PROXY_SERVICE, PacProxyManager.class, new CachedServiceFetcher<PacProxyManager>() { @Override public PacProxyManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.PAC_PROXY_SERVICE); IPacProxyManager service = IPacProxyManager.Stub.asInterface(b); return new PacProxyManager(ctx.getOuterContext(), service); }})381 registerService(Context.PAC_PROXY_SERVICE, PacProxyManager.class, 382 new CachedServiceFetcher<PacProxyManager>() { 383 @Override 384 public PacProxyManager createService(ContextImpl ctx) throws ServiceNotFoundException { 385 IBinder b = ServiceManager.getServiceOrThrow(Context.PAC_PROXY_SERVICE); 386 IPacProxyManager service = IPacProxyManager.Stub.asInterface(b); 387 return new PacProxyManager(ctx.getOuterContext(), service); 388 }}); 389 registerService(Context.NETD_SERVICE, IBinder.class, new StaticServiceFetcher<IBinder>() { @Override public IBinder createService() throws ServiceNotFoundException { return ServiceManager.getServiceOrThrow(Context.NETD_SERVICE); } })390 registerService(Context.NETD_SERVICE, IBinder.class, new StaticServiceFetcher<IBinder>() { 391 @Override 392 public IBinder createService() throws ServiceNotFoundException { 393 return ServiceManager.getServiceOrThrow(Context.NETD_SERVICE); 394 } 395 }); 396 registerService(Context.TETHERING_SERVICE, TetheringManager.class, new CachedServiceFetcher<TetheringManager>() { @Override public TetheringManager createService(ContextImpl ctx) { return new TetheringManager( ctx, () -> ServiceManager.getService(Context.TETHERING_SERVICE)); }})397 registerService(Context.TETHERING_SERVICE, TetheringManager.class, 398 new CachedServiceFetcher<TetheringManager>() { 399 @Override 400 public TetheringManager createService(ContextImpl ctx) { 401 return new TetheringManager( 402 ctx, () -> ServiceManager.getService(Context.TETHERING_SERVICE)); 403 }}); 404 registerService(Context.VPN_MANAGEMENT_SERVICE, VpnManager.class, new CachedServiceFetcher<VpnManager>() { @Override public VpnManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getService(Context.VPN_MANAGEMENT_SERVICE); IVpnManager service = IVpnManager.Stub.asInterface(b); return new VpnManager(ctx, service); }})405 registerService(Context.VPN_MANAGEMENT_SERVICE, VpnManager.class, 406 new CachedServiceFetcher<VpnManager>() { 407 @Override 408 public VpnManager createService(ContextImpl ctx) throws ServiceNotFoundException { 409 IBinder b = ServiceManager.getService(Context.VPN_MANAGEMENT_SERVICE); 410 IVpnManager service = IVpnManager.Stub.asInterface(b); 411 return new VpnManager(ctx, service); 412 }}); 413 registerService(Context.VCN_MANAGEMENT_SERVICE, VcnManager.class, new CachedServiceFetcher<VcnManager>() { @Override public VcnManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getService(Context.VCN_MANAGEMENT_SERVICE); IVcnManagementService service = IVcnManagementService.Stub.asInterface(b); return new VcnManager(ctx, service); }})414 registerService(Context.VCN_MANAGEMENT_SERVICE, VcnManager.class, 415 new CachedServiceFetcher<VcnManager>() { 416 @Override 417 public VcnManager createService(ContextImpl ctx) throws ServiceNotFoundException { 418 IBinder b = ServiceManager.getService(Context.VCN_MANAGEMENT_SERVICE); 419 IVcnManagementService service = IVcnManagementService.Stub.asInterface(b); 420 return new VcnManager(ctx, service); 421 }}); 422 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); }})423 registerService(Context.IPSEC_SERVICE, IpSecManager.class, 424 new CachedServiceFetcher<IpSecManager>() { 425 @Override 426 public IpSecManager createService(ContextImpl ctx) throws ServiceNotFoundException { 427 IBinder b = ServiceManager.getService(Context.IPSEC_SERVICE); 428 IIpSecService service = IIpSecService.Stub.asInterface(b); 429 return new IpSecManager(ctx, service); 430 }}); 431 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)); }})432 registerService(Context.COUNTRY_DETECTOR, CountryDetector.class, 433 new StaticServiceFetcher<CountryDetector>() { 434 @Override 435 public CountryDetector createService() throws ServiceNotFoundException { 436 IBinder b = ServiceManager.getServiceOrThrow(Context.COUNTRY_DETECTOR); 437 return new CountryDetector(ICountryDetector.Stub.asInterface(b)); 438 }}); 439 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)); }})440 registerService(Context.DEVICE_POLICY_SERVICE, DevicePolicyManager.class, 441 new CachedServiceFetcher<DevicePolicyManager>() { 442 @Override 443 public DevicePolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { 444 IBinder b = ServiceManager.getServiceOrThrow(Context.DEVICE_POLICY_SERVICE); 445 return new DevicePolicyManager(ctx, IDevicePolicyManager.Stub.asInterface(b)); 446 }}); 447 registerService(Context.DOWNLOAD_SERVICE, DownloadManager.class, new CachedServiceFetcher<DownloadManager>() { @Override public DownloadManager createService(ContextImpl ctx) { return new DownloadManager(ctx); }})448 registerService(Context.DOWNLOAD_SERVICE, DownloadManager.class, 449 new CachedServiceFetcher<DownloadManager>() { 450 @Override 451 public DownloadManager createService(ContextImpl ctx) { 452 return new DownloadManager(ctx); 453 }}); 454 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); }})455 registerService(Context.BATTERY_SERVICE, BatteryManager.class, 456 new CachedServiceFetcher<BatteryManager>() { 457 @Override 458 public BatteryManager createService(ContextImpl ctx) throws ServiceNotFoundException { 459 IBatteryStats stats = IBatteryStats.Stub.asInterface( 460 ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME)); 461 IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub 462 .asInterface(ServiceManager.getServiceOrThrow("batteryproperties")); 463 return new BatteryManager(ctx, stats, registrar); 464 }}); 465 registerService(Context.NFC_SERVICE, NfcManager.class, new CachedServiceFetcher<NfcManager>() { @Override public NfcManager createService(ContextImpl ctx) { return new NfcManager(ctx); }})466 registerService(Context.NFC_SERVICE, NfcManager.class, 467 new CachedServiceFetcher<NfcManager>() { 468 @Override 469 public NfcManager createService(ContextImpl ctx) { 470 return new NfcManager(ctx); 471 }}); 472 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); }})473 registerService(Context.DROPBOX_SERVICE, DropBoxManager.class, 474 new CachedServiceFetcher<DropBoxManager>() { 475 @Override 476 public DropBoxManager createService(ContextImpl ctx) throws ServiceNotFoundException { 477 IBinder b = ServiceManager.getServiceOrThrow(Context.DROPBOX_SERVICE); 478 IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b); 479 return new DropBoxManager(ctx, service); 480 }}); 481 registerService(Context.INPUT_SERVICE, InputManager.class, new StaticServiceFetcher<InputManager>() { @Override public InputManager createService() { return InputManager.getInstance(); }})482 registerService(Context.INPUT_SERVICE, InputManager.class, 483 new StaticServiceFetcher<InputManager>() { 484 @Override 485 public InputManager createService() { 486 return InputManager.getInstance(); 487 }}); 488 registerService(Context.DISPLAY_SERVICE, DisplayManager.class, new CachedServiceFetcher<DisplayManager>() { @Override public DisplayManager createService(ContextImpl ctx) { return new DisplayManager(ctx.getOuterContext()); }})489 registerService(Context.DISPLAY_SERVICE, DisplayManager.class, 490 new CachedServiceFetcher<DisplayManager>() { 491 @Override 492 public DisplayManager createService(ContextImpl ctx) { 493 return new DisplayManager(ctx.getOuterContext()); 494 }}); 495 registerService(Context.COLOR_DISPLAY_SERVICE, ColorDisplayManager.class, new CachedServiceFetcher<ColorDisplayManager>() { @Override public ColorDisplayManager createService(ContextImpl ctx) { return new ColorDisplayManager(); } })496 registerService(Context.COLOR_DISPLAY_SERVICE, ColorDisplayManager.class, 497 new CachedServiceFetcher<ColorDisplayManager>() { 498 @Override 499 public ColorDisplayManager createService(ContextImpl ctx) { 500 return new ColorDisplayManager(); 501 } 502 }); 503 504 // InputMethodManager has its own cache strategy based on display id to support apps that 505 // still assume InputMethodManager is a per-process singleton and it's safe to directly 506 // access internal fields via reflection. Hence directly use ServiceFetcher instead of 507 // StaticServiceFetcher/CachedServiceFetcher. registerService(Context.INPUT_METHOD_SERVICE, InputMethodManager.class, new ServiceFetcher<InputMethodManager>() { @Override public InputMethodManager getService(ContextImpl ctx) { return InputMethodManager.forContext(ctx.getOuterContext()); }})508 registerService(Context.INPUT_METHOD_SERVICE, InputMethodManager.class, 509 new ServiceFetcher<InputMethodManager>() { 510 @Override 511 public InputMethodManager getService(ContextImpl ctx) { 512 return InputMethodManager.forContext(ctx.getOuterContext()); 513 }}); 514 registerService(Context.TEXT_SERVICES_MANAGER_SERVICE, TextServicesManager.class, new CachedServiceFetcher<TextServicesManager>() { @Override public TextServicesManager createService(ContextImpl ctx) throws ServiceNotFoundException { return TextServicesManager.createInstance(ctx); }})515 registerService(Context.TEXT_SERVICES_MANAGER_SERVICE, TextServicesManager.class, 516 new CachedServiceFetcher<TextServicesManager>() { 517 @Override 518 public TextServicesManager createService(ContextImpl ctx) 519 throws ServiceNotFoundException { 520 return TextServicesManager.createInstance(ctx); 521 }}); 522 registerService(Context.KEYGUARD_SERVICE, KeyguardManager.class, new CachedServiceFetcher<KeyguardManager>() { @Override public KeyguardManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new KeyguardManager(ctx); }})523 registerService(Context.KEYGUARD_SERVICE, KeyguardManager.class, 524 new CachedServiceFetcher<KeyguardManager>() { 525 @Override 526 public KeyguardManager createService(ContextImpl ctx) throws ServiceNotFoundException { 527 return new KeyguardManager(ctx); 528 }}); 529 registerService(Context.LAYOUT_INFLATER_SERVICE, LayoutInflater.class, new CachedServiceFetcher<LayoutInflater>() { @Override public LayoutInflater createService(ContextImpl ctx) { return new PhoneLayoutInflater(ctx.getOuterContext()); }})530 registerService(Context.LAYOUT_INFLATER_SERVICE, LayoutInflater.class, 531 new CachedServiceFetcher<LayoutInflater>() { 532 @Override 533 public LayoutInflater createService(ContextImpl ctx) { 534 return new PhoneLayoutInflater(ctx.getOuterContext()); 535 }}); 536 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)); }})537 registerService(Context.LOCATION_SERVICE, LocationManager.class, 538 new CachedServiceFetcher<LocationManager>() { 539 @Override 540 public LocationManager createService(ContextImpl ctx) throws ServiceNotFoundException { 541 IBinder b = ServiceManager.getServiceOrThrow(Context.LOCATION_SERVICE); 542 return new LocationManager(ctx, ILocationManager.Stub.asInterface(b)); 543 }}); 544 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))); }})545 registerService(Context.NETWORK_POLICY_SERVICE, NetworkPolicyManager.class, 546 new CachedServiceFetcher<NetworkPolicyManager>() { 547 @Override 548 public NetworkPolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { 549 return new NetworkPolicyManager(ctx, INetworkPolicyManager.Stub.asInterface( 550 ServiceManager.getServiceOrThrow(Context.NETWORK_POLICY_SERVICE))); 551 }}); 552 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()); }})553 registerService(Context.NOTIFICATION_SERVICE, NotificationManager.class, 554 new CachedServiceFetcher<NotificationManager>() { 555 @Override 556 public NotificationManager createService(ContextImpl ctx) { 557 final Context outerContext = ctx.getOuterContext(); 558 return new NotificationManager( 559 new ContextThemeWrapper(outerContext, 560 Resources.selectSystemTheme(0, 561 outerContext.getApplicationInfo().targetSdkVersion, 562 com.android.internal.R.style.Theme_Dialog, 563 com.android.internal.R.style.Theme_Holo_Dialog, 564 com.android.internal.R.style.Theme_DeviceDefault_Dialog, 565 com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog)), 566 ctx.mMainThread.getHandler()); 567 }}); 568 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); }})569 registerService(Context.NSD_SERVICE, NsdManager.class, 570 new CachedServiceFetcher<NsdManager>() { 571 @Override 572 public NsdManager createService(ContextImpl ctx) throws ServiceNotFoundException { 573 IBinder b = ServiceManager.getServiceOrThrow(Context.NSD_SERVICE); 574 INsdManager service = INsdManager.Stub.asInterface(b); 575 return new NsdManager(ctx.getOuterContext(), service); 576 }}); 577 registerService(Context.PEOPLE_SERVICE, PeopleManager.class, new CachedServiceFetcher<PeopleManager>() { @Override public PeopleManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new PeopleManager(ctx); }})578 registerService(Context.PEOPLE_SERVICE, PeopleManager.class, 579 new CachedServiceFetcher<PeopleManager>() { 580 @Override 581 public PeopleManager createService(ContextImpl ctx) throws ServiceNotFoundException { 582 return new PeopleManager(ctx); 583 }}); 584 registerService(Context.POWER_SERVICE, PowerManager.class, new CachedServiceFetcher<PowerManager>() { @Override public PowerManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder powerBinder = ServiceManager.getServiceOrThrow(Context.POWER_SERVICE); IPowerManager powerService = IPowerManager.Stub.asInterface(powerBinder); IBinder thermalBinder = ServiceManager.getServiceOrThrow(Context.THERMAL_SERVICE); IThermalService thermalService = IThermalService.Stub.asInterface(thermalBinder); return new PowerManager(ctx.getOuterContext(), powerService, thermalService, ctx.mMainThread.getHandler()); }})585 registerService(Context.POWER_SERVICE, PowerManager.class, 586 new CachedServiceFetcher<PowerManager>() { 587 @Override 588 public PowerManager createService(ContextImpl ctx) throws ServiceNotFoundException { 589 IBinder powerBinder = ServiceManager.getServiceOrThrow(Context.POWER_SERVICE); 590 IPowerManager powerService = IPowerManager.Stub.asInterface(powerBinder); 591 IBinder thermalBinder = ServiceManager.getServiceOrThrow(Context.THERMAL_SERVICE); 592 IThermalService thermalService = IThermalService.Stub.asInterface(thermalBinder); 593 return new PowerManager(ctx.getOuterContext(), powerService, thermalService, 594 ctx.mMainThread.getHandler()); 595 }}); 596 registerService(Context.PERFORMANCE_HINT_SERVICE, PerformanceHintManager.class, new CachedServiceFetcher<PerformanceHintManager>() { @Override public PerformanceHintManager createService(ContextImpl ctx) throws ServiceNotFoundException { return PerformanceHintManager.create(); }})597 registerService(Context.PERFORMANCE_HINT_SERVICE, PerformanceHintManager.class, 598 new CachedServiceFetcher<PerformanceHintManager>() { 599 @Override 600 public PerformanceHintManager createService(ContextImpl ctx) 601 throws ServiceNotFoundException { 602 return PerformanceHintManager.create(); 603 }}); 604 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); }})605 registerService(Context.RECOVERY_SERVICE, RecoverySystem.class, 606 new CachedServiceFetcher<RecoverySystem>() { 607 @Override 608 public RecoverySystem createService(ContextImpl ctx) throws ServiceNotFoundException { 609 IBinder b = ServiceManager.getServiceOrThrow(Context.RECOVERY_SERVICE); 610 IRecoverySystem service = IRecoverySystem.Stub.asInterface(b); 611 return new RecoverySystem(service); 612 }}); 613 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()); }})614 registerService(Context.SEARCH_SERVICE, SearchManager.class, 615 new CachedServiceFetcher<SearchManager>() { 616 @Override 617 public SearchManager createService(ContextImpl ctx) throws ServiceNotFoundException { 618 return new SearchManager(ctx.getOuterContext(), 619 ctx.mMainThread.getHandler()); 620 }}); 621 registerService(Context.SENSOR_SERVICE, SensorManager.class, new CachedServiceFetcher<SensorManager>() { @Override public SensorManager createService(ContextImpl ctx) { return new SystemSensorManager(ctx.getOuterContext(), ctx.mMainThread.getHandler().getLooper()); }})622 registerService(Context.SENSOR_SERVICE, SensorManager.class, 623 new CachedServiceFetcher<SensorManager>() { 624 @Override 625 public SensorManager createService(ContextImpl ctx) { 626 return new SystemSensorManager(ctx.getOuterContext(), 627 ctx.mMainThread.getHandler().getLooper()); 628 }}); 629 registerService(Context.SENSOR_PRIVACY_SERVICE, SensorPrivacyManager.class, new CachedServiceFetcher<SensorPrivacyManager>() { @Override public SensorPrivacyManager createService(ContextImpl ctx) { return SensorPrivacyManager.getInstance(ctx); }})630 registerService(Context.SENSOR_PRIVACY_SERVICE, SensorPrivacyManager.class, 631 new CachedServiceFetcher<SensorPrivacyManager>() { 632 @Override 633 public SensorPrivacyManager createService(ContextImpl ctx) { 634 return SensorPrivacyManager.getInstance(ctx); 635 }}); 636 registerService(Context.STATUS_BAR_SERVICE, StatusBarManager.class, new CachedServiceFetcher<StatusBarManager>() { @Override public StatusBarManager createService(ContextImpl ctx) { return new StatusBarManager(ctx.getOuterContext()); }})637 registerService(Context.STATUS_BAR_SERVICE, StatusBarManager.class, 638 new CachedServiceFetcher<StatusBarManager>() { 639 @Override 640 public StatusBarManager createService(ContextImpl ctx) { 641 return new StatusBarManager(ctx.getOuterContext()); 642 }}); 643 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()); }})644 registerService(Context.STORAGE_SERVICE, StorageManager.class, 645 new CachedServiceFetcher<StorageManager>() { 646 @Override 647 public StorageManager createService(ContextImpl ctx) throws ServiceNotFoundException { 648 return new StorageManager(ctx, ctx.mMainThread.getHandler().getLooper()); 649 }}); 650 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); }})651 registerService(Context.STORAGE_STATS_SERVICE, StorageStatsManager.class, 652 new CachedServiceFetcher<StorageStatsManager>() { 653 @Override 654 public StorageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { 655 IStorageStatsManager service = IStorageStatsManager.Stub.asInterface( 656 ServiceManager.getServiceOrThrow(Context.STORAGE_STATS_SERVICE)); 657 return new StorageStatsManager(ctx, service); 658 }}); 659 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); }})660 registerService(Context.SYSTEM_UPDATE_SERVICE, SystemUpdateManager.class, 661 new CachedServiceFetcher<SystemUpdateManager>() { 662 @Override 663 public SystemUpdateManager createService(ContextImpl ctx) 664 throws ServiceNotFoundException { 665 IBinder b = ServiceManager.getServiceOrThrow( 666 Context.SYSTEM_UPDATE_SERVICE); 667 ISystemUpdateManager service = ISystemUpdateManager.Stub.asInterface(b); 668 return new SystemUpdateManager(service); 669 }}); 670 registerService(Context.SYSTEM_CONFIG_SERVICE, SystemConfigManager.class, new CachedServiceFetcher<SystemConfigManager>() { @Override public SystemConfigManager createService(ContextImpl ctx) { return new SystemConfigManager(); }})671 registerService(Context.SYSTEM_CONFIG_SERVICE, SystemConfigManager.class, 672 new CachedServiceFetcher<SystemConfigManager>() { 673 @Override 674 public SystemConfigManager createService(ContextImpl ctx) { 675 return new SystemConfigManager(); 676 }}); 677 registerService(Context.TELEPHONY_REGISTRY_SERVICE, TelephonyRegistryManager.class, new CachedServiceFetcher<TelephonyRegistryManager>() { @Override public TelephonyRegistryManager createService(ContextImpl ctx) { return new TelephonyRegistryManager(ctx); }})678 registerService(Context.TELEPHONY_REGISTRY_SERVICE, TelephonyRegistryManager.class, 679 new CachedServiceFetcher<TelephonyRegistryManager>() { 680 @Override 681 public TelephonyRegistryManager createService(ContextImpl ctx) { 682 return new TelephonyRegistryManager(ctx); 683 }}); 684 registerService(Context.TELECOM_SERVICE, TelecomManager.class, new CachedServiceFetcher<TelecomManager>() { @Override public TelecomManager createService(ContextImpl ctx) { return new TelecomManager(ctx.getOuterContext()); }})685 registerService(Context.TELECOM_SERVICE, TelecomManager.class, 686 new CachedServiceFetcher<TelecomManager>() { 687 @Override 688 public TelecomManager createService(ContextImpl ctx) { 689 return new TelecomManager(ctx.getOuterContext()); 690 }}); 691 registerService(Context.MMS_SERVICE, MmsManager.class, new CachedServiceFetcher<MmsManager>() { @Override public MmsManager createService(ContextImpl ctx) { return new MmsManager(ctx.getOuterContext()); }})692 registerService(Context.MMS_SERVICE, MmsManager.class, 693 new CachedServiceFetcher<MmsManager>() { 694 @Override 695 public MmsManager createService(ContextImpl ctx) { 696 return new MmsManager(ctx.getOuterContext()); 697 }}); 698 registerService(Context.UI_MODE_SERVICE, UiModeManager.class, new CachedServiceFetcher<UiModeManager>() { @Override public UiModeManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new UiModeManager(ctx.getOuterContext()); }})699 registerService(Context.UI_MODE_SERVICE, UiModeManager.class, 700 new CachedServiceFetcher<UiModeManager>() { 701 @Override 702 public UiModeManager createService(ContextImpl ctx) throws ServiceNotFoundException { 703 return new UiModeManager(ctx.getOuterContext()); 704 }}); 705 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)); }})706 registerService(Context.USB_SERVICE, UsbManager.class, 707 new CachedServiceFetcher<UsbManager>() { 708 @Override 709 public UsbManager createService(ContextImpl ctx) throws ServiceNotFoundException { 710 IBinder b = ServiceManager.getServiceOrThrow(Context.USB_SERVICE); 711 return new UsbManager(ctx, IUsbManager.Stub.asInterface(b)); 712 }}); 713 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)); }})714 registerService(Context.ADB_SERVICE, AdbManager.class, 715 new CachedServiceFetcher<AdbManager>() { 716 @Override 717 public AdbManager createService(ContextImpl ctx) 718 throws ServiceNotFoundException { 719 IBinder b = ServiceManager.getServiceOrThrow(Context.ADB_SERVICE); 720 return new AdbManager(ctx, IAdbManager.Stub.asInterface(b)); 721 }}); 722 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)); }})723 registerService(Context.SERIAL_SERVICE, SerialManager.class, 724 new CachedServiceFetcher<SerialManager>() { 725 @Override 726 public SerialManager createService(ContextImpl ctx) throws ServiceNotFoundException { 727 IBinder b = ServiceManager.getServiceOrThrow(Context.SERIAL_SERVICE); 728 return new SerialManager(ctx, ISerialManager.Stub.asInterface(b)); 729 }}); 730 registerService(Context.UWB_SERVICE, UwbManager.class, new CachedServiceFetcher<UwbManager>() { @Override public UwbManager createService(ContextImpl ctx) { return UwbManager.getInstance(ctx); } })731 registerService(Context.UWB_SERVICE, UwbManager.class, 732 new CachedServiceFetcher<UwbManager>() { 733 @Override 734 public UwbManager createService(ContextImpl ctx) { 735 return UwbManager.getInstance(ctx); 736 } 737 }); 738 registerService(Context.VIBRATOR_MANAGER_SERVICE, VibratorManager.class, new CachedServiceFetcher<VibratorManager>() { @Override public VibratorManager createService(ContextImpl ctx) { return new SystemVibratorManager(ctx); }})739 registerService(Context.VIBRATOR_MANAGER_SERVICE, VibratorManager.class, 740 new CachedServiceFetcher<VibratorManager>() { 741 @Override 742 public VibratorManager createService(ContextImpl ctx) { 743 return new SystemVibratorManager(ctx); 744 }}); 745 registerService(Context.VIBRATOR_SERVICE, Vibrator.class, new CachedServiceFetcher<Vibrator>() { @Override public Vibrator createService(ContextImpl ctx) { return new SystemVibrator(ctx); }})746 registerService(Context.VIBRATOR_SERVICE, Vibrator.class, 747 new CachedServiceFetcher<Vibrator>() { 748 @Override 749 public Vibrator createService(ContextImpl ctx) { 750 return new SystemVibrator(ctx); 751 }}); 752 registerService(Context.WALLPAPER_SERVICE, WallpaperManager.class, new CachedServiceFetcher<WallpaperManager>() { @Override public WallpaperManager createService(ContextImpl ctx) throws ServiceNotFoundException { final IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE); if (b == null) { ApplicationInfo appInfo = ctx.getApplicationInfo(); if (appInfo.targetSdkVersion >= Build.VERSION_CODES.P && appInfo.isInstantApp()) { throw new ServiceNotFoundException(Context.WALLPAPER_SERVICE); } final boolean enabled = Resources.getSystem() .getBoolean(com.android.internal.R.bool.config_enableWallpaperService); if (!enabled) { return DisabledWallpaperManager.getInstance(); } Log.e(TAG, "No wallpaper service"); } IWallpaperManager service = IWallpaperManager.Stub.asInterface(b); return new WallpaperManager(service, ctx.getOuterContext(), ctx.mMainThread.getHandler()); }})753 registerService(Context.WALLPAPER_SERVICE, WallpaperManager.class, 754 new CachedServiceFetcher<WallpaperManager>() { 755 @Override 756 public WallpaperManager createService(ContextImpl ctx) 757 throws ServiceNotFoundException { 758 final IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE); 759 if (b == null) { 760 ApplicationInfo appInfo = ctx.getApplicationInfo(); 761 if (appInfo.targetSdkVersion >= Build.VERSION_CODES.P 762 && appInfo.isInstantApp()) { 763 // Instant app 764 throw new ServiceNotFoundException(Context.WALLPAPER_SERVICE); 765 } 766 final boolean enabled = Resources.getSystem() 767 .getBoolean(com.android.internal.R.bool.config_enableWallpaperService); 768 if (!enabled) { 769 // Device doesn't support wallpaper, return a limited manager 770 return DisabledWallpaperManager.getInstance(); 771 } 772 // Bad state - WallpaperManager methods will throw exception 773 Log.e(TAG, "No wallpaper service"); 774 } 775 IWallpaperManager service = IWallpaperManager.Stub.asInterface(b); 776 return new WallpaperManager(service, ctx.getOuterContext(), 777 ctx.mMainThread.getHandler()); 778 }}); 779 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); }})780 registerService(Context.LOWPAN_SERVICE, LowpanManager.class, 781 new CachedServiceFetcher<LowpanManager>() { 782 @Override 783 public LowpanManager createService(ContextImpl ctx) throws ServiceNotFoundException { 784 IBinder b = ServiceManager.getServiceOrThrow(Context.LOWPAN_SERVICE); 785 ILowpanManager service = ILowpanManager.Stub.asInterface(b); 786 return new LowpanManager(ctx.getOuterContext(), service); 787 }}); 788 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); }})789 registerService(Context.ETHERNET_SERVICE, EthernetManager.class, 790 new CachedServiceFetcher<EthernetManager>() { 791 @Override 792 public EthernetManager createService(ContextImpl ctx) throws ServiceNotFoundException { 793 IBinder b = ServiceManager.getServiceOrThrow(Context.ETHERNET_SERVICE); 794 IEthernetManager service = IEthernetManager.Stub.asInterface(b); 795 return new EthernetManager(ctx.getOuterContext(), service); 796 }}); 797 registerService(Context.WIFI_NL80211_SERVICE, WifiNl80211Manager.class, new CachedServiceFetcher<WifiNl80211Manager>() { @Override public WifiNl80211Manager createService(ContextImpl ctx) { return new WifiNl80211Manager(ctx.getOuterContext()); } })798 registerService(Context.WIFI_NL80211_SERVICE, WifiNl80211Manager.class, 799 new CachedServiceFetcher<WifiNl80211Manager>() { 800 @Override 801 public WifiNl80211Manager createService(ContextImpl ctx) { 802 return new WifiNl80211Manager(ctx.getOuterContext()); 803 } 804 }); 805 registerService(Context.WINDOW_SERVICE, WindowManager.class, new CachedServiceFetcher<WindowManager>() { @Override public WindowManager createService(ContextImpl ctx) { return new WindowManagerImpl(ctx); }})806 registerService(Context.WINDOW_SERVICE, WindowManager.class, 807 new CachedServiceFetcher<WindowManager>() { 808 @Override 809 public WindowManager createService(ContextImpl ctx) { 810 return new WindowManagerImpl(ctx); 811 }}); 812 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); }})813 registerService(Context.USER_SERVICE, UserManager.class, 814 new CachedServiceFetcher<UserManager>() { 815 @Override 816 public UserManager createService(ContextImpl ctx) throws ServiceNotFoundException { 817 IBinder b = ServiceManager.getServiceOrThrow(Context.USER_SERVICE); 818 IUserManager service = IUserManager.Stub.asInterface(b); 819 return new UserManager(ctx, service); 820 }}); 821 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); }})822 registerService(Context.APP_OPS_SERVICE, AppOpsManager.class, 823 new CachedServiceFetcher<AppOpsManager>() { 824 @Override 825 public AppOpsManager createService(ContextImpl ctx) throws ServiceNotFoundException { 826 IBinder b = ServiceManager.getServiceOrThrow(Context.APP_OPS_SERVICE); 827 IAppOpsService service = IAppOpsService.Stub.asInterface(b); 828 return new AppOpsManager(ctx, service); 829 }}); 830 registerService(Context.CAMERA_SERVICE, CameraManager.class, new CachedServiceFetcher<CameraManager>() { @Override public CameraManager createService(ContextImpl ctx) { return new CameraManager(ctx); }})831 registerService(Context.CAMERA_SERVICE, CameraManager.class, 832 new CachedServiceFetcher<CameraManager>() { 833 @Override 834 public CameraManager createService(ContextImpl ctx) { 835 return new CameraManager(ctx); 836 }}); 837 registerService(Context.LAUNCHER_APPS_SERVICE, LauncherApps.class, new CachedServiceFetcher<LauncherApps>() { @Override public LauncherApps createService(ContextImpl ctx) { return new LauncherApps(ctx); }})838 registerService(Context.LAUNCHER_APPS_SERVICE, LauncherApps.class, 839 new CachedServiceFetcher<LauncherApps>() { 840 @Override 841 public LauncherApps createService(ContextImpl ctx) { 842 return new LauncherApps(ctx); 843 }}); 844 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); }})845 registerService(Context.RESTRICTIONS_SERVICE, RestrictionsManager.class, 846 new CachedServiceFetcher<RestrictionsManager>() { 847 @Override 848 public RestrictionsManager createService(ContextImpl ctx) throws ServiceNotFoundException { 849 IBinder b = ServiceManager.getServiceOrThrow(Context.RESTRICTIONS_SERVICE); 850 IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b); 851 return new RestrictionsManager(ctx, service); 852 }}); 853 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); }})854 registerService(Context.PRINT_SERVICE, PrintManager.class, 855 new CachedServiceFetcher<PrintManager>() { 856 @Override 857 public PrintManager createService(ContextImpl ctx) throws ServiceNotFoundException { 858 IPrintManager service = null; 859 // If the feature not present, don't try to look up every time 860 if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PRINTING)) { 861 service = IPrintManager.Stub.asInterface(ServiceManager 862 .getServiceOrThrow(Context.PRINT_SERVICE)); 863 } 864 final int userId = ctx.getUserId(); 865 final int appId = UserHandle.getAppId(ctx.getApplicationInfo().uid); 866 return new PrintManager(ctx.getOuterContext(), service, userId, appId); 867 }}); 868 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()); }})869 registerService(Context.COMPANION_DEVICE_SERVICE, CompanionDeviceManager.class, 870 new CachedServiceFetcher<CompanionDeviceManager>() { 871 @Override 872 public CompanionDeviceManager createService(ContextImpl ctx) 873 throws ServiceNotFoundException { 874 ICompanionDeviceManager service = null; 875 // If the feature not present, don't try to look up every time 876 if (ctx.getPackageManager().hasSystemFeature( 877 PackageManager.FEATURE_COMPANION_DEVICE_SETUP)) { 878 service = ICompanionDeviceManager.Stub.asInterface( 879 ServiceManager.getServiceOrThrow(Context.COMPANION_DEVICE_SERVICE)); 880 } 881 return new CompanionDeviceManager(service, ctx.getOuterContext()); 882 }}); 883 registerService(Context.CONSUMER_IR_SERVICE, ConsumerIrManager.class, new CachedServiceFetcher<ConsumerIrManager>() { @Override public ConsumerIrManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new ConsumerIrManager(ctx); }})884 registerService(Context.CONSUMER_IR_SERVICE, ConsumerIrManager.class, 885 new CachedServiceFetcher<ConsumerIrManager>() { 886 @Override 887 public ConsumerIrManager createService(ContextImpl ctx) throws ServiceNotFoundException { 888 return new ConsumerIrManager(ctx); 889 }}); 890 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); }})891 registerService(Context.TRUST_SERVICE, TrustManager.class, 892 new StaticServiceFetcher<TrustManager>() { 893 @Override 894 public TrustManager createService() throws ServiceNotFoundException { 895 IBinder b = ServiceManager.getServiceOrThrow(Context.TRUST_SERVICE); 896 return new TrustManager(b); 897 }}); 898 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); }})899 registerService(Context.FINGERPRINT_SERVICE, FingerprintManager.class, 900 new CachedServiceFetcher<FingerprintManager>() { 901 @Override 902 public FingerprintManager createService(ContextImpl ctx) throws ServiceNotFoundException { 903 final IBinder binder; 904 if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { 905 binder = ServiceManager.getServiceOrThrow(Context.FINGERPRINT_SERVICE); 906 } else { 907 binder = ServiceManager.getService(Context.FINGERPRINT_SERVICE); 908 } 909 IFingerprintService service = IFingerprintService.Stub.asInterface(binder); 910 return new FingerprintManager(ctx.getOuterContext(), service); 911 }}); 912 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); } })913 registerService(Context.FACE_SERVICE, FaceManager.class, 914 new CachedServiceFetcher<FaceManager>() { 915 @Override 916 public FaceManager createService(ContextImpl ctx) 917 throws ServiceNotFoundException { 918 final IBinder binder; 919 if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { 920 binder = ServiceManager.getServiceOrThrow(Context.FACE_SERVICE); 921 } else { 922 binder = ServiceManager.getService(Context.FACE_SERVICE); 923 } 924 IFaceService service = IFaceService.Stub.asInterface(binder); 925 return new FaceManager(ctx.getOuterContext(), service); 926 } 927 }); 928 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); } })929 registerService(Context.IRIS_SERVICE, IrisManager.class, 930 new CachedServiceFetcher<IrisManager>() { 931 @Override 932 public IrisManager createService(ContextImpl ctx) 933 throws ServiceNotFoundException { 934 final IBinder binder = 935 ServiceManager.getServiceOrThrow(Context.IRIS_SERVICE); 936 IIrisService service = IIrisService.Stub.asInterface(binder); 937 return new IrisManager(ctx.getOuterContext(), service); 938 } 939 }); 940 registerService(Context.BIOMETRIC_SERVICE, BiometricManager.class, new CachedServiceFetcher<BiometricManager>() { @Override public BiometricManager createService(ContextImpl ctx) throws ServiceNotFoundException { final IBinder binder = ServiceManager.getServiceOrThrow(Context.AUTH_SERVICE); final IAuthService service = IAuthService.Stub.asInterface(binder); return new BiometricManager(ctx.getOuterContext(), service); } })941 registerService(Context.BIOMETRIC_SERVICE, BiometricManager.class, 942 new CachedServiceFetcher<BiometricManager>() { 943 @Override 944 public BiometricManager createService(ContextImpl ctx) 945 throws ServiceNotFoundException { 946 final IBinder binder = 947 ServiceManager.getServiceOrThrow(Context.AUTH_SERVICE); 948 final IAuthService service = 949 IAuthService.Stub.asInterface(binder); 950 return new BiometricManager(ctx.getOuterContext(), service); 951 } 952 }); 953 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()); }})954 registerService(Context.TV_INPUT_SERVICE, TvInputManager.class, 955 new CachedServiceFetcher<TvInputManager>() { 956 @Override 957 public TvInputManager createService(ContextImpl ctx) throws ServiceNotFoundException { 958 IBinder iBinder = ServiceManager.getServiceOrThrow(Context.TV_INPUT_SERVICE); 959 ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder); 960 return new TvInputManager(service, ctx.getUserId()); 961 }}); 962 registerService(Context.TV_TUNER_RESOURCE_MGR_SERVICE, TunerResourceManager.class, new CachedServiceFetcher<TunerResourceManager>() { @Override public TunerResourceManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder iBinder = ServiceManager.getServiceOrThrow(Context.TV_TUNER_RESOURCE_MGR_SERVICE); ITunerResourceManager service = ITunerResourceManager.Stub.asInterface(iBinder); return new TunerResourceManager(service, ctx.getUserId()); }})963 registerService(Context.TV_TUNER_RESOURCE_MGR_SERVICE, TunerResourceManager.class, 964 new CachedServiceFetcher<TunerResourceManager>() { 965 @Override 966 public TunerResourceManager createService(ContextImpl ctx) 967 throws ServiceNotFoundException { 968 IBinder iBinder = 969 ServiceManager.getServiceOrThrow(Context.TV_TUNER_RESOURCE_MGR_SERVICE); 970 ITunerResourceManager service = ITunerResourceManager.Stub.asInterface(iBinder); 971 return new TunerResourceManager(service, ctx.getUserId()); 972 }}); 973 registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class, new CachedServiceFetcher<NetworkScoreManager>() { @Override public NetworkScoreManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new NetworkScoreManager(ctx); }})974 registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class, 975 new CachedServiceFetcher<NetworkScoreManager>() { 976 @Override 977 public NetworkScoreManager createService(ContextImpl ctx) throws ServiceNotFoundException { 978 return new NetworkScoreManager(ctx); 979 }}); 980 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); }})981 registerService(Context.USAGE_STATS_SERVICE, UsageStatsManager.class, 982 new CachedServiceFetcher<UsageStatsManager>() { 983 @Override 984 public UsageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { 985 IBinder iBinder = ServiceManager.getServiceOrThrow(Context.USAGE_STATS_SERVICE); 986 IUsageStatsManager service = IUsageStatsManager.Stub.asInterface(iBinder); 987 return new UsageStatsManager(ctx.getOuterContext(), service); 988 }}); 989 registerService(Context.NETWORK_STATS_SERVICE, NetworkStatsManager.class, new CachedServiceFetcher<NetworkStatsManager>() { @Override public NetworkStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new NetworkStatsManager(ctx.getOuterContext()); }})990 registerService(Context.NETWORK_STATS_SERVICE, NetworkStatsManager.class, 991 new CachedServiceFetcher<NetworkStatsManager>() { 992 @Override 993 public NetworkStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { 994 return new NetworkStatsManager(ctx.getOuterContext()); 995 }}); 996 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; } }})997 registerService(Context.PERSISTENT_DATA_BLOCK_SERVICE, PersistentDataBlockManager.class, 998 new StaticServiceFetcher<PersistentDataBlockManager>() { 999 @Override 1000 public PersistentDataBlockManager createService() throws ServiceNotFoundException { 1001 IBinder b = ServiceManager.getServiceOrThrow(Context.PERSISTENT_DATA_BLOCK_SERVICE); 1002 IPersistentDataBlockService persistentDataBlockService = 1003 IPersistentDataBlockService.Stub.asInterface(b); 1004 if (persistentDataBlockService != null) { 1005 return new PersistentDataBlockManager(persistentDataBlockService); 1006 } else { 1007 // not supported 1008 return null; 1009 } 1010 }}); 1011 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; } }})1012 registerService(Context.OEM_LOCK_SERVICE, OemLockManager.class, 1013 new StaticServiceFetcher<OemLockManager>() { 1014 @Override 1015 public OemLockManager createService() throws ServiceNotFoundException { 1016 IBinder b = ServiceManager.getServiceOrThrow(Context.OEM_LOCK_SERVICE); 1017 IOemLockService oemLockService = IOemLockService.Stub.asInterface(b); 1018 if (oemLockService != null) { 1019 return new OemLockManager(oemLockService); 1020 } else { 1021 // not supported 1022 return null; 1023 } 1024 }}); 1025 registerService(Context.MEDIA_PROJECTION_SERVICE, MediaProjectionManager.class, new CachedServiceFetcher<MediaProjectionManager>() { @Override public MediaProjectionManager createService(ContextImpl ctx) { return new MediaProjectionManager(ctx); }})1026 registerService(Context.MEDIA_PROJECTION_SERVICE, MediaProjectionManager.class, 1027 new CachedServiceFetcher<MediaProjectionManager>() { 1028 @Override 1029 public MediaProjectionManager createService(ContextImpl ctx) { 1030 return new MediaProjectionManager(ctx); 1031 }}); 1032 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)); }})1033 registerService(Context.APPWIDGET_SERVICE, AppWidgetManager.class, 1034 new CachedServiceFetcher<AppWidgetManager>() { 1035 @Override 1036 public AppWidgetManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1037 IBinder b = ServiceManager.getServiceOrThrow(Context.APPWIDGET_SERVICE); 1038 return new AppWidgetManager(ctx, IAppWidgetService.Stub.asInterface(b)); 1039 }}); 1040 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)); }})1041 registerService(Context.MIDI_SERVICE, MidiManager.class, 1042 new CachedServiceFetcher<MidiManager>() { 1043 @Override 1044 public MidiManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1045 IBinder b = ServiceManager.getServiceOrThrow(Context.MIDI_SERVICE); 1046 return new MidiManager(IMidiManager.Stub.asInterface(b)); 1047 }}); 1048 registerService(Context.RADIO_SERVICE, RadioManager.class, new CachedServiceFetcher<RadioManager>() { @Override public RadioManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new RadioManager(ctx); }})1049 registerService(Context.RADIO_SERVICE, RadioManager.class, 1050 new CachedServiceFetcher<RadioManager>() { 1051 @Override 1052 public RadioManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1053 return new RadioManager(ctx); 1054 }}); 1055 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); }})1056 registerService(Context.HARDWARE_PROPERTIES_SERVICE, HardwarePropertiesManager.class, 1057 new CachedServiceFetcher<HardwarePropertiesManager>() { 1058 @Override 1059 public HardwarePropertiesManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1060 IBinder b = ServiceManager.getServiceOrThrow(Context.HARDWARE_PROPERTIES_SERVICE); 1061 IHardwarePropertiesManager service = 1062 IHardwarePropertiesManager.Stub.asInterface(b); 1063 return new HardwarePropertiesManager(ctx, service); 1064 }}); 1065 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)); }})1066 registerService(Context.SOUND_TRIGGER_SERVICE, SoundTriggerManager.class, 1067 new CachedServiceFetcher<SoundTriggerManager>() { 1068 @Override 1069 public SoundTriggerManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1070 IBinder b = ServiceManager.getServiceOrThrow(Context.SOUND_TRIGGER_SERVICE); 1071 return new SoundTriggerManager(ctx, ISoundTriggerService.Stub.asInterface(b)); 1072 }}); 1073 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)); }})1074 registerService(Context.SHORTCUT_SERVICE, ShortcutManager.class, 1075 new CachedServiceFetcher<ShortcutManager>() { 1076 @Override 1077 public ShortcutManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1078 IBinder b = ServiceManager.getServiceOrThrow(Context.SHORTCUT_SERVICE); 1079 return new ShortcutManager(ctx, IShortcutService.Stub.asInterface(b)); 1080 }}); 1081 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)); }})1082 registerService(Context.OVERLAY_SERVICE, OverlayManager.class, 1083 new CachedServiceFetcher<OverlayManager>() { 1084 @Override 1085 public OverlayManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1086 IBinder b = ServiceManager.getServiceOrThrow(Context.OVERLAY_SERVICE); 1087 return new OverlayManager(ctx, IOverlayManager.Stub.asInterface(b)); 1088 }}); 1089 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)); }})1090 registerService(Context.NETWORK_WATCHLIST_SERVICE, NetworkWatchlistManager.class, 1091 new CachedServiceFetcher<NetworkWatchlistManager>() { 1092 @Override 1093 public NetworkWatchlistManager createService(ContextImpl ctx) 1094 throws ServiceNotFoundException { 1095 IBinder b = 1096 ServiceManager.getServiceOrThrow(Context.NETWORK_WATCHLIST_SERVICE); 1097 return new NetworkWatchlistManager(ctx, 1098 INetworkWatchlistManager.Stub.asInterface(b)); 1099 }}); 1100 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)); }})1101 registerService(Context.SYSTEM_HEALTH_SERVICE, SystemHealthManager.class, 1102 new CachedServiceFetcher<SystemHealthManager>() { 1103 @Override 1104 public SystemHealthManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1105 IBinder b = ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME); 1106 return new SystemHealthManager(IBatteryStats.Stub.asInterface(b)); 1107 }}); 1108 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()); }})1109 registerService(Context.CONTEXTHUB_SERVICE, ContextHubManager.class, 1110 new CachedServiceFetcher<ContextHubManager>() { 1111 @Override 1112 public ContextHubManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1113 return new ContextHubManager(ctx.getOuterContext(), 1114 ctx.mMainThread.getHandler().getLooper()); 1115 }}); 1116 registerService(Context.INCIDENT_SERVICE, IncidentManager.class, new CachedServiceFetcher<IncidentManager>() { @Override public IncidentManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new IncidentManager(ctx); }})1117 registerService(Context.INCIDENT_SERVICE, IncidentManager.class, 1118 new CachedServiceFetcher<IncidentManager>() { 1119 @Override 1120 public IncidentManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1121 return new IncidentManager(ctx); 1122 }}); 1123 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)); }})1124 registerService(Context.BUGREPORT_SERVICE, BugreportManager.class, 1125 new CachedServiceFetcher<BugreportManager>() { 1126 @Override 1127 public BugreportManager createService(ContextImpl ctx) 1128 throws ServiceNotFoundException { 1129 IBinder b = ServiceManager.getServiceOrThrow(Context.BUGREPORT_SERVICE); 1130 return new BugreportManager(ctx.getOuterContext(), 1131 IDumpstate.Stub.asInterface(b)); 1132 }}); 1133 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); }})1134 registerService(Context.AUTOFILL_MANAGER_SERVICE, AutofillManager.class, 1135 new CachedServiceFetcher<AutofillManager>() { 1136 @Override 1137 public AutofillManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1138 // Get the services without throwing as this is an optional feature 1139 IBinder b = ServiceManager.getService(Context.AUTOFILL_MANAGER_SERVICE); 1140 IAutoFillManager service = IAutoFillManager.Stub.asInterface(b); 1141 return new AutofillManager(ctx.getOuterContext(), service); 1142 }}); 1143 registerService(Context.MUSIC_RECOGNITION_SERVICE, MusicRecognitionManager.class, new CachedServiceFetcher<MusicRecognitionManager>() { @Override public MusicRecognitionManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService( Context.MUSIC_RECOGNITION_SERVICE); return new MusicRecognitionManager( IMusicRecognitionManager.Stub.asInterface(b)); } })1144 registerService(Context.MUSIC_RECOGNITION_SERVICE, MusicRecognitionManager.class, 1145 new CachedServiceFetcher<MusicRecognitionManager>() { 1146 @Override 1147 public MusicRecognitionManager createService(ContextImpl ctx) { 1148 IBinder b = ServiceManager.getService( 1149 Context.MUSIC_RECOGNITION_SERVICE); 1150 return new MusicRecognitionManager( 1151 IMusicRecognitionManager.Stub.asInterface(b)); 1152 } 1153 }); 1154 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; }})1155 registerService(Context.CONTENT_CAPTURE_MANAGER_SERVICE, ContentCaptureManager.class, 1156 new CachedServiceFetcher<ContentCaptureManager>() { 1157 @Override 1158 public ContentCaptureManager createService(ContextImpl ctx) 1159 throws ServiceNotFoundException { 1160 // Get the services without throwing as this is an optional feature 1161 Context outerContext = ctx.getOuterContext(); 1162 ContentCaptureOptions options = outerContext.getContentCaptureOptions(); 1163 // Options is null when the service didn't allowlist the activity or package 1164 if (options != null && (options.lite || options.isWhitelisted(outerContext))) { 1165 IBinder b = ServiceManager 1166 .getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE); 1167 IContentCaptureManager service = IContentCaptureManager.Stub.asInterface(b); 1168 // Service is null when not provided by OEM or disabled by kill-switch. 1169 if (service != null) { 1170 return new ContentCaptureManager(outerContext, service, options); 1171 } 1172 } 1173 // When feature is disabled or app / package not allowlisted, we return a null 1174 // manager to apps so the performance impact is practically zero 1175 return null; 1176 }}); 1177 registerService(Context.TRANSLATION_MANAGER_SERVICE, TranslationManager.class, new CachedServiceFetcher<TranslationManager>() { @Override public TranslationManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getService(Context.TRANSLATION_MANAGER_SERVICE); ITranslationManager service = ITranslationManager.Stub.asInterface(b); if (service != null) { return new TranslationManager(ctx.getOuterContext(), service); } return null; }})1178 registerService(Context.TRANSLATION_MANAGER_SERVICE, TranslationManager.class, 1179 new CachedServiceFetcher<TranslationManager>() { 1180 @Override 1181 public TranslationManager createService(ContextImpl ctx) 1182 throws ServiceNotFoundException { 1183 IBinder b = ServiceManager.getService(Context.TRANSLATION_MANAGER_SERVICE); 1184 ITranslationManager service = ITranslationManager.Stub.asInterface(b); 1185 // Service is null when not provided by OEM. 1186 if (service != null) { 1187 return new TranslationManager(ctx.getOuterContext(), service); 1188 } 1189 return null; 1190 }}); 1191 registerService(Context.UI_TRANSLATION_SERVICE, UiTranslationManager.class, new CachedServiceFetcher<UiTranslationManager>() { @Override public UiTranslationManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getService(Context.TRANSLATION_MANAGER_SERVICE); ITranslationManager service = ITranslationManager.Stub.asInterface(b); if (service != null) { return new UiTranslationManager(ctx.getOuterContext(), service); } return null; }})1192 registerService(Context.UI_TRANSLATION_SERVICE, UiTranslationManager.class, 1193 new CachedServiceFetcher<UiTranslationManager>() { 1194 @Override 1195 public UiTranslationManager createService(ContextImpl ctx) 1196 throws ServiceNotFoundException { 1197 IBinder b = ServiceManager.getService(Context.TRANSLATION_MANAGER_SERVICE); 1198 ITranslationManager service = ITranslationManager.Stub.asInterface(b); 1199 if (service != null) { 1200 return new UiTranslationManager(ctx.getOuterContext(), service); 1201 } 1202 return null; 1203 }}); 1204 registerService(Context.SEARCH_UI_SERVICE, SearchUiManager.class, new CachedServiceFetcher<SearchUiManager>() { @Override public SearchUiManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getService(Context.SEARCH_UI_SERVICE); return b == null ? null : new SearchUiManager(ctx); } })1205 registerService(Context.SEARCH_UI_SERVICE, SearchUiManager.class, 1206 new CachedServiceFetcher<SearchUiManager>() { 1207 @Override 1208 public SearchUiManager createService(ContextImpl ctx) 1209 throws ServiceNotFoundException { 1210 IBinder b = ServiceManager.getService(Context.SEARCH_UI_SERVICE); 1211 return b == null ? null : new SearchUiManager(ctx); 1212 } 1213 }); 1214 registerService(Context.SMARTSPACE_SERVICE, SmartspaceManager.class, new CachedServiceFetcher<SmartspaceManager>() { @Override public SmartspaceManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getService(Context.SMARTSPACE_SERVICE); return b == null ? null : new SmartspaceManager(ctx); } })1215 registerService(Context.SMARTSPACE_SERVICE, SmartspaceManager.class, 1216 new CachedServiceFetcher<SmartspaceManager>() { 1217 @Override 1218 public SmartspaceManager createService(ContextImpl ctx) 1219 throws ServiceNotFoundException { 1220 IBinder b = ServiceManager.getService(Context.SMARTSPACE_SERVICE); 1221 return b == null ? null : new SmartspaceManager(ctx); 1222 } 1223 }); 1224 registerService(Context.APP_PREDICTION_SERVICE, AppPredictionManager.class, new CachedServiceFetcher<AppPredictionManager>() { @Override public AppPredictionManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getService(Context.APP_PREDICTION_SERVICE); return b == null ? null : new AppPredictionManager(ctx); } })1225 registerService(Context.APP_PREDICTION_SERVICE, AppPredictionManager.class, 1226 new CachedServiceFetcher<AppPredictionManager>() { 1227 @Override 1228 public AppPredictionManager createService(ContextImpl ctx) 1229 throws ServiceNotFoundException { 1230 IBinder b = ServiceManager.getService(Context.APP_PREDICTION_SERVICE); 1231 return b == null ? null : new AppPredictionManager(ctx); 1232 } 1233 }); 1234 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); } })1235 registerService(Context.CONTENT_SUGGESTIONS_SERVICE, 1236 ContentSuggestionsManager.class, 1237 new CachedServiceFetcher<ContentSuggestionsManager>() { 1238 @Override 1239 public ContentSuggestionsManager createService(ContextImpl ctx) { 1240 // No throw as this is an optional service 1241 IBinder b = ServiceManager.getService( 1242 Context.CONTENT_SUGGESTIONS_SERVICE); 1243 IContentSuggestionsManager service = 1244 IContentSuggestionsManager.Stub.asInterface(b); 1245 return new ContentSuggestionsManager(ctx.getUserId(), service); 1246 } 1247 }); 1248 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)); } })1249 registerService(Context.VR_SERVICE, VrManager.class, new CachedServiceFetcher<VrManager>() { 1250 @Override 1251 public VrManager createService(ContextImpl ctx) throws ServiceNotFoundException { 1252 IBinder b = ServiceManager.getServiceOrThrow(Context.VR_SERVICE); 1253 return new VrManager(IVrManager.Stub.asInterface(b)); 1254 } 1255 }); 1256 registerService(Context.TIME_ZONE_RULES_MANAGER_SERVICE, RulesManager.class, new CachedServiceFetcher<RulesManager>() { @Override public RulesManager createService(ContextImpl ctx) { return new RulesManager(ctx.getOuterContext()); }})1257 registerService(Context.TIME_ZONE_RULES_MANAGER_SERVICE, RulesManager.class, 1258 new CachedServiceFetcher<RulesManager>() { 1259 @Override 1260 public RulesManager createService(ContextImpl ctx) { 1261 return new RulesManager(ctx.getOuterContext()); 1262 }}); 1263 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)); } })1264 registerService(Context.CROSS_PROFILE_APPS_SERVICE, CrossProfileApps.class, 1265 new CachedServiceFetcher<CrossProfileApps>() { 1266 @Override 1267 public CrossProfileApps createService(ContextImpl ctx) 1268 throws ServiceNotFoundException { 1269 IBinder b = ServiceManager.getServiceOrThrow( 1270 Context.CROSS_PROFILE_APPS_SERVICE); 1271 return new CrossProfileApps(ctx.getOuterContext(), 1272 ICrossProfileApps.Stub.asInterface(b)); 1273 } 1274 }); 1275 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()); } })1276 registerService(Context.SLICE_SERVICE, SliceManager.class, 1277 new CachedServiceFetcher<SliceManager>() { 1278 @Override 1279 public SliceManager createService(ContextImpl ctx) 1280 throws ServiceNotFoundException { 1281 return new SliceManager(ctx.getOuterContext(), 1282 ctx.mMainThread.getHandler()); 1283 } 1284 }); 1285 registerService(Context.TIME_DETECTOR_SERVICE, TimeDetector.class, new CachedServiceFetcher<TimeDetector>() { @Override public TimeDetector createService(ContextImpl ctx) throws ServiceNotFoundException { return new TimeDetectorImpl(); }})1286 registerService(Context.TIME_DETECTOR_SERVICE, TimeDetector.class, 1287 new CachedServiceFetcher<TimeDetector>() { 1288 @Override 1289 public TimeDetector createService(ContextImpl ctx) 1290 throws ServiceNotFoundException { 1291 return new TimeDetectorImpl(); 1292 }}); 1293 registerService(Context.TIME_ZONE_DETECTOR_SERVICE, TimeZoneDetector.class, new CachedServiceFetcher<TimeZoneDetector>() { @Override public TimeZoneDetector createService(ContextImpl ctx) throws ServiceNotFoundException { return new TimeZoneDetectorImpl(); }})1294 registerService(Context.TIME_ZONE_DETECTOR_SERVICE, TimeZoneDetector.class, 1295 new CachedServiceFetcher<TimeZoneDetector>() { 1296 @Override 1297 public TimeZoneDetector createService(ContextImpl ctx) 1298 throws ServiceNotFoundException { 1299 return new TimeZoneDetectorImpl(); 1300 }}); 1301 registerService(Context.TIME_MANAGER, TimeManager.class, new CachedServiceFetcher<TimeManager>() { @Override public TimeManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new TimeManager(); }})1302 registerService(Context.TIME_MANAGER, TimeManager.class, 1303 new CachedServiceFetcher<TimeManager>() { 1304 @Override 1305 public TimeManager createService(ContextImpl ctx) 1306 throws ServiceNotFoundException { 1307 return new TimeManager(); 1308 }}); 1309 registerService(Context.PERMISSION_SERVICE, PermissionManager.class, new CachedServiceFetcher<PermissionManager>() { @Override public PermissionManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new PermissionManager(ctx.getOuterContext()); }})1310 registerService(Context.PERMISSION_SERVICE, PermissionManager.class, 1311 new CachedServiceFetcher<PermissionManager>() { 1312 @Override 1313 public PermissionManager createService(ContextImpl ctx) 1314 throws ServiceNotFoundException { 1315 return new PermissionManager(ctx.getOuterContext()); 1316 }}); 1317 registerService(Context.LEGACY_PERMISSION_SERVICE, LegacyPermissionManager.class, new CachedServiceFetcher<LegacyPermissionManager>() { @Override public LegacyPermissionManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new LegacyPermissionManager(); }})1318 registerService(Context.LEGACY_PERMISSION_SERVICE, LegacyPermissionManager.class, 1319 new CachedServiceFetcher<LegacyPermissionManager>() { 1320 @Override 1321 public LegacyPermissionManager createService(ContextImpl ctx) 1322 throws ServiceNotFoundException { 1323 return new LegacyPermissionManager(); 1324 }}); 1325 registerService(Context.PERMISSION_CONTROLLER_SERVICE, PermissionControllerManager.class, new CachedServiceFetcher<PermissionControllerManager>() { @Override public PermissionControllerManager createService(ContextImpl ctx) { return new PermissionControllerManager(ctx.getOuterContext(), ctx.getMainThreadHandler()); }})1326 registerService(Context.PERMISSION_CONTROLLER_SERVICE, PermissionControllerManager.class, 1327 new CachedServiceFetcher<PermissionControllerManager>() { 1328 @Override 1329 public PermissionControllerManager createService(ContextImpl ctx) { 1330 return new PermissionControllerManager(ctx.getOuterContext(), 1331 ctx.getMainThreadHandler()); 1332 }}); 1333 registerService(Context.PERMISSION_CHECKER_SERVICE, PermissionCheckerManager.class, new CachedServiceFetcher<PermissionCheckerManager>() { @Override public PermissionCheckerManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new PermissionCheckerManager(ctx.getOuterContext()); }})1334 registerService(Context.PERMISSION_CHECKER_SERVICE, PermissionCheckerManager.class, 1335 new CachedServiceFetcher<PermissionCheckerManager>() { 1336 @Override 1337 public PermissionCheckerManager createService(ContextImpl ctx) 1338 throws ServiceNotFoundException { 1339 return new PermissionCheckerManager(ctx.getOuterContext()); 1340 }}); 1341 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)); }})1342 registerService(Context.DYNAMIC_SYSTEM_SERVICE, DynamicSystemManager.class, 1343 new CachedServiceFetcher<DynamicSystemManager>() { 1344 @Override 1345 public DynamicSystemManager createService(ContextImpl ctx) 1346 throws ServiceNotFoundException { 1347 IBinder b = ServiceManager.getServiceOrThrow( 1348 Context.DYNAMIC_SYSTEM_SERVICE); 1349 return new DynamicSystemManager( 1350 IDynamicSystemService.Stub.asInterface(b)); 1351 }}); 1352 registerService(Context.BATTERY_STATS_SERVICE, BatteryStatsManager.class, new CachedServiceFetcher<BatteryStatsManager>() { @Override public BatteryStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow( Context.BATTERY_STATS_SERVICE); return new BatteryStatsManager( IBatteryStats.Stub.asInterface(b)); }})1353 registerService(Context.BATTERY_STATS_SERVICE, BatteryStatsManager.class, 1354 new CachedServiceFetcher<BatteryStatsManager>() { 1355 @Override 1356 public BatteryStatsManager createService(ContextImpl ctx) 1357 throws ServiceNotFoundException { 1358 IBinder b = ServiceManager.getServiceOrThrow( 1359 Context.BATTERY_STATS_SERVICE); 1360 return new BatteryStatsManager( 1361 IBatteryStats.Stub.asInterface(b)); 1362 }}); registerService(Context.DATA_LOADER_MANAGER_SERVICE, DataLoaderManager.class, new CachedServiceFetcher<DataLoaderManager>() { @Override public DataLoaderManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow( Context.DATA_LOADER_MANAGER_SERVICE); return new DataLoaderManager(IDataLoaderManager.Stub.asInterface(b)); }})1363 registerService(Context.DATA_LOADER_MANAGER_SERVICE, DataLoaderManager.class, 1364 new CachedServiceFetcher<DataLoaderManager>() { 1365 @Override 1366 public DataLoaderManager createService(ContextImpl ctx) 1367 throws ServiceNotFoundException { 1368 IBinder b = ServiceManager.getServiceOrThrow( 1369 Context.DATA_LOADER_MANAGER_SERVICE); 1370 return new DataLoaderManager(IDataLoaderManager.Stub.asInterface(b)); 1371 }}); registerService(Context.LIGHTS_SERVICE, LightsManager.class, new CachedServiceFetcher<LightsManager>() { @Override public LightsManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new SystemLightsManager(ctx); }})1372 registerService(Context.LIGHTS_SERVICE, LightsManager.class, 1373 new CachedServiceFetcher<LightsManager>() { 1374 @Override 1375 public LightsManager createService(ContextImpl ctx) 1376 throws ServiceNotFoundException { 1377 return new SystemLightsManager(ctx); 1378 }}); registerService(Context.INCREMENTAL_SERVICE, IncrementalManager.class, new CachedServiceFetcher<IncrementalManager>() { @Override public IncrementalManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(Context.INCREMENTAL_SERVICE); if (b == null) { return null; } return new IncrementalManager( IIncrementalService.Stub.asInterface(b)); }})1379 registerService(Context.INCREMENTAL_SERVICE, IncrementalManager.class, 1380 new CachedServiceFetcher<IncrementalManager>() { 1381 @Override 1382 public IncrementalManager createService(ContextImpl ctx) { 1383 IBinder b = ServiceManager.getService(Context.INCREMENTAL_SERVICE); 1384 if (b == null) { 1385 return null; 1386 } 1387 return new IncrementalManager( 1388 IIncrementalService.Stub.asInterface(b)); 1389 }}); 1390 registerService(Context.FILE_INTEGRITY_SERVICE, FileIntegrityManager.class, new CachedServiceFetcher<FileIntegrityManager>() { @Override public FileIntegrityManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow( Context.FILE_INTEGRITY_SERVICE); return new FileIntegrityManager(ctx.getOuterContext(), IFileIntegrityService.Stub.asInterface(b)); }})1391 registerService(Context.FILE_INTEGRITY_SERVICE, FileIntegrityManager.class, 1392 new CachedServiceFetcher<FileIntegrityManager>() { 1393 @Override 1394 public FileIntegrityManager createService(ContextImpl ctx) 1395 throws ServiceNotFoundException { 1396 IBinder b = ServiceManager.getServiceOrThrow( 1397 Context.FILE_INTEGRITY_SERVICE); 1398 return new FileIntegrityManager(ctx.getOuterContext(), 1399 IFileIntegrityService.Stub.asInterface(b)); 1400 }}); 1401 //CHECKSTYLE:ON IndentationCheck registerService(Context.APP_INTEGRITY_SERVICE, AppIntegrityManager.class, new CachedServiceFetcher<AppIntegrityManager>() { @Override public AppIntegrityManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder b = ServiceManager.getServiceOrThrow(Context.APP_INTEGRITY_SERVICE); return new AppIntegrityManager(IAppIntegrityManager.Stub.asInterface(b)); }})1402 registerService(Context.APP_INTEGRITY_SERVICE, AppIntegrityManager.class, 1403 new CachedServiceFetcher<AppIntegrityManager>() { 1404 @Override 1405 public AppIntegrityManager createService(ContextImpl ctx) 1406 throws ServiceNotFoundException { 1407 IBinder b = ServiceManager.getServiceOrThrow(Context.APP_INTEGRITY_SERVICE); 1408 return new AppIntegrityManager(IAppIntegrityManager.Stub.asInterface(b)); 1409 }}); registerService(Context.APP_HIBERNATION_SERVICE, AppHibernationManager.class, new CachedServiceFetcher<AppHibernationManager>() { @Override public AppHibernationManager createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(Context.APP_HIBERNATION_SERVICE); return b == null ? null : new AppHibernationManager(ctx); }})1410 registerService(Context.APP_HIBERNATION_SERVICE, AppHibernationManager.class, 1411 new CachedServiceFetcher<AppHibernationManager>() { 1412 @Override 1413 public AppHibernationManager createService(ContextImpl ctx) { 1414 IBinder b = ServiceManager.getService(Context.APP_HIBERNATION_SERVICE); 1415 return b == null ? null : new AppHibernationManager(ctx); 1416 }}); registerService(Context.DREAM_SERVICE, DreamManager.class, new CachedServiceFetcher<DreamManager>() { @Override public DreamManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new DreamManager(ctx); }})1417 registerService(Context.DREAM_SERVICE, DreamManager.class, 1418 new CachedServiceFetcher<DreamManager>() { 1419 @Override 1420 public DreamManager createService(ContextImpl ctx) 1421 throws ServiceNotFoundException { 1422 return new DreamManager(ctx); 1423 }}); registerService(Context.DEVICE_STATE_SERVICE, DeviceStateManager.class, new CachedServiceFetcher<DeviceStateManager>() { @Override public DeviceStateManager createService(ContextImpl ctx) { return new DeviceStateManager(); }})1424 registerService(Context.DEVICE_STATE_SERVICE, DeviceStateManager.class, 1425 new CachedServiceFetcher<DeviceStateManager>() { 1426 @Override 1427 public DeviceStateManager createService(ContextImpl ctx) { 1428 return new DeviceStateManager(); 1429 }}); 1430 registerService(Context.MEDIA_METRICS_SERVICE, MediaMetricsManager.class, new CachedServiceFetcher<MediaMetricsManager>() { @Override public MediaMetricsManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBinder iBinder = ServiceManager.getServiceOrThrow(Context.MEDIA_METRICS_SERVICE); IMediaMetricsManager service = IMediaMetricsManager.Stub.asInterface(iBinder); return new MediaMetricsManager(service, ctx.getUserId()); }})1431 registerService(Context.MEDIA_METRICS_SERVICE, MediaMetricsManager.class, 1432 new CachedServiceFetcher<MediaMetricsManager>() { 1433 @Override 1434 public MediaMetricsManager createService(ContextImpl ctx) 1435 throws ServiceNotFoundException { 1436 IBinder iBinder = 1437 ServiceManager.getServiceOrThrow(Context.MEDIA_METRICS_SERVICE); 1438 IMediaMetricsManager service = 1439 IMediaMetricsManager.Stub.asInterface(iBinder); 1440 return new MediaMetricsManager(service, ctx.getUserId()); 1441 }}); 1442 registerService(Context.GAME_SERVICE, GameManager.class, new CachedServiceFetcher<GameManager>() { @Override public GameManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new GameManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); } })1443 registerService(Context.GAME_SERVICE, GameManager.class, 1444 new CachedServiceFetcher<GameManager>() { 1445 @Override 1446 public GameManager createService(ContextImpl ctx) 1447 throws ServiceNotFoundException { 1448 return new GameManager(ctx.getOuterContext(), 1449 ctx.mMainThread.getHandler()); 1450 } 1451 }); 1452 registerService(Context.DOMAIN_VERIFICATION_SERVICE, DomainVerificationManager.class, new CachedServiceFetcher<DomainVerificationManager>() { @Override public DomainVerificationManager createService(ContextImpl context) throws ServiceNotFoundException { IBinder binder = ServiceManager.getServiceOrThrow( Context.DOMAIN_VERIFICATION_SERVICE); IDomainVerificationManager service = IDomainVerificationManager.Stub.asInterface(binder); return new DomainVerificationManager(context, service); } })1453 registerService(Context.DOMAIN_VERIFICATION_SERVICE, DomainVerificationManager.class, 1454 new CachedServiceFetcher<DomainVerificationManager>() { 1455 @Override 1456 public DomainVerificationManager createService(ContextImpl context) 1457 throws ServiceNotFoundException { 1458 IBinder binder = ServiceManager.getServiceOrThrow( 1459 Context.DOMAIN_VERIFICATION_SERVICE); 1460 IDomainVerificationManager service = 1461 IDomainVerificationManager.Stub.asInterface(binder); 1462 return new DomainVerificationManager(context, service); 1463 } 1464 }); 1465 registerService(Context.DISPLAY_HASH_SERVICE, DisplayHashManager.class, new CachedServiceFetcher<DisplayHashManager>() { @Override public DisplayHashManager createService(ContextImpl ctx) { return new DisplayHashManager(); }})1466 registerService(Context.DISPLAY_HASH_SERVICE, DisplayHashManager.class, 1467 new CachedServiceFetcher<DisplayHashManager>() { 1468 @Override 1469 public DisplayHashManager createService(ContextImpl ctx) { 1470 return new DisplayHashManager(); 1471 }}); 1472 1473 sInitializing = true; 1474 try { 1475 // Note: the following functions need to be @SystemApis, once they become mainline 1476 // modules. ConnectivityFrameworkInitializer.registerServiceWrappers()1477 ConnectivityFrameworkInitializer.registerServiceWrappers(); JobSchedulerFrameworkInitializer.registerServiceWrappers()1478 JobSchedulerFrameworkInitializer.registerServiceWrappers(); BlobStoreManagerFrameworkInitializer.initialize()1479 BlobStoreManagerFrameworkInitializer.initialize(); TelephonyFrameworkInitializer.registerServiceWrappers()1480 TelephonyFrameworkInitializer.registerServiceWrappers(); AppSearchManagerFrameworkInitializer.initialize()1481 AppSearchManagerFrameworkInitializer.initialize(); WifiFrameworkInitializer.registerServiceWrappers()1482 WifiFrameworkInitializer.registerServiceWrappers(); StatsFrameworkInitializer.registerServiceWrappers()1483 StatsFrameworkInitializer.registerServiceWrappers(); RollbackManagerFrameworkInitializer.initialize()1484 RollbackManagerFrameworkInitializer.initialize(); MediaFrameworkPlatformInitializer.registerServiceWrappers()1485 MediaFrameworkPlatformInitializer.registerServiceWrappers(); MediaFrameworkInitializer.registerServiceWrappers()1486 MediaFrameworkInitializer.registerServiceWrappers(); RoleFrameworkInitializer.registerServiceWrappers()1487 RoleFrameworkInitializer.registerServiceWrappers(); SchedulingFrameworkInitializer.registerServiceWrappers()1488 SchedulingFrameworkInitializer.registerServiceWrappers(); 1489 } finally { 1490 // If any of the above code throws, we're in a pretty bad shape and the process 1491 // will likely crash, but we'll reset it just in case there's an exception handler... 1492 sInitializing = false; 1493 } 1494 } 1495 1496 /** Throws {@link IllegalStateException} if not during a static initialization. */ ensureInitializing(String methodName)1497 private static void ensureInitializing(String methodName) { 1498 Preconditions.checkState(sInitializing, "Internal error: %s" 1499 + " can only be called during class initialization.", methodName); 1500 } 1501 /** 1502 * Creates an array which is used to cache per-Context service instances. 1503 * @hide 1504 */ createServiceCache()1505 public static Object[] createServiceCache() { 1506 return new Object[sServiceCacheSize]; 1507 } 1508 1509 /** 1510 * Gets a system service from a given context. 1511 * @hide 1512 */ getSystemService(ContextImpl ctx, String name)1513 public static Object getSystemService(ContextImpl ctx, String name) { 1514 if (name == null) { 1515 return null; 1516 } 1517 final ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name); 1518 if (fetcher == null) { 1519 if (sEnableServiceNotFoundWtf) { 1520 Slog.wtf(TAG, "Unknown manager requested: " + name); 1521 } 1522 return null; 1523 } 1524 1525 final Object ret = fetcher.getService(ctx); 1526 if (sEnableServiceNotFoundWtf && ret == null) { 1527 // Some services do return null in certain situations, so don't do WTF for them. 1528 switch (name) { 1529 case Context.CONTENT_CAPTURE_MANAGER_SERVICE: 1530 case Context.APP_PREDICTION_SERVICE: 1531 case Context.INCREMENTAL_SERVICE: 1532 case Context.ETHERNET_SERVICE: 1533 return null; 1534 } 1535 Slog.wtf(TAG, "Manager wrapper not available: " + name); 1536 return null; 1537 } 1538 return ret; 1539 } 1540 1541 /** 1542 * Gets the name of the system-level service that is represented by the specified class. 1543 * @hide 1544 */ getSystemServiceName(Class<?> serviceClass)1545 public static String getSystemServiceName(Class<?> serviceClass) { 1546 if (serviceClass == null) { 1547 return null; 1548 } 1549 final String serviceName = SYSTEM_SERVICE_NAMES.get(serviceClass); 1550 if (sEnableServiceNotFoundWtf && serviceName == null) { 1551 // This should be a caller bug. 1552 Slog.wtf(TAG, "Unknown manager requested: " + serviceClass.getCanonicalName()); 1553 } 1554 return serviceName; 1555 } 1556 1557 /** 1558 * Statically registers a system service with the context. 1559 * This method must be called during static initialization only. 1560 */ registerService(@onNull String serviceName, @NonNull Class<T> serviceClass, @NonNull ServiceFetcher<T> serviceFetcher)1561 private static <T> void registerService(@NonNull String serviceName, 1562 @NonNull Class<T> serviceClass, @NonNull ServiceFetcher<T> serviceFetcher) { 1563 SYSTEM_SERVICE_NAMES.put(serviceClass, serviceName); 1564 SYSTEM_SERVICE_FETCHERS.put(serviceName, serviceFetcher); 1565 SYSTEM_SERVICE_CLASS_NAMES.put(serviceName, serviceClass.getSimpleName()); 1566 } 1567 1568 /** 1569 * Returns system service class name by system service name. This method is mostly an inverse of 1570 * {@link #getSystemServiceName(Class)} 1571 * 1572 * @return system service class name. {@code null} if service name is invalid. 1573 * @hide 1574 */ 1575 @Nullable getSystemServiceClassName(@onNull String name)1576 public static String getSystemServiceClassName(@NonNull String name) { 1577 return SYSTEM_SERVICE_CLASS_NAMES.get(name); 1578 } 1579 1580 /** 1581 * Callback interface used as a parameter to {@link #registerStaticService( 1582 * String, Class, StaticServiceProducerWithoutBinder)}, which generates a service wrapper 1583 * instance that's not tied to any context and does not take a service binder object in the 1584 * constructor. 1585 * 1586 * @param <TServiceClass> type of the service wrapper class. 1587 * 1588 * @hide 1589 */ 1590 @SystemApi 1591 public interface StaticServiceProducerWithoutBinder<TServiceClass> { 1592 /** 1593 * Return a new service wrapper of type {@code TServiceClass}. 1594 */ 1595 @NonNull createService()1596 TServiceClass createService(); 1597 } 1598 1599 /** 1600 * Callback interface used as a parameter to {@link #registerStaticService( 1601 * String, Class, StaticServiceProducerWithBinder)}, which generates a service wrapper instance 1602 * that's not tied to any context and takes a service binder object in the constructor. 1603 * 1604 * @param <TServiceClass> type of the service wrapper class. 1605 * 1606 * @hide 1607 */ 1608 @SystemApi 1609 public interface StaticServiceProducerWithBinder<TServiceClass> { 1610 /** 1611 * Return a new service wrapper of type {@code TServiceClass} backed by a given 1612 * service binder object. 1613 */ 1614 @NonNull createService(@onNull IBinder serviceBinder)1615 TServiceClass createService(@NonNull IBinder serviceBinder); 1616 } 1617 1618 /** 1619 * Callback interface used as a parameter to {@link #registerContextAwareService( 1620 * String, Class, ContextAwareServiceProducerWithoutBinder)}, 1621 * which generates a service wrapper instance 1622 * that's tied to a specific context and does not take a service binder object in the 1623 * constructor. 1624 * 1625 * @param <TServiceClass> type of the service wrapper class. 1626 * 1627 * @hide 1628 */ 1629 @SystemApi 1630 public interface ContextAwareServiceProducerWithoutBinder<TServiceClass> { 1631 /** 1632 * Return a new service wrapper of type {@code TServiceClass} tied to a given 1633 * {@code context}. 1634 */ 1635 @NonNull 1636 //TODO Do we need to pass the "base context" too? createService(@onNull Context context)1637 TServiceClass createService(@NonNull Context context); 1638 } 1639 1640 /** 1641 * Callback interface used as a parameter to {@link #registerContextAwareService( 1642 * String, Class, ContextAwareServiceProducerWithBinder)}, 1643 * which generates a service wrapper instance 1644 * that's tied to a specific context and takes a service binder object in the constructor. 1645 * 1646 * @param <TServiceClass> type of the service wrapper class. 1647 * 1648 * @hide 1649 */ 1650 @SystemApi 1651 public interface ContextAwareServiceProducerWithBinder<TServiceClass> { 1652 /** 1653 * Return a new service wrapper of type {@code TServiceClass} backed by a given 1654 * service binder object that's tied to a given {@code context}. 1655 */ 1656 @NonNull 1657 //TODO Do we need to pass the "base context" too? createService(@onNull Context context, @NonNull IBinder serviceBinder)1658 TServiceClass createService(@NonNull Context context, @NonNull IBinder serviceBinder); 1659 } 1660 1661 /** 1662 * Used by apex modules to register a "service wrapper" that is not tied to any {@link Context}. 1663 * 1664 * <p>This can only be called from the methods called by the static initializer of 1665 * {@link SystemServiceRegistry}. (Otherwise it throws a {@link IllegalStateException}.) 1666 * 1667 * @param serviceName the name of the binder object, such as 1668 * {@link Context#JOB_SCHEDULER_SERVICE}. 1669 * @param serviceWrapperClass the wrapper class, such as the class of 1670 * {@link android.app.job.JobScheduler}. 1671 * @param serviceProducer Callback that takes the service binder object with the name 1672 * {@code serviceName} and returns an actual service wrapper instance. 1673 * 1674 * @hide 1675 */ 1676 @SystemApi registerStaticService( @onNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, @NonNull StaticServiceProducerWithBinder<TServiceClass> serviceProducer)1677 public static <TServiceClass> void registerStaticService( 1678 @NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, 1679 @NonNull StaticServiceProducerWithBinder<TServiceClass> serviceProducer) { 1680 ensureInitializing("registerStaticService"); 1681 Preconditions.checkStringNotEmpty(serviceName); 1682 Objects.requireNonNull(serviceWrapperClass); 1683 Objects.requireNonNull(serviceProducer); 1684 1685 registerService(serviceName, serviceWrapperClass, 1686 new StaticServiceFetcher<TServiceClass>() { 1687 @Override 1688 public TServiceClass createService() throws ServiceNotFoundException { 1689 return serviceProducer.createService( 1690 ServiceManager.getServiceOrThrow(serviceName)); 1691 }}); 1692 } 1693 1694 /** 1695 * Similar to {@link #registerStaticService(String, Class, StaticServiceProducerWithBinder)}, 1696 * but used for a "service wrapper" that doesn't take a service binder in its constructor. 1697 * 1698 * @hide 1699 */ 1700 @SystemApi registerStaticService( @onNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, @NonNull StaticServiceProducerWithoutBinder<TServiceClass> serviceProducer)1701 public static <TServiceClass> void registerStaticService( 1702 @NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, 1703 @NonNull StaticServiceProducerWithoutBinder<TServiceClass> serviceProducer) { 1704 ensureInitializing("registerStaticService"); 1705 Preconditions.checkStringNotEmpty(serviceName); 1706 Objects.requireNonNull(serviceWrapperClass); 1707 Objects.requireNonNull(serviceProducer); 1708 1709 registerService(serviceName, serviceWrapperClass, 1710 new StaticServiceFetcher<TServiceClass>() { 1711 @Override 1712 public TServiceClass createService() { 1713 return serviceProducer.createService(); 1714 }}); 1715 } 1716 1717 /** 1718 * Used by apex modules to register a "service wrapper" that is tied to a specific 1719 * {@link Context}. 1720 * 1721 * <p>This can only be called from the methods called by the static initializer of 1722 * {@link SystemServiceRegistry}. (Otherwise it throws a {@link IllegalStateException}.) 1723 * 1724 * @param serviceName the name of the binder object, such as 1725 * {@link Context#JOB_SCHEDULER_SERVICE}. 1726 * @param serviceWrapperClass the wrapper class, such as the class of 1727 * {@link android.app.job.JobScheduler}. 1728 * @param serviceProducer lambda that takes the service binder object with the name 1729 * {@code serviceName}, a {@link Context} and returns an actual service wrapper instance. 1730 * 1731 * @hide 1732 */ 1733 @SystemApi registerContextAwareService( @onNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, @NonNull ContextAwareServiceProducerWithBinder<TServiceClass> serviceProducer)1734 public static <TServiceClass> void registerContextAwareService( 1735 @NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, 1736 @NonNull ContextAwareServiceProducerWithBinder<TServiceClass> serviceProducer) { 1737 ensureInitializing("registerContextAwareService"); 1738 Preconditions.checkStringNotEmpty(serviceName); 1739 Objects.requireNonNull(serviceWrapperClass); 1740 Objects.requireNonNull(serviceProducer); 1741 1742 registerService(serviceName, serviceWrapperClass, 1743 new CachedServiceFetcher<TServiceClass>() { 1744 @Override 1745 public TServiceClass createService(ContextImpl ctx) 1746 throws ServiceNotFoundException { 1747 return serviceProducer.createService( 1748 ctx.getOuterContext(), 1749 ServiceManager.getServiceOrThrow(serviceName)); 1750 }}); 1751 } 1752 1753 1754 /** 1755 * Similar to {@link #registerContextAwareService(String, Class, 1756 * ContextAwareServiceProducerWithBinder)}, 1757 * but used for a "service wrapper" that doesn't take a service binder in its constructor. 1758 * 1759 * @hide 1760 */ 1761 @SystemApi registerContextAwareService( @onNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, @NonNull ContextAwareServiceProducerWithoutBinder<TServiceClass> serviceProducer)1762 public static <TServiceClass> void registerContextAwareService( 1763 @NonNull String serviceName, @NonNull Class<TServiceClass> serviceWrapperClass, 1764 @NonNull ContextAwareServiceProducerWithoutBinder<TServiceClass> serviceProducer) { 1765 ensureInitializing("registerContextAwareService"); 1766 Preconditions.checkStringNotEmpty(serviceName); 1767 Objects.requireNonNull(serviceWrapperClass); 1768 Objects.requireNonNull(serviceProducer); 1769 1770 registerService(serviceName, serviceWrapperClass, 1771 new CachedServiceFetcher<TServiceClass>() { 1772 @Override 1773 public TServiceClass createService(ContextImpl ctx) { 1774 return serviceProducer.createService(ctx.getOuterContext()); 1775 }}); 1776 } 1777 1778 /** 1779 * Base interface for classes that fetch services. 1780 * These objects must only be created during static initialization. 1781 */ 1782 static abstract interface ServiceFetcher<T> { getService(ContextImpl ctx)1783 T getService(ContextImpl ctx); 1784 } 1785 1786 /** 1787 * Override this class when the system service constructor needs a 1788 * ContextImpl and should be cached and retained by that context. 1789 */ 1790 static abstract class CachedServiceFetcher<T> implements ServiceFetcher<T> { 1791 private final int mCacheIndex; 1792 CachedServiceFetcher()1793 CachedServiceFetcher() { 1794 // Note this class must be instantiated only by the static initializer of the 1795 // outer class (SystemServiceRegistry), which already does the synchronization, 1796 // so bare access to sServiceCacheSize is okay here. 1797 mCacheIndex = sServiceCacheSize++; 1798 } 1799 1800 @Override 1801 @SuppressWarnings("unchecked") getService(ContextImpl ctx)1802 public final T getService(ContextImpl ctx) { 1803 final Object[] cache = ctx.mServiceCache; 1804 final int[] gates = ctx.mServiceInitializationStateArray; 1805 boolean interrupted = false; 1806 1807 T ret = null; 1808 1809 for (;;) { 1810 boolean doInitialize = false; 1811 synchronized (cache) { 1812 // Return it if we already have a cached instance. 1813 T service = (T) cache[mCacheIndex]; 1814 if (service != null) { 1815 ret = service; 1816 break; // exit the for (;;) 1817 } 1818 1819 // If we get here, there's no cached instance. 1820 1821 // Grr... if gate is STATE_READY, then this means we initialized the service 1822 // once but someone cleared it. 1823 // We start over from STATE_UNINITIALIZED. 1824 // Similarly, if the previous attempt returned null, we'll retry again. 1825 if (gates[mCacheIndex] == ContextImpl.STATE_READY 1826 || gates[mCacheIndex] == ContextImpl.STATE_NOT_FOUND) { 1827 gates[mCacheIndex] = ContextImpl.STATE_UNINITIALIZED; 1828 } 1829 1830 // It's possible for multiple threads to get here at the same time, so 1831 // use the "gate" to make sure only the first thread will call createService(). 1832 1833 // At this point, the gate must be either UNINITIALIZED or INITIALIZING. 1834 if (gates[mCacheIndex] == ContextImpl.STATE_UNINITIALIZED) { 1835 doInitialize = true; 1836 gates[mCacheIndex] = ContextImpl.STATE_INITIALIZING; 1837 } 1838 } 1839 1840 if (doInitialize) { 1841 // Only the first thread gets here. 1842 1843 T service = null; 1844 @ServiceInitializationState int newState = ContextImpl.STATE_NOT_FOUND; 1845 try { 1846 // This thread is the first one to get here. Instantiate the service 1847 // *without* the cache lock held. 1848 service = createService(ctx); 1849 newState = ContextImpl.STATE_READY; 1850 1851 } catch (ServiceNotFoundException e) { 1852 onServiceNotFound(e); 1853 1854 } finally { 1855 synchronized (cache) { 1856 cache[mCacheIndex] = service; 1857 gates[mCacheIndex] = newState; 1858 cache.notifyAll(); 1859 } 1860 } 1861 ret = service; 1862 break; // exit the for (;;) 1863 } 1864 // The other threads will wait for the first thread to call notifyAll(), 1865 // and go back to the top and retry. 1866 synchronized (cache) { 1867 // Repeat until the state becomes STATE_READY or STATE_NOT_FOUND. 1868 // We can't respond to interrupts here; just like we can't in the "doInitialize" 1869 // path, so we remember the interrupt state here and re-interrupt later. 1870 while (gates[mCacheIndex] < ContextImpl.STATE_READY) { 1871 try { 1872 // Clear the interrupt state. 1873 interrupted |= Thread.interrupted(); 1874 cache.wait(); 1875 } catch (InterruptedException e) { 1876 // This shouldn't normally happen, but if someone interrupts the 1877 // thread, it will. 1878 Slog.w(TAG, "getService() interrupted"); 1879 interrupted = true; 1880 } 1881 } 1882 } 1883 } 1884 if (interrupted) { 1885 Thread.currentThread().interrupt(); 1886 } 1887 return ret; 1888 } 1889 createService(ContextImpl ctx)1890 public abstract T createService(ContextImpl ctx) throws ServiceNotFoundException; 1891 } 1892 1893 /** 1894 * Override this class when the system service does not need a ContextImpl 1895 * and should be cached and retained process-wide. 1896 */ 1897 static abstract class StaticServiceFetcher<T> implements ServiceFetcher<T> { 1898 private T mCachedInstance; 1899 1900 @Override getService(ContextImpl ctx)1901 public final T getService(ContextImpl ctx) { 1902 synchronized (StaticServiceFetcher.this) { 1903 if (mCachedInstance == null) { 1904 try { 1905 mCachedInstance = createService(); 1906 } catch (ServiceNotFoundException e) { 1907 onServiceNotFound(e); 1908 } 1909 } 1910 return mCachedInstance; 1911 } 1912 } 1913 createService()1914 public abstract T createService() throws ServiceNotFoundException; 1915 } 1916 1917 /** 1918 * Like StaticServiceFetcher, creates only one instance of the service per application, but when 1919 * creating the service for the first time, passes it the application context of the creating 1920 * application. 1921 * 1922 * TODO: Delete this once its only user (ConnectivityManager) is known to work well in the 1923 * case where multiple application components each have their own ConnectivityManager object. 1924 */ 1925 static abstract class StaticApplicationContextServiceFetcher<T> implements ServiceFetcher<T> { 1926 private T mCachedInstance; 1927 1928 @Override getService(ContextImpl ctx)1929 public final T getService(ContextImpl ctx) { 1930 synchronized (StaticApplicationContextServiceFetcher.this) { 1931 if (mCachedInstance == null) { 1932 Context appContext = ctx.getApplicationContext(); 1933 // If the application context is null, we're either in the system process or 1934 // it's the application context very early in app initialization. In both these 1935 // cases, the passed-in ContextImpl will not be freed, so it's safe to pass it 1936 // to the service. http://b/27532714 . 1937 try { 1938 mCachedInstance = createService(appContext != null ? appContext : ctx); 1939 } catch (ServiceNotFoundException e) { 1940 onServiceNotFound(e); 1941 } 1942 } 1943 return mCachedInstance; 1944 } 1945 } 1946 createService(Context applicationContext)1947 public abstract T createService(Context applicationContext) throws ServiceNotFoundException; 1948 } 1949 1950 /** @hide */ onServiceNotFound(ServiceNotFoundException e)1951 public static void onServiceNotFound(ServiceNotFoundException e) { 1952 // We're mostly interested in tracking down long-lived core system 1953 // components that might stumble if they obtain bad references; just 1954 // emit a tidy log message for normal apps 1955 if (android.os.Process.myUid() < android.os.Process.FIRST_APPLICATION_UID) { 1956 Log.wtf(TAG, e.getMessage(), e); 1957 } else { 1958 Log.w(TAG, e.getMessage()); 1959 } 1960 } 1961 } 1962