Binder機制詳解
阿新 • • 發佈:2019-02-20
class Proxy implements com.example.hezhe.myapplication.test.IBookManager
{
private android.os.IBinder mRemote;
Proxy(android.os.IBinder remote)
{
mRemote = remote;
}
@Override public android.os.IBinder asBinder()
{
return mRemote;
}
public java.lang.String getInterfaceDescriptor()
{
return DESCRIPTOR ;
}
/**
* Demonstrates some basic types that you can use as parameters
* and return values in AIDL.
*/
@Override public java.util.List<com.example.hezhe.myapplication.test.Book> getBookList() throws android.os.RemoteException
{
android.os.Parcel _data = android.os.Parcel.obtain();
android .os.Parcel _reply = android.os.Parcel.obtain();
java.util.List<com.example.hezhe.myapplication.test.Book> _result;
try {
_data.writeInterfaceToken(DESCRIPTOR);
//rpc 遠端過程呼叫。當前執行緒掛起,服務端ontransat方法會被呼叫直到RPC 過程返回
mRemote.transact(Stub.TRANSACTION_getBookList, _data, _reply, 0);
//_data輸入型物件,_reply輸出型物件
_reply .readException();
_result = _reply.createTypedArrayList(com.example.hezhe.myapplication.test.Book.CREATOR);
}
finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
//沒有返回值不需要從_reply中取返回值
@Override public void addBook(com.example.hezhe.myapplication.test.Book book) throws android.os.RemoteException
{
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
try {
_data.writeInterfaceToken(DESCRIPTOR);
if ((book!=null)) {
_data.writeInt(1);
book.writeToParcel(_data, 0);
}
else {
_data.writeInt(0);
}
mRemote.transact(Stub.TRANSACTION_addBook, _data, _reply, 0);
_reply.readException();
}
finally {
_reply.recycle();
_data.recycle();
}
}
}
static final int TRANSACTION_getBookList = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
static final int TRANSACTION_addBook = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
}
/**
* Demonstrates some basic types that you can use as parameters
* and return values in AIDL.
*/
public java.util.List<com.example.hezhe.myapplication.test.Book> getBookList() throws android.os.RemoteException;
public void addBook(com.example.hezhe.myapplication.test.Book book) throws android.os.RemoteException;
}