blob: d8ccc62447757ebdc2e4e6fa999db80aef6e2656 [file] [log] [blame]
Jeff Brown6e539312015-02-24 18:53:21 -08001/*
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
17package android.app;
18
Jeff Brown6e539312015-02-24 18:53:21 -080019import android.accounts.AccountManager;
20import android.accounts.IAccountManager;
Makoto Onukid67070e2018-03-30 12:39:14 -070021import android.app.ContextImpl.ServiceInitializationState;
Jeff Brown6e539312015-02-24 18:53:21 -080022import android.app.admin.DevicePolicyManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -060023import android.app.admin.IDevicePolicyManager;
Winson Chung3fb0f252019-01-08 17:41:55 -080024import android.app.contentsuggestions.ContentSuggestionsManager;
25import android.app.contentsuggestions.IContentSuggestionsManager;
Jeff Brown6e539312015-02-24 18:53:21 -080026import android.app.job.IJobScheduler;
27import android.app.job.JobScheduler;
Sunny Goyal54e91342018-11-14 11:59:02 -080028import android.app.prediction.AppPredictionManager;
Hai Zhanga4959e52019-03-06 12:21:07 -080029import android.app.role.RoleControllerManager;
Hai Zhang4ef21d02018-11-09 14:43:51 -080030import android.app.role.RoleManager;
Jason Monk8f5f7ff2017-10-17 14:12:42 -040031import android.app.slice.SliceManager;
Neil Fullerfeeee682018-05-30 14:35:24 +010032import android.app.timedetector.TimeDetector;
Neil Fuller328532a2017-03-16 18:32:21 +000033import android.app.timezone.RulesManager;
Neil Fuller3352cfc2019-11-07 15:35:05 +000034import android.app.timezonedetector.TimeZoneDetector;
Jeff Brown6e539312015-02-24 18:53:21 -080035import android.app.trust.TrustManager;
Jeff Sharkeye8cece92017-01-04 11:33:33 -070036import android.app.usage.IStorageStatsManager;
Jeff Brown6e539312015-02-24 18:53:21 -080037import android.app.usage.IUsageStatsManager;
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +000038import android.app.usage.NetworkStatsManager;
Jeff Sharkeye8cece92017-01-04 11:33:33 -070039import android.app.usage.StorageStatsManager;
Jeff Brown6e539312015-02-24 18:53:21 -080040import android.app.usage.UsageStatsManager;
41import android.appwidget.AppWidgetManager;
42import android.bluetooth.BluetoothManager;
Eugene Susla6ed45d82017-01-22 13:52:51 -080043import android.companion.CompanionDeviceManager;
44import android.companion.ICompanionDeviceManager;
Jeff Brown6e539312015-02-24 18:53:21 -080045import android.content.ClipboardManager;
Felipe Leme326f15a2019-02-19 09:42:24 -080046import android.content.ContentCaptureOptions;
Jeff Brown6e539312015-02-24 18:53:21 -080047import android.content.Context;
48import android.content.IRestrictionsManager;
49import android.content.RestrictionsManager;
Hyunyoung Song880a9512018-12-20 11:24:48 -080050import android.content.om.IOverlayManager;
51import android.content.om.OverlayManager;
Tony Makb0d22622018-01-18 12:49:49 +000052import android.content.pm.CrossProfileApps;
53import android.content.pm.ICrossProfileApps;
Svet Ganovd8eb8b22019-04-05 18:52:08 -070054import android.content.pm.IPackageManager;
Makoto Onuki6f7362d92016-03-04 13:39:41 -080055import android.content.pm.IShortcutService;
Jeff Brown6e539312015-02-24 18:53:21 -080056import android.content.pm.LauncherApps;
Svet Ganovec7daa52017-06-30 12:02:59 -070057import android.content.pm.PackageManager;
Makoto Onuki6f7362d92016-03-04 13:39:41 -080058import android.content.pm.ShortcutManager;
Jeff Brown6e539312015-02-24 18:53:21 -080059import android.content.res.Resources;
Richard Uhlerb29f1452018-09-12 16:38:15 +010060import android.content.rollback.IRollbackManager;
61import android.content.rollback.RollbackManager;
Kenny Rootf74bfde2018-01-18 15:42:48 -080062import android.debug.AdbManager;
63import android.debug.IAdbManager;
Jeff Brown6e539312015-02-24 18:53:21 -080064import android.hardware.ConsumerIrManager;
65import android.hardware.ISerialManager;
66import android.hardware.SensorManager;
Chad Brubaker90f391f2018-10-19 10:26:19 -070067import android.hardware.SensorPrivacyManager;
Jeff Brown6e539312015-02-24 18:53:21 -080068import android.hardware.SerialManager;
69import android.hardware.SystemSensorManager;
Kevin Chyn05c21502018-09-18 13:07:19 -070070import android.hardware.biometrics.BiometricManager;
71import android.hardware.biometrics.IBiometricService;
Jeff Brown6e539312015-02-24 18:53:21 -080072import android.hardware.camera2.CameraManager;
Christine Franks39b03112018-07-03 14:46:07 -070073import android.hardware.display.ColorDisplayManager;
Jeff Brown6e539312015-02-24 18:53:21 -080074import android.hardware.display.DisplayManager;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020075import android.hardware.face.FaceManager;
76import android.hardware.face.IFaceService;
Jeff Sharkey49ca5292016-05-10 12:54:45 -060077import android.hardware.fingerprint.FingerprintManager;
78import android.hardware.fingerprint.IFingerprintService;
Jeff Brown6e539312015-02-24 18:53:21 -080079import android.hardware.hdmi.HdmiControlManager;
80import android.hardware.hdmi.IHdmiControlService;
81import android.hardware.input.InputManager;
Kevin Chyn51676d22018-11-05 18:00:43 -080082import android.hardware.iris.IIrisService;
Felipe Lemee348dc32018-11-05 12:35:29 -080083import android.hardware.iris.IrisManager;
Peng Xu9ff7d222016-02-11 13:02:05 -080084import android.hardware.location.ContextHubManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -060085import android.hardware.radio.RadioManager;
Jeff Brown6e539312015-02-24 18:53:21 -080086import android.hardware.usb.IUsbManager;
87import android.hardware.usb.UsbManager;
88import android.location.CountryDetector;
89import android.location.ICountryDetector;
90import android.location.ILocationManager;
91import android.location.LocationManager;
92import android.media.AudioManager;
93import android.media.MediaRouter;
94import android.media.midi.IMidiManager;
95import android.media.midi.MidiManager;
96import android.media.projection.MediaProjectionManager;
97import android.media.session.MediaSessionManager;
Arunesh Mishraa772e5f2016-01-25 10:33:11 -080098import android.media.soundtrigger.SoundTriggerManager;
Jeff Brown6e539312015-02-24 18:53:21 -080099import android.media.tv.ITvInputManager;
100import android.media.tv.TvInputManager;
101import android.net.ConnectivityManager;
Paul Stewartbf8cbb052016-03-17 10:11:54 -0700102import android.net.ConnectivityThread;
Jeff Brown6e539312015-02-24 18:53:21 -0800103import android.net.EthernetManager;
104import android.net.IConnectivityManager;
105import android.net.IEthernetManager;
Nathan Harold28084d82017-03-01 18:55:06 -0800106import android.net.IIpSecService;
Jeff Brown6e539312015-02-24 18:53:21 -0800107import android.net.INetworkPolicyManager;
Benedict Wong99a48412018-11-09 14:45:34 -0800108import android.net.ITestNetworkManager;
Nathan Harold28084d82017-03-01 18:55:06 -0800109import android.net.IpSecManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800110import android.net.NetworkPolicyManager;
111import android.net.NetworkScoreManager;
Ricky Wai1a6e6672017-10-27 14:46:01 +0100112import android.net.NetworkWatchlistManager;
Benedict Wong99a48412018-11-09 14:45:34 -0800113import android.net.TestNetworkManager;
Robert Quattlebaum87a71042017-05-15 15:45:20 -0700114import android.net.lowpan.ILowpanManager;
115import android.net.lowpan.LowpanManager;
Etan Cohen17ba4722017-08-21 10:52:17 -0700116import android.net.nsd.INsdManager;
117import android.net.nsd.NsdManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800118import android.net.wifi.IWifiManager;
119import android.net.wifi.IWifiScanner;
120import android.net.wifi.RttManager;
121import android.net.wifi.WifiManager;
122import android.net.wifi.WifiScanner;
Etan Cohen04133272016-10-26 11:22:06 -0700123import android.net.wifi.aware.IWifiAwareManager;
124import android.net.wifi.aware.WifiAwareManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800125import android.net.wifi.p2p.IWifiP2pManager;
126import android.net.wifi.p2p.WifiP2pManager;
Etan Cohen17ba4722017-08-21 10:52:17 -0700127import android.net.wifi.rtt.IWifiRttManager;
128import android.net.wifi.rtt.WifiRttManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800129import android.nfc.NfcManager;
130import android.os.BatteryManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600131import android.os.BatteryStats;
Nandana Duttd11850c2018-12-12 17:26:57 +0000132import android.os.BugreportManager;
Jeff Sharkey351c2c22017-03-18 16:48:02 -0600133import android.os.Build;
Philip P. Moltmannf80809f2018-04-04 11:20:44 -0700134import android.os.DeviceIdleManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800135import android.os.DropBoxManager;
Polina Bondarenko965ecbb2015-11-13 15:34:28 +0100136import android.os.HardwarePropertiesManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600137import android.os.IBatteryPropertiesRegistrar;
Jeff Brown6e539312015-02-24 18:53:21 -0800138import android.os.IBinder;
Philip P. Moltmannf80809f2018-04-04 11:20:44 -0700139import android.os.IDeviceIdleController;
Nandana Duttd11850c2018-12-12 17:26:57 +0000140import android.os.IDumpstate;
Polina Bondarenkof8754ac2016-02-12 20:38:23 +0100141import android.os.IHardwarePropertiesManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800142import android.os.IPowerManager;
Tao Baoe8a403d2015-12-31 07:44:55 -0800143import android.os.IRecoverySystem;
Tao Bao07342dc2017-01-24 15:08:21 -0800144import android.os.ISystemUpdateManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800145import android.os.IUserManager;
Joe Onorato1754d742016-11-21 17:51:35 -0800146import android.os.IncidentManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800147import android.os.PowerManager;
Tao Baoe8a403d2015-12-31 07:44:55 -0800148import android.os.RecoverySystem;
Benedict Wong99a48412018-11-09 14:45:34 -0800149import android.os.RemoteException;
Jeff Brown6e539312015-02-24 18:53:21 -0800150import android.os.ServiceManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600151import android.os.ServiceManager.ServiceNotFoundException;
Tao Bao07342dc2017-01-24 15:08:21 -0800152import android.os.SystemUpdateManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800153import android.os.SystemVibrator;
154import android.os.UserHandle;
155import android.os.UserManager;
156import android.os.Vibrator;
Joe Onorato713fec82016-03-04 10:34:02 -0800157import android.os.health.SystemHealthManager;
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +0800158import android.os.image.DynamicSystemManager;
159import android.os.image.IDynamicSystemService;
Jeff Brown6e539312015-02-24 18:53:21 -0800160import android.os.storage.StorageManager;
Chen Xu8eb62f92019-10-13 17:30:32 -0700161import android.telephony.TelephonyRegistryManager;
Philip P. Moltmannbc054d82018-12-21 09:41:58 -0800162import android.permission.PermissionControllerManager;
Philip P. Moltmann039678e2018-09-18 13:04:38 -0700163import android.permission.PermissionManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800164import android.print.IPrintManager;
165import android.print.PrintManager;
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000166import android.service.oemlock.IOemLockService;
167import android.service.oemlock.OemLockManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800168import android.service.persistentdata.IPersistentDataBlockService;
169import android.service.persistentdata.PersistentDataBlockManager;
Zak Cohen56345f42017-01-26 13:54:28 -0800170import android.service.vr.IVrManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800171import android.telecom.TelecomManager;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800172import android.telephony.CarrierConfigManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800173import android.telephony.SubscriptionManager;
174import android.telephony.TelephonyManager;
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -0800175import android.telephony.euicc.EuiccCardManager;
Neil Fuller009e77a2017-05-04 16:53:41 +0100176import android.telephony.euicc.EuiccManager;
Robert Benea1901a5b2018-05-15 16:36:07 -0700177import android.util.ArrayMap;
Jeff Brown6e539312015-02-24 18:53:21 -0800178import android.util.Log;
179import android.view.ContextThemeWrapper;
180import android.view.LayoutInflater;
Jeff Brown6e539312015-02-24 18:53:21 -0800181import android.view.WindowManager;
182import android.view.WindowManagerImpl;
183import android.view.accessibility.AccessibilityManager;
184import android.view.accessibility.CaptioningManager;
Neil Fuller009e77a2017-05-04 16:53:41 +0100185import android.view.autofill.AutofillManager;
186import android.view.autofill.IAutoFillManager;
Felipe Leme749b8892018-12-03 16:30:30 -0800187import android.view.contentcapture.ContentCaptureManager;
188import android.view.contentcapture.IContentCaptureManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800189import android.view.inputmethod.InputMethodManager;
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +0000190import android.view.textclassifier.TextClassificationManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800191import android.view.textservice.TextServicesManager;
192
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600193import com.android.internal.app.IAppOpsService;
194import com.android.internal.app.IBatteryStats;
195import com.android.internal.app.ISoundTriggerService;
196import com.android.internal.appwidget.IAppWidgetService;
Ricky Wai1a6e6672017-10-27 14:46:01 +0100197import com.android.internal.net.INetworkWatchlistManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600198import com.android.internal.os.IDropBoxManagerService;
199import com.android.internal.policy.PhoneLayoutInflater;
200
Robert Benea1901a5b2018-05-15 16:36:07 -0700201import java.util.Map;
Jeff Brown6e539312015-02-24 18:53:21 -0800202
203/**
204 * Manages all of the system services that can be returned by {@link Context#getSystemService}.
205 * Used by {@link ContextImpl}.
206 */
207final class SystemServiceRegistry {
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600208 private static final String TAG = "SystemServiceRegistry";
209
Jeff Brown6e539312015-02-24 18:53:21 -0800210 // Service registry information.
211 // This information is never changed once static initialization has completed.
Robert Benea1901a5b2018-05-15 16:36:07 -0700212 private static final Map<Class<?>, String> SYSTEM_SERVICE_NAMES =
213 new ArrayMap<Class<?>, String>();
214 private static final Map<String, ServiceFetcher<?>> SYSTEM_SERVICE_FETCHERS =
215 new ArrayMap<String, ServiceFetcher<?>>();
Jeff Brown6e539312015-02-24 18:53:21 -0800216 private static int sServiceCacheSize;
217
218 // Not instantiable.
219 private SystemServiceRegistry() { }
220
221 static {
Felipe Lemeecb08be2018-11-27 15:48:47 -0800222 //CHECKSTYLE:OFF IndentationCheck
Jeff Brown6e539312015-02-24 18:53:21 -0800223 registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class,
224 new CachedServiceFetcher<AccessibilityManager>() {
225 @Override
226 public AccessibilityManager createService(ContextImpl ctx) {
227 return AccessibilityManager.getInstance(ctx);
228 }});
229
230 registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class,
231 new CachedServiceFetcher<CaptioningManager>() {
232 @Override
233 public CaptioningManager createService(ContextImpl ctx) {
234 return new CaptioningManager(ctx);
235 }});
236
237 registerService(Context.ACCOUNT_SERVICE, AccountManager.class,
238 new CachedServiceFetcher<AccountManager>() {
239 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600240 public AccountManager createService(ContextImpl ctx) throws ServiceNotFoundException {
241 IBinder b = ServiceManager.getServiceOrThrow(Context.ACCOUNT_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800242 IAccountManager service = IAccountManager.Stub.asInterface(b);
243 return new AccountManager(ctx, service);
244 }});
245
246 registerService(Context.ACTIVITY_SERVICE, ActivityManager.class,
247 new CachedServiceFetcher<ActivityManager>() {
248 @Override
249 public ActivityManager createService(ContextImpl ctx) {
250 return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler());
251 }});
252
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700253 registerService(Context.ACTIVITY_TASK_SERVICE, ActivityTaskManager.class,
254 new CachedServiceFetcher<ActivityTaskManager>() {
255 @Override
256 public ActivityTaskManager createService(ContextImpl ctx) {
257 return new ActivityTaskManager(
258 ctx.getOuterContext(), ctx.mMainThread.getHandler());
259 }});
260
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -0700261 registerService(Context.URI_GRANTS_SERVICE, UriGrantsManager.class,
262 new CachedServiceFetcher<UriGrantsManager>() {
263 @Override
264 public UriGrantsManager createService(ContextImpl ctx) {
265 return new UriGrantsManager(
266 ctx.getOuterContext(), ctx.mMainThread.getHandler());
267 }});
268
Jeff Brown6e539312015-02-24 18:53:21 -0800269 registerService(Context.ALARM_SERVICE, AlarmManager.class,
270 new CachedServiceFetcher<AlarmManager>() {
271 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600272 public AlarmManager createService(ContextImpl ctx) throws ServiceNotFoundException {
273 IBinder b = ServiceManager.getServiceOrThrow(Context.ALARM_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800274 IAlarmManager service = IAlarmManager.Stub.asInterface(b);
275 return new AlarmManager(service, ctx);
276 }});
277
278 registerService(Context.AUDIO_SERVICE, AudioManager.class,
279 new CachedServiceFetcher<AudioManager>() {
280 @Override
281 public AudioManager createService(ContextImpl ctx) {
282 return new AudioManager(ctx);
283 }});
284
285 registerService(Context.MEDIA_ROUTER_SERVICE, MediaRouter.class,
286 new CachedServiceFetcher<MediaRouter>() {
287 @Override
288 public MediaRouter createService(ContextImpl ctx) {
289 return new MediaRouter(ctx);
290 }});
291
292 registerService(Context.BLUETOOTH_SERVICE, BluetoothManager.class,
293 new CachedServiceFetcher<BluetoothManager>() {
294 @Override
295 public BluetoothManager createService(ContextImpl ctx) {
296 return new BluetoothManager(ctx);
297 }});
298
299 registerService(Context.HDMI_CONTROL_SERVICE, HdmiControlManager.class,
300 new StaticServiceFetcher<HdmiControlManager>() {
301 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600302 public HdmiControlManager createService() throws ServiceNotFoundException {
303 IBinder b = ServiceManager.getServiceOrThrow(Context.HDMI_CONTROL_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800304 return new HdmiControlManager(IHdmiControlService.Stub.asInterface(b));
305 }});
306
Abodunrinwa Toki8158af52016-11-23 20:41:09 +0000307 registerService(Context.TEXT_CLASSIFICATION_SERVICE, TextClassificationManager.class,
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +0000308 new CachedServiceFetcher<TextClassificationManager>() {
Abodunrinwa Toki8158af52016-11-23 20:41:09 +0000309 @Override
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +0000310 public TextClassificationManager createService(ContextImpl ctx) {
311 return new TextClassificationManager(ctx);
Abodunrinwa Toki8158af52016-11-23 20:41:09 +0000312 }});
313
Jeff Brown6e539312015-02-24 18:53:21 -0800314 registerService(Context.CLIPBOARD_SERVICE, ClipboardManager.class,
315 new CachedServiceFetcher<ClipboardManager>() {
316 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600317 public ClipboardManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Brown6e539312015-02-24 18:53:21 -0800318 return new ClipboardManager(ctx.getOuterContext(),
319 ctx.mMainThread.getHandler());
320 }});
321
322 // The clipboard service moved to a new package. If someone asks for the old
323 // interface by class then we want to redirect over to the new interface instead
324 // (which extends it).
325 SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE);
326
327 registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class,
Lorenzo Colitticf959772016-02-29 16:07:37 +0900328 new StaticApplicationContextServiceFetcher<ConnectivityManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800329 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600330 public ConnectivityManager createService(Context context) throws ServiceNotFoundException {
331 IBinder b = ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE);
Lorenzo Colittiffc42b02015-07-29 11:41:21 +0900332 IConnectivityManager service = IConnectivityManager.Stub.asInterface(b);
333 return new ConnectivityManager(context, service);
Jeff Brown6e539312015-02-24 18:53:21 -0800334 }});
335
Remi NGUYEN VANf9a8c2e2019-02-13 18:28:35 +0900336 registerService(Context.NETD_SERVICE, IBinder.class, new StaticServiceFetcher<IBinder>() {
Remi NGUYEN VAN31935982019-01-28 11:40:08 +0900337 @Override
Remi NGUYEN VANf9a8c2e2019-02-13 18:28:35 +0900338 public IBinder createService() throws ServiceNotFoundException {
339 return ServiceManager.getServiceOrThrow(Context.NETD_SERVICE);
Remi NGUYEN VAN31935982019-01-28 11:40:08 +0900340 }
341 });
342
Nathan Harold28084d82017-03-01 18:55:06 -0800343 registerService(Context.IPSEC_SERVICE, IpSecManager.class,
Nathan Harold592dadb2018-03-15 18:06:06 -0700344 new CachedServiceFetcher<IpSecManager>() {
Nathan Harold28084d82017-03-01 18:55:06 -0800345 @Override
Nathan Harold592dadb2018-03-15 18:06:06 -0700346 public IpSecManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Nathan Harold28084d82017-03-01 18:55:06 -0800347 IBinder b = ServiceManager.getService(Context.IPSEC_SERVICE);
348 IIpSecService service = IIpSecService.Stub.asInterface(b);
Nathan Harold592dadb2018-03-15 18:06:06 -0700349 return new IpSecManager(ctx, service);
Nathan Harold28084d82017-03-01 18:55:06 -0800350 }});
351
Benedict Wong99a48412018-11-09 14:45:34 -0800352 registerService(
353 Context.TEST_NETWORK_SERVICE,
354 TestNetworkManager.class,
355 new StaticApplicationContextServiceFetcher<TestNetworkManager>() {
356 @Override
357 public TestNetworkManager createService(Context context)
358 throws ServiceNotFoundException {
359 IBinder csBinder =
360 ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE);
361 IConnectivityManager csMgr =
362 IConnectivityManager.Stub.asInterface(csBinder);
363
364 final IBinder tnBinder;
365 try {
366 tnBinder = csMgr.startOrGetTestNetworkService();
367 } catch (RemoteException e) {
368 throw new ServiceNotFoundException(Context.TEST_NETWORK_SERVICE);
369 }
370 ITestNetworkManager tnMgr = ITestNetworkManager.Stub.asInterface(tnBinder);
Benedict Wongb4e98f32019-03-12 21:54:16 -0700371 return new TestNetworkManager(tnMgr);
Benedict Wong99a48412018-11-09 14:45:34 -0800372 }
373 });
374
Jeff Brown6e539312015-02-24 18:53:21 -0800375 registerService(Context.COUNTRY_DETECTOR, CountryDetector.class,
376 new StaticServiceFetcher<CountryDetector>() {
377 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600378 public CountryDetector createService() throws ServiceNotFoundException {
379 IBinder b = ServiceManager.getServiceOrThrow(Context.COUNTRY_DETECTOR);
Jeff Brown6e539312015-02-24 18:53:21 -0800380 return new CountryDetector(ICountryDetector.Stub.asInterface(b));
381 }});
382
383 registerService(Context.DEVICE_POLICY_SERVICE, DevicePolicyManager.class,
384 new CachedServiceFetcher<DevicePolicyManager>() {
385 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600386 public DevicePolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException {
387 IBinder b = ServiceManager.getServiceOrThrow(Context.DEVICE_POLICY_SERVICE);
388 return new DevicePolicyManager(ctx, IDevicePolicyManager.Stub.asInterface(b));
Jeff Brown6e539312015-02-24 18:53:21 -0800389 }});
390
391 registerService(Context.DOWNLOAD_SERVICE, DownloadManager.class,
392 new CachedServiceFetcher<DownloadManager>() {
393 @Override
394 public DownloadManager createService(ContextImpl ctx) {
Jeff Sharkey60cfad82016-01-05 17:30:57 -0700395 return new DownloadManager(ctx);
Jeff Brown6e539312015-02-24 18:53:21 -0800396 }});
397
398 registerService(Context.BATTERY_SERVICE, BatteryManager.class,
Yifan Hongb0f13522017-10-31 15:48:50 -0700399 new CachedServiceFetcher<BatteryManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800400 @Override
Yifan Hongb0f13522017-10-31 15:48:50 -0700401 public BatteryManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600402 IBatteryStats stats = IBatteryStats.Stub.asInterface(
403 ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME));
404 IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub
405 .asInterface(ServiceManager.getServiceOrThrow("batteryproperties"));
Yifan Hongb0f13522017-10-31 15:48:50 -0700406 return new BatteryManager(ctx, stats, registrar);
Jeff Brown6e539312015-02-24 18:53:21 -0800407 }});
408
409 registerService(Context.NFC_SERVICE, NfcManager.class,
410 new CachedServiceFetcher<NfcManager>() {
411 @Override
412 public NfcManager createService(ContextImpl ctx) {
413 return new NfcManager(ctx);
414 }});
415
416 registerService(Context.DROPBOX_SERVICE, DropBoxManager.class,
Jeff Sharkeyb8e8a912016-03-09 16:27:40 -0700417 new CachedServiceFetcher<DropBoxManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800418 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600419 public DropBoxManager createService(ContextImpl ctx) throws ServiceNotFoundException {
420 IBinder b = ServiceManager.getServiceOrThrow(Context.DROPBOX_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800421 IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b);
Jeff Sharkeyb8e8a912016-03-09 16:27:40 -0700422 return new DropBoxManager(ctx, service);
Jeff Brown6e539312015-02-24 18:53:21 -0800423 }});
424
425 registerService(Context.INPUT_SERVICE, InputManager.class,
426 new StaticServiceFetcher<InputManager>() {
427 @Override
428 public InputManager createService() {
429 return InputManager.getInstance();
430 }});
431
432 registerService(Context.DISPLAY_SERVICE, DisplayManager.class,
433 new CachedServiceFetcher<DisplayManager>() {
434 @Override
435 public DisplayManager createService(ContextImpl ctx) {
436 return new DisplayManager(ctx.getOuterContext());
437 }});
438
Christine Franks39b03112018-07-03 14:46:07 -0700439 registerService(Context.COLOR_DISPLAY_SERVICE, ColorDisplayManager.class,
440 new CachedServiceFetcher<ColorDisplayManager>() {
441 @Override
442 public ColorDisplayManager createService(ContextImpl ctx) {
443 return new ColorDisplayManager();
444 }
445 });
446
Yohei Yukawa4052a10f2018-10-15 15:35:55 +0800447 // InputMethodManager has its own cache strategy based on display id to support apps that
448 // still assume InputMethodManager is a per-process singleton and it's safe to directly
449 // access internal fields via reflection. Hence directly use ServiceFetcher instead of
450 // StaticServiceFetcher/CachedServiceFetcher.
Jeff Brown6e539312015-02-24 18:53:21 -0800451 registerService(Context.INPUT_METHOD_SERVICE, InputMethodManager.class,
Yohei Yukawa4052a10f2018-10-15 15:35:55 +0800452 new ServiceFetcher<InputMethodManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800453 @Override
Yohei Yukawa4052a10f2018-10-15 15:35:55 +0800454 public InputMethodManager getService(ContextImpl ctx) {
455 return InputMethodManager.forContext(ctx.getOuterContext());
Jeff Brown6e539312015-02-24 18:53:21 -0800456 }});
457
458 registerService(Context.TEXT_SERVICES_MANAGER_SERVICE, TextServicesManager.class,
Yohei Yukawa9f141ee2019-01-18 09:17:16 -0800459 new CachedServiceFetcher<TextServicesManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800460 @Override
Yohei Yukawa9f141ee2019-01-18 09:17:16 -0800461 public TextServicesManager createService(ContextImpl ctx)
462 throws ServiceNotFoundException {
463 return TextServicesManager.createInstance(ctx);
Jeff Brown6e539312015-02-24 18:53:21 -0800464 }});
465
466 registerService(Context.KEYGUARD_SERVICE, KeyguardManager.class,
Nancy Zheng43f166d2016-11-18 18:15:09 -0800467 new CachedServiceFetcher<KeyguardManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800468 @Override
Nancy Zheng40cd8e42016-11-21 12:58:16 -0800469 public KeyguardManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Nancy Zheng43f166d2016-11-18 18:15:09 -0800470 return new KeyguardManager(ctx);
Jeff Brown6e539312015-02-24 18:53:21 -0800471 }});
472
473 registerService(Context.LAYOUT_INFLATER_SERVICE, LayoutInflater.class,
474 new CachedServiceFetcher<LayoutInflater>() {
475 @Override
476 public LayoutInflater createService(ContextImpl ctx) {
477 return new PhoneLayoutInflater(ctx.getOuterContext());
478 }});
479
480 registerService(Context.LOCATION_SERVICE, LocationManager.class,
481 new CachedServiceFetcher<LocationManager>() {
482 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600483 public LocationManager createService(ContextImpl ctx) throws ServiceNotFoundException {
484 IBinder b = ServiceManager.getServiceOrThrow(Context.LOCATION_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800485 return new LocationManager(ctx, ILocationManager.Stub.asInterface(b));
486 }});
487
488 registerService(Context.NETWORK_POLICY_SERVICE, NetworkPolicyManager.class,
Svet Ganov16a16892015-04-16 10:32:04 -0700489 new CachedServiceFetcher<NetworkPolicyManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800490 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600491 public NetworkPolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Svet Ganov16a16892015-04-16 10:32:04 -0700492 return new NetworkPolicyManager(ctx, INetworkPolicyManager.Stub.asInterface(
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600493 ServiceManager.getServiceOrThrow(Context.NETWORK_POLICY_SERVICE)));
Jeff Brown6e539312015-02-24 18:53:21 -0800494 }});
495
496 registerService(Context.NOTIFICATION_SERVICE, NotificationManager.class,
497 new CachedServiceFetcher<NotificationManager>() {
498 @Override
499 public NotificationManager createService(ContextImpl ctx) {
500 final Context outerContext = ctx.getOuterContext();
501 return new NotificationManager(
502 new ContextThemeWrapper(outerContext,
503 Resources.selectSystemTheme(0,
504 outerContext.getApplicationInfo().targetSdkVersion,
505 com.android.internal.R.style.Theme_Dialog,
506 com.android.internal.R.style.Theme_Holo_Dialog,
507 com.android.internal.R.style.Theme_DeviceDefault_Dialog,
508 com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog)),
509 ctx.mMainThread.getHandler());
510 }});
511
512 registerService(Context.NSD_SERVICE, NsdManager.class,
513 new CachedServiceFetcher<NsdManager>() {
514 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600515 public NsdManager createService(ContextImpl ctx) throws ServiceNotFoundException {
516 IBinder b = ServiceManager.getServiceOrThrow(Context.NSD_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800517 INsdManager service = INsdManager.Stub.asInterface(b);
518 return new NsdManager(ctx.getOuterContext(), service);
519 }});
520
521 registerService(Context.POWER_SERVICE, PowerManager.class,
522 new CachedServiceFetcher<PowerManager>() {
523 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600524 public PowerManager createService(ContextImpl ctx) throws ServiceNotFoundException {
525 IBinder b = ServiceManager.getServiceOrThrow(Context.POWER_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800526 IPowerManager service = IPowerManager.Stub.asInterface(b);
Jeff Brown6e539312015-02-24 18:53:21 -0800527 return new PowerManager(ctx.getOuterContext(),
528 service, ctx.mMainThread.getHandler());
529 }});
530
Tao Baoe8a403d2015-12-31 07:44:55 -0800531 registerService(Context.RECOVERY_SERVICE, RecoverySystem.class,
532 new CachedServiceFetcher<RecoverySystem>() {
533 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600534 public RecoverySystem createService(ContextImpl ctx) throws ServiceNotFoundException {
535 IBinder b = ServiceManager.getServiceOrThrow(Context.RECOVERY_SERVICE);
Tao Baoe8a403d2015-12-31 07:44:55 -0800536 IRecoverySystem service = IRecoverySystem.Stub.asInterface(b);
Tao Baoe8a403d2015-12-31 07:44:55 -0800537 return new RecoverySystem(service);
538 }});
539
Jeff Brown6e539312015-02-24 18:53:21 -0800540 registerService(Context.SEARCH_SERVICE, SearchManager.class,
541 new CachedServiceFetcher<SearchManager>() {
542 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600543 public SearchManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Brown6e539312015-02-24 18:53:21 -0800544 return new SearchManager(ctx.getOuterContext(),
545 ctx.mMainThread.getHandler());
546 }});
547
548 registerService(Context.SENSOR_SERVICE, SensorManager.class,
549 new CachedServiceFetcher<SensorManager>() {
550 @Override
551 public SensorManager createService(ContextImpl ctx) {
552 return new SystemSensorManager(ctx.getOuterContext(),
553 ctx.mMainThread.getHandler().getLooper());
554 }});
555
Chad Brubaker90f391f2018-10-19 10:26:19 -0700556 registerService(Context.SENSOR_PRIVACY_SERVICE, SensorPrivacyManager.class,
557 new CachedServiceFetcher<SensorPrivacyManager>() {
558 @Override
559 public SensorPrivacyManager createService(ContextImpl ctx) {
560 return SensorPrivacyManager.getInstance(ctx);
561 }});
562
David Chenadaf8b32017-11-03 15:42:08 -0700563 registerService(Context.STATS_MANAGER, StatsManager.class,
Jeff Sharkey6b649252018-04-16 09:50:22 -0600564 new CachedServiceFetcher<StatsManager>() {
565 @Override
566 public StatsManager createService(ContextImpl ctx) {
567 return new StatsManager(ctx.getOuterContext());
568 }});
David Chenadaf8b32017-11-03 15:42:08 -0700569
Jeff Brown6e539312015-02-24 18:53:21 -0800570 registerService(Context.STATUS_BAR_SERVICE, StatusBarManager.class,
571 new CachedServiceFetcher<StatusBarManager>() {
572 @Override
573 public StatusBarManager createService(ContextImpl ctx) {
574 return new StatusBarManager(ctx.getOuterContext());
575 }});
576
577 registerService(Context.STORAGE_SERVICE, StorageManager.class,
578 new CachedServiceFetcher<StorageManager>() {
579 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600580 public StorageManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Sharkey48877892015-03-18 11:27:19 -0700581 return new StorageManager(ctx, ctx.mMainThread.getHandler().getLooper());
Jeff Brown6e539312015-02-24 18:53:21 -0800582 }});
583
Jeff Sharkeye8cece92017-01-04 11:33:33 -0700584 registerService(Context.STORAGE_STATS_SERVICE, StorageStatsManager.class,
585 new CachedServiceFetcher<StorageStatsManager>() {
586 @Override
587 public StorageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
588 IStorageStatsManager service = IStorageStatsManager.Stub.asInterface(
589 ServiceManager.getServiceOrThrow(Context.STORAGE_STATS_SERVICE));
590 return new StorageStatsManager(ctx, service);
591 }});
592
Tao Bao07342dc2017-01-24 15:08:21 -0800593 registerService(Context.SYSTEM_UPDATE_SERVICE, SystemUpdateManager.class,
594 new CachedServiceFetcher<SystemUpdateManager>() {
595 @Override
596 public SystemUpdateManager createService(ContextImpl ctx)
597 throws ServiceNotFoundException {
598 IBinder b = ServiceManager.getServiceOrThrow(
599 Context.SYSTEM_UPDATE_SERVICE);
600 ISystemUpdateManager service = ISystemUpdateManager.Stub.asInterface(b);
601 return new SystemUpdateManager(service);
602 }});
603
Jeff Brown6e539312015-02-24 18:53:21 -0800604 registerService(Context.TELEPHONY_SERVICE, TelephonyManager.class,
605 new CachedServiceFetcher<TelephonyManager>() {
606 @Override
607 public TelephonyManager createService(ContextImpl ctx) {
608 return new TelephonyManager(ctx.getOuterContext());
609 }});
610
Chen Xu1f1c25e2019-09-15 18:28:21 -0700611 registerService(Context.TELEPHONY_REGISTRY_SERVICE, TelephonyRegistryManager.class,
612 new CachedServiceFetcher<TelephonyRegistryManager>() {
613 @Override
614 public TelephonyRegistryManager createService(ContextImpl ctx) {
Chen Xu8eb62f92019-10-13 17:30:32 -0700615 return new TelephonyRegistryManager(ctx);
Chen Xu1f1c25e2019-09-15 18:28:21 -0700616 }});
617
Jeff Brown6e539312015-02-24 18:53:21 -0800618 registerService(Context.TELEPHONY_SUBSCRIPTION_SERVICE, SubscriptionManager.class,
619 new CachedServiceFetcher<SubscriptionManager>() {
620 @Override
Jeff Sharkey717f52f2018-01-04 16:04:11 -0700621 public SubscriptionManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Brown6e539312015-02-24 18:53:21 -0800622 return new SubscriptionManager(ctx.getOuterContext());
623 }});
624
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800625 registerService(Context.CARRIER_CONFIG_SERVICE, CarrierConfigManager.class,
626 new CachedServiceFetcher<CarrierConfigManager>() {
627 @Override
628 public CarrierConfigManager createService(ContextImpl ctx) {
Malcolm Chend1272d12018-02-28 15:20:45 -0800629 return new CarrierConfigManager(ctx.getOuterContext());
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800630 }});
631
Jeff Brown6e539312015-02-24 18:53:21 -0800632 registerService(Context.TELECOM_SERVICE, TelecomManager.class,
633 new CachedServiceFetcher<TelecomManager>() {
634 @Override
635 public TelecomManager createService(ContextImpl ctx) {
636 return new TelecomManager(ctx.getOuterContext());
637 }});
638
Jeff Davidson35cda392017-02-27 09:46:00 -0800639 registerService(Context.EUICC_SERVICE, EuiccManager.class,
640 new CachedServiceFetcher<EuiccManager>() {
641 @Override
642 public EuiccManager createService(ContextImpl ctx) {
643 return new EuiccManager(ctx.getOuterContext());
644 }});
645
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -0800646 registerService(Context.EUICC_CARD_SERVICE, EuiccCardManager.class,
647 new CachedServiceFetcher<EuiccCardManager>() {
648 @Override
649 public EuiccCardManager createService(ContextImpl ctx) {
650 return new EuiccCardManager(ctx.getOuterContext());
651 }});
652
Jeff Brown6e539312015-02-24 18:53:21 -0800653 registerService(Context.UI_MODE_SERVICE, UiModeManager.class,
654 new CachedServiceFetcher<UiModeManager>() {
655 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600656 public UiModeManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Tyler Gunnf05f2c22019-09-30 15:12:24 -0700657 return new UiModeManager(ctx.getOuterContext());
Jeff Brown6e539312015-02-24 18:53:21 -0800658 }});
659
660 registerService(Context.USB_SERVICE, UsbManager.class,
661 new CachedServiceFetcher<UsbManager>() {
662 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600663 public UsbManager createService(ContextImpl ctx) throws ServiceNotFoundException {
664 IBinder b = ServiceManager.getServiceOrThrow(Context.USB_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800665 return new UsbManager(ctx, IUsbManager.Stub.asInterface(b));
666 }});
667
Kenny Rootf74bfde2018-01-18 15:42:48 -0800668 registerService(Context.ADB_SERVICE, AdbManager.class,
669 new CachedServiceFetcher<AdbManager>() {
670 @Override
671 public AdbManager createService(ContextImpl ctx)
672 throws ServiceNotFoundException {
673 IBinder b = ServiceManager.getServiceOrThrow(Context.ADB_SERVICE);
674 return new AdbManager(ctx, IAdbManager.Stub.asInterface(b));
675 }});
676
Jeff Brown6e539312015-02-24 18:53:21 -0800677 registerService(Context.SERIAL_SERVICE, SerialManager.class,
678 new CachedServiceFetcher<SerialManager>() {
679 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600680 public SerialManager createService(ContextImpl ctx) throws ServiceNotFoundException {
681 IBinder b = ServiceManager.getServiceOrThrow(Context.SERIAL_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800682 return new SerialManager(ctx, ISerialManager.Stub.asInterface(b));
683 }});
684
685 registerService(Context.VIBRATOR_SERVICE, Vibrator.class,
686 new CachedServiceFetcher<Vibrator>() {
687 @Override
688 public Vibrator createService(ContextImpl ctx) {
689 return new SystemVibrator(ctx);
690 }});
691
692 registerService(Context.WALLPAPER_SERVICE, WallpaperManager.class,
693 new CachedServiceFetcher<WallpaperManager>() {
694 @Override
Svet Ganov8f90bcc2017-12-22 23:29:24 -0800695 public WallpaperManager createService(ContextImpl ctx)
696 throws ServiceNotFoundException {
697 final IBinder b;
698 if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) {
699 b = ServiceManager.getServiceOrThrow(Context.WALLPAPER_SERVICE);
700 } else {
701 b = ServiceManager.getService(Context.WALLPAPER_SERVICE);
702 }
703 IWallpaperManager service = IWallpaperManager.Stub.asInterface(b);
704 return new WallpaperManager(service, ctx.getOuterContext(),
Jeff Brown6e539312015-02-24 18:53:21 -0800705 ctx.mMainThread.getHandler());
706 }});
707
Robert Quattlebaum87a71042017-05-15 15:45:20 -0700708 registerService(Context.LOWPAN_SERVICE, LowpanManager.class,
709 new CachedServiceFetcher<LowpanManager>() {
710 @Override
711 public LowpanManager createService(ContextImpl ctx) throws ServiceNotFoundException {
712 IBinder b = ServiceManager.getServiceOrThrow(Context.LOWPAN_SERVICE);
713 ILowpanManager service = ILowpanManager.Stub.asInterface(b);
714 return new LowpanManager(ctx.getOuterContext(), service,
715 ConnectivityThread.getInstanceLooper());
716 }});
717
Jeff Brown6e539312015-02-24 18:53:21 -0800718 registerService(Context.WIFI_SERVICE, WifiManager.class,
719 new CachedServiceFetcher<WifiManager>() {
720 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600721 public WifiManager createService(ContextImpl ctx) throws ServiceNotFoundException {
722 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800723 IWifiManager service = IWifiManager.Stub.asInterface(b);
Paul Stewartbf8cbb052016-03-17 10:11:54 -0700724 return new WifiManager(ctx.getOuterContext(), service,
725 ConnectivityThread.getInstanceLooper());
Jeff Brown6e539312015-02-24 18:53:21 -0800726 }});
727
Jeff Brown6e539312015-02-24 18:53:21 -0800728 registerService(Context.WIFI_P2P_SERVICE, WifiP2pManager.class,
729 new StaticServiceFetcher<WifiP2pManager>() {
730 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600731 public WifiP2pManager createService() throws ServiceNotFoundException {
732 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_P2P_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800733 IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b);
734 return new WifiP2pManager(service);
735 }});
736
Etan Cohen04133272016-10-26 11:22:06 -0700737 registerService(Context.WIFI_AWARE_SERVICE, WifiAwareManager.class,
738 new CachedServiceFetcher<WifiAwareManager>() {
Etan Cohen20d329b2015-09-29 13:49:02 -0700739 @Override
Etan Cohen04133272016-10-26 11:22:06 -0700740 public WifiAwareManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Sharkey589f3092016-11-29 12:54:39 -0700741 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_AWARE_SERVICE);
Etan Cohen04133272016-10-26 11:22:06 -0700742 IWifiAwareManager service = IWifiAwareManager.Stub.asInterface(b);
Etan Cohen20d329b2015-09-29 13:49:02 -0700743 if (service == null) {
744 return null;
745 }
Etan Cohen04133272016-10-26 11:22:06 -0700746 return new WifiAwareManager(ctx.getOuterContext(), service);
Etan Cohen20d329b2015-09-29 13:49:02 -0700747 }});
748
Jeff Brown6e539312015-02-24 18:53:21 -0800749 registerService(Context.WIFI_SCANNING_SERVICE, WifiScanner.class,
750 new CachedServiceFetcher<WifiScanner>() {
751 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600752 public WifiScanner createService(ContextImpl ctx) throws ServiceNotFoundException {
753 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SCANNING_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800754 IWifiScanner service = IWifiScanner.Stub.asInterface(b);
Mitchell Wills91312c72016-04-06 17:03:35 -0700755 return new WifiScanner(ctx.getOuterContext(), service,
756 ConnectivityThread.getInstanceLooper());
Jeff Brown6e539312015-02-24 18:53:21 -0800757 }});
758
759 registerService(Context.WIFI_RTT_SERVICE, RttManager.class,
760 new CachedServiceFetcher<RttManager>() {
Etan Cohen9accbba2018-01-30 16:41:00 -0800761 @Override
762 public RttManager createService(ContextImpl ctx) throws ServiceNotFoundException {
763 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_RTT_RANGING_SERVICE);
764 IWifiRttManager service = IWifiRttManager.Stub.asInterface(b);
765 return new RttManager(ctx.getOuterContext(),
766 new WifiRttManager(ctx.getOuterContext(), service));
767 }});
Jeff Brown6e539312015-02-24 18:53:21 -0800768
Etan Cohen46efb482017-12-07 13:50:57 -0800769 registerService(Context.WIFI_RTT_RANGING_SERVICE, WifiRttManager.class,
Etan Cohen17ba4722017-08-21 10:52:17 -0700770 new CachedServiceFetcher<WifiRttManager>() {
771 @Override
772 public WifiRttManager createService(ContextImpl ctx)
773 throws ServiceNotFoundException {
Etan Cohen46efb482017-12-07 13:50:57 -0800774 IBinder b = ServiceManager.getServiceOrThrow(
775 Context.WIFI_RTT_RANGING_SERVICE);
Etan Cohen17ba4722017-08-21 10:52:17 -0700776 IWifiRttManager service = IWifiRttManager.Stub.asInterface(b);
777 return new WifiRttManager(ctx.getOuterContext(), service);
778 }});
779
Jeff Brown6e539312015-02-24 18:53:21 -0800780 registerService(Context.ETHERNET_SERVICE, EthernetManager.class,
781 new CachedServiceFetcher<EthernetManager>() {
782 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600783 public EthernetManager createService(ContextImpl ctx) throws ServiceNotFoundException {
784 IBinder b = ServiceManager.getServiceOrThrow(Context.ETHERNET_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800785 IEthernetManager service = IEthernetManager.Stub.asInterface(b);
786 return new EthernetManager(ctx.getOuterContext(), service);
787 }});
788
789 registerService(Context.WINDOW_SERVICE, WindowManager.class,
790 new CachedServiceFetcher<WindowManager>() {
791 @Override
792 public WindowManager createService(ContextImpl ctx) {
Adam Lesinski4ece3d62016-06-16 18:05:41 -0700793 return new WindowManagerImpl(ctx);
Jeff Brown6e539312015-02-24 18:53:21 -0800794 }});
795
796 registerService(Context.USER_SERVICE, UserManager.class,
797 new CachedServiceFetcher<UserManager>() {
798 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600799 public UserManager createService(ContextImpl ctx) throws ServiceNotFoundException {
800 IBinder b = ServiceManager.getServiceOrThrow(Context.USER_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800801 IUserManager service = IUserManager.Stub.asInterface(b);
802 return new UserManager(ctx, service);
803 }});
804
805 registerService(Context.APP_OPS_SERVICE, AppOpsManager.class,
806 new CachedServiceFetcher<AppOpsManager>() {
807 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600808 public AppOpsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
809 IBinder b = ServiceManager.getServiceOrThrow(Context.APP_OPS_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800810 IAppOpsService service = IAppOpsService.Stub.asInterface(b);
811 return new AppOpsManager(ctx, service);
812 }});
813
814 registerService(Context.CAMERA_SERVICE, CameraManager.class,
815 new CachedServiceFetcher<CameraManager>() {
816 @Override
817 public CameraManager createService(ContextImpl ctx) {
818 return new CameraManager(ctx);
819 }});
820
821 registerService(Context.LAUNCHER_APPS_SERVICE, LauncherApps.class,
822 new CachedServiceFetcher<LauncherApps>() {
823 @Override
824 public LauncherApps createService(ContextImpl ctx) {
Makoto Onuki5ba0d3e2016-04-11 14:03:46 -0700825 return new LauncherApps(ctx);
Jeff Brown6e539312015-02-24 18:53:21 -0800826 }});
827
828 registerService(Context.RESTRICTIONS_SERVICE, RestrictionsManager.class,
829 new CachedServiceFetcher<RestrictionsManager>() {
830 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600831 public RestrictionsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
832 IBinder b = ServiceManager.getServiceOrThrow(Context.RESTRICTIONS_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800833 IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b);
834 return new RestrictionsManager(ctx, service);
835 }});
836
837 registerService(Context.PRINT_SERVICE, PrintManager.class,
838 new CachedServiceFetcher<PrintManager>() {
839 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600840 public PrintManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Svet Ganovec7daa52017-06-30 12:02:59 -0700841 IPrintManager service = null;
842 // If the feature not present, don't try to look up every time
843 if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
844 service = IPrintManager.Stub.asInterface(ServiceManager
845 .getServiceOrThrow(Context.PRINT_SERVICE));
846 }
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700847 final int userId = ctx.getUserId();
848 final int appId = UserHandle.getAppId(ctx.getApplicationInfo().uid);
849 return new PrintManager(ctx.getOuterContext(), service, userId, appId);
Jeff Brown6e539312015-02-24 18:53:21 -0800850 }});
851
Eugene Susla6ed45d82017-01-22 13:52:51 -0800852 registerService(Context.COMPANION_DEVICE_SERVICE, CompanionDeviceManager.class,
853 new CachedServiceFetcher<CompanionDeviceManager>() {
Svet Ganovec7daa52017-06-30 12:02:59 -0700854 @Override
855 public CompanionDeviceManager createService(ContextImpl ctx)
856 throws ServiceNotFoundException {
857 ICompanionDeviceManager service = null;
858 // If the feature not present, don't try to look up every time
859 if (ctx.getPackageManager().hasSystemFeature(
860 PackageManager.FEATURE_COMPANION_DEVICE_SETUP)) {
861 service = ICompanionDeviceManager.Stub.asInterface(
862 ServiceManager.getServiceOrThrow(Context.COMPANION_DEVICE_SERVICE));
863 }
864 return new CompanionDeviceManager(service, ctx.getOuterContext());
865 }});
Eugene Susla6ed45d82017-01-22 13:52:51 -0800866
Jeff Brown6e539312015-02-24 18:53:21 -0800867 registerService(Context.CONSUMER_IR_SERVICE, ConsumerIrManager.class,
868 new CachedServiceFetcher<ConsumerIrManager>() {
869 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600870 public ConsumerIrManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Brown6e539312015-02-24 18:53:21 -0800871 return new ConsumerIrManager(ctx);
872 }});
873
874 registerService(Context.MEDIA_SESSION_SERVICE, MediaSessionManager.class,
875 new CachedServiceFetcher<MediaSessionManager>() {
876 @Override
877 public MediaSessionManager createService(ContextImpl ctx) {
878 return new MediaSessionManager(ctx);
879 }});
880
881 registerService(Context.TRUST_SERVICE, TrustManager.class,
882 new StaticServiceFetcher<TrustManager>() {
883 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600884 public TrustManager createService() throws ServiceNotFoundException {
885 IBinder b = ServiceManager.getServiceOrThrow(Context.TRUST_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800886 return new TrustManager(b);
887 }});
888
889 registerService(Context.FINGERPRINT_SERVICE, FingerprintManager.class,
890 new CachedServiceFetcher<FingerprintManager>() {
891 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600892 public FingerprintManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Sharkey351c2c22017-03-18 16:48:02 -0600893 final IBinder binder;
894 if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
895 binder = ServiceManager.getServiceOrThrow(Context.FINGERPRINT_SERVICE);
896 } else {
897 binder = ServiceManager.getService(Context.FINGERPRINT_SERVICE);
898 }
Jeff Brown6e539312015-02-24 18:53:21 -0800899 IFingerprintService service = IFingerprintService.Stub.asInterface(binder);
900 return new FingerprintManager(ctx.getOuterContext(), service);
901 }});
902
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200903 registerService(Context.FACE_SERVICE, FaceManager.class,
904 new CachedServiceFetcher<FaceManager>() {
905 @Override
906 public FaceManager createService(ContextImpl ctx)
907 throws ServiceNotFoundException {
908 final IBinder binder;
909 if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
910 binder = ServiceManager.getServiceOrThrow(Context.FACE_SERVICE);
911 } else {
912 binder = ServiceManager.getService(Context.FACE_SERVICE);
913 }
914 IFaceService service = IFaceService.Stub.asInterface(binder);
915 return new FaceManager(ctx.getOuterContext(), service);
916 }
917 });
918
Kevin Chyn51676d22018-11-05 18:00:43 -0800919 registerService(Context.IRIS_SERVICE, IrisManager.class,
920 new CachedServiceFetcher<IrisManager>() {
921 @Override
922 public IrisManager createService(ContextImpl ctx)
923 throws ServiceNotFoundException {
924 final IBinder binder =
925 ServiceManager.getServiceOrThrow(Context.IRIS_SERVICE);
926 IIrisService service = IIrisService.Stub.asInterface(binder);
927 return new IrisManager(ctx.getOuterContext(), service);
928 }
929 });
930
Kevin Chyn05c21502018-09-18 13:07:19 -0700931 registerService(Context.BIOMETRIC_SERVICE, BiometricManager.class,
932 new CachedServiceFetcher<BiometricManager>() {
933 @Override
934 public BiometricManager createService(ContextImpl ctx)
935 throws ServiceNotFoundException {
Kevin Chyne739daf2018-11-06 17:11:06 -0800936 if (BiometricManager.hasBiometrics(ctx)) {
937 final IBinder binder =
938 ServiceManager.getServiceOrThrow(Context.BIOMETRIC_SERVICE);
939 final IBiometricService service =
940 IBiometricService.Stub.asInterface(binder);
941 return new BiometricManager(ctx.getOuterContext(), service);
942 } else {
943 // Allow access to the manager when service is null. This saves memory
944 // on devices without biometric hardware.
945 return new BiometricManager(ctx.getOuterContext(), null);
946 }
Kevin Chyn05c21502018-09-18 13:07:19 -0700947 }
948 });
949
Jeff Brown6e539312015-02-24 18:53:21 -0800950 registerService(Context.TV_INPUT_SERVICE, TvInputManager.class,
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700951 new CachedServiceFetcher<TvInputManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800952 @Override
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700953 public TvInputManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600954 IBinder iBinder = ServiceManager.getServiceOrThrow(Context.TV_INPUT_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800955 ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder);
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700956 return new TvInputManager(service, ctx.getUserId());
Jeff Brown6e539312015-02-24 18:53:21 -0800957 }});
958
959 registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class,
960 new CachedServiceFetcher<NetworkScoreManager>() {
961 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600962 public NetworkScoreManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Brown6e539312015-02-24 18:53:21 -0800963 return new NetworkScoreManager(ctx);
964 }});
965
966 registerService(Context.USAGE_STATS_SERVICE, UsageStatsManager.class,
967 new CachedServiceFetcher<UsageStatsManager>() {
968 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600969 public UsageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
970 IBinder iBinder = ServiceManager.getServiceOrThrow(Context.USAGE_STATS_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800971 IUsageStatsManager service = IUsageStatsManager.Stub.asInterface(iBinder);
972 return new UsageStatsManager(ctx.getOuterContext(), service);
973 }});
974
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +0000975 registerService(Context.NETWORK_STATS_SERVICE, NetworkStatsManager.class,
976 new CachedServiceFetcher<NetworkStatsManager>() {
977 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600978 public NetworkStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +0000979 return new NetworkStatsManager(ctx.getOuterContext());
980 }});
981
Jeff Brown6e539312015-02-24 18:53:21 -0800982 registerService(Context.JOB_SCHEDULER_SERVICE, JobScheduler.class,
983 new StaticServiceFetcher<JobScheduler>() {
984 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600985 public JobScheduler createService() throws ServiceNotFoundException {
986 IBinder b = ServiceManager.getServiceOrThrow(Context.JOB_SCHEDULER_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800987 return new JobSchedulerImpl(IJobScheduler.Stub.asInterface(b));
988 }});
989
990 registerService(Context.PERSISTENT_DATA_BLOCK_SERVICE, PersistentDataBlockManager.class,
991 new StaticServiceFetcher<PersistentDataBlockManager>() {
992 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600993 public PersistentDataBlockManager createService() throws ServiceNotFoundException {
994 IBinder b = ServiceManager.getServiceOrThrow(Context.PERSISTENT_DATA_BLOCK_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800995 IPersistentDataBlockService persistentDataBlockService =
996 IPersistentDataBlockService.Stub.asInterface(b);
997 if (persistentDataBlockService != null) {
998 return new PersistentDataBlockManager(persistentDataBlockService);
999 } else {
1000 // not supported
1001 return null;
1002 }
1003 }});
1004
Andrew Scull3b8b46f2017-02-13 18:12:15 +00001005 registerService(Context.OEM_LOCK_SERVICE, OemLockManager.class,
1006 new StaticServiceFetcher<OemLockManager>() {
1007 @Override
1008 public OemLockManager createService() throws ServiceNotFoundException {
1009 IBinder b = ServiceManager.getServiceOrThrow(Context.OEM_LOCK_SERVICE);
1010 IOemLockService oemLockService = IOemLockService.Stub.asInterface(b);
1011 if (oemLockService != null) {
1012 return new OemLockManager(oemLockService);
1013 } else {
1014 // not supported
1015 return null;
1016 }
1017 }});
1018
Jeff Brown6e539312015-02-24 18:53:21 -08001019 registerService(Context.MEDIA_PROJECTION_SERVICE, MediaProjectionManager.class,
1020 new CachedServiceFetcher<MediaProjectionManager>() {
1021 @Override
1022 public MediaProjectionManager createService(ContextImpl ctx) {
1023 return new MediaProjectionManager(ctx);
1024 }});
1025
1026 registerService(Context.APPWIDGET_SERVICE, AppWidgetManager.class,
1027 new CachedServiceFetcher<AppWidgetManager>() {
1028 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001029 public AppWidgetManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1030 IBinder b = ServiceManager.getServiceOrThrow(Context.APPWIDGET_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -08001031 return new AppWidgetManager(ctx, IAppWidgetService.Stub.asInterface(b));
1032 }});
1033
1034 registerService(Context.MIDI_SERVICE, MidiManager.class,
1035 new CachedServiceFetcher<MidiManager>() {
1036 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001037 public MidiManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1038 IBinder b = ServiceManager.getServiceOrThrow(Context.MIDI_SERVICE);
Mike Lockwoode0a6ca62015-06-04 13:43:56 -07001039 return new MidiManager(IMidiManager.Stub.asInterface(b));
Jeff Brown6e539312015-02-24 18:53:21 -08001040 }});
Eric Laurent2035ac82015-03-05 15:18:44 -08001041
1042 registerService(Context.RADIO_SERVICE, RadioManager.class,
1043 new CachedServiceFetcher<RadioManager>() {
1044 @Override
Tomasz Wasilczyk347192e2017-04-04 11:13:44 -07001045 public RadioManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Eric Laurent2035ac82015-03-05 15:18:44 -08001046 return new RadioManager(ctx);
1047 }});
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001048
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01001049 registerService(Context.HARDWARE_PROPERTIES_SERVICE, HardwarePropertiesManager.class,
1050 new CachedServiceFetcher<HardwarePropertiesManager>() {
1051 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001052 public HardwarePropertiesManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1053 IBinder b = ServiceManager.getServiceOrThrow(Context.HARDWARE_PROPERTIES_SERVICE);
1054 IHardwarePropertiesManager service =
1055 IHardwarePropertiesManager.Stub.asInterface(b);
1056 return new HardwarePropertiesManager(ctx, service);
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01001057 }});
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001058
1059 registerService(Context.SOUND_TRIGGER_SERVICE, SoundTriggerManager.class,
1060 new CachedServiceFetcher<SoundTriggerManager>() {
1061 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001062 public SoundTriggerManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1063 IBinder b = ServiceManager.getServiceOrThrow(Context.SOUND_TRIGGER_SERVICE);
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001064 return new SoundTriggerManager(ctx, ISoundTriggerService.Stub.asInterface(b));
1065 }});
Makoto Onuki6f7362d92016-03-04 13:39:41 -08001066
1067 registerService(Context.SHORTCUT_SERVICE, ShortcutManager.class,
1068 new CachedServiceFetcher<ShortcutManager>() {
Makoto Onuki55046222016-03-08 10:49:47 -08001069 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001070 public ShortcutManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1071 IBinder b = ServiceManager.getServiceOrThrow(Context.SHORTCUT_SERVICE);
1072 return new ShortcutManager(ctx, IShortcutService.Stub.asInterface(b));
Makoto Onuki55046222016-03-08 10:49:47 -08001073 }});
Joe Onorato713fec82016-03-04 10:34:02 -08001074
Hyunyoung Song880a9512018-12-20 11:24:48 -08001075 registerService(Context.OVERLAY_SERVICE, OverlayManager.class,
1076 new CachedServiceFetcher<OverlayManager>() {
1077 @Override
1078 public OverlayManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1079 IBinder b = ServiceManager.getServiceOrThrow(Context.OVERLAY_SERVICE);
1080 return new OverlayManager(ctx, IOverlayManager.Stub.asInterface(b));
1081 }});
1082
Ricky Wai1a6e6672017-10-27 14:46:01 +01001083 registerService(Context.NETWORK_WATCHLIST_SERVICE, NetworkWatchlistManager.class,
1084 new CachedServiceFetcher<NetworkWatchlistManager>() {
1085 @Override
1086 public NetworkWatchlistManager createService(ContextImpl ctx)
1087 throws ServiceNotFoundException {
1088 IBinder b =
1089 ServiceManager.getServiceOrThrow(Context.NETWORK_WATCHLIST_SERVICE);
1090 return new NetworkWatchlistManager(ctx,
1091 INetworkWatchlistManager.Stub.asInterface(b));
1092 }});
1093
Joe Onorato713fec82016-03-04 10:34:02 -08001094 registerService(Context.SYSTEM_HEALTH_SERVICE, SystemHealthManager.class,
1095 new CachedServiceFetcher<SystemHealthManager>() {
1096 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001097 public SystemHealthManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1098 IBinder b = ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME);
1099 return new SystemHealthManager(IBatteryStats.Stub.asInterface(b));
Joe Onorato713fec82016-03-04 10:34:02 -08001100 }});
Peng Xu9ff7d222016-02-11 13:02:05 -08001101
1102 registerService(Context.CONTEXTHUB_SERVICE, ContextHubManager.class,
1103 new CachedServiceFetcher<ContextHubManager>() {
1104 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001105 public ContextHubManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Peng Xu9ff7d222016-02-11 13:02:05 -08001106 return new ContextHubManager(ctx.getOuterContext(),
1107 ctx.mMainThread.getHandler().getLooper());
1108 }});
Joe Onorato1754d742016-11-21 17:51:35 -08001109
1110 registerService(Context.INCIDENT_SERVICE, IncidentManager.class,
1111 new CachedServiceFetcher<IncidentManager>() {
1112 @Override
1113 public IncidentManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1114 return new IncidentManager(ctx);
1115 }});
Clara Bayarri04d72ab2017-01-10 09:31:51 -08001116
Nandana Duttd11850c2018-12-12 17:26:57 +00001117 registerService(Context.BUGREPORT_SERVICE, BugreportManager.class,
1118 new CachedServiceFetcher<BugreportManager>() {
1119 @Override
1120 public BugreportManager createService(ContextImpl ctx)
1121 throws ServiceNotFoundException {
1122 IBinder b = ServiceManager.getServiceOrThrow(Context.BUGREPORT_SERVICE);
1123 return new BugreportManager(ctx.getOuterContext(),
1124 IDumpstate.Stub.asInterface(b));
1125 }});
1126
Felipe Leme640f30a2017-03-06 15:44:06 -08001127 registerService(Context.AUTOFILL_MANAGER_SERVICE, AutofillManager.class,
1128 new CachedServiceFetcher<AutofillManager>() {
Felipe Leme3461d3c2017-01-19 08:54:55 -08001129 @Override
Felipe Leme640f30a2017-03-06 15:44:06 -08001130 public AutofillManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Svet Ganov43574b02017-04-12 09:25:20 -07001131 // Get the services without throwing as this is an optional feature
1132 IBinder b = ServiceManager.getService(Context.AUTOFILL_MANAGER_SERVICE);
Svet Ganov782043c2017-02-11 00:52:02 +00001133 IAutoFillManager service = IAutoFillManager.Stub.asInterface(b);
Felipe Leme640f30a2017-03-06 15:44:06 -08001134 return new AutofillManager(ctx.getOuterContext(), service);
Felipe Leme3461d3c2017-01-19 08:54:55 -08001135 }});
Zak Cohen56345f42017-01-26 13:54:28 -08001136
Felipe Lemeecb08be2018-11-27 15:48:47 -08001137 registerService(Context.CONTENT_CAPTURE_MANAGER_SERVICE, ContentCaptureManager.class,
1138 new CachedServiceFetcher<ContentCaptureManager>() {
Felipe Lemee348dc32018-11-05 12:35:29 -08001139 @Override
Felipe Lemeecb08be2018-11-27 15:48:47 -08001140 public ContentCaptureManager createService(ContextImpl ctx)
Felipe Lemee348dc32018-11-05 12:35:29 -08001141 throws ServiceNotFoundException {
1142 // Get the services without throwing as this is an optional feature
Felipe Lemeecb08be2018-11-27 15:48:47 -08001143 Context outerContext = ctx.getOuterContext();
Felipe Leme326f15a2019-02-19 09:42:24 -08001144 ContentCaptureOptions options = outerContext.getContentCaptureOptions();
1145 // Options is null when the service didn't whitelist the activity or package
Felipe Lemecbf7f262019-04-17 13:57:59 -07001146 if (options != null && (options.lite || options.isWhitelisted(outerContext))) {
Felipe Lemeecb08be2018-11-27 15:48:47 -08001147 IBinder b = ServiceManager
1148 .getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE);
Felipe Leme749b8892018-12-03 16:30:30 -08001149 IContentCaptureManager service = IContentCaptureManager.Stub.asInterface(b);
Felipe Leme326f15a2019-02-19 09:42:24 -08001150 // Service is null when not provided by OEM or disabled by kill-switch.
Felipe Lemed49d52c2019-02-15 09:48:20 -08001151 if (service != null) {
Felipe Leme326f15a2019-02-19 09:42:24 -08001152 return new ContentCaptureManager(outerContext, service, options);
Felipe Lemed49d52c2019-02-15 09:48:20 -08001153 }
Felipe Lemeecb08be2018-11-27 15:48:47 -08001154 }
Felipe Leme326f15a2019-02-19 09:42:24 -08001155 // When feature is disabled or app / package not whitelisted, we return a null
1156 // manager to apps so the performance impact is practically zero
Felipe Lemeecb08be2018-11-27 15:48:47 -08001157 return null;
Felipe Lemee348dc32018-11-05 12:35:29 -08001158 }});
1159
Sunny Goyal54e91342018-11-14 11:59:02 -08001160 registerService(Context.APP_PREDICTION_SERVICE, AppPredictionManager.class,
1161 new CachedServiceFetcher<AppPredictionManager>() {
1162 @Override
1163 public AppPredictionManager createService(ContextImpl ctx)
1164 throws ServiceNotFoundException {
Felipe Leme87c58552019-08-14 18:14:55 -07001165 IBinder b = ServiceManager.getService(Context.APP_PREDICTION_SERVICE);
1166 return b == null ? null : new AppPredictionManager(ctx);
Sunny Goyal54e91342018-11-14 11:59:02 -08001167 }
1168 });
1169
Winson Chung3fb0f252019-01-08 17:41:55 -08001170 registerService(Context.CONTENT_SUGGESTIONS_SERVICE,
1171 ContentSuggestionsManager.class,
1172 new CachedServiceFetcher<ContentSuggestionsManager>() {
1173 @Override
1174 public ContentSuggestionsManager createService(ContextImpl ctx) {
1175 // No throw as this is an optional service
1176 IBinder b = ServiceManager.getService(
1177 Context.CONTENT_SUGGESTIONS_SERVICE);
1178 IContentSuggestionsManager service =
1179 IContentSuggestionsManager.Stub.asInterface(b);
Zak Cohen4834e9f2019-03-08 12:59:01 -08001180 return new ContentSuggestionsManager(ctx.getUserId(), service);
Winson Chung3fb0f252019-01-08 17:41:55 -08001181 }
1182 });
1183
Zak Cohen56345f42017-01-26 13:54:28 -08001184 registerService(Context.VR_SERVICE, VrManager.class, new CachedServiceFetcher<VrManager>() {
1185 @Override
1186 public VrManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1187 IBinder b = ServiceManager.getServiceOrThrow(Context.VR_SERVICE);
1188 return new VrManager(IVrManager.Stub.asInterface(b));
1189 }
1190 });
Neil Fuller328532a2017-03-16 18:32:21 +00001191
1192 registerService(Context.TIME_ZONE_RULES_MANAGER_SERVICE, RulesManager.class,
1193 new CachedServiceFetcher<RulesManager>() {
1194 @Override
1195 public RulesManager createService(ContextImpl ctx) {
1196 return new RulesManager(ctx.getOuterContext());
1197 }});
Tony Mak1b708e62017-10-12 10:59:11 +01001198
1199 registerService(Context.CROSS_PROFILE_APPS_SERVICE, CrossProfileApps.class,
1200 new CachedServiceFetcher<CrossProfileApps>() {
1201 @Override
1202 public CrossProfileApps createService(ContextImpl ctx)
1203 throws ServiceNotFoundException {
1204 IBinder b = ServiceManager.getServiceOrThrow(
1205 Context.CROSS_PROFILE_APPS_SERVICE);
1206 return new CrossProfileApps(ctx.getOuterContext(),
1207 ICrossProfileApps.Stub.asInterface(b));
1208 }
1209 });
Jason Monk8f5f7ff2017-10-17 14:12:42 -04001210
1211 registerService(Context.SLICE_SERVICE, SliceManager.class,
1212 new CachedServiceFetcher<SliceManager>() {
1213 @Override
1214 public SliceManager createService(ContextImpl ctx)
1215 throws ServiceNotFoundException {
1216 return new SliceManager(ctx.getOuterContext(),
1217 ctx.mMainThread.getHandler());
1218 }
1219 });
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07001220
1221 registerService(Context.DEVICE_IDLE_CONTROLLER, DeviceIdleManager.class,
1222 new CachedServiceFetcher<DeviceIdleManager>() {
1223 @Override
1224 public DeviceIdleManager createService(ContextImpl ctx)
1225 throws ServiceNotFoundException {
1226 IDeviceIdleController service = IDeviceIdleController.Stub.asInterface(
1227 ServiceManager.getServiceOrThrow(
1228 Context.DEVICE_IDLE_CONTROLLER));
1229 return new DeviceIdleManager(ctx.getOuterContext(), service);
1230 }});
Neil Fullerfeeee682018-05-30 14:35:24 +01001231
1232 registerService(Context.TIME_DETECTOR_SERVICE, TimeDetector.class,
1233 new CachedServiceFetcher<TimeDetector>() {
1234 @Override
1235 public TimeDetector createService(ContextImpl ctx)
1236 throws ServiceNotFoundException {
1237 return new TimeDetector();
1238 }});
Philip P. Moltmann039678e2018-09-18 13:04:38 -07001239
Neil Fuller3352cfc2019-11-07 15:35:05 +00001240 registerService(Context.TIME_ZONE_DETECTOR_SERVICE, TimeZoneDetector.class,
1241 new CachedServiceFetcher<TimeZoneDetector>() {
1242 @Override
1243 public TimeZoneDetector createService(ContextImpl ctx)
1244 throws ServiceNotFoundException {
1245 return new TimeZoneDetector();
1246 }});
1247
Philip P. Moltmann039678e2018-09-18 13:04:38 -07001248 registerService(Context.PERMISSION_SERVICE, PermissionManager.class,
1249 new CachedServiceFetcher<PermissionManager>() {
1250 @Override
1251 public PermissionManager createService(ContextImpl ctx) {
Svet Ganovd8eb8b22019-04-05 18:52:08 -07001252 IPackageManager packageManager = AppGlobals.getPackageManager();
1253 return new PermissionManager(ctx.getOuterContext(), packageManager);
Philip P. Moltmann039678e2018-09-18 13:04:38 -07001254 }});
Hai Zhang4ef21d02018-11-09 14:43:51 -08001255
Philip P. Moltmannbc054d82018-12-21 09:41:58 -08001256 registerService(Context.PERMISSION_CONTROLLER_SERVICE, PermissionControllerManager.class,
1257 new CachedServiceFetcher<PermissionControllerManager>() {
1258 @Override
1259 public PermissionControllerManager createService(ContextImpl ctx) {
Svet Ganovd8eb8b22019-04-05 18:52:08 -07001260 return new PermissionControllerManager(ctx.getOuterContext(),
1261 ctx.getMainThreadHandler());
Philip P. Moltmannbc054d82018-12-21 09:41:58 -08001262 }});
1263
Hai Zhang4ef21d02018-11-09 14:43:51 -08001264 registerService(Context.ROLE_SERVICE, RoleManager.class,
1265 new CachedServiceFetcher<RoleManager>() {
1266 @Override
1267 public RoleManager createService(ContextImpl ctx)
1268 throws ServiceNotFoundException {
1269 return new RoleManager(ctx.getOuterContext());
1270 }});
Richard Uhlerb29f1452018-09-12 16:38:15 +01001271
Hai Zhanga4959e52019-03-06 12:21:07 -08001272 registerService(Context.ROLE_CONTROLLER_SERVICE, RoleControllerManager.class,
1273 new CachedServiceFetcher<RoleControllerManager>() {
1274 @Override
1275 public RoleControllerManager createService(ContextImpl ctx)
1276 throws ServiceNotFoundException {
1277 return new RoleControllerManager(ctx.getOuterContext());
1278 }});
1279
Richard Uhlerb29f1452018-09-12 16:38:15 +01001280 registerService(Context.ROLLBACK_SERVICE, RollbackManager.class,
1281 new CachedServiceFetcher<RollbackManager>() {
1282 @Override
1283 public RollbackManager createService(ContextImpl ctx)
1284 throws ServiceNotFoundException {
1285 IBinder b = ServiceManager.getServiceOrThrow(Context.ROLLBACK_SERVICE);
1286 return new RollbackManager(ctx.getOuterContext(),
1287 IRollbackManager.Stub.asInterface(b));
1288 }});
Howard Chen0a947642019-01-07 14:10:44 +08001289
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08001290 registerService(Context.DYNAMIC_SYSTEM_SERVICE, DynamicSystemManager.class,
1291 new CachedServiceFetcher<DynamicSystemManager>() {
Howard Chen0a947642019-01-07 14:10:44 +08001292 @Override
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08001293 public DynamicSystemManager createService(ContextImpl ctx)
Howard Chen0a947642019-01-07 14:10:44 +08001294 throws ServiceNotFoundException {
1295 IBinder b = ServiceManager.getServiceOrThrow(
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08001296 Context.DYNAMIC_SYSTEM_SERVICE);
1297 return new DynamicSystemManager(
1298 IDynamicSystemService.Stub.asInterface(b));
Howard Chen0a947642019-01-07 14:10:44 +08001299 }});
Felipe Lemeecb08be2018-11-27 15:48:47 -08001300 //CHECKSTYLE:ON IndentationCheck
Jeff Brown6e539312015-02-24 18:53:21 -08001301 }
1302
1303 /**
1304 * Creates an array which is used to cache per-Context service instances.
1305 */
1306 public static Object[] createServiceCache() {
1307 return new Object[sServiceCacheSize];
1308 }
1309
1310 /**
1311 * Gets a system service from a given context.
1312 */
1313 public static Object getSystemService(ContextImpl ctx, String name) {
1314 ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name);
1315 return fetcher != null ? fetcher.getService(ctx) : null;
1316 }
1317
1318 /**
Paul McLeane3383cc2015-05-08 11:41:20 -07001319 * Gets the name of the system-level service that is represented by the specified class.
Jeff Brown6e539312015-02-24 18:53:21 -08001320 */
1321 public static String getSystemServiceName(Class<?> serviceClass) {
1322 return SYSTEM_SERVICE_NAMES.get(serviceClass);
1323 }
1324
1325 /**
1326 * Statically registers a system service with the context.
1327 * This method must be called during static initialization only.
1328 */
1329 private static <T> void registerService(String serviceName, Class<T> serviceClass,
1330 ServiceFetcher<T> serviceFetcher) {
1331 SYSTEM_SERVICE_NAMES.put(serviceClass, serviceName);
1332 SYSTEM_SERVICE_FETCHERS.put(serviceName, serviceFetcher);
1333 }
1334
1335 /**
1336 * Base interface for classes that fetch services.
1337 * These objects must only be created during static initialization.
1338 */
1339 static abstract interface ServiceFetcher<T> {
1340 T getService(ContextImpl ctx);
1341 }
1342
1343 /**
1344 * Override this class when the system service constructor needs a
1345 * ContextImpl and should be cached and retained by that context.
1346 */
1347 static abstract class CachedServiceFetcher<T> implements ServiceFetcher<T> {
1348 private final int mCacheIndex;
1349
Makoto Onukid67070e2018-03-30 12:39:14 -07001350 CachedServiceFetcher() {
1351 // Note this class must be instantiated only by the static initializer of the
1352 // outer class (SystemServiceRegistry), which already does the synchronization,
1353 // so bare access to sServiceCacheSize is okay here.
Jeff Brown6e539312015-02-24 18:53:21 -08001354 mCacheIndex = sServiceCacheSize++;
1355 }
1356
1357 @Override
1358 @SuppressWarnings("unchecked")
1359 public final T getService(ContextImpl ctx) {
1360 final Object[] cache = ctx.mServiceCache;
Makoto Onukid67070e2018-03-30 12:39:14 -07001361 final int[] gates = ctx.mServiceInitializationStateArray;
Makoto Onukif896f122018-01-25 09:50:24 -08001362
Makoto Onukid67070e2018-03-30 12:39:14 -07001363 for (;;) {
1364 boolean doInitialize = false;
1365 synchronized (cache) {
1366 // Return it if we already have a cached instance.
1367 T service = (T) cache[mCacheIndex];
1368 if (service != null || gates[mCacheIndex] == ContextImpl.STATE_NOT_FOUND) {
1369 return service;
1370 }
Makoto Onukif896f122018-01-25 09:50:24 -08001371
Makoto Onukid67070e2018-03-30 12:39:14 -07001372 // If we get here, there's no cached instance.
Makoto Onukif896f122018-01-25 09:50:24 -08001373
Makoto Onukid67070e2018-03-30 12:39:14 -07001374 // Grr... if gate is STATE_READY, then this means we initialized the service
1375 // once but someone cleared it.
1376 // We start over from STATE_UNINITIALIZED.
1377 if (gates[mCacheIndex] == ContextImpl.STATE_READY) {
1378 gates[mCacheIndex] = ContextImpl.STATE_UNINITIALIZED;
1379 }
1380
1381 // It's possible for multiple threads to get here at the same time, so
1382 // use the "gate" to make sure only the first thread will call createService().
1383
1384 // At this point, the gate must be either UNINITIALIZED or INITIALIZING.
1385 if (gates[mCacheIndex] == ContextImpl.STATE_UNINITIALIZED) {
1386 doInitialize = true;
1387 gates[mCacheIndex] = ContextImpl.STATE_INITIALIZING;
1388 }
Makoto Onukif896f122018-01-25 09:50:24 -08001389 }
1390
Makoto Onukid67070e2018-03-30 12:39:14 -07001391 if (doInitialize) {
1392 // Only the first thread gets here.
Makoto Onukif896f122018-01-25 09:50:24 -08001393
Makoto Onukid67070e2018-03-30 12:39:14 -07001394 T service = null;
1395 @ServiceInitializationState int newState = ContextImpl.STATE_NOT_FOUND;
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001396 try {
Makoto Onukid67070e2018-03-30 12:39:14 -07001397 // This thread is the first one to get here. Instantiate the service
1398 // *without* the cache lock held.
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001399 service = createService(ctx);
Makoto Onukid67070e2018-03-30 12:39:14 -07001400 newState = ContextImpl.STATE_READY;
Makoto Onukif896f122018-01-25 09:50:24 -08001401
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001402 } catch (ServiceNotFoundException e) {
Jeff Sharkey589f3092016-11-29 12:54:39 -07001403 onServiceNotFound(e);
Makoto Onukif896f122018-01-25 09:50:24 -08001404
Makoto Onukid67070e2018-03-30 12:39:14 -07001405 } finally {
1406 synchronized (cache) {
1407 cache[mCacheIndex] = service;
1408 gates[mCacheIndex] = newState;
1409 cache.notifyAll();
1410 }
1411 }
1412 return service;
1413 }
1414 // The other threads will wait for the first thread to call notifyAll(),
1415 // and go back to the top and retry.
1416 synchronized (cache) {
1417 while (gates[mCacheIndex] < ContextImpl.STATE_READY) {
1418 try {
1419 cache.wait();
1420 } catch (InterruptedException e) {
1421 Log.w(TAG, "getService() interrupted");
1422 Thread.currentThread().interrupt();
1423 return null;
1424 }
Makoto Onukif896f122018-01-25 09:50:24 -08001425 }
1426 }
Makoto Onukif896f122018-01-25 09:50:24 -08001427 }
Jeff Brown6e539312015-02-24 18:53:21 -08001428 }
1429
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001430 public abstract T createService(ContextImpl ctx) throws ServiceNotFoundException;
Jeff Brown6e539312015-02-24 18:53:21 -08001431 }
1432
1433 /**
1434 * Override this class when the system service does not need a ContextImpl
1435 * and should be cached and retained process-wide.
1436 */
1437 static abstract class StaticServiceFetcher<T> implements ServiceFetcher<T> {
1438 private T mCachedInstance;
1439
1440 @Override
Jeff Sharkey589f3092016-11-29 12:54:39 -07001441 public final T getService(ContextImpl ctx) {
Jeff Brown6e539312015-02-24 18:53:21 -08001442 synchronized (StaticServiceFetcher.this) {
1443 if (mCachedInstance == null) {
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001444 try {
1445 mCachedInstance = createService();
1446 } catch (ServiceNotFoundException e) {
Jeff Sharkey589f3092016-11-29 12:54:39 -07001447 onServiceNotFound(e);
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001448 }
Jeff Brown6e539312015-02-24 18:53:21 -08001449 }
1450 return mCachedInstance;
1451 }
1452 }
1453
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001454 public abstract T createService() throws ServiceNotFoundException;
Jeff Brown6e539312015-02-24 18:53:21 -08001455 }
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001456
1457 /**
Lorenzo Colitticf959772016-02-29 16:07:37 +09001458 * Like StaticServiceFetcher, creates only one instance of the service per application, but when
1459 * creating the service for the first time, passes it the application context of the creating
1460 * application.
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001461 *
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001462 * TODO: Delete this once its only user (ConnectivityManager) is known to work well in the
1463 * case where multiple application components each have their own ConnectivityManager object.
1464 */
Lorenzo Colitticf959772016-02-29 16:07:37 +09001465 static abstract class StaticApplicationContextServiceFetcher<T> implements ServiceFetcher<T> {
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001466 private T mCachedInstance;
1467
1468 @Override
1469 public final T getService(ContextImpl ctx) {
Lorenzo Colitticf959772016-02-29 16:07:37 +09001470 synchronized (StaticApplicationContextServiceFetcher.this) {
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001471 if (mCachedInstance == null) {
Lorenzo Colitti0ad9ab02016-03-25 17:40:11 +09001472 Context appContext = ctx.getApplicationContext();
1473 // If the application context is null, we're either in the system process or
1474 // it's the application context very early in app initialization. In both these
1475 // cases, the passed-in ContextImpl will not be freed, so it's safe to pass it
1476 // to the service. http://b/27532714 .
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001477 try {
1478 mCachedInstance = createService(appContext != null ? appContext : ctx);
1479 } catch (ServiceNotFoundException e) {
Jeff Sharkey589f3092016-11-29 12:54:39 -07001480 onServiceNotFound(e);
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001481 }
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001482 }
1483 return mCachedInstance;
1484 }
1485 }
1486
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001487 public abstract T createService(Context applicationContext) throws ServiceNotFoundException;
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001488 }
Jeff Sharkey589f3092016-11-29 12:54:39 -07001489
1490 public static void onServiceNotFound(ServiceNotFoundException e) {
1491 // We're mostly interested in tracking down long-lived core system
1492 // components that might stumble if they obtain bad references; just
1493 // emit a tidy log message for normal apps
1494 if (android.os.Process.myUid() < android.os.Process.FIRST_APPLICATION_UID) {
1495 Log.wtf(TAG, e.getMessage(), e);
1496 } else {
1497 Log.w(TAG, e.getMessage());
1498 }
1499 }
Jeff Brown6e539312015-02-24 18:53:21 -08001500}