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