/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);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章