之前在使用adb时,用过很多命令 比如adb install 等最后是调用了 pm相关命令,和Java service相关的命令都在Framework/base/cmds目录下,今天我们来讲下service命令,这个命令可以和任何一个注册到servicemanager的service进行通信。代码在Framework/native/cmds/service下。
一、命令
我们先看下help介绍:
- Usage: service [-h|-?]
- service list
- service check SERVICE
- service call SERVICE CODE [i32 N | i64 N | f N | d N | s16 STR ] ...
- Options:
- i32: Write the 32-bit integer N into the send parcel.
- i64: Write the 64-bit integer N into the send parcel.
- f: Write the 32-bit single-precision number N into the send parcel.
- d: Write the 64-bit double-precision number N into the send parcel.
- s16: Write the UTF-16 string STR into the send parcel.
service list列出所有的service,call service就是向相关service传递命令,各个参数的类型可以用i32等表示。
例子:
比如命令
- service call phone 2 s16 "123"
就是调用了下面函数 s16代表String类型 "123"就是参数。
- void call(String number);
service list //列出系统中的服务
$ service list
Found 87 services:
0 media_projection: [android.media.projection.IMediaProjectionManager]
1 touchsh: [android.sharpnow.ITouchShManager]
2 launcherapps: [android.content.pm.ILauncherApps]
3 trust: [android.app.trust.ITrustManager]
4 media_router: [android.media.IMediaRouterService]
5 media_session: [android.media.session.ISessionManager]
6 restrictions: [android.content.IRestrictionsManager]
7 graphicsstats: [android.view.IGraphicsStats]
8 assetatlas: [android.view.IAssetAtlas]
9 dreams: [android.service.dreams.IDreamManager]
10 commontime_management: []
11 samplingprofiler: []
12 diskstats: []
13 appwidget: [com.android.internal.appwidget.IAppWidgetService]
14 backup: [android.app.backup.IBackupManager]
15 jobscheduler: [android.app.job.IJobScheduler]
16 serial: [android.hardware.ISerialManager]
17 usb: [android.hardware.usb.IUsbManager]
18 DockObserver: []
19 audio: [android.media.IAudioService]
20 wallpaper: [android.app.IWallpaperManager]
21 dropbox: [com.android.internal.os.IDropBoxManagerService]
22 search: [android.app.ISearchManager]
23 devicestoragemonitor: []
24 notification: [android.app.INotificationManager]
25 updatelock: [android.os.IUpdateLock]
26 servicediscovery: [android.net.nsd.INsdManager]
27 connectivity: [android.net.IConnectivityManager]
28 ethernet: [android.net.IEthernetManager]
29 rttmanager: [android.net.wifi.IRttManager]
30 wifiscanner: [android.net.wifi.IWifiScanner]
31 wifi: [android.net.wifi.IWifiManager]
32 wifip2p: [android.net.wifi.p2p.IWifiP2pManager]
33 netpolicy: [android.net.INetworkPolicyManager]
34 netstats: [android.net.INetworkStatsService]
35 network_score: [android.net.INetworkScoreService]
36 textservices: [com.android.internal.textservice.ITextServicesManager]
37 network_management: [android.os.INetworkManagementService]
38 statusbar: [com.android.internal.statusbar.IStatusBarService]
39 device_policy: [android.app.admin.IDevicePolicyManager]
40 deviceidle: [android.os.IDeviceIdleController]
41 lock_settings: [com.android.internal.widget.ILockSettings]
42 media.radio: [android.hardware.IRadioService]
43 media.sound_trigger_hw: [android.hardware.ISoundTriggerHwService]
44 media.audio_policy: [android.media.IAudioPolicyService]
45 uimode: [android.app.IUiModeManager]
46 mount: [IMountService]
47 accessibility: [android.view.accessibility.IAccessibilityManager]
48 input_method: [com.android.internal.view.IInputMethodManager]
49 bluetooth_manager: [android.bluetooth.IBluetoothManager]
50 input: [android.hardware.input.IInputManager]
51 window: [android.view.IWindowManager]
52 alarm: [android.app.IAlarmManager]
53 vibrator: [android.os.IVibratorService]
54 content: [android.content.IContentService]
55 account: [android.accounts.IAccountManager]
56 media.camera.proxy: [android.hardware.ICameraServiceProxy]
57 media.camera: [android.hardware.ICameraService]
58 scheduling_policy: [android.os.ISchedulingPolicyService]
59 webviewupdate: [android.webkit.IWebViewUpdateService]
60 usagestats: [android.app.usage.IUsageStatsManager]
61 battery: []
62 sensorservice: [android.gui.SensorServer]
63 processinfo: [android.os.IProcessInfoService]
64 permission: [android.os.IPermissionController]
65 cpuinfo: []
66 dbinfo: []
67 gfxinfo: []
68 meminfo: []
69 procstats: [com.android.internal.app.IProcessStats]
70 activity: [android.app.IActivityManager]
71 user: [android.os.IUserManager]
72 package: [android.content.pm.IPackageManager]
73 display: [android.hardware.display.IDisplayManager]
74 power: [android.os.IPowerManager]
75 appops: [com.android.internal.app.IAppOpsService]
76 batterystats: [com.android.internal.app.IBatteryStats]
77 media.resource_manager: [android.media.IResourceManagerService]
78 media.player: [android.media.IMediaPlayerService]
79 media.audio_flinger: [android.media.IAudioFlinger]
80 drm.drmManager: [drm.IDrmManagerService]
81 android.security.keystore: [android.security.IKeystoreService]
82 android.service.gatekeeper.IGateKeeperService: [android.service.gatekeeper.IGateKeeperService]
83 batteryproperties: [android.os.IBatteryPropertiesRegistrar]
84 SurfaceFlinger: [android.ui.ISurfaceComposer]
85 Exynos.DisplayService: [android.hal.ExynosDisplayService]
86 Exynos.HWCService: [android.hal.ExynosHWCService]