19-09-2017, 10:58 AM
AIDL (Android Interface Definition Language) is similar to other IDLs with which it might have worked. It allows you to define the programming interface that both the client and the service agree to communicate with each other through interprocess communication (IPC). On Android, one process normally can not access the memory of another process. So to speak, they need to decompose their objects into primitives that the operating system can understand, and sort the objects across that boundary for you. The code to make sorting is tedious to write, so Android manages for you with AIDL.
Before you start designing your AIDL interface, keep in mind that calls to an AIDL interface are direct function calls. You should not make assumptions about the thread in which the call occurs. What happens is different depending on whether the call comes from a thread in the local process or in a remote process. Specifically:
• Calls made from the local process run on the same thread as the caller. If this is the main UI thread, that thread continues to run on the AIDL interface. If it is another thread, it is the one that runs your code in the service. So, if only local threads are accessing the service, you can fully control which threads are running on it (but if that is the case, then you should not use AIDL at all, but you should create the interface by implementing a Binder).
• Calls from a remote process are sent from a group of threads that the platform maintains within its own process. You must be prepared for incoming calls from unknown threads, with multiple calls happening at the same time. In other words, the implementation of an AIDL interface must be completely secure.
• The unidirectional keyword modifies the behavior of remote calls. When used, a remote call does not block; simply send the data of the transaction and immediately returns. The interface implementation eventually receives this as a regular call from the Binder subprocess group as a normal remote call. If oneway is used with a local call, there is no impact and the call is still synchronous.
Before you start designing your AIDL interface, keep in mind that calls to an AIDL interface are direct function calls. You should not make assumptions about the thread in which the call occurs. What happens is different depending on whether the call comes from a thread in the local process or in a remote process. Specifically:
• Calls made from the local process run on the same thread as the caller. If this is the main UI thread, that thread continues to run on the AIDL interface. If it is another thread, it is the one that runs your code in the service. So, if only local threads are accessing the service, you can fully control which threads are running on it (but if that is the case, then you should not use AIDL at all, but you should create the interface by implementing a Binder).
• Calls from a remote process are sent from a group of threads that the platform maintains within its own process. You must be prepared for incoming calls from unknown threads, with multiple calls happening at the same time. In other words, the implementation of an AIDL interface must be completely secure.
• The unidirectional keyword modifies the behavior of remote calls. When used, a remote call does not block; simply send the data of the transaction and immediately returns. The interface implementation eventually receives this as a regular call from the Binder subprocess group as a normal remote call. If oneway is used with a local call, there is no impact and the call is still synchronous.