blob: 90bc0a6dd11e5a4b8dd88580fd6753af9c41a040 [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;
Jeff Brown6e539312015-02-24 18:53:21 -080034import android.app.trust.TrustManager;
Jeff Sharkeye8cece92017-01-04 11:33:33 -070035import android.app.usage.IStorageStatsManager;
Jeff Brown6e539312015-02-24 18:53:21 -080036import android.app.usage.IUsageStatsManager;
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +000037import android.app.usage.NetworkStatsManager;
Jeff Sharkeye8cece92017-01-04 11:33:33 -070038import android.app.usage.StorageStatsManager;
Jeff Brown6e539312015-02-24 18:53:21 -080039import android.app.usage.UsageStatsManager;
40import android.appwidget.AppWidgetManager;
41import android.bluetooth.BluetoothManager;
Eugene Susla6ed45d82017-01-22 13:52:51 -080042import android.companion.CompanionDeviceManager;
43import android.companion.ICompanionDeviceManager;
Jeff Brown6e539312015-02-24 18:53:21 -080044import android.content.ClipboardManager;
Felipe Leme326f15a2019-02-19 09:42:24 -080045import android.content.ContentCaptureOptions;
Jeff Brown6e539312015-02-24 18:53:21 -080046import android.content.Context;
47import android.content.IRestrictionsManager;
48import android.content.RestrictionsManager;
Hyunyoung Song880a9512018-12-20 11:24:48 -080049import android.content.om.IOverlayManager;
50import android.content.om.OverlayManager;
Tony Makb0d22622018-01-18 12:49:49 +000051import android.content.pm.CrossProfileApps;
52import android.content.pm.ICrossProfileApps;
Makoto Onuki6f7362d92016-03-04 13:39:41 -080053import android.content.pm.IShortcutService;
Jeff Brown6e539312015-02-24 18:53:21 -080054import android.content.pm.LauncherApps;
Svet Ganovec7daa52017-06-30 12:02:59 -070055import android.content.pm.PackageManager;
Makoto Onuki6f7362d92016-03-04 13:39:41 -080056import android.content.pm.ShortcutManager;
Jeff Brown6e539312015-02-24 18:53:21 -080057import android.content.res.Resources;
Richard Uhlerb29f1452018-09-12 16:38:15 +010058import android.content.rollback.IRollbackManager;
59import android.content.rollback.RollbackManager;
Kenny Rootf74bfde2018-01-18 15:42:48 -080060import android.debug.AdbManager;
61import android.debug.IAdbManager;
Jeff Brown6e539312015-02-24 18:53:21 -080062import android.hardware.ConsumerIrManager;
63import android.hardware.ISerialManager;
64import android.hardware.SensorManager;
Chad Brubaker90f391f2018-10-19 10:26:19 -070065import android.hardware.SensorPrivacyManager;
Jeff Brown6e539312015-02-24 18:53:21 -080066import android.hardware.SerialManager;
67import android.hardware.SystemSensorManager;
Kevin Chyn05c21502018-09-18 13:07:19 -070068import android.hardware.biometrics.BiometricManager;
69import android.hardware.biometrics.IBiometricService;
Jeff Brown6e539312015-02-24 18:53:21 -080070import android.hardware.camera2.CameraManager;
Christine Franks39b03112018-07-03 14:46:07 -070071import android.hardware.display.ColorDisplayManager;
Jeff Brown6e539312015-02-24 18:53:21 -080072import android.hardware.display.DisplayManager;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020073import android.hardware.face.FaceManager;
74import android.hardware.face.IFaceService;
Jeff Sharkey49ca5292016-05-10 12:54:45 -060075import android.hardware.fingerprint.FingerprintManager;
76import android.hardware.fingerprint.IFingerprintService;
Jeff Brown6e539312015-02-24 18:53:21 -080077import android.hardware.hdmi.HdmiControlManager;
78import android.hardware.hdmi.IHdmiControlService;
79import android.hardware.input.InputManager;
Kevin Chyn51676d22018-11-05 18:00:43 -080080import android.hardware.iris.IIrisService;
Felipe Lemee348dc32018-11-05 12:35:29 -080081import android.hardware.iris.IrisManager;
Peng Xu9ff7d222016-02-11 13:02:05 -080082import android.hardware.location.ContextHubManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -060083import android.hardware.radio.RadioManager;
Jeff Brown6e539312015-02-24 18:53:21 -080084import android.hardware.usb.IUsbManager;
85import android.hardware.usb.UsbManager;
86import android.location.CountryDetector;
87import android.location.ICountryDetector;
88import android.location.ILocationManager;
89import android.location.LocationManager;
90import android.media.AudioManager;
91import android.media.MediaRouter;
92import android.media.midi.IMidiManager;
93import android.media.midi.MidiManager;
94import android.media.projection.MediaProjectionManager;
95import android.media.session.MediaSessionManager;
Arunesh Mishraa772e5f2016-01-25 10:33:11 -080096import android.media.soundtrigger.SoundTriggerManager;
Jeff Brown6e539312015-02-24 18:53:21 -080097import android.media.tv.ITvInputManager;
98import android.media.tv.TvInputManager;
99import android.net.ConnectivityManager;
Paul Stewartbf8cbb052016-03-17 10:11:54 -0700100import android.net.ConnectivityThread;
Jeff Brown6e539312015-02-24 18:53:21 -0800101import android.net.EthernetManager;
102import android.net.IConnectivityManager;
103import android.net.IEthernetManager;
Chalard Jean8c141bd2018-12-04 20:20:56 +0900104import android.net.IIpMemoryStore;
Nathan Harold28084d82017-03-01 18:55:06 -0800105import android.net.IIpSecService;
Jeff Brown6e539312015-02-24 18:53:21 -0800106import android.net.INetworkPolicyManager;
Chalard Jean8c141bd2018-12-04 20:20:56 +0900107import android.net.IpMemoryStore;
Nathan Harold28084d82017-03-01 18:55:06 -0800108import android.net.IpSecManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800109import android.net.NetworkPolicyManager;
110import android.net.NetworkScoreManager;
Ricky Wai1a6e6672017-10-27 14:46:01 +0100111import android.net.NetworkWatchlistManager;
Robert Quattlebaum87a71042017-05-15 15:45:20 -0700112import android.net.lowpan.ILowpanManager;
113import android.net.lowpan.LowpanManager;
Etan Cohen17ba4722017-08-21 10:52:17 -0700114import android.net.nsd.INsdManager;
115import android.net.nsd.NsdManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800116import android.net.wifi.IWifiManager;
117import android.net.wifi.IWifiScanner;
118import android.net.wifi.RttManager;
119import android.net.wifi.WifiManager;
120import android.net.wifi.WifiScanner;
Etan Cohen04133272016-10-26 11:22:06 -0700121import android.net.wifi.aware.IWifiAwareManager;
122import android.net.wifi.aware.WifiAwareManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800123import android.net.wifi.p2p.IWifiP2pManager;
124import android.net.wifi.p2p.WifiP2pManager;
Etan Cohen17ba4722017-08-21 10:52:17 -0700125import android.net.wifi.rtt.IWifiRttManager;
126import android.net.wifi.rtt.WifiRttManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800127import android.nfc.NfcManager;
128import android.os.BatteryManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600129import android.os.BatteryStats;
Nandana Duttd11850c2018-12-12 17:26:57 +0000130import android.os.BugreportManager;
Jeff Sharkey351c2c22017-03-18 16:48:02 -0600131import android.os.Build;
Philip P. Moltmannf80809f2018-04-04 11:20:44 -0700132import android.os.DeviceIdleManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800133import android.os.DropBoxManager;
Howard Chen0a947642019-01-07 14:10:44 +0800134import android.os.DynamicAndroidManager;
Polina Bondarenko965ecbb2015-11-13 15:34:28 +0100135import android.os.HardwarePropertiesManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600136import android.os.IBatteryPropertiesRegistrar;
Jeff Brown6e539312015-02-24 18:53:21 -0800137import android.os.IBinder;
Philip P. Moltmannf80809f2018-04-04 11:20:44 -0700138import android.os.IDeviceIdleController;
Nandana Duttd11850c2018-12-12 17:26:57 +0000139import android.os.IDumpstate;
Howard Chen0a947642019-01-07 14:10:44 +0800140import android.os.IDynamicAndroidService;
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;
Jeff Brown6e539312015-02-24 18:53:21 -0800149import android.os.ServiceManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600150import android.os.ServiceManager.ServiceNotFoundException;
Tao Bao07342dc2017-01-24 15:08:21 -0800151import android.os.SystemUpdateManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800152import android.os.SystemVibrator;
153import android.os.UserHandle;
154import android.os.UserManager;
155import android.os.Vibrator;
Joe Onorato713fec82016-03-04 10:34:02 -0800156import android.os.health.SystemHealthManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800157import android.os.storage.StorageManager;
Philip P. Moltmannbc054d82018-12-21 09:41:58 -0800158import android.permission.PermissionControllerManager;
Philip P. Moltmann039678e2018-09-18 13:04:38 -0700159import android.permission.PermissionManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800160import android.print.IPrintManager;
161import android.print.PrintManager;
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000162import android.service.oemlock.IOemLockService;
163import android.service.oemlock.OemLockManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800164import android.service.persistentdata.IPersistentDataBlockService;
165import android.service.persistentdata.PersistentDataBlockManager;
Zak Cohen56345f42017-01-26 13:54:28 -0800166import android.service.vr.IVrManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800167import android.telecom.TelecomManager;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800168import android.telephony.CarrierConfigManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800169import android.telephony.SubscriptionManager;
170import android.telephony.TelephonyManager;
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -0800171import android.telephony.euicc.EuiccCardManager;
Neil Fuller009e77a2017-05-04 16:53:41 +0100172import android.telephony.euicc.EuiccManager;
Sahin Caliskan84dd3062018-12-03 14:06:39 -0800173import android.telephony.ims.RcsManager;
Robert Benea1901a5b2018-05-15 16:36:07 -0700174import android.util.ArrayMap;
Jeff Brown6e539312015-02-24 18:53:21 -0800175import android.util.Log;
176import android.view.ContextThemeWrapper;
177import android.view.LayoutInflater;
Jeff Brown6e539312015-02-24 18:53:21 -0800178import android.view.WindowManager;
179import android.view.WindowManagerImpl;
180import android.view.accessibility.AccessibilityManager;
181import android.view.accessibility.CaptioningManager;
Neil Fuller009e77a2017-05-04 16:53:41 +0100182import android.view.autofill.AutofillManager;
183import android.view.autofill.IAutoFillManager;
Felipe Leme749b8892018-12-03 16:30:30 -0800184import android.view.contentcapture.ContentCaptureManager;
185import android.view.contentcapture.IContentCaptureManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800186import android.view.inputmethod.InputMethodManager;
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +0000187import android.view.textclassifier.TextClassificationManager;
Jeff Brown6e539312015-02-24 18:53:21 -0800188import android.view.textservice.TextServicesManager;
189
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600190import com.android.internal.app.IAppOpsService;
191import com.android.internal.app.IBatteryStats;
192import com.android.internal.app.ISoundTriggerService;
193import com.android.internal.appwidget.IAppWidgetService;
Ricky Wai1a6e6672017-10-27 14:46:01 +0100194import com.android.internal.net.INetworkWatchlistManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600195import com.android.internal.os.IDropBoxManagerService;
196import com.android.internal.policy.PhoneLayoutInflater;
197
Robert Benea1901a5b2018-05-15 16:36:07 -0700198import java.util.Map;
Jeff Brown6e539312015-02-24 18:53:21 -0800199
200/**
201 * Manages all of the system services that can be returned by {@link Context#getSystemService}.
202 * Used by {@link ContextImpl}.
203 */
204final class SystemServiceRegistry {
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600205 private static final String TAG = "SystemServiceRegistry";
206
Jeff Brown6e539312015-02-24 18:53:21 -0800207 // Service registry information.
208 // This information is never changed once static initialization has completed.
Robert Benea1901a5b2018-05-15 16:36:07 -0700209 private static final Map<Class<?>, String> SYSTEM_SERVICE_NAMES =
210 new ArrayMap<Class<?>, String>();
211 private static final Map<String, ServiceFetcher<?>> SYSTEM_SERVICE_FETCHERS =
212 new ArrayMap<String, ServiceFetcher<?>>();
Jeff Brown6e539312015-02-24 18:53:21 -0800213 private static int sServiceCacheSize;
214
215 // Not instantiable.
216 private SystemServiceRegistry() { }
217
218 static {
Felipe Lemeecb08be2018-11-27 15:48:47 -0800219 //CHECKSTYLE:OFF IndentationCheck
Jeff Brown6e539312015-02-24 18:53:21 -0800220 registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class,
221 new CachedServiceFetcher<AccessibilityManager>() {
222 @Override
223 public AccessibilityManager createService(ContextImpl ctx) {
224 return AccessibilityManager.getInstance(ctx);
225 }});
226
227 registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class,
228 new CachedServiceFetcher<CaptioningManager>() {
229 @Override
230 public CaptioningManager createService(ContextImpl ctx) {
231 return new CaptioningManager(ctx);
232 }});
233
234 registerService(Context.ACCOUNT_SERVICE, AccountManager.class,
235 new CachedServiceFetcher<AccountManager>() {
236 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600237 public AccountManager createService(ContextImpl ctx) throws ServiceNotFoundException {
238 IBinder b = ServiceManager.getServiceOrThrow(Context.ACCOUNT_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800239 IAccountManager service = IAccountManager.Stub.asInterface(b);
240 return new AccountManager(ctx, service);
241 }});
242
243 registerService(Context.ACTIVITY_SERVICE, ActivityManager.class,
244 new CachedServiceFetcher<ActivityManager>() {
245 @Override
246 public ActivityManager createService(ContextImpl ctx) {
247 return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler());
248 }});
249
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700250 registerService(Context.ACTIVITY_TASK_SERVICE, ActivityTaskManager.class,
251 new CachedServiceFetcher<ActivityTaskManager>() {
252 @Override
253 public ActivityTaskManager createService(ContextImpl ctx) {
254 return new ActivityTaskManager(
255 ctx.getOuterContext(), ctx.mMainThread.getHandler());
256 }});
257
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -0700258 registerService(Context.URI_GRANTS_SERVICE, UriGrantsManager.class,
259 new CachedServiceFetcher<UriGrantsManager>() {
260 @Override
261 public UriGrantsManager createService(ContextImpl ctx) {
262 return new UriGrantsManager(
263 ctx.getOuterContext(), ctx.mMainThread.getHandler());
264 }});
265
Jeff Brown6e539312015-02-24 18:53:21 -0800266 registerService(Context.ALARM_SERVICE, AlarmManager.class,
267 new CachedServiceFetcher<AlarmManager>() {
268 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600269 public AlarmManager createService(ContextImpl ctx) throws ServiceNotFoundException {
270 IBinder b = ServiceManager.getServiceOrThrow(Context.ALARM_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800271 IAlarmManager service = IAlarmManager.Stub.asInterface(b);
272 return new AlarmManager(service, ctx);
273 }});
274
275 registerService(Context.AUDIO_SERVICE, AudioManager.class,
276 new CachedServiceFetcher<AudioManager>() {
277 @Override
278 public AudioManager createService(ContextImpl ctx) {
279 return new AudioManager(ctx);
280 }});
281
282 registerService(Context.MEDIA_ROUTER_SERVICE, MediaRouter.class,
283 new CachedServiceFetcher<MediaRouter>() {
284 @Override
285 public MediaRouter createService(ContextImpl ctx) {
286 return new MediaRouter(ctx);
287 }});
288
289 registerService(Context.BLUETOOTH_SERVICE, BluetoothManager.class,
290 new CachedServiceFetcher<BluetoothManager>() {
291 @Override
292 public BluetoothManager createService(ContextImpl ctx) {
293 return new BluetoothManager(ctx);
294 }});
295
296 registerService(Context.HDMI_CONTROL_SERVICE, HdmiControlManager.class,
297 new StaticServiceFetcher<HdmiControlManager>() {
298 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600299 public HdmiControlManager createService() throws ServiceNotFoundException {
300 IBinder b = ServiceManager.getServiceOrThrow(Context.HDMI_CONTROL_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800301 return new HdmiControlManager(IHdmiControlService.Stub.asInterface(b));
302 }});
303
Abodunrinwa Toki8158af52016-11-23 20:41:09 +0000304 registerService(Context.TEXT_CLASSIFICATION_SERVICE, TextClassificationManager.class,
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +0000305 new CachedServiceFetcher<TextClassificationManager>() {
Abodunrinwa Toki8158af52016-11-23 20:41:09 +0000306 @Override
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +0000307 public TextClassificationManager createService(ContextImpl ctx) {
308 return new TextClassificationManager(ctx);
Abodunrinwa Toki8158af52016-11-23 20:41:09 +0000309 }});
310
Jeff Brown6e539312015-02-24 18:53:21 -0800311 registerService(Context.CLIPBOARD_SERVICE, ClipboardManager.class,
312 new CachedServiceFetcher<ClipboardManager>() {
313 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600314 public ClipboardManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Brown6e539312015-02-24 18:53:21 -0800315 return new ClipboardManager(ctx.getOuterContext(),
316 ctx.mMainThread.getHandler());
317 }});
318
319 // The clipboard service moved to a new package. If someone asks for the old
320 // interface by class then we want to redirect over to the new interface instead
321 // (which extends it).
322 SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE);
323
324 registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class,
Lorenzo Colitticf959772016-02-29 16:07:37 +0900325 new StaticApplicationContextServiceFetcher<ConnectivityManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800326 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600327 public ConnectivityManager createService(Context context) throws ServiceNotFoundException {
328 IBinder b = ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE);
Lorenzo Colittiffc42b02015-07-29 11:41:21 +0900329 IConnectivityManager service = IConnectivityManager.Stub.asInterface(b);
330 return new ConnectivityManager(context, service);
Jeff Brown6e539312015-02-24 18:53:21 -0800331 }});
332
Remi NGUYEN VANf9a8c2e2019-02-13 18:28:35 +0900333 registerService(Context.NETD_SERVICE, IBinder.class, new StaticServiceFetcher<IBinder>() {
Remi NGUYEN VAN31935982019-01-28 11:40:08 +0900334 @Override
Remi NGUYEN VANf9a8c2e2019-02-13 18:28:35 +0900335 public IBinder createService() throws ServiceNotFoundException {
336 return ServiceManager.getServiceOrThrow(Context.NETD_SERVICE);
Remi NGUYEN VAN31935982019-01-28 11:40:08 +0900337 }
338 });
339
Chalard Jean8c141bd2018-12-04 20:20:56 +0900340 registerService(Context.IP_MEMORY_STORE_SERVICE, IpMemoryStore.class,
341 new CachedServiceFetcher<IpMemoryStore>() {
342 @Override
343 public IpMemoryStore createService(final ContextImpl ctx)
344 throws ServiceNotFoundException {
345 IBinder b = ServiceManager.getServiceOrThrow(
346 Context.IP_MEMORY_STORE_SERVICE);
347 IIpMemoryStore service = IIpMemoryStore.Stub.asInterface(b);
348 return new IpMemoryStore(ctx, service);
349 }});
Remi NGUYEN VANc094a542018-12-07 16:52:24 +0900350
Nathan Harold28084d82017-03-01 18:55:06 -0800351 registerService(Context.IPSEC_SERVICE, IpSecManager.class,
Nathan Harold592dadb2018-03-15 18:06:06 -0700352 new CachedServiceFetcher<IpSecManager>() {
Nathan Harold28084d82017-03-01 18:55:06 -0800353 @Override
Nathan Harold592dadb2018-03-15 18:06:06 -0700354 public IpSecManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Nathan Harold28084d82017-03-01 18:55:06 -0800355 IBinder b = ServiceManager.getService(Context.IPSEC_SERVICE);
356 IIpSecService service = IIpSecService.Stub.asInterface(b);
Nathan Harold592dadb2018-03-15 18:06:06 -0700357 return new IpSecManager(ctx, service);
Nathan Harold28084d82017-03-01 18:55:06 -0800358 }});
359
Jeff Brown6e539312015-02-24 18:53:21 -0800360 registerService(Context.COUNTRY_DETECTOR, CountryDetector.class,
361 new StaticServiceFetcher<CountryDetector>() {
362 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600363 public CountryDetector createService() throws ServiceNotFoundException {
364 IBinder b = ServiceManager.getServiceOrThrow(Context.COUNTRY_DETECTOR);
Jeff Brown6e539312015-02-24 18:53:21 -0800365 return new CountryDetector(ICountryDetector.Stub.asInterface(b));
366 }});
367
368 registerService(Context.DEVICE_POLICY_SERVICE, DevicePolicyManager.class,
369 new CachedServiceFetcher<DevicePolicyManager>() {
370 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600371 public DevicePolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException {
372 IBinder b = ServiceManager.getServiceOrThrow(Context.DEVICE_POLICY_SERVICE);
373 return new DevicePolicyManager(ctx, IDevicePolicyManager.Stub.asInterface(b));
Jeff Brown6e539312015-02-24 18:53:21 -0800374 }});
375
376 registerService(Context.DOWNLOAD_SERVICE, DownloadManager.class,
377 new CachedServiceFetcher<DownloadManager>() {
378 @Override
379 public DownloadManager createService(ContextImpl ctx) {
Jeff Sharkey60cfad82016-01-05 17:30:57 -0700380 return new DownloadManager(ctx);
Jeff Brown6e539312015-02-24 18:53:21 -0800381 }});
382
383 registerService(Context.BATTERY_SERVICE, BatteryManager.class,
Yifan Hongb0f13522017-10-31 15:48:50 -0700384 new CachedServiceFetcher<BatteryManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800385 @Override
Yifan Hongb0f13522017-10-31 15:48:50 -0700386 public BatteryManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600387 IBatteryStats stats = IBatteryStats.Stub.asInterface(
388 ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME));
389 IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub
390 .asInterface(ServiceManager.getServiceOrThrow("batteryproperties"));
Yifan Hongb0f13522017-10-31 15:48:50 -0700391 return new BatteryManager(ctx, stats, registrar);
Jeff Brown6e539312015-02-24 18:53:21 -0800392 }});
393
394 registerService(Context.NFC_SERVICE, NfcManager.class,
395 new CachedServiceFetcher<NfcManager>() {
396 @Override
397 public NfcManager createService(ContextImpl ctx) {
398 return new NfcManager(ctx);
399 }});
400
401 registerService(Context.DROPBOX_SERVICE, DropBoxManager.class,
Jeff Sharkeyb8e8a912016-03-09 16:27:40 -0700402 new CachedServiceFetcher<DropBoxManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800403 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600404 public DropBoxManager createService(ContextImpl ctx) throws ServiceNotFoundException {
405 IBinder b = ServiceManager.getServiceOrThrow(Context.DROPBOX_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800406 IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b);
Jeff Sharkeyb8e8a912016-03-09 16:27:40 -0700407 return new DropBoxManager(ctx, service);
Jeff Brown6e539312015-02-24 18:53:21 -0800408 }});
409
410 registerService(Context.INPUT_SERVICE, InputManager.class,
411 new StaticServiceFetcher<InputManager>() {
412 @Override
413 public InputManager createService() {
414 return InputManager.getInstance();
415 }});
416
417 registerService(Context.DISPLAY_SERVICE, DisplayManager.class,
418 new CachedServiceFetcher<DisplayManager>() {
419 @Override
420 public DisplayManager createService(ContextImpl ctx) {
421 return new DisplayManager(ctx.getOuterContext());
422 }});
423
Christine Franks39b03112018-07-03 14:46:07 -0700424 registerService(Context.COLOR_DISPLAY_SERVICE, ColorDisplayManager.class,
425 new CachedServiceFetcher<ColorDisplayManager>() {
426 @Override
427 public ColorDisplayManager createService(ContextImpl ctx) {
428 return new ColorDisplayManager();
429 }
430 });
431
Yohei Yukawa4052a10f2018-10-15 15:35:55 +0800432 // InputMethodManager has its own cache strategy based on display id to support apps that
433 // still assume InputMethodManager is a per-process singleton and it's safe to directly
434 // access internal fields via reflection. Hence directly use ServiceFetcher instead of
435 // StaticServiceFetcher/CachedServiceFetcher.
Jeff Brown6e539312015-02-24 18:53:21 -0800436 registerService(Context.INPUT_METHOD_SERVICE, InputMethodManager.class,
Yohei Yukawa4052a10f2018-10-15 15:35:55 +0800437 new ServiceFetcher<InputMethodManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800438 @Override
Yohei Yukawa4052a10f2018-10-15 15:35:55 +0800439 public InputMethodManager getService(ContextImpl ctx) {
440 return InputMethodManager.forContext(ctx.getOuterContext());
Jeff Brown6e539312015-02-24 18:53:21 -0800441 }});
442
443 registerService(Context.TEXT_SERVICES_MANAGER_SERVICE, TextServicesManager.class,
Yohei Yukawa9f141ee2019-01-18 09:17:16 -0800444 new CachedServiceFetcher<TextServicesManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800445 @Override
Yohei Yukawa9f141ee2019-01-18 09:17:16 -0800446 public TextServicesManager createService(ContextImpl ctx)
447 throws ServiceNotFoundException {
448 return TextServicesManager.createInstance(ctx);
Jeff Brown6e539312015-02-24 18:53:21 -0800449 }});
450
451 registerService(Context.KEYGUARD_SERVICE, KeyguardManager.class,
Nancy Zheng43f166d2016-11-18 18:15:09 -0800452 new CachedServiceFetcher<KeyguardManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800453 @Override
Nancy Zheng40cd8e42016-11-21 12:58:16 -0800454 public KeyguardManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Nancy Zheng43f166d2016-11-18 18:15:09 -0800455 return new KeyguardManager(ctx);
Jeff Brown6e539312015-02-24 18:53:21 -0800456 }});
457
458 registerService(Context.LAYOUT_INFLATER_SERVICE, LayoutInflater.class,
459 new CachedServiceFetcher<LayoutInflater>() {
460 @Override
461 public LayoutInflater createService(ContextImpl ctx) {
462 return new PhoneLayoutInflater(ctx.getOuterContext());
463 }});
464
465 registerService(Context.LOCATION_SERVICE, LocationManager.class,
466 new CachedServiceFetcher<LocationManager>() {
467 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600468 public LocationManager createService(ContextImpl ctx) throws ServiceNotFoundException {
469 IBinder b = ServiceManager.getServiceOrThrow(Context.LOCATION_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800470 return new LocationManager(ctx, ILocationManager.Stub.asInterface(b));
471 }});
472
473 registerService(Context.NETWORK_POLICY_SERVICE, NetworkPolicyManager.class,
Svet Ganov16a16892015-04-16 10:32:04 -0700474 new CachedServiceFetcher<NetworkPolicyManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800475 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600476 public NetworkPolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Svet Ganov16a16892015-04-16 10:32:04 -0700477 return new NetworkPolicyManager(ctx, INetworkPolicyManager.Stub.asInterface(
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600478 ServiceManager.getServiceOrThrow(Context.NETWORK_POLICY_SERVICE)));
Jeff Brown6e539312015-02-24 18:53:21 -0800479 }});
480
481 registerService(Context.NOTIFICATION_SERVICE, NotificationManager.class,
482 new CachedServiceFetcher<NotificationManager>() {
483 @Override
484 public NotificationManager createService(ContextImpl ctx) {
485 final Context outerContext = ctx.getOuterContext();
486 return new NotificationManager(
487 new ContextThemeWrapper(outerContext,
488 Resources.selectSystemTheme(0,
489 outerContext.getApplicationInfo().targetSdkVersion,
490 com.android.internal.R.style.Theme_Dialog,
491 com.android.internal.R.style.Theme_Holo_Dialog,
492 com.android.internal.R.style.Theme_DeviceDefault_Dialog,
493 com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog)),
494 ctx.mMainThread.getHandler());
495 }});
496
497 registerService(Context.NSD_SERVICE, NsdManager.class,
498 new CachedServiceFetcher<NsdManager>() {
499 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600500 public NsdManager createService(ContextImpl ctx) throws ServiceNotFoundException {
501 IBinder b = ServiceManager.getServiceOrThrow(Context.NSD_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800502 INsdManager service = INsdManager.Stub.asInterface(b);
503 return new NsdManager(ctx.getOuterContext(), service);
504 }});
505
506 registerService(Context.POWER_SERVICE, PowerManager.class,
507 new CachedServiceFetcher<PowerManager>() {
508 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600509 public PowerManager createService(ContextImpl ctx) throws ServiceNotFoundException {
510 IBinder b = ServiceManager.getServiceOrThrow(Context.POWER_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800511 IPowerManager service = IPowerManager.Stub.asInterface(b);
Jeff Brown6e539312015-02-24 18:53:21 -0800512 return new PowerManager(ctx.getOuterContext(),
513 service, ctx.mMainThread.getHandler());
514 }});
515
Tao Baoe8a403d2015-12-31 07:44:55 -0800516 registerService(Context.RECOVERY_SERVICE, RecoverySystem.class,
517 new CachedServiceFetcher<RecoverySystem>() {
518 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600519 public RecoverySystem createService(ContextImpl ctx) throws ServiceNotFoundException {
520 IBinder b = ServiceManager.getServiceOrThrow(Context.RECOVERY_SERVICE);
Tao Baoe8a403d2015-12-31 07:44:55 -0800521 IRecoverySystem service = IRecoverySystem.Stub.asInterface(b);
Tao Baoe8a403d2015-12-31 07:44:55 -0800522 return new RecoverySystem(service);
523 }});
524
Jeff Brown6e539312015-02-24 18:53:21 -0800525 registerService(Context.SEARCH_SERVICE, SearchManager.class,
526 new CachedServiceFetcher<SearchManager>() {
527 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600528 public SearchManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Brown6e539312015-02-24 18:53:21 -0800529 return new SearchManager(ctx.getOuterContext(),
530 ctx.mMainThread.getHandler());
531 }});
532
533 registerService(Context.SENSOR_SERVICE, SensorManager.class,
534 new CachedServiceFetcher<SensorManager>() {
535 @Override
536 public SensorManager createService(ContextImpl ctx) {
537 return new SystemSensorManager(ctx.getOuterContext(),
538 ctx.mMainThread.getHandler().getLooper());
539 }});
540
Chad Brubaker90f391f2018-10-19 10:26:19 -0700541 registerService(Context.SENSOR_PRIVACY_SERVICE, SensorPrivacyManager.class,
542 new CachedServiceFetcher<SensorPrivacyManager>() {
543 @Override
544 public SensorPrivacyManager createService(ContextImpl ctx) {
545 return SensorPrivacyManager.getInstance(ctx);
546 }});
547
David Chenadaf8b32017-11-03 15:42:08 -0700548 registerService(Context.STATS_MANAGER, StatsManager.class,
Jeff Sharkey6b649252018-04-16 09:50:22 -0600549 new CachedServiceFetcher<StatsManager>() {
550 @Override
551 public StatsManager createService(ContextImpl ctx) {
552 return new StatsManager(ctx.getOuterContext());
553 }});
David Chenadaf8b32017-11-03 15:42:08 -0700554
Jeff Brown6e539312015-02-24 18:53:21 -0800555 registerService(Context.STATUS_BAR_SERVICE, StatusBarManager.class,
556 new CachedServiceFetcher<StatusBarManager>() {
557 @Override
558 public StatusBarManager createService(ContextImpl ctx) {
559 return new StatusBarManager(ctx.getOuterContext());
560 }});
561
562 registerService(Context.STORAGE_SERVICE, StorageManager.class,
563 new CachedServiceFetcher<StorageManager>() {
564 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600565 public StorageManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Sharkey48877892015-03-18 11:27:19 -0700566 return new StorageManager(ctx, ctx.mMainThread.getHandler().getLooper());
Jeff Brown6e539312015-02-24 18:53:21 -0800567 }});
568
Jeff Sharkeye8cece92017-01-04 11:33:33 -0700569 registerService(Context.STORAGE_STATS_SERVICE, StorageStatsManager.class,
570 new CachedServiceFetcher<StorageStatsManager>() {
571 @Override
572 public StorageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
573 IStorageStatsManager service = IStorageStatsManager.Stub.asInterface(
574 ServiceManager.getServiceOrThrow(Context.STORAGE_STATS_SERVICE));
575 return new StorageStatsManager(ctx, service);
576 }});
577
Tao Bao07342dc2017-01-24 15:08:21 -0800578 registerService(Context.SYSTEM_UPDATE_SERVICE, SystemUpdateManager.class,
579 new CachedServiceFetcher<SystemUpdateManager>() {
580 @Override
581 public SystemUpdateManager createService(ContextImpl ctx)
582 throws ServiceNotFoundException {
583 IBinder b = ServiceManager.getServiceOrThrow(
584 Context.SYSTEM_UPDATE_SERVICE);
585 ISystemUpdateManager service = ISystemUpdateManager.Stub.asInterface(b);
586 return new SystemUpdateManager(service);
587 }});
588
Jeff Brown6e539312015-02-24 18:53:21 -0800589 registerService(Context.TELEPHONY_SERVICE, TelephonyManager.class,
590 new CachedServiceFetcher<TelephonyManager>() {
591 @Override
592 public TelephonyManager createService(ContextImpl ctx) {
593 return new TelephonyManager(ctx.getOuterContext());
594 }});
595
596 registerService(Context.TELEPHONY_SUBSCRIPTION_SERVICE, SubscriptionManager.class,
597 new CachedServiceFetcher<SubscriptionManager>() {
598 @Override
Jeff Sharkey717f52f2018-01-04 16:04:11 -0700599 public SubscriptionManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Brown6e539312015-02-24 18:53:21 -0800600 return new SubscriptionManager(ctx.getOuterContext());
601 }});
602
Sahin Caliskan9458ebc2018-10-31 13:23:29 -0700603 registerService(Context.TELEPHONY_RCS_SERVICE, RcsManager.class,
604 new CachedServiceFetcher<RcsManager>() {
605 @Override
606 public RcsManager createService(ContextImpl ctx) {
607 return new RcsManager();
608 }
609 });
610
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800611 registerService(Context.CARRIER_CONFIG_SERVICE, CarrierConfigManager.class,
612 new CachedServiceFetcher<CarrierConfigManager>() {
613 @Override
614 public CarrierConfigManager createService(ContextImpl ctx) {
Malcolm Chend1272d12018-02-28 15:20:45 -0800615 return new CarrierConfigManager(ctx.getOuterContext());
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800616 }});
617
Jeff Brown6e539312015-02-24 18:53:21 -0800618 registerService(Context.TELECOM_SERVICE, TelecomManager.class,
619 new CachedServiceFetcher<TelecomManager>() {
620 @Override
621 public TelecomManager createService(ContextImpl ctx) {
622 return new TelecomManager(ctx.getOuterContext());
623 }});
624
Jeff Davidson35cda392017-02-27 09:46:00 -0800625 registerService(Context.EUICC_SERVICE, EuiccManager.class,
626 new CachedServiceFetcher<EuiccManager>() {
627 @Override
628 public EuiccManager createService(ContextImpl ctx) {
629 return new EuiccManager(ctx.getOuterContext());
630 }});
631
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -0800632 registerService(Context.EUICC_CARD_SERVICE, EuiccCardManager.class,
633 new CachedServiceFetcher<EuiccCardManager>() {
634 @Override
635 public EuiccCardManager createService(ContextImpl ctx) {
636 return new EuiccCardManager(ctx.getOuterContext());
637 }});
638
Jeff Brown6e539312015-02-24 18:53:21 -0800639 registerService(Context.UI_MODE_SERVICE, UiModeManager.class,
640 new CachedServiceFetcher<UiModeManager>() {
641 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600642 public UiModeManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Brown6e539312015-02-24 18:53:21 -0800643 return new UiModeManager();
644 }});
645
646 registerService(Context.USB_SERVICE, UsbManager.class,
647 new CachedServiceFetcher<UsbManager>() {
648 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600649 public UsbManager createService(ContextImpl ctx) throws ServiceNotFoundException {
650 IBinder b = ServiceManager.getServiceOrThrow(Context.USB_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800651 return new UsbManager(ctx, IUsbManager.Stub.asInterface(b));
652 }});
653
Kenny Rootf74bfde2018-01-18 15:42:48 -0800654 registerService(Context.ADB_SERVICE, AdbManager.class,
655 new CachedServiceFetcher<AdbManager>() {
656 @Override
657 public AdbManager createService(ContextImpl ctx)
658 throws ServiceNotFoundException {
659 IBinder b = ServiceManager.getServiceOrThrow(Context.ADB_SERVICE);
660 return new AdbManager(ctx, IAdbManager.Stub.asInterface(b));
661 }});
662
Jeff Brown6e539312015-02-24 18:53:21 -0800663 registerService(Context.SERIAL_SERVICE, SerialManager.class,
664 new CachedServiceFetcher<SerialManager>() {
665 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600666 public SerialManager createService(ContextImpl ctx) throws ServiceNotFoundException {
667 IBinder b = ServiceManager.getServiceOrThrow(Context.SERIAL_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800668 return new SerialManager(ctx, ISerialManager.Stub.asInterface(b));
669 }});
670
671 registerService(Context.VIBRATOR_SERVICE, Vibrator.class,
672 new CachedServiceFetcher<Vibrator>() {
673 @Override
674 public Vibrator createService(ContextImpl ctx) {
675 return new SystemVibrator(ctx);
676 }});
677
678 registerService(Context.WALLPAPER_SERVICE, WallpaperManager.class,
679 new CachedServiceFetcher<WallpaperManager>() {
680 @Override
Svet Ganov8f90bcc2017-12-22 23:29:24 -0800681 public WallpaperManager createService(ContextImpl ctx)
682 throws ServiceNotFoundException {
683 final IBinder b;
684 if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) {
685 b = ServiceManager.getServiceOrThrow(Context.WALLPAPER_SERVICE);
686 } else {
687 b = ServiceManager.getService(Context.WALLPAPER_SERVICE);
688 }
689 IWallpaperManager service = IWallpaperManager.Stub.asInterface(b);
690 return new WallpaperManager(service, ctx.getOuterContext(),
Jeff Brown6e539312015-02-24 18:53:21 -0800691 ctx.mMainThread.getHandler());
692 }});
693
Robert Quattlebaum87a71042017-05-15 15:45:20 -0700694 registerService(Context.LOWPAN_SERVICE, LowpanManager.class,
695 new CachedServiceFetcher<LowpanManager>() {
696 @Override
697 public LowpanManager createService(ContextImpl ctx) throws ServiceNotFoundException {
698 IBinder b = ServiceManager.getServiceOrThrow(Context.LOWPAN_SERVICE);
699 ILowpanManager service = ILowpanManager.Stub.asInterface(b);
700 return new LowpanManager(ctx.getOuterContext(), service,
701 ConnectivityThread.getInstanceLooper());
702 }});
703
Jeff Brown6e539312015-02-24 18:53:21 -0800704 registerService(Context.WIFI_SERVICE, WifiManager.class,
705 new CachedServiceFetcher<WifiManager>() {
706 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600707 public WifiManager createService(ContextImpl ctx) throws ServiceNotFoundException {
708 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800709 IWifiManager service = IWifiManager.Stub.asInterface(b);
Paul Stewartbf8cbb052016-03-17 10:11:54 -0700710 return new WifiManager(ctx.getOuterContext(), service,
711 ConnectivityThread.getInstanceLooper());
Jeff Brown6e539312015-02-24 18:53:21 -0800712 }});
713
Jeff Brown6e539312015-02-24 18:53:21 -0800714 registerService(Context.WIFI_P2P_SERVICE, WifiP2pManager.class,
715 new StaticServiceFetcher<WifiP2pManager>() {
716 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600717 public WifiP2pManager createService() throws ServiceNotFoundException {
718 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_P2P_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800719 IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b);
720 return new WifiP2pManager(service);
721 }});
722
Etan Cohen04133272016-10-26 11:22:06 -0700723 registerService(Context.WIFI_AWARE_SERVICE, WifiAwareManager.class,
724 new CachedServiceFetcher<WifiAwareManager>() {
Etan Cohen20d329b2015-09-29 13:49:02 -0700725 @Override
Etan Cohen04133272016-10-26 11:22:06 -0700726 public WifiAwareManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Sharkey589f3092016-11-29 12:54:39 -0700727 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_AWARE_SERVICE);
Etan Cohen04133272016-10-26 11:22:06 -0700728 IWifiAwareManager service = IWifiAwareManager.Stub.asInterface(b);
Etan Cohen20d329b2015-09-29 13:49:02 -0700729 if (service == null) {
730 return null;
731 }
Etan Cohen04133272016-10-26 11:22:06 -0700732 return new WifiAwareManager(ctx.getOuterContext(), service);
Etan Cohen20d329b2015-09-29 13:49:02 -0700733 }});
734
Jeff Brown6e539312015-02-24 18:53:21 -0800735 registerService(Context.WIFI_SCANNING_SERVICE, WifiScanner.class,
736 new CachedServiceFetcher<WifiScanner>() {
737 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600738 public WifiScanner createService(ContextImpl ctx) throws ServiceNotFoundException {
739 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SCANNING_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800740 IWifiScanner service = IWifiScanner.Stub.asInterface(b);
Mitchell Wills91312c72016-04-06 17:03:35 -0700741 return new WifiScanner(ctx.getOuterContext(), service,
742 ConnectivityThread.getInstanceLooper());
Jeff Brown6e539312015-02-24 18:53:21 -0800743 }});
744
745 registerService(Context.WIFI_RTT_SERVICE, RttManager.class,
746 new CachedServiceFetcher<RttManager>() {
Etan Cohen9accbba2018-01-30 16:41:00 -0800747 @Override
748 public RttManager createService(ContextImpl ctx) throws ServiceNotFoundException {
749 IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_RTT_RANGING_SERVICE);
750 IWifiRttManager service = IWifiRttManager.Stub.asInterface(b);
751 return new RttManager(ctx.getOuterContext(),
752 new WifiRttManager(ctx.getOuterContext(), service));
753 }});
Jeff Brown6e539312015-02-24 18:53:21 -0800754
Etan Cohen46efb482017-12-07 13:50:57 -0800755 registerService(Context.WIFI_RTT_RANGING_SERVICE, WifiRttManager.class,
Etan Cohen17ba4722017-08-21 10:52:17 -0700756 new CachedServiceFetcher<WifiRttManager>() {
757 @Override
758 public WifiRttManager createService(ContextImpl ctx)
759 throws ServiceNotFoundException {
Etan Cohen46efb482017-12-07 13:50:57 -0800760 IBinder b = ServiceManager.getServiceOrThrow(
761 Context.WIFI_RTT_RANGING_SERVICE);
Etan Cohen17ba4722017-08-21 10:52:17 -0700762 IWifiRttManager service = IWifiRttManager.Stub.asInterface(b);
763 return new WifiRttManager(ctx.getOuterContext(), service);
764 }});
765
Jeff Brown6e539312015-02-24 18:53:21 -0800766 registerService(Context.ETHERNET_SERVICE, EthernetManager.class,
767 new CachedServiceFetcher<EthernetManager>() {
768 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600769 public EthernetManager createService(ContextImpl ctx) throws ServiceNotFoundException {
770 IBinder b = ServiceManager.getServiceOrThrow(Context.ETHERNET_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800771 IEthernetManager service = IEthernetManager.Stub.asInterface(b);
772 return new EthernetManager(ctx.getOuterContext(), service);
773 }});
774
775 registerService(Context.WINDOW_SERVICE, WindowManager.class,
776 new CachedServiceFetcher<WindowManager>() {
777 @Override
778 public WindowManager createService(ContextImpl ctx) {
Adam Lesinski4ece3d62016-06-16 18:05:41 -0700779 return new WindowManagerImpl(ctx);
Jeff Brown6e539312015-02-24 18:53:21 -0800780 }});
781
782 registerService(Context.USER_SERVICE, UserManager.class,
783 new CachedServiceFetcher<UserManager>() {
784 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600785 public UserManager createService(ContextImpl ctx) throws ServiceNotFoundException {
786 IBinder b = ServiceManager.getServiceOrThrow(Context.USER_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800787 IUserManager service = IUserManager.Stub.asInterface(b);
788 return new UserManager(ctx, service);
789 }});
790
791 registerService(Context.APP_OPS_SERVICE, AppOpsManager.class,
792 new CachedServiceFetcher<AppOpsManager>() {
793 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600794 public AppOpsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
795 IBinder b = ServiceManager.getServiceOrThrow(Context.APP_OPS_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800796 IAppOpsService service = IAppOpsService.Stub.asInterface(b);
797 return new AppOpsManager(ctx, service);
798 }});
799
800 registerService(Context.CAMERA_SERVICE, CameraManager.class,
801 new CachedServiceFetcher<CameraManager>() {
802 @Override
803 public CameraManager createService(ContextImpl ctx) {
804 return new CameraManager(ctx);
805 }});
806
807 registerService(Context.LAUNCHER_APPS_SERVICE, LauncherApps.class,
808 new CachedServiceFetcher<LauncherApps>() {
809 @Override
810 public LauncherApps createService(ContextImpl ctx) {
Makoto Onuki5ba0d3e2016-04-11 14:03:46 -0700811 return new LauncherApps(ctx);
Jeff Brown6e539312015-02-24 18:53:21 -0800812 }});
813
814 registerService(Context.RESTRICTIONS_SERVICE, RestrictionsManager.class,
815 new CachedServiceFetcher<RestrictionsManager>() {
816 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600817 public RestrictionsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
818 IBinder b = ServiceManager.getServiceOrThrow(Context.RESTRICTIONS_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800819 IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b);
820 return new RestrictionsManager(ctx, service);
821 }});
822
823 registerService(Context.PRINT_SERVICE, PrintManager.class,
824 new CachedServiceFetcher<PrintManager>() {
825 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600826 public PrintManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Svet Ganovec7daa52017-06-30 12:02:59 -0700827 IPrintManager service = null;
828 // If the feature not present, don't try to look up every time
829 if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
830 service = IPrintManager.Stub.asInterface(ServiceManager
831 .getServiceOrThrow(Context.PRINT_SERVICE));
832 }
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700833 final int userId = ctx.getUserId();
834 final int appId = UserHandle.getAppId(ctx.getApplicationInfo().uid);
835 return new PrintManager(ctx.getOuterContext(), service, userId, appId);
Jeff Brown6e539312015-02-24 18:53:21 -0800836 }});
837
Eugene Susla6ed45d82017-01-22 13:52:51 -0800838 registerService(Context.COMPANION_DEVICE_SERVICE, CompanionDeviceManager.class,
839 new CachedServiceFetcher<CompanionDeviceManager>() {
Svet Ganovec7daa52017-06-30 12:02:59 -0700840 @Override
841 public CompanionDeviceManager createService(ContextImpl ctx)
842 throws ServiceNotFoundException {
843 ICompanionDeviceManager service = null;
844 // If the feature not present, don't try to look up every time
845 if (ctx.getPackageManager().hasSystemFeature(
846 PackageManager.FEATURE_COMPANION_DEVICE_SETUP)) {
847 service = ICompanionDeviceManager.Stub.asInterface(
848 ServiceManager.getServiceOrThrow(Context.COMPANION_DEVICE_SERVICE));
849 }
850 return new CompanionDeviceManager(service, ctx.getOuterContext());
851 }});
Eugene Susla6ed45d82017-01-22 13:52:51 -0800852
Jeff Brown6e539312015-02-24 18:53:21 -0800853 registerService(Context.CONSUMER_IR_SERVICE, ConsumerIrManager.class,
854 new CachedServiceFetcher<ConsumerIrManager>() {
855 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600856 public ConsumerIrManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Brown6e539312015-02-24 18:53:21 -0800857 return new ConsumerIrManager(ctx);
858 }});
859
860 registerService(Context.MEDIA_SESSION_SERVICE, MediaSessionManager.class,
861 new CachedServiceFetcher<MediaSessionManager>() {
862 @Override
863 public MediaSessionManager createService(ContextImpl ctx) {
864 return new MediaSessionManager(ctx);
865 }});
866
867 registerService(Context.TRUST_SERVICE, TrustManager.class,
868 new StaticServiceFetcher<TrustManager>() {
869 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600870 public TrustManager createService() throws ServiceNotFoundException {
871 IBinder b = ServiceManager.getServiceOrThrow(Context.TRUST_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800872 return new TrustManager(b);
873 }});
874
875 registerService(Context.FINGERPRINT_SERVICE, FingerprintManager.class,
876 new CachedServiceFetcher<FingerprintManager>() {
877 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600878 public FingerprintManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Sharkey351c2c22017-03-18 16:48:02 -0600879 final IBinder binder;
880 if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
881 binder = ServiceManager.getServiceOrThrow(Context.FINGERPRINT_SERVICE);
882 } else {
883 binder = ServiceManager.getService(Context.FINGERPRINT_SERVICE);
884 }
Jeff Brown6e539312015-02-24 18:53:21 -0800885 IFingerprintService service = IFingerprintService.Stub.asInterface(binder);
886 return new FingerprintManager(ctx.getOuterContext(), service);
887 }});
888
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200889 registerService(Context.FACE_SERVICE, FaceManager.class,
890 new CachedServiceFetcher<FaceManager>() {
891 @Override
892 public FaceManager createService(ContextImpl ctx)
893 throws ServiceNotFoundException {
894 final IBinder binder;
895 if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
896 binder = ServiceManager.getServiceOrThrow(Context.FACE_SERVICE);
897 } else {
898 binder = ServiceManager.getService(Context.FACE_SERVICE);
899 }
900 IFaceService service = IFaceService.Stub.asInterface(binder);
901 return new FaceManager(ctx.getOuterContext(), service);
902 }
903 });
904
Kevin Chyn51676d22018-11-05 18:00:43 -0800905 registerService(Context.IRIS_SERVICE, IrisManager.class,
906 new CachedServiceFetcher<IrisManager>() {
907 @Override
908 public IrisManager createService(ContextImpl ctx)
909 throws ServiceNotFoundException {
910 final IBinder binder =
911 ServiceManager.getServiceOrThrow(Context.IRIS_SERVICE);
912 IIrisService service = IIrisService.Stub.asInterface(binder);
913 return new IrisManager(ctx.getOuterContext(), service);
914 }
915 });
916
Kevin Chyn05c21502018-09-18 13:07:19 -0700917 registerService(Context.BIOMETRIC_SERVICE, BiometricManager.class,
918 new CachedServiceFetcher<BiometricManager>() {
919 @Override
920 public BiometricManager createService(ContextImpl ctx)
921 throws ServiceNotFoundException {
Kevin Chyne739daf2018-11-06 17:11:06 -0800922 if (BiometricManager.hasBiometrics(ctx)) {
923 final IBinder binder =
924 ServiceManager.getServiceOrThrow(Context.BIOMETRIC_SERVICE);
925 final IBiometricService service =
926 IBiometricService.Stub.asInterface(binder);
927 return new BiometricManager(ctx.getOuterContext(), service);
928 } else {
929 // Allow access to the manager when service is null. This saves memory
930 // on devices without biometric hardware.
931 return new BiometricManager(ctx.getOuterContext(), null);
932 }
Kevin Chyn05c21502018-09-18 13:07:19 -0700933 }
934 });
935
Jeff Brown6e539312015-02-24 18:53:21 -0800936 registerService(Context.TV_INPUT_SERVICE, TvInputManager.class,
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700937 new CachedServiceFetcher<TvInputManager>() {
Jeff Brown6e539312015-02-24 18:53:21 -0800938 @Override
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700939 public TvInputManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600940 IBinder iBinder = ServiceManager.getServiceOrThrow(Context.TV_INPUT_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800941 ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder);
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700942 return new TvInputManager(service, ctx.getUserId());
Jeff Brown6e539312015-02-24 18:53:21 -0800943 }});
944
945 registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class,
946 new CachedServiceFetcher<NetworkScoreManager>() {
947 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600948 public NetworkScoreManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Jeff Brown6e539312015-02-24 18:53:21 -0800949 return new NetworkScoreManager(ctx);
950 }});
951
952 registerService(Context.USAGE_STATS_SERVICE, UsageStatsManager.class,
953 new CachedServiceFetcher<UsageStatsManager>() {
954 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600955 public UsageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
956 IBinder iBinder = ServiceManager.getServiceOrThrow(Context.USAGE_STATS_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800957 IUsageStatsManager service = IUsageStatsManager.Stub.asInterface(iBinder);
958 return new UsageStatsManager(ctx.getOuterContext(), service);
959 }});
960
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +0000961 registerService(Context.NETWORK_STATS_SERVICE, NetworkStatsManager.class,
962 new CachedServiceFetcher<NetworkStatsManager>() {
963 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600964 public NetworkStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +0000965 return new NetworkStatsManager(ctx.getOuterContext());
966 }});
967
Jeff Brown6e539312015-02-24 18:53:21 -0800968 registerService(Context.JOB_SCHEDULER_SERVICE, JobScheduler.class,
969 new StaticServiceFetcher<JobScheduler>() {
970 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600971 public JobScheduler createService() throws ServiceNotFoundException {
972 IBinder b = ServiceManager.getServiceOrThrow(Context.JOB_SCHEDULER_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800973 return new JobSchedulerImpl(IJobScheduler.Stub.asInterface(b));
974 }});
975
976 registerService(Context.PERSISTENT_DATA_BLOCK_SERVICE, PersistentDataBlockManager.class,
977 new StaticServiceFetcher<PersistentDataBlockManager>() {
978 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600979 public PersistentDataBlockManager createService() throws ServiceNotFoundException {
980 IBinder b = ServiceManager.getServiceOrThrow(Context.PERSISTENT_DATA_BLOCK_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -0800981 IPersistentDataBlockService persistentDataBlockService =
982 IPersistentDataBlockService.Stub.asInterface(b);
983 if (persistentDataBlockService != null) {
984 return new PersistentDataBlockManager(persistentDataBlockService);
985 } else {
986 // not supported
987 return null;
988 }
989 }});
990
Andrew Scull3b8b46f2017-02-13 18:12:15 +0000991 registerService(Context.OEM_LOCK_SERVICE, OemLockManager.class,
992 new StaticServiceFetcher<OemLockManager>() {
993 @Override
994 public OemLockManager createService() throws ServiceNotFoundException {
995 IBinder b = ServiceManager.getServiceOrThrow(Context.OEM_LOCK_SERVICE);
996 IOemLockService oemLockService = IOemLockService.Stub.asInterface(b);
997 if (oemLockService != null) {
998 return new OemLockManager(oemLockService);
999 } else {
1000 // not supported
1001 return null;
1002 }
1003 }});
1004
Jeff Brown6e539312015-02-24 18:53:21 -08001005 registerService(Context.MEDIA_PROJECTION_SERVICE, MediaProjectionManager.class,
1006 new CachedServiceFetcher<MediaProjectionManager>() {
1007 @Override
1008 public MediaProjectionManager createService(ContextImpl ctx) {
1009 return new MediaProjectionManager(ctx);
1010 }});
1011
1012 registerService(Context.APPWIDGET_SERVICE, AppWidgetManager.class,
1013 new CachedServiceFetcher<AppWidgetManager>() {
1014 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001015 public AppWidgetManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1016 IBinder b = ServiceManager.getServiceOrThrow(Context.APPWIDGET_SERVICE);
Jeff Brown6e539312015-02-24 18:53:21 -08001017 return new AppWidgetManager(ctx, IAppWidgetService.Stub.asInterface(b));
1018 }});
1019
1020 registerService(Context.MIDI_SERVICE, MidiManager.class,
1021 new CachedServiceFetcher<MidiManager>() {
1022 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001023 public MidiManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1024 IBinder b = ServiceManager.getServiceOrThrow(Context.MIDI_SERVICE);
Mike Lockwoode0a6ca62015-06-04 13:43:56 -07001025 return new MidiManager(IMidiManager.Stub.asInterface(b));
Jeff Brown6e539312015-02-24 18:53:21 -08001026 }});
Eric Laurent2035ac82015-03-05 15:18:44 -08001027
1028 registerService(Context.RADIO_SERVICE, RadioManager.class,
1029 new CachedServiceFetcher<RadioManager>() {
1030 @Override
Tomasz Wasilczyk347192e2017-04-04 11:13:44 -07001031 public RadioManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Eric Laurent2035ac82015-03-05 15:18:44 -08001032 return new RadioManager(ctx);
1033 }});
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001034
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01001035 registerService(Context.HARDWARE_PROPERTIES_SERVICE, HardwarePropertiesManager.class,
1036 new CachedServiceFetcher<HardwarePropertiesManager>() {
1037 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001038 public HardwarePropertiesManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1039 IBinder b = ServiceManager.getServiceOrThrow(Context.HARDWARE_PROPERTIES_SERVICE);
1040 IHardwarePropertiesManager service =
1041 IHardwarePropertiesManager.Stub.asInterface(b);
1042 return new HardwarePropertiesManager(ctx, service);
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01001043 }});
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001044
1045 registerService(Context.SOUND_TRIGGER_SERVICE, SoundTriggerManager.class,
1046 new CachedServiceFetcher<SoundTriggerManager>() {
1047 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001048 public SoundTriggerManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1049 IBinder b = ServiceManager.getServiceOrThrow(Context.SOUND_TRIGGER_SERVICE);
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001050 return new SoundTriggerManager(ctx, ISoundTriggerService.Stub.asInterface(b));
1051 }});
Makoto Onuki6f7362d92016-03-04 13:39:41 -08001052
1053 registerService(Context.SHORTCUT_SERVICE, ShortcutManager.class,
1054 new CachedServiceFetcher<ShortcutManager>() {
Makoto Onuki55046222016-03-08 10:49:47 -08001055 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001056 public ShortcutManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1057 IBinder b = ServiceManager.getServiceOrThrow(Context.SHORTCUT_SERVICE);
1058 return new ShortcutManager(ctx, IShortcutService.Stub.asInterface(b));
Makoto Onuki55046222016-03-08 10:49:47 -08001059 }});
Joe Onorato713fec82016-03-04 10:34:02 -08001060
Hyunyoung Song880a9512018-12-20 11:24:48 -08001061 registerService(Context.OVERLAY_SERVICE, OverlayManager.class,
1062 new CachedServiceFetcher<OverlayManager>() {
1063 @Override
1064 public OverlayManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1065 IBinder b = ServiceManager.getServiceOrThrow(Context.OVERLAY_SERVICE);
1066 return new OverlayManager(ctx, IOverlayManager.Stub.asInterface(b));
1067 }});
1068
Ricky Wai1a6e6672017-10-27 14:46:01 +01001069 registerService(Context.NETWORK_WATCHLIST_SERVICE, NetworkWatchlistManager.class,
1070 new CachedServiceFetcher<NetworkWatchlistManager>() {
1071 @Override
1072 public NetworkWatchlistManager createService(ContextImpl ctx)
1073 throws ServiceNotFoundException {
1074 IBinder b =
1075 ServiceManager.getServiceOrThrow(Context.NETWORK_WATCHLIST_SERVICE);
1076 return new NetworkWatchlistManager(ctx,
1077 INetworkWatchlistManager.Stub.asInterface(b));
1078 }});
1079
Joe Onorato713fec82016-03-04 10:34:02 -08001080 registerService(Context.SYSTEM_HEALTH_SERVICE, SystemHealthManager.class,
1081 new CachedServiceFetcher<SystemHealthManager>() {
1082 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001083 public SystemHealthManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1084 IBinder b = ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME);
1085 return new SystemHealthManager(IBatteryStats.Stub.asInterface(b));
Joe Onorato713fec82016-03-04 10:34:02 -08001086 }});
Peng Xu9ff7d222016-02-11 13:02:05 -08001087
1088 registerService(Context.CONTEXTHUB_SERVICE, ContextHubManager.class,
1089 new CachedServiceFetcher<ContextHubManager>() {
1090 @Override
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001091 public ContextHubManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Peng Xu9ff7d222016-02-11 13:02:05 -08001092 return new ContextHubManager(ctx.getOuterContext(),
1093 ctx.mMainThread.getHandler().getLooper());
1094 }});
Joe Onorato1754d742016-11-21 17:51:35 -08001095
1096 registerService(Context.INCIDENT_SERVICE, IncidentManager.class,
1097 new CachedServiceFetcher<IncidentManager>() {
1098 @Override
1099 public IncidentManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1100 return new IncidentManager(ctx);
1101 }});
Clara Bayarri04d72ab2017-01-10 09:31:51 -08001102
Nandana Duttd11850c2018-12-12 17:26:57 +00001103 registerService(Context.BUGREPORT_SERVICE, BugreportManager.class,
1104 new CachedServiceFetcher<BugreportManager>() {
1105 @Override
1106 public BugreportManager createService(ContextImpl ctx)
1107 throws ServiceNotFoundException {
1108 IBinder b = ServiceManager.getServiceOrThrow(Context.BUGREPORT_SERVICE);
1109 return new BugreportManager(ctx.getOuterContext(),
1110 IDumpstate.Stub.asInterface(b));
1111 }});
1112
Felipe Leme640f30a2017-03-06 15:44:06 -08001113 registerService(Context.AUTOFILL_MANAGER_SERVICE, AutofillManager.class,
1114 new CachedServiceFetcher<AutofillManager>() {
Felipe Leme3461d3c2017-01-19 08:54:55 -08001115 @Override
Felipe Leme640f30a2017-03-06 15:44:06 -08001116 public AutofillManager createService(ContextImpl ctx) throws ServiceNotFoundException {
Svet Ganov43574b02017-04-12 09:25:20 -07001117 // Get the services without throwing as this is an optional feature
1118 IBinder b = ServiceManager.getService(Context.AUTOFILL_MANAGER_SERVICE);
Svet Ganov782043c2017-02-11 00:52:02 +00001119 IAutoFillManager service = IAutoFillManager.Stub.asInterface(b);
Felipe Leme640f30a2017-03-06 15:44:06 -08001120 return new AutofillManager(ctx.getOuterContext(), service);
Felipe Leme3461d3c2017-01-19 08:54:55 -08001121 }});
Zak Cohen56345f42017-01-26 13:54:28 -08001122
Felipe Lemeecb08be2018-11-27 15:48:47 -08001123 registerService(Context.CONTENT_CAPTURE_MANAGER_SERVICE, ContentCaptureManager.class,
1124 new CachedServiceFetcher<ContentCaptureManager>() {
Felipe Lemee348dc32018-11-05 12:35:29 -08001125 @Override
Felipe Lemeecb08be2018-11-27 15:48:47 -08001126 public ContentCaptureManager createService(ContextImpl ctx)
Felipe Lemee348dc32018-11-05 12:35:29 -08001127 throws ServiceNotFoundException {
1128 // Get the services without throwing as this is an optional feature
Felipe Lemeecb08be2018-11-27 15:48:47 -08001129 Context outerContext = ctx.getOuterContext();
Felipe Leme326f15a2019-02-19 09:42:24 -08001130 ContentCaptureOptions options = outerContext.getContentCaptureOptions();
1131 // Options is null when the service didn't whitelist the activity or package
1132 if (options != null) {
Felipe Lemeecb08be2018-11-27 15:48:47 -08001133 IBinder b = ServiceManager
1134 .getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE);
Felipe Leme749b8892018-12-03 16:30:30 -08001135 IContentCaptureManager service = IContentCaptureManager.Stub.asInterface(b);
Felipe Leme326f15a2019-02-19 09:42:24 -08001136 // Service is null when not provided by OEM or disabled by kill-switch.
Felipe Lemed49d52c2019-02-15 09:48:20 -08001137 if (service != null) {
Felipe Leme326f15a2019-02-19 09:42:24 -08001138 return new ContentCaptureManager(outerContext, service, options);
Felipe Lemed49d52c2019-02-15 09:48:20 -08001139 }
Felipe Lemeecb08be2018-11-27 15:48:47 -08001140 }
Felipe Leme326f15a2019-02-19 09:42:24 -08001141 // When feature is disabled or app / package not whitelisted, we return a null
1142 // manager to apps so the performance impact is practically zero
Felipe Lemeecb08be2018-11-27 15:48:47 -08001143 return null;
Felipe Lemee348dc32018-11-05 12:35:29 -08001144 }});
1145
Sunny Goyal54e91342018-11-14 11:59:02 -08001146 registerService(Context.APP_PREDICTION_SERVICE, AppPredictionManager.class,
1147 new CachedServiceFetcher<AppPredictionManager>() {
1148 @Override
1149 public AppPredictionManager createService(ContextImpl ctx)
1150 throws ServiceNotFoundException {
1151 return new AppPredictionManager(ctx);
1152 }
1153 });
1154
Winson Chung3fb0f252019-01-08 17:41:55 -08001155 registerService(Context.CONTENT_SUGGESTIONS_SERVICE,
1156 ContentSuggestionsManager.class,
1157 new CachedServiceFetcher<ContentSuggestionsManager>() {
1158 @Override
1159 public ContentSuggestionsManager createService(ContextImpl ctx) {
1160 // No throw as this is an optional service
1161 IBinder b = ServiceManager.getService(
1162 Context.CONTENT_SUGGESTIONS_SERVICE);
1163 IContentSuggestionsManager service =
1164 IContentSuggestionsManager.Stub.asInterface(b);
1165 return new ContentSuggestionsManager(service);
1166 }
1167 });
1168
Zak Cohen56345f42017-01-26 13:54:28 -08001169 registerService(Context.VR_SERVICE, VrManager.class, new CachedServiceFetcher<VrManager>() {
1170 @Override
1171 public VrManager createService(ContextImpl ctx) throws ServiceNotFoundException {
1172 IBinder b = ServiceManager.getServiceOrThrow(Context.VR_SERVICE);
1173 return new VrManager(IVrManager.Stub.asInterface(b));
1174 }
1175 });
Neil Fuller328532a2017-03-16 18:32:21 +00001176
1177 registerService(Context.TIME_ZONE_RULES_MANAGER_SERVICE, RulesManager.class,
1178 new CachedServiceFetcher<RulesManager>() {
1179 @Override
1180 public RulesManager createService(ContextImpl ctx) {
1181 return new RulesManager(ctx.getOuterContext());
1182 }});
Tony Mak1b708e62017-10-12 10:59:11 +01001183
1184 registerService(Context.CROSS_PROFILE_APPS_SERVICE, CrossProfileApps.class,
1185 new CachedServiceFetcher<CrossProfileApps>() {
1186 @Override
1187 public CrossProfileApps createService(ContextImpl ctx)
1188 throws ServiceNotFoundException {
1189 IBinder b = ServiceManager.getServiceOrThrow(
1190 Context.CROSS_PROFILE_APPS_SERVICE);
1191 return new CrossProfileApps(ctx.getOuterContext(),
1192 ICrossProfileApps.Stub.asInterface(b));
1193 }
1194 });
Jason Monk8f5f7ff2017-10-17 14:12:42 -04001195
1196 registerService(Context.SLICE_SERVICE, SliceManager.class,
1197 new CachedServiceFetcher<SliceManager>() {
1198 @Override
1199 public SliceManager createService(ContextImpl ctx)
1200 throws ServiceNotFoundException {
1201 return new SliceManager(ctx.getOuterContext(),
1202 ctx.mMainThread.getHandler());
1203 }
1204 });
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07001205
1206 registerService(Context.DEVICE_IDLE_CONTROLLER, DeviceIdleManager.class,
1207 new CachedServiceFetcher<DeviceIdleManager>() {
1208 @Override
1209 public DeviceIdleManager createService(ContextImpl ctx)
1210 throws ServiceNotFoundException {
1211 IDeviceIdleController service = IDeviceIdleController.Stub.asInterface(
1212 ServiceManager.getServiceOrThrow(
1213 Context.DEVICE_IDLE_CONTROLLER));
1214 return new DeviceIdleManager(ctx.getOuterContext(), service);
1215 }});
Neil Fullerfeeee682018-05-30 14:35:24 +01001216
1217 registerService(Context.TIME_DETECTOR_SERVICE, TimeDetector.class,
1218 new CachedServiceFetcher<TimeDetector>() {
1219 @Override
1220 public TimeDetector createService(ContextImpl ctx)
1221 throws ServiceNotFoundException {
1222 return new TimeDetector();
1223 }});
Philip P. Moltmann039678e2018-09-18 13:04:38 -07001224
1225 registerService(Context.PERMISSION_SERVICE, PermissionManager.class,
1226 new CachedServiceFetcher<PermissionManager>() {
1227 @Override
1228 public PermissionManager createService(ContextImpl ctx) {
1229 return new PermissionManager(ctx.getOuterContext());
1230 }});
Hai Zhang4ef21d02018-11-09 14:43:51 -08001231
Philip P. Moltmannbc054d82018-12-21 09:41:58 -08001232 registerService(Context.PERMISSION_CONTROLLER_SERVICE, PermissionControllerManager.class,
1233 new CachedServiceFetcher<PermissionControllerManager>() {
1234 @Override
1235 public PermissionControllerManager createService(ContextImpl ctx) {
1236 return new PermissionControllerManager(ctx.getOuterContext());
1237 }});
1238
Hai Zhang4ef21d02018-11-09 14:43:51 -08001239 registerService(Context.ROLE_SERVICE, RoleManager.class,
1240 new CachedServiceFetcher<RoleManager>() {
1241 @Override
1242 public RoleManager createService(ContextImpl ctx)
1243 throws ServiceNotFoundException {
1244 return new RoleManager(ctx.getOuterContext());
1245 }});
Richard Uhlerb29f1452018-09-12 16:38:15 +01001246
Hai Zhanga4959e52019-03-06 12:21:07 -08001247 registerService(Context.ROLE_CONTROLLER_SERVICE, RoleControllerManager.class,
1248 new CachedServiceFetcher<RoleControllerManager>() {
1249 @Override
1250 public RoleControllerManager createService(ContextImpl ctx)
1251 throws ServiceNotFoundException {
1252 return new RoleControllerManager(ctx.getOuterContext());
1253 }});
1254
Richard Uhlerb29f1452018-09-12 16:38:15 +01001255 registerService(Context.ROLLBACK_SERVICE, RollbackManager.class,
1256 new CachedServiceFetcher<RollbackManager>() {
1257 @Override
1258 public RollbackManager createService(ContextImpl ctx)
1259 throws ServiceNotFoundException {
1260 IBinder b = ServiceManager.getServiceOrThrow(Context.ROLLBACK_SERVICE);
1261 return new RollbackManager(ctx.getOuterContext(),
1262 IRollbackManager.Stub.asInterface(b));
1263 }});
Howard Chen0a947642019-01-07 14:10:44 +08001264
1265 registerService(Context.DYNAMIC_ANDROID_SERVICE, DynamicAndroidManager.class,
1266 new CachedServiceFetcher<DynamicAndroidManager>() {
1267 @Override
1268 public DynamicAndroidManager createService(ContextImpl ctx)
1269 throws ServiceNotFoundException {
1270 IBinder b = ServiceManager.getServiceOrThrow(
1271 Context.DYNAMIC_ANDROID_SERVICE);
1272 return new DynamicAndroidManager(
1273 IDynamicAndroidService.Stub.asInterface(b));
1274 }});
Felipe Lemeecb08be2018-11-27 15:48:47 -08001275 //CHECKSTYLE:ON IndentationCheck
Jeff Brown6e539312015-02-24 18:53:21 -08001276 }
1277
1278 /**
1279 * Creates an array which is used to cache per-Context service instances.
1280 */
1281 public static Object[] createServiceCache() {
1282 return new Object[sServiceCacheSize];
1283 }
1284
1285 /**
1286 * Gets a system service from a given context.
1287 */
1288 public static Object getSystemService(ContextImpl ctx, String name) {
1289 ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name);
1290 return fetcher != null ? fetcher.getService(ctx) : null;
1291 }
1292
1293 /**
Paul McLeane3383cc2015-05-08 11:41:20 -07001294 * Gets the name of the system-level service that is represented by the specified class.
Jeff Brown6e539312015-02-24 18:53:21 -08001295 */
1296 public static String getSystemServiceName(Class<?> serviceClass) {
1297 return SYSTEM_SERVICE_NAMES.get(serviceClass);
1298 }
1299
1300 /**
1301 * Statically registers a system service with the context.
1302 * This method must be called during static initialization only.
1303 */
1304 private static <T> void registerService(String serviceName, Class<T> serviceClass,
1305 ServiceFetcher<T> serviceFetcher) {
1306 SYSTEM_SERVICE_NAMES.put(serviceClass, serviceName);
1307 SYSTEM_SERVICE_FETCHERS.put(serviceName, serviceFetcher);
1308 }
1309
1310 /**
1311 * Base interface for classes that fetch services.
1312 * These objects must only be created during static initialization.
1313 */
1314 static abstract interface ServiceFetcher<T> {
1315 T getService(ContextImpl ctx);
1316 }
1317
1318 /**
1319 * Override this class when the system service constructor needs a
1320 * ContextImpl and should be cached and retained by that context.
1321 */
1322 static abstract class CachedServiceFetcher<T> implements ServiceFetcher<T> {
1323 private final int mCacheIndex;
1324
Makoto Onukid67070e2018-03-30 12:39:14 -07001325 CachedServiceFetcher() {
1326 // Note this class must be instantiated only by the static initializer of the
1327 // outer class (SystemServiceRegistry), which already does the synchronization,
1328 // so bare access to sServiceCacheSize is okay here.
Jeff Brown6e539312015-02-24 18:53:21 -08001329 mCacheIndex = sServiceCacheSize++;
1330 }
1331
1332 @Override
1333 @SuppressWarnings("unchecked")
1334 public final T getService(ContextImpl ctx) {
1335 final Object[] cache = ctx.mServiceCache;
Makoto Onukid67070e2018-03-30 12:39:14 -07001336 final int[] gates = ctx.mServiceInitializationStateArray;
Makoto Onukif896f122018-01-25 09:50:24 -08001337
Makoto Onukid67070e2018-03-30 12:39:14 -07001338 for (;;) {
1339 boolean doInitialize = false;
1340 synchronized (cache) {
1341 // Return it if we already have a cached instance.
1342 T service = (T) cache[mCacheIndex];
1343 if (service != null || gates[mCacheIndex] == ContextImpl.STATE_NOT_FOUND) {
1344 return service;
1345 }
Makoto Onukif896f122018-01-25 09:50:24 -08001346
Makoto Onukid67070e2018-03-30 12:39:14 -07001347 // If we get here, there's no cached instance.
Makoto Onukif896f122018-01-25 09:50:24 -08001348
Makoto Onukid67070e2018-03-30 12:39:14 -07001349 // Grr... if gate is STATE_READY, then this means we initialized the service
1350 // once but someone cleared it.
1351 // We start over from STATE_UNINITIALIZED.
1352 if (gates[mCacheIndex] == ContextImpl.STATE_READY) {
1353 gates[mCacheIndex] = ContextImpl.STATE_UNINITIALIZED;
1354 }
1355
1356 // It's possible for multiple threads to get here at the same time, so
1357 // use the "gate" to make sure only the first thread will call createService().
1358
1359 // At this point, the gate must be either UNINITIALIZED or INITIALIZING.
1360 if (gates[mCacheIndex] == ContextImpl.STATE_UNINITIALIZED) {
1361 doInitialize = true;
1362 gates[mCacheIndex] = ContextImpl.STATE_INITIALIZING;
1363 }
Makoto Onukif896f122018-01-25 09:50:24 -08001364 }
1365
Makoto Onukid67070e2018-03-30 12:39:14 -07001366 if (doInitialize) {
1367 // Only the first thread gets here.
Makoto Onukif896f122018-01-25 09:50:24 -08001368
Makoto Onukid67070e2018-03-30 12:39:14 -07001369 T service = null;
1370 @ServiceInitializationState int newState = ContextImpl.STATE_NOT_FOUND;
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001371 try {
Makoto Onukid67070e2018-03-30 12:39:14 -07001372 // This thread is the first one to get here. Instantiate the service
1373 // *without* the cache lock held.
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001374 service = createService(ctx);
Makoto Onukid67070e2018-03-30 12:39:14 -07001375 newState = ContextImpl.STATE_READY;
Makoto Onukif896f122018-01-25 09:50:24 -08001376
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001377 } catch (ServiceNotFoundException e) {
Jeff Sharkey589f3092016-11-29 12:54:39 -07001378 onServiceNotFound(e);
Makoto Onukif896f122018-01-25 09:50:24 -08001379
Makoto Onukid67070e2018-03-30 12:39:14 -07001380 } finally {
1381 synchronized (cache) {
1382 cache[mCacheIndex] = service;
1383 gates[mCacheIndex] = newState;
1384 cache.notifyAll();
1385 }
1386 }
1387 return service;
1388 }
1389 // The other threads will wait for the first thread to call notifyAll(),
1390 // and go back to the top and retry.
1391 synchronized (cache) {
1392 while (gates[mCacheIndex] < ContextImpl.STATE_READY) {
1393 try {
1394 cache.wait();
1395 } catch (InterruptedException e) {
1396 Log.w(TAG, "getService() interrupted");
1397 Thread.currentThread().interrupt();
1398 return null;
1399 }
Makoto Onukif896f122018-01-25 09:50:24 -08001400 }
1401 }
Makoto Onukif896f122018-01-25 09:50:24 -08001402 }
Jeff Brown6e539312015-02-24 18:53:21 -08001403 }
1404
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001405 public abstract T createService(ContextImpl ctx) throws ServiceNotFoundException;
Jeff Brown6e539312015-02-24 18:53:21 -08001406 }
1407
1408 /**
1409 * Override this class when the system service does not need a ContextImpl
1410 * and should be cached and retained process-wide.
1411 */
1412 static abstract class StaticServiceFetcher<T> implements ServiceFetcher<T> {
1413 private T mCachedInstance;
1414
1415 @Override
Jeff Sharkey589f3092016-11-29 12:54:39 -07001416 public final T getService(ContextImpl ctx) {
Jeff Brown6e539312015-02-24 18:53:21 -08001417 synchronized (StaticServiceFetcher.this) {
1418 if (mCachedInstance == null) {
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001419 try {
1420 mCachedInstance = createService();
1421 } catch (ServiceNotFoundException e) {
Jeff Sharkey589f3092016-11-29 12:54:39 -07001422 onServiceNotFound(e);
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001423 }
Jeff Brown6e539312015-02-24 18:53:21 -08001424 }
1425 return mCachedInstance;
1426 }
1427 }
1428
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001429 public abstract T createService() throws ServiceNotFoundException;
Jeff Brown6e539312015-02-24 18:53:21 -08001430 }
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001431
1432 /**
Lorenzo Colitticf959772016-02-29 16:07:37 +09001433 * Like StaticServiceFetcher, creates only one instance of the service per application, but when
1434 * creating the service for the first time, passes it the application context of the creating
1435 * application.
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001436 *
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001437 * TODO: Delete this once its only user (ConnectivityManager) is known to work well in the
1438 * case where multiple application components each have their own ConnectivityManager object.
1439 */
Lorenzo Colitticf959772016-02-29 16:07:37 +09001440 static abstract class StaticApplicationContextServiceFetcher<T> implements ServiceFetcher<T> {
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001441 private T mCachedInstance;
1442
1443 @Override
1444 public final T getService(ContextImpl ctx) {
Lorenzo Colitticf959772016-02-29 16:07:37 +09001445 synchronized (StaticApplicationContextServiceFetcher.this) {
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001446 if (mCachedInstance == null) {
Lorenzo Colitti0ad9ab02016-03-25 17:40:11 +09001447 Context appContext = ctx.getApplicationContext();
1448 // If the application context is null, we're either in the system process or
1449 // it's the application context very early in app initialization. In both these
1450 // cases, the passed-in ContextImpl will not be freed, so it's safe to pass it
1451 // to the service. http://b/27532714 .
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001452 try {
1453 mCachedInstance = createService(appContext != null ? appContext : ctx);
1454 } catch (ServiceNotFoundException e) {
Jeff Sharkey589f3092016-11-29 12:54:39 -07001455 onServiceNotFound(e);
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001456 }
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001457 }
1458 return mCachedInstance;
1459 }
1460 }
1461
Jeff Sharkey49ca5292016-05-10 12:54:45 -06001462 public abstract T createService(Context applicationContext) throws ServiceNotFoundException;
Lorenzo Colittiffc42b02015-07-29 11:41:21 +09001463 }
Jeff Sharkey589f3092016-11-29 12:54:39 -07001464
1465 public static void onServiceNotFound(ServiceNotFoundException e) {
1466 // We're mostly interested in tracking down long-lived core system
1467 // components that might stumble if they obtain bad references; just
1468 // emit a tidy log message for normal apps
1469 if (android.os.Process.myUid() < android.os.Process.FIRST_APPLICATION_UID) {
1470 Log.wtf(TAG, e.getMessage(), e);
1471 } else {
1472 Log.w(TAG, e.getMessage());
1473 }
1474 }
Jeff Brown6e539312015-02-24 18:53:21 -08001475}