经常使用命令:service list
但是你有没有执行过service --h,察看过其他的Option
Usage: service [-h|-?]
service list
service check SERVICE
service call SERVICE CODE [i32 INT | s16 STR] ...
Options:
i32: Write the integer INT into the send parcel.
s16: Write the UTF-16 string STR into the send parcel.
看看他的源码的具体位置:
android\frameworks\native\cmds\service
结构也非常简单。首先概略御览源码:
本质上是通过Native 层的servicemanager接口实现具体功能。
对于service call这条命令的实现,我从来没用过,新比较好奇。所以探究了一下源码的实现:
解析所有传入的argv,打包数据:
很好,可以通过service call命令来检验binder服务是否正确。那么有个神奇的问题,可以和java端的binder直接通讯吗?
尝试一下确认一下:我们以mountservice为例:
1.service list |grep mount
2.
为什么是call 30?
其中含义自行理解。重点关注Parcel这个值,java层binder调用,结果通过Parcel回传到Native层。言外之意,java层的binder可以和native层的binder直接通讯。
举例:
service call audio 4 i32 3 i32 15 i32 1 s16 com.skyworthdigital.settings;service call audio 4 i32 3 i32 8 i32 1 s16 com.skyworthdigital.settings;service call audio 4 i32 3 i32 17 i32 1 s16 com.skyworthdigital.settings;