You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.4 KiB
1.4 KiB
说一说 binder 的 oneway 机制
- binder 的 oneway 是什么意思?
- oneway 有哪些特性?
- 它的实现原理是怎样的?
interface IRemoteCaller{
void publishBinder(ICallback callback);
}
public void publishBinder(ICallback callback){
mRemote.transact(Stub.TRANSACTION_publishBinder, _data, _reply, 0);
}
oneway interface IRemoteCaller{
void publishBinder(ICallback callback);
}
public void publishBinder(ICallback callback){
mRemote.transact(Stub.TRANSACTION_publishBinder, _data, null, IBinder.FLAG_ONEWAY);
}
// 带 oneway
status_t transact(int32_t handle, uint32_t code, Parcel& data, Parcel* reply, uint32_t flags){
writeTransactionData(BC_TRANSACTION, flags, handle, code, data, NULL);
waitForResponse(NULL, NULL);
}
// 不带 oneway
status_t transact(int32_t handle, uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags){
writeTransactionData(BC_TRANSACTION, flags, handle, code, data, NULL);
waitForResponse(reply);
}
例子:
final void scheduleLauncherActivity(Intent intent, IBinder token, ...){
mRemote.transact(SCHEDULT_LAUNCH_ACTIVITY_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
}
oneway interface IWindow{}
oneway interface IServiceConnection{}
oneway interface IIntentReceiver{}
总结
- oneway 是异步 binder 调用
- server 端串行化处理
- oneway 的实现机制