Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single service with multiple AIDL interfaces in Android

How can I serve multiple AIDL interfaces from a single Service? The scenario is the following:

                    |---Client_1
          |--AIDL1--|     ...
          |         |---Client_6
MyService |
          |         |---Client_4
          |--AIDL2--|     ...
                    |---Client_9
  • Single service with multiple AIDL;
  • Each client may access any number of AIDL interfaces;
  • For better understanding consider the diagram above, where some clients (e.g. Client_1, Client_8) only use one interface, while other clients (e.g. Client_4, Client_5, Client_6) access both AIDL1 and AIDL2.

My idea was to use the intent from the method public IBinder onBind(Intent intent) to somehow find out the type of client application calling and the AIDL in which this client is interested in. Is this possible?

like image 671
Daniel Avatar asked Oct 19 '22 22:10

Daniel


1 Answers

I also have the same question and write the prototype for testing. Actually it should works by examine the intent and return different binder according to the intent extras.

But after testing, I found the onBind only call once for the first client. After that, system will return the cached binder to later clients who want to bind the service.

Android official document describe

Multiple clients can connect to the service at once. However, the system calls your service's onBind() method to retrieve the IBinder only when the first client binds. The system then delivers the same IBinder to any additional clients that bind, without calling onBind() again.

I still try to find ways but it seems not possible to do that.

like image 188
HolaMan Avatar answered Oct 22 '22 11:10

HolaMan