Android进程间通讯之初见(IPC,RPC,LPC,BINDER,AIDL..)

Inter-process communication (IPC) is a set of methods for the exchange of data among multiple threads in one or more processes. Processes may be running on one or more computers connected by a network

也就是说,理论上所有跨线程的交互都可又称为IPC。它大致会分成两种,即LPC和RPC
The Local Procedure Call (LPC, often also referred to as Lightweight Procedure Call or Local Inter-Process Communication) is an internal, undocumented inter-process communication facility provided by the Microsoft Windows NT kernel for lightweight IPC between processes on the SAME computer.

In computer science, a remote procedure call (RPC) is an inter-process communication that allows a computer program to cause a subroutine or procedure to execute in another address space (commonly on another computer on a shared network)


对于Android系统来说,除了linux所提供的IPC机制外,它还有个binder机制(实际上用哪一种IPC并不是目的,关键是要看具体的应用环境)。对于binder机制,网上有铺天盖地的资料,这里我只想谈谈自己学习中的几点看法。
学习binder最好的还是官网上的资料,http://developer.android.com/guide/index.html 
先仔细把dev guide上有关的知识点研究一下,然后再针对自己的疑问搜索解答。
因为android很像一个杂合体,涉及太多概念,而且命名组织方面个人感觉还是很乱(可能是高手们并不会太介意这类东西,他们更看重思想的过程),所以在学习过程中,时常会被很多杂揉在一起的东西搞混。这里理一下一些基本的东西

binder提供了IPC的基础,它的base interface是Ibinder, 不过我们只会从binder继承。而对于AIDL,它更像一种工具,目的就是让binder的接口更亲切可人。也就是说,AIDL照其字面意思,AIDL (Android Interface Definition Language) is similar to other IDLs you might haveworked with. It allows you to define the programming interface that both the client and service agree upon in order to communicate with each other usinginterprocess communication (IPC)。所以千万不要以为AIDL是另一种IPC,它只是让BINDER更好看的makeup。

binder的大概流程是(比如A调用B),A和B之间有共同的ibinder的reference,A利用这个reference通过底层binder驱动调用到B中的onTransact(此时A会block住),当B返回结果时,A继承执行。
对于它们如何得到共用的ibinder,对于应用场景为service的情况,就牵涉到service manager了。B先向service manager注册,这样后续A只要向service manager查询,就可以得到B的ibinder了。

你可能感兴趣的:(android,manager,service,interface,reference,通讯)