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