1

I'm somewhere in the code, where i have only very limited permissions, but have to ship data outside to an android application. (Android system C code) Obviously I cannot start a binder service in there, but I can connect to an already running service. Therefore my implementation checks every second if the service is available, and if it is available, it connects and starts sending data. This works fine.

My issue is the following. If I kill the service binary/process, the clients somehow do not see that the service is not available anymore. Is there a way to remove a service I added using addService(...)? The clients do getService().

Onik
  • 19,396
  • 14
  • 68
  • 91
user3387542
  • 611
  • 1
  • 8
  • 28

2 Answers2

0

I could solve the problem by just periodically do a getService() again at the client side. Like this they won't see it immediately if the service is gone, but they get it at some point. Like this they can reconnect if the service is available again.

I didn't find anything to "remove" the service. But this workaround works nice.

user3387542
  • 611
  • 1
  • 8
  • 28
0

There is no API to remove a service handle, although when a service dies, service manager will release the handle using svcinfo_death(). The only valid incoming transaction codes in the native service manager are SVC_MGR_GET_SERVICE, SVC_MGR_CHECK_SERVICE, SVC_MGR_ADD_SERVICE, and SVC_MGR_LIST_SERVICES (see service_manager.c).

That said, you may find that applying this solution to your problem could be more efficient and reliable for deciding if another call to getService() is necessary.

Community
  • 1
  • 1
Paul Ratazzi
  • 6,289
  • 3
  • 38
  • 50
  • I cannot use the "this solution" part, as both ends are C code, I'm not even in jni. The client is some running android system code with no permissions, and the server is a small executable written in C and started with su from the command line, invoked by java. But you are right, I should have a look on check_service inside the client every few seconds, this might be cheaper than a getservice. I studied the service_manager before (http://stackoverflow.com/questions/22460097/c-binder-without-addservice/25768973#25768973) – user3387542 Sep 11 '14 at 15:00
  • Or do you have an idea how to pass continuous data from a very non unauthorized system-internal to a normal non-root java app? I cannot start them as root. But I could start a third process as root, that's my current solution. One doesn't even has the ability to access the filesystem. Therefor I didn't even bother about sockets. – user3387542 Sep 11 '14 at 15:09
  • I wanted to use check_service now, but I could not find an implementation example or a reference on how to use it. add_service() and getService() are working, but how to check if a service is available? My Code is similar to this https://github.com/vecio/AndroidIPC. – user3387542 Sep 16 '14 at 10:14