Are Android AIDL / Binder Object Interfaces Objects?

If I have a Binder object representing a remote interface (for the Android service or a callback interface for a remote client), do I need explicit synchronization when sending IPC through this object from multiple threads or will the basic Android component take care of this?

+4
source share
2 answers

A limited service is implemented using the Binder class if we want the client and service to be running in the same process and not want to perform parallel IPC in different applications. This way, the thread (in the client) that calls the service method will be blocked until it returns. There may be several threads generated in the client (activity) programmatically, each of which calls the service method at any time. Therefore, the service must be implemented in such a way that it is thread safe, since there can simultaneously be several threads that call the service method. Conclusion: Android does not synchronize when the Binder class expands to implement the Limited Service.

A limited service is implemented using AIDL if we want to allow clients from different applications to access the service for IPC and try to handle multithreading in the service. Conclusion: Android does not synchronize when AIDL is used to implement a limited service.

+3
source

Calling the Binder RPC method on Android is thread safe; you can call a call from multiple threads without synchronization.

On the receiving side - provided that the Service is in a different process, as usual - you receive calls from the Binder thread pool, regardless of how it was called on the caller side. This means that your Service can make multiple calls at the same time, so be careful on this side.

Additional Info at Android Docs: Processes and Threads

+1
source

Source: https://habr.com/ru/post/1315415/


All Articles