Android debugging using service call

1 Introduction

        The service command is used to query whether a certain service is started, and to call a method in a certain service.

2. Related commands

service command:

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.

2.1 service list

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]
......

Format (take wifi as an example): wifi: [android.net.wifi.IWifiManager]

Service name: the aidl interface implemented by the service

The service name is defined in Context.java

https://www.androidos.net.cn/android/6.0.1_r16/xref/frameworks/base/core/java/android/content/Context.java

The service interface aidl is defined in IWifiManager.aidl

https://www.androidos.net.cn/android/6.0.1_r16/xref/frameworks/base/wifi/java/android/net/wifi/IWifiManager.aidl

2.2 service check

service check The existence of the service can be confirmed by  the command

Reference blog:

[Android debugging skills] Why is the service information printed by the service list empty? _android service list_The blog that writes code-CSDN blog

2.3 service call

The format of the service call command is

service call SERVICE CODE [i32 N | i64 N | f N | d N | s16 STR ] ...

CODE is a serial number

If the parameters are more complicated, it may be in a format like this;

service call someservice [seq] i32 [type] i32 [len] i32 [value] i32 [value] i32 ......

The format of the execution result is generally:

Result: Parcel(00000000 00000001   '........')

00000000: Indicates that the execution is successful. If it is not 0, it is generally an error code.

3. Use the service call debugging function

3.1 Android calls the AIDL service of the phone through the service call command

reference blog

Android calls the AIDL service of the phone through the service call command_Sixi Ta Dad's Blog-CSDN Blog

3.2 Android turns on or off the wifi service through the service call command

 turn on wifi

Ditest:/ # service call wifi 22 i64 1
Result: Parcel(00000000 00000001   '........')

turn off wifi

Ditest:/ # service call wifi 22 i64 0
Result: Parcel(00000000 00000001   '........')

If the execution fails, the reason is sometimes printed

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                   ').......        ')

4. Finally

service is a convenient and easy-to-use debugging tool, but its functions also have certain limitations.

Guess you like

Origin blog.csdn.net/qq_33163046/article/details/131180882