0

I have a library, .aar bundle, that I want to share with other Android developers so that they can embed my code in their applications.

My library has a background service. There should only be one background service running or the services will compete for the same resources on the phone and conflict with each other.

The problem I see is that if someone has my google play app installed and then they install my partners app and I have the same service running on the phone on two apps neither app will run the way it should.

In another scenario I could have two clients using my libraries and both apps of my clients could be installed on one device. The same problem. My background service would be running on both applications and creating conflicts.

How do I distribute my .aar bundle and ensure that I only have one background service running for a shared library between two applications?

I'm wondering if maybe I am using the wrong distribution model.

pjc
  • 240
  • 5
  • 14
  • 1
    Perhaps the library should actually be installed as a separate APK on each device so that it is installed only once. See [Install Application programmatically on Android](http://stackoverflow.com/questions/4604239/install-application-programmatically-on-android). – Code-Apprentice Aug 30 '16 at 23:42
  • Suppose App A and App B both have your library and both are installed on a device. You, by some means, decide that App A's copy of your service is the one that should run. What happens to App B? If the answer is "App A sends data to App B from App A's service", you have security problems, because if App A can send data to App B, then Malware C through Z can also participate in those communications. If the answer is "App B is just screwed", that's unlikely to please the user or App B's developer. – CommonsWare Aug 30 '16 at 23:44
  • I think that Code-Apprentice has the answer and CommonsWare is making good points in support of that answer. Perhaps you can propose your comment as an answer and I can call this solved on your input? – pjc Aug 31 '16 at 00:16
  • As the other comments have suggested, you should have a separate apk that installs the service and an [AIDL](https://developer.android.com/guide/components/aidl.html) interface that interacts with it. Take a look at the Open VPN interface for Android as an example. – Gary Bak Aug 31 '16 at 00:58

0 Answers0