如何理解AndroidBinder递归
How to understand Android Binder recursion
我阅读了 Android Developer about IBinder/Binder 上的文档。
它说
The Binder system also supports recursion across processes. For
example if process A performs a transaction to process B, and process
B while handling that transaction calls transact() on an IBinder that
is implemented in A, then the thread in A that is currently waiting
for the original transaction to finish will take care of calling
Binder.onTransact() on the object being called by B. This ensures that
the recursion semantics when calling remote binder object are the same
as when calling local objects.
关于这个我有两个问题
then the thread in A that is currently waiting for the original
transaction to finish will take care of calling Binder.onTransact() on
the object being called by B
首先,如何通知被阻塞的线程去做除原始过程之外的其他事情?
其次,线程完成onTransact()
后,是否会再次阻塞等待原始事务。
First, How can a blocked thread be notified to do other stuff other than original procedure?
Binder是为了抽象出IPC的过程,所以这道题本质上就简化为"how can a called function call a function before returning"。由于这显然是可行且明智的,因此它也应该与 Binder 一起使用。
在实施方面,它将通过解释从活页夹交易操作接收到的数据来完成——如果这是 "call this method for me" 的编码而不是 "your return value is" 那么这就是将会发生的事情。
Second, After the thread finishes the onTransact(), will it block again to wait for original transaction.
是的,因为从处理 binder 事务的代码中调用的方法最终会 return 存在(除非出现异常、进程死亡、信号或类似情况)
我阅读了 Android Developer about IBinder/Binder 上的文档。
它说
The Binder system also supports recursion across processes. For example if process A performs a transaction to process B, and process B while handling that transaction calls transact() on an IBinder that is implemented in A, then the thread in A that is currently waiting for the original transaction to finish will take care of calling Binder.onTransact() on the object being called by B. This ensures that the recursion semantics when calling remote binder object are the same as when calling local objects.
关于这个我有两个问题
then the thread in A that is currently waiting for the original transaction to finish will take care of calling Binder.onTransact() on the object being called by B
首先,如何通知被阻塞的线程去做除原始过程之外的其他事情?
其次,线程完成onTransact()
后,是否会再次阻塞等待原始事务。
First, How can a blocked thread be notified to do other stuff other than original procedure?
Binder是为了抽象出IPC的过程,所以这道题本质上就简化为"how can a called function call a function before returning"。由于这显然是可行且明智的,因此它也应该与 Binder 一起使用。
在实施方面,它将通过解释从活页夹交易操作接收到的数据来完成——如果这是 "call this method for me" 的编码而不是 "your return value is" 那么这就是将会发生的事情。
Second, After the thread finishes the onTransact(), will it block again to wait for original transaction.
是的,因为从处理 binder 事务的代码中调用的方法最终会 return 存在(除非出现异常、进程死亡、信号或类似情况)