/system/bin/service分析与使用

service可以列出android使用的所有服务,还可以通过Binder与实现了aidl的服务通信
mmm frameworks/native/cmds/service编译出来的service
root@tcc893x:/ # /system/bin/service
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.

1) list的使用
root@tcc893x:/ # service list
Found 92 services:
0 goodbye: []
1 hello: []
2 AutoService: [com.semisky.midLevel.aidl.IAutoIPCService]
3 McuService: [com.semisky.midLevel.aidl.IMcuService]
4 KeyEventService: [com.semisky.midLevel.aidl.IKeyEventService]
5 RadioService: [com.semisky.midLevel.aidl.IRadioService]
6 CarInfoService: [com.semisky.midLevel.aidl.ICarInfoService]
7 sip: [android.net.sip.ISipService]
8 phone: [com.android.internal.telephony.ITelephony]
2)call的使用
调用服务定义的方法service call CarInfoService 4 i32 7,将会执行CarInfoService.test(7),其中4就是代表 void test(int code)
aidl文件在eclipse里面会自动生产java文件,名字和aidl相同。
每个方法自动对于一个code,列如ICarInfoService.aidl里面的test的方法
/*
*ICarInfoService.aidl
*/
interface ICarInfoService {
void requestWaitRsgInit(IServiceCallBack serviceCallBack,String packageName,int grpId, int subId, in byte[] reqData);
 void observer(IServiceCallBack serviceCallBack,String packageName,int grpId, int subId);
void unregisterListener(IServiceCallBack serviceCallBack,String packageName);
void test(int code);
}
eclipse自动给test()分配 android.os.IBinder.FIRST_CALL_TRANSACTION + 3 = 4
static final int TRANSACTION_requestWaitRsgInit = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
static final int TRANSACTION_observer = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
static final int TRANSACTION_unregisterListener = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
static final int TRANSACTION_test = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);

你可能感兴趣的:(android,Android)