SystemServe学习记录

1.What?

SystemServe是什么呢?

要理解SystemService,首先要理解Android系统的基本结构。

大家经常看到Android系统是C/S架构这样的表述,但是又有多少人真正理解这句话呢?所谓的架构是指什么呢?首先让我们来看两张图:

这两张图是我操作系统课本上的原话。操作系统如何组织运行时结构呢?大家也许都知道C语言里的系统调用,采用系统调用是把整个操作系统视为一种服务,用户通过系统调用和操作系统进行交互。而Android是采用的则是另外一种方式,以C/S架构的形式把所有操作系统可以提供的服务进行集合包装在一个进程里,这个进程就叫做系统服务进程,我们不与操作系统内核直接进行交互,而是以系统服务进程为中介,通过这个进程来调用操作系统提供的服务。

Customservice

我们自己的App要与System Server通信,实际上要通过进程间通信的方式,但是SDK已经封装好了一些系统服务,所以使用起来还是很简单的。

现在你应该明白SystemServe是什么了吧?这也是科班出身的优势,如果没有操作系统方面的知识,学起SystemServe这样的底层内容就是盲人摸象!我看了网上不少的博客,但是基本没有人从操作系统这个角度来分析SystemServe,动不动就是跑到SystemServe内部的各个服务,一下子让人一头雾水,学完了也是不知所谓。

下面我来总结一下:

SystemServe是Android系统所有核心服务所在的进程,比如负责启动Activity的ActivityManagerService,负责电源管理的PowerManagerService和负责创建Window的WindowManagerService,在这个进程里,每一个核心服务占据一个线程,我们通过SystemService这个进程来使用一些Android的核心服务。

这个进程属于Java层,由Zygote进程孵化而来,它是Android Runtime的一个重要组成部分。

在我们写App的时候,调用xxServiceManager实际上就是在与它交互。

2.How?

搞明白了SystemServe是什么,接下来就是怎么使用这个SystemServe。

使用SystemServe就是使用它包含的各个系统服务,首先我们来看看有哪些系统服务。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.os.PowerManager} for controlling power management,
* including "wake locks," which let you keep the device on while
* you're running long tasks.
*/
public static final String POWER_SERVICE = "power";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.os.RecoverySystem} for accessing the recovery system
* service.
*
* @see #getSystemService
* @hide
*/
public static final String RECOVERY_SERVICE = "recovery";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.view.WindowManager} for accessing the system's window
* manager.
*
* @see #getSystemService
* @see android.view.WindowManager
*/
public static final String WINDOW_SERVICE = "window";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.view.LayoutInflater} for inflating layout resources in this
* context.
*
* @see #getSystemService
* @see android.view.LayoutInflater
*/
public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.accounts.AccountManager} for receiving intents at a
* time of your choosing.
*
* @see #getSystemService
* @see android.accounts.AccountManager
*/
public static final String ACCOUNT_SERVICE = "account";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.app.ActivityManager} for interacting with the global
* system state.
*
* @see #getSystemService
* @see android.app.ActivityManager
*/
public static final String ACTIVITY_SERVICE = "activity";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.app.AlarmManager} for receiving intents at a
* time of your choosing.
*
* @see #getSystemService
* @see android.app.AlarmManager
*/
public static final String ALARM_SERVICE = "alarm";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.app.NotificationManager} for informing the user of
* background events.
*
* @see #getSystemService
* @see android.app.NotificationManager
*/
public static final String NOTIFICATION_SERVICE = "notification";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.view.accessibility.AccessibilityManager} for giving the user
* feedback for UI events through the registered event listeners.
*
* @see #getSystemService
* @see android.view.accessibility.AccessibilityManager
*/
public static final String ACCESSIBILITY_SERVICE = "accessibility";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.view.accessibility.CaptioningManager} for obtaining
* captioning properties and listening for changes in captioning
* preferences.
*
* @see #getSystemService
* @see android.view.accessibility.CaptioningManager
*/
public static final String CAPTIONING_SERVICE = "captioning";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.app.NotificationManager} for controlling keyguard.
*
* @see #getSystemService
* @see android.app.KeyguardManager
*/
public static final String KEYGUARD_SERVICE = "keyguard";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.location.LocationManager} for controlling location
* updates.
*
* @see #getSystemService
* @see android.location.LocationManager
*/
public static final String LOCATION_SERVICE = "location";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.location.CountryDetector} for detecting the country that
* the user is in.
*
* @hide
*/
public static final String COUNTRY_DETECTOR = "country_detector";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.app.SearchManager} for handling searches.
*
* @see #getSystemService
* @see android.app.SearchManager
*/
public static final String SEARCH_SERVICE = "search";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.hardware.SensorManager} for accessing sensors.
*
* @see #getSystemService
* @see android.hardware.SensorManager
*/
public static final String SENSOR_SERVICE = "sensor";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.os.storage.StorageManager} for accessing system storage
* functions.
*
* @see #getSystemService
* @see android.os.storage.StorageManager
*/
public static final String STORAGE_SERVICE = "storage";

/**
* Use with {@link #getSystemService} to retrieve a
* com.android.server.WallpaperService for accessing wallpapers.
*
* @see #getSystemService
*/
public static final String WALLPAPER_SERVICE = "wallpaper";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.os.Vibrator} for interacting with the vibration hardware.
*
* @see #getSystemService
* @see android.os.Vibrator
*/
public static final String VIBRATOR_SERVICE = "vibrator";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.app.StatusBarManager} for interacting with the status bar.
*
* @see #getSystemService
* @see android.app.StatusBarManager
* @hide
*/
public static final String STATUS_BAR_SERVICE = "statusbar";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.net.ConnectivityManager} for handling management of
* network connections.
*
* @see #getSystemService
* @see android.net.ConnectivityManager
*/
public static final String CONNECTIVITY_SERVICE = "connectivity";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.os.IUpdateLock} for managing runtime sequences that
* must not be interrupted by headless OTA application or similar.
*
* @hide
* @see #getSystemService
* @see android.os.UpdateLock
*/
public static final String UPDATE_LOCK_SERVICE = "updatelock";

/**
* Constant for the internal network management service, not really a Context service.
* @hide
*/
public static final String NETWORKMANAGEMENT_SERVICE = "network_management";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.app.usage.NetworkStatsManager} for querying network usage stats.
*
* @see #getSystemService
* @see android.app.usage.NetworkStatsManager
*/
public static final String NETWORK_STATS_SERVICE = "netstats";
/** {@hide} */
public static final String NETWORK_POLICY_SERVICE = "netpolicy";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.net.wifi.WifiManager} for handling management of
* Wi-Fi access.
*
* @see #getSystemService
* @see android.net.wifi.WifiManager
*/
public static final String WIFI_SERVICE = "wifi";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.net.wifi.p2p.WifiP2pManager} for handling management of
* Wi-Fi peer-to-peer connections.
*
* @see #getSystemService
* @see android.net.wifi.p2p.WifiP2pManager
*/
public static final String WIFI_P2P_SERVICE = "wifip2p";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.net.wifi.nan.WifiNanManager} for handling management of
* Wi-Fi NAN discovery and connections.
*
* @see #getSystemService
* @see android.net.wifi.nan.WifiNanManager
* @hide PROPOSED_NAN_API
*/
public static final String WIFI_NAN_SERVICE = "wifinan";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.net.wifi.WifiScanner} for scanning the wifi universe
*
* @see #getSystemService
* @see android.net.wifi.WifiScanner
* @hide
*/
@SystemApi
public static final String WIFI_SCANNING_SERVICE = "wifiscanner";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.net.wifi.RttManager} for ranging devices with wifi
*
* @see #getSystemService
* @see android.net.wifi.RttManager
* @hide
*/
@SystemApi
public static final String WIFI_RTT_SERVICE = "rttmanager";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.net.EthernetManager} for handling management of
* Ethernet access.
*
* @see #getSystemService
* @see android.net.EthernetManager
*
* @hide
*/
public static final String ETHERNET_SERVICE = "ethernet";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.net.nsd.NsdManager} for handling management of network service
* discovery
*
* @see #getSystemService
* @see android.net.nsd.NsdManager
*/
public static final String NSD_SERVICE = "servicediscovery";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.media.AudioManager} for handling management of volume,
* ringer modes and audio routing.
*
* @see #getSystemService
* @see android.media.AudioManager
*/
public static final String AUDIO_SERVICE = "audio";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.hardware.fingerprint.FingerprintManager} for handling management
* of fingerprints.
*
* @see #getSystemService
* @see android.hardware.fingerprint.FingerprintManager
*/
public static final String FINGERPRINT_SERVICE = "fingerprint";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.media.MediaRouter} for controlling and managing
* routing of media.
*
* @see #getSystemService
* @see android.media.MediaRouter
*/
public static final String MEDIA_ROUTER_SERVICE = "media_router";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.media.session.MediaSessionManager} for managing media Sessions.
*
* @see #getSystemService
* @see android.media.session.MediaSessionManager
*/
public static final String MEDIA_SESSION_SERVICE = "media_session";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.telephony.TelephonyManager} for handling management the
* telephony features of the device.
*
* @see #getSystemService
* @see android.telephony.TelephonyManager
*/
public static final String TELEPHONY_SERVICE = "phone";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.telephony.SubscriptionManager} for handling management the
* telephony subscriptions of the device.
*
* @see #getSystemService
* @see android.telephony.SubscriptionManager
*/
public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.telecom.TelecomManager} to manage telecom-related features
* of the device.
*
* @see #getSystemService
* @see android.telecom.TelecomManager
*/
public static final String TELECOM_SERVICE = "telecom";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
*
* @see #getSystemService
* @see android.telephony.CarrierConfigManager
*/
public static final String CARRIER_CONFIG_SERVICE = "carrier_config";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.text.ClipboardManager} for accessing and modifying
* {@link android.content.ClipboardManager} for accessing and modifying
* the contents of the global clipboard.
*
* @see #getSystemService
* @see android.content.ClipboardManager
*/
public static final String CLIPBOARD_SERVICE = "clipboard";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.view.inputmethod.InputMethodManager} for accessing input
* methods.
*
* @see #getSystemService
*/
public static final String INPUT_METHOD_SERVICE = "input_method";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.view.textservice.TextServicesManager} for accessing
* text services.
*
* @see #getSystemService
*/
public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
*
* @see #getSystemService
*/
public static final String APPWIDGET_SERVICE = "appwidget";

/**
* Official published name of the (internal) voice interaction manager service.
*
* @hide
* @see #getSystemService
*/
public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";

/**
* Use with {@link #getSystemService} to access the
* {@link com.android.server.voiceinteraction.SoundTriggerService}.
*
* @hide
* @see #getSystemService
*/
public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";


/**
* Use with {@link #getSystemService} to retrieve an
* {@link android.app.backup.IBackupManager IBackupManager} for communicating
* with the backup mechanism.
* @hide
*
* @see #getSystemService
*/
@SystemApi
public static final String BACKUP_SERVICE = "backup";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.os.DropBoxManager} instance for recording
* diagnostic logs.
* @see #getSystemService
*/
public static final String DROPBOX_SERVICE = "dropbox";

/**
* System service name for the DeviceIdleController. There is no Java API for this.
* @see #getSystemService
* @hide
*/
public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.app.admin.DevicePolicyManager} for working with global
* device policy management.
*
* @see #getSystemService
*/
public static final String DEVICE_POLICY_SERVICE = "device_policy";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.app.UiModeManager} for controlling UI modes.
*
* @see #getSystemService
*/
public static final String UI_MODE_SERVICE = "uimode";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.app.DownloadManager} for requesting HTTP downloads.
*
* @see #getSystemService
*/
public static final String DOWNLOAD_SERVICE = "download";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.os.BatteryManager} for managing battery state.
*
* @see #getSystemService
*/
public static final String BATTERY_SERVICE = "batterymanager";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.nfc.NfcManager} for using NFC.
*
* @see #getSystemService
*/
public static final String NFC_SERVICE = "nfc";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.bluetooth.BluetoothManager} for using Bluetooth.
*
* @see #getSystemService
*/
public static final String BLUETOOTH_SERVICE = "bluetooth";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.net.sip.SipManager} for accessing the SIP related service.
*
* @see #getSystemService
*/
/** @hide */
public static final String SIP_SERVICE = "sip";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
* and for controlling this device's behavior as a USB device.
*
* @see #getSystemService
* @see android.hardware.usb.UsbManager
*/
public static final String USB_SERVICE = "usb";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.hardware.SerialManager} for access to serial ports.
*
* @see #getSystemService
* @see android.hardware.SerialManager
*
* @hide
*/
public static final String SERIAL_SERVICE = "serial";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
* HDMI-CEC protocol.
*
* @see #getSystemService
* @see android.hardware.hdmi.HdmiControlManager
* @hide
*/
@SystemApi
public static final String HDMI_CONTROL_SERVICE = "hdmi_control";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.hardware.input.InputManager} for interacting with input devices.
*
* @see #getSystemService
* @see android.hardware.input.InputManager
*/
public static final String INPUT_SERVICE = "input";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.hardware.display.DisplayManager} for interacting with display devices.
*
* @see #getSystemService
* @see android.hardware.display.DisplayManager
*/
public static final String DISPLAY_SERVICE = "display";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.os.UserManager} for managing users on devices that support multiple users.
*
* @see #getSystemService
* @see android.os.UserManager
*/
public static final String USER_SERVICE = "user";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
* profiles of a user.
*
* @see #getSystemService
* @see android.content.pm.LauncherApps
*/
public static final String LAUNCHER_APPS_SERVICE = "launcherapps";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.content.RestrictionsManager} for retrieving application restrictions
* and requesting permissions for restricted operations.
* @see #getSystemService
* @see android.content.RestrictionsManager
*/
public static final String RESTRICTIONS_SERVICE = "restrictions";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.app.AppOpsManager} for tracking application operations
* on the device.
*
* @see #getSystemService
* @see android.app.AppOpsManager
*/
public static final String APP_OPS_SERVICE = "appops";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.hardware.camera2.CameraManager} for interacting with
* camera devices.
*
* @see #getSystemService
* @see android.hardware.camera2.CameraManager
*/
public static final String CAMERA_SERVICE = "camera";

/**
* {@link android.print.PrintManager} for printing and managing
* printers and print tasks.
*
* @see #getSystemService
* @see android.print.PrintManager
*/
public static final String PRINT_SERVICE = "print";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.hardware.ConsumerIrManager} for transmitting infrared
* signals from the device.
*
* @see #getSystemService
* @see android.hardware.ConsumerIrManager
*/
public static final String CONSUMER_IR_SERVICE = "consumer_ir";

/**
* {@link android.app.trust.TrustManager} for managing trust agents.
* @see #getSystemService
* @see android.app.trust.TrustManager
* @hide
*/
public static final String TRUST_SERVICE = "trust";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.media.tv.TvInputManager} for interacting with TV inputs
* on the device.
*
* @see #getSystemService
* @see android.media.tv.TvInputManager
*/
public static final String TV_INPUT_SERVICE = "tv_input";

/**
* {@link android.net.NetworkScoreManager} for managing network scoring.
* @see #getSystemService
* @see android.net.NetworkScoreManager
* @hide
*/
@SystemApi
public static final String NETWORK_SCORE_SERVICE = "network_score";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.app.usage.UsageStatsManager} for querying device usage stats.
*
* @see #getSystemService
* @see android.app.usage.UsageStatsManager
*/
public static final String USAGE_STATS_SERVICE = "usagestats";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.app.job.JobScheduler} instance for managing occasional
* background tasks.
* @see #getSystemService
* @see android.app.job.JobScheduler
*/
public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.service.persistentdata.PersistentDataBlockManager} instance
* for interacting with a storage device that lives across factory resets.
*
* @see #getSystemService
* @see android.service.persistentdata.PersistentDataBlockManager
* @hide
*/
@SystemApi
public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.media.projection.MediaProjectionManager} instance for managing
* media projection sessions.
* @see #getSystemService
* @see android.media.projection.MediaProjectionManager
*/
public static final String MEDIA_PROJECTION_SERVICE = "media_projection";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.media.midi.MidiManager} for accessing the MIDI service.
*
* @see #getSystemService
*/
public static final String MIDI_SERVICE = "midi";


/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
*
* @see #getSystemService
* @hide
*/
public static final String RADIO_SERVICE = "radio";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
*
* @see #getSystemService
*/
public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";

/**
* TODO Javadoc
*
* @see #getSystemService
* @see android.content.pm.ShortcutManager
*
* @hide
*/
public static final String SHORTCUT_SERVICE = "shortcut";

/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.hardware.location.ContextHubManager} for accessing context hubs.
*
* @see #getSystemService
* @see android.hardware.location.ContextHubManager
*
* @hide
*/
@SystemApi
public static final String CONTEXTHUB_SERVICE = "contexthub";

/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
* memory, etc) metrics.
*
* @see #getSystemService
*/
public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";

/**
* Gatekeeper Service.
* @hide
*/
public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";

我把所有的SystemServe都贴出来,注意:其中有一部分加上了注解@SystemApi,这些Service不是给App开发者使用的,通过SystemServe也拿不到这个Service实例。

使用这些系统核心服务的方法是很简单的:

getSystemService(XXXX_SERVICE)

通过xxServiceManager调用的方法最后都会被Binder转移到对应的Serve。

至于怎么Binder怎么实现这个过程,具体有哪些Service,这又是另一个问题了。

这次就到这里,接下来的内容涉及到底层的C++代码,留置以后解决。