Bootstrap

[Android]service命令的使用

在前面的讨论中,我们说到,如果在客户端懒得使用aidl文件生成的接口类进行binder,可以使用IBinder的transcat方法

	    	 Parcel dataParcel = Parcel.obtain(); 
	    	 Parcel resultParcel = Parcel.obtain();
	  dataParcel.writeInterfaceToken(DESCRIPTOR);
	   //发起请求	 
	     aProxyBinder.transact(3, dataParcel, resultParcel, 0);

还有一个更方便的binder调用测试方式,使用service命令。

service命令

看看help信息,

$ service -h
Usage: service [-h|-?]
       service list
       service check SERVICE
       service call SERVICE CODE [i32 N | i64 N | f N | d N | s16 STR | null | fd f | nfd n | afd f ] ...
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.
  null: Write a null binder into the send parcel.
    fd: Write a file descriptor for the file f into the send parcel.
   nfd: Write the file descriptor n into the send parcel.
   afd: Write an ashmem file descriptor for a region containing the data from
          file f into the send parcel.

service call调用传入对应的参数信息即可,比如

service call SERVICE_name 1 i32 112

表示调用SERVICE_name这个binder服务的第1个接口方法,传入int32类型的参数值112

service的代码在

frameworks/native/cmds/

;