service命令用来查询某一个服务是否启动,以及调用某一个服务中的一个方法。
service 命令:
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.
D:\test>adb shell service list
Found 207 services:
0 gsiservice: []
1 sip: [android.net.sip.ISipService]
2 dpmservice: [com.qti.dpm.IDpmService]
......
82 wifi: [android.net.wifi.IWifiManager]
......
格式(以wifi为例): wifi: [android.net.wifi.IWifiManager]
服务名 : 服务实现的aidl接口
服务名在Context.java中有定义
https://www.androidos.net.cn/android/6.0.1_r16/xref/frameworks/base/core/java/android/content/Context.java
服务接口aidl在IWifiManager.aidl中有定义
https://www.androidos.net.cn/android/6.0.1_r16/xref/frameworks/base/wifi/java/android/net/wifi/IWifiManager.aidl
通过 service check
命令可以确认服务存在
参考博客:
[ Android 调试技巧 ] 为什么 service list 打印出来的服务信息为空?_android service list_那个写代码的的博客-CSDN博客
service call命令的格式是
service call SERVICE CODE [i32 N | i64 N | f N | d N | s16 STR ] ...
CODE是个序号数字
如果参数比较复杂,可能是类似这样的格式;
service call someservice [seq] i32 [type] i32 [len] i32 [value] i32 [value] i32 ......
执行结果的格式一般是:
Result: Parcel(00000000 00000001 '........')
00000000: 表示执行成功,如果非0,一般填的是错误码。
参考博客
Android通过 service call 命令调用 phone 的 AIDL 服务_傻熙Ta爸的博客-CSDN博客
打开WIFI
Ditest:/ # service call wifi 22 i64 1
Result: Parcel(00000000 00000001 '........')
关闭WIFI
Ditest:/ # service call wifi 22 i64 0
Result: Parcel(00000000 00000001 '........')
如果执行失败,有时会打印出原因
DiLink4.0:/ # service call wifi 19 i64 1
Result: Parcel(
0x00000000: fffffffc ffffffff 00000340 0000019a '........@.......'
0x00000010: 00610009 00200074 006f0063 002e006d '..a.t. .c.o.m...'
0x00000020: 006e0061 00720064 0069006f 002e0064 'a.n.d.r.o.i.d...'
0x00000030: 006e0069 00650074 006e0072 006c0061 'i.n.t.e.r.n.a.l.'
0x00000040: 0075002e 00690074 002e006c 00720050 '..u.t.i.l...P.r.'
0x00000050: 00630065 006e006f 00690064 00690074 'e.c.o.n.d.i.t.i.'
0x00000060: 006e006f 002e0073 00680063 00630065 'o.n.s...c.h.e.c.'
0x00000070: 004e006b 0074006f 0075004e 006c006c 'k.N.o.t.N.u.l.l.'
0x00000080: 00500028 00650072 006f0063 0064006e '(.P.r.e.c.o.n.d.'
0x00000090: 00740069 006f0069 0073006e 006a002e 'i.t.i.o.n.s...j.'
0x000000a0: 00760061 003a0061 00310031 00290035 'a.v.a.:.1.1.5.).'
0x000000b0: 0009000a 00740061 00630020 006d006f '....a.t. .c.o.m.'
0x000000c0: 0061002e 0064006e 006f0072 00640069 '..a.n.d.r.o.i.d.'
0x000000d0: 0073002e 00720065 00650076 002e0072 '..s.e.r.v.e.r...'
0x000000e0: 00700061 006f0070 002e0070 00700041 'a.p.p.o.p...A.p.'
0x000000f0: 004f0070 00730070 00650053 00760072 'p.O.p.s.S.e.r.v.'
0x00000100: 00630069 002e0065 00680063 00630065 'i.c.e...c.h.e.c.'
0x00000110: 0050006b 00630061 0061006b 00650067 'k.P.a.c.k.a.g.e.'
0x00000120: 00410028 00700070 0070004f 00530073 '(.A.p.p.O.p.s.S.'
0x00000130: 00720065 00690076 00650063 006a002e 'e.r.v.i.c.e...j.'
0x00000140: 00760061 003a0061 00390031 00340037 'a.v.a.:.1.9.7.4.'
0x00000150: 000a0029 00610009 00200074 006e0061 ').....a.t. .a.n.'
0x00000160: 00720064 0069006f 002e0064 00700061 'd.r.o.i.d...a.p.'
0x00000170: 002e0070 00700041 004f0070 00730070 'p...A.p.p.O.p.s.'
0x00000180: 0061004d 0061006e 00650067 002e0072 'M.a.n.a.g.e.r...'
0x00000190: 00680063 00630065 0050006b 00630061 'c.h.e.c.k.P.a.c.'
0x000001a0: 0061006b 00650067 00410028 00700070 'k.a.g.e.(.A.p.p.'
0x000001b0: 0070004f 004d0073 006e0061 00670061 'O.p.s.M.a.n.a.g.'
0x000001c0: 00720065 006a002e 00760061 003a0061 'e.r...j.a.v.a.:.'
0x000001d0: 00320035 00370035 000a0029 00610009 '5.2.5.7.).....a.'
0x000001e0: 00200074 006f0063 002e006d 006e0061 't. .c.o.m...a.n.'
0x000001f0: 00720064 0069006f 002e0064 00650073 'd.r.o.i.d...s.e.'
0x00000200: 00760072 00720065 0077002e 00660069 'r.v.e.r...w.i.f.'
0x00000210: 002e0069 00690057 00690066 00650053 'i...W.i.f.i.S.e.'
0x00000220: 00760072 00630069 00490065 0070006d 'r.v.i.c.e.I.m.p.'
0x00000230: 002e006c 006e0065 006f0066 00630072 'l...e.n.f.o.r.c.'
0x00000240: 00430065 00610068 0067006e 00500065 'e.C.h.a.n.g.e.P.'
0x00000250: 00720065 0069006d 00730073 006f0069 'e.r.m.i.s.s.i.o.'
0x00000260: 0028006e 00690057 00690066 00650053 'n.(.W.i.f.i.S.e.'
0x00000270: 00760072 00630069 00490065 0070006d 'r.v.i.c.e.I.m.p.'
0x00000280: 002e006c 0061006a 00610076 0039003a 'l...j.a.v.a.:.9.'
0x00000290: 00310036 000a0029 00610009 00200074 '6.1.).....a.t. .'
0x000002a0: 006f0063 002e006d 006e0061 00720064 'c.o.m...a.n.d.r.'
0x000002b0: 0069006f 002e0064 00650073 00760072 'o.i.d...s.e.r.v.'
0x000002c0: 00720065 0077002e 00660069 002e0069 'e.r...w.i.f.i...'
0x000002d0: 00690057 00690066 00650053 00760072 'W.i.f.i.S.e.r.v.'
0x000002e0: 00630069 00490065 0070006d 002e006c 'i.c.e.I.m.p.l...'
0x000002f0: 00690064 00610073 006c0062 004e0065 'd.i.s.a.b.l.e.N.'
0x00000300: 00740065 006f0077 006b0072 00570028 'e.t.w.o.r.k.(.W.'
0x00000310: 00660069 00530069 00720065 00690076 'i.f.i.S.e.r.v.i.'
0x00000320: 00650063 006d0049 006c0070 006a002e 'c.e.I.m.p.l...j.'
0x00000330: 00760061 003a0061 00360032 00340032 'a.v.a.:.2.6.2.4.'
0x00000340: 000a0029 00000000 ')....... ')
service 是一种方便好用的调试工具,同时它的使用功能也有一定局限性。