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