0

In my Service I have a list of listeners (RemoteCallbackList) and I'm broadcasting some messages. Not every process is supposed to get the broadcast, so I'd like to filter them out. Is there a way to get PID of listening process from Listener itself?

Currently in my registerNewListener method I get callingPid and save it in a cookie stored by RemoteCallbackList, but between registration of a Listener, and broadcast, this could change and I have no way of knowing that...

  • When you broadcast,you have only 2 options ie: internal to the app or to the system.The choice of listening is upto the receiving app with the receiver.You cannot control which app listens to your broadcast.That goes against the definition of a Broadcast – Droidekas Feb 20 '15 at 09:07
  • So let's say I don't want to broadcast, but inform about changes some, but not all apps. The system knows, who is listening using specified Listener (because it somehow reach the listening app), so why couldn't I know it too? – Bartholomew Surma Feb 20 '15 at 09:34
  • Because these would be added at anytime.Say if you want to register a list of apps to inform ,you could do that.But when you say broadcast its a system wide to those who care to listen to it.If an app were to add a broadcast receiver for your app at a later stage how would that occur? – Droidekas Feb 20 '15 at 09:37
  • You could look intoa messenger service with a list of registered targets.That way you could send to specific apps – Droidekas Feb 20 '15 at 09:37
  • My service, has public method: addMyEventListener, which basically adds the new listener to a List in my Service. Now I iterate over this List, and do sth like: listener.dispatchMyEvent(). I can choose to send it or not and I do it based on Pid of a process that registered the listener. I'd like to get Pid of a process that will actually receive my info. – Bartholomew Surma Feb 20 '15 at 09:47
  • could you store the app package name instead and use [this]?(http://stackoverflow.com/questions/14168202/how-to-get-app-package-name-by-pid) – Droidekas Feb 20 '15 at 09:54
  • One app package could have many processes, and some of them might have privileges to receive my info, and some might not, so using one app package name for all of them won't solve my problem. – Bartholomew Surma Feb 20 '15 at 10:28

0 Answers0