关于IBinder运行的线程

根据官方文档说明

This is primarily true for methods that can be called remotely—such as methods in a bound service. When a call on a method implemented in an IBinder originates in the same process in which the IBinder is running, the method is executed in the caller’s thread. However, when the call originates in another process, the method is executed in a thread chosen from a pool of threads that the system maintains in the same process as the IBinder (it’s not executed in the UI thread of the process). For example, whereas a service’s onBind() method would be called from the UI thread of the service’s process, methods implemented in the object that onBind() returns (for example, a subclass that implements RPC methods) would be called from threads in the pool. Because a service can have more than one client, more than one pool thread can engage the same IBinder method at the same time. IBinder methods must, therefore, be implemented to be thread-safe.

当IBinder的实现函数与调用者处于同一process中时,IBinder的实现函数运行在与调用者相同的线程,如果调用者从UI线程通过binder调用,则binder的实现函数在UI线程运行,如果调用者从new出来的thread调用,则binder的实现函数在这个thread中运行。

当IBinder的实现函数与调用者处于不同process时,IBinder的实现函数在binder的thread中运行。