0

I'm building an Android service into a lib, when it is called to start, it runs in its own process. Other APPs could communicate with this service through AIDL interface.

The situation is: this service gets data from a particular web, and later on, it delivers the retrieved data to different APPs through callbacks.

Becuase different APPs may need different data. Therefore, one thing I don't understand is that how can the service differetiates the APPs when delivering data?

Thanks in advance.

2 Answers2

0

You may use the method Binder.getCallingPid() in the Service to know the calling process:

public static final int getCallingPid ()

Added in API level 1 Return the ID of the process that sent you the current transaction that is being processed. This pid can be used with higher-level system services to determine its identity and check permissions. If the current thread is not currently executing an incoming transaction, then its own pid is returned.

From the process id, you can find other information about the calling application.

prk
  • 338
  • 1
  • 4
  • 10
  • Thank you, and yes this a way, but an application doesn't necessarily have the same PID every time it starts. For example, APP1 and APP2 using the same service, when the service gets some msg, the msg itself must has some way to tell its destination. I'm thinking maybe just using the package name to differentiate the the applications. And the msg is simply broadcasted by the service... Thanks. – user3603784 Aug 06 '14 at 04:58
0

You can take package name out of process id and from that package name one can decide what is application that is calling aidl.

Package name can be deduced as given in solution :

Retrieving Java package name of AIDL consumer

Community
  • 1
  • 1
Harneev
  • 544
  • 4
  • 12