kotlinaltbeacon

Android foreground service in manifest - Altbeacon


Good morning!

I've been using Altbeacon for a while and I love the quiet background mode of it. Unfortunately, by updating the lib to its latest version, I noticed the foreground service permission was by default in the Manifest.

FOREGROUND_SERVICE_LOCATION

Since I do not use the lib in foreground, I would rather not have that permission at all in the Manifest, which would force me to justify it when I upload an app on the store.

I tried force removing the permission from my app's manifest and it seems to work just fine while not using the foreground service of altbeacon, but I know this is not a recommended way to integrate the library.

Is it safe for me to remove the permission that way? Am I missing something? Shouldn't this permission not be in the Manifest by default and added only when the user needs it?

Thank you for your time.


Solution

  • Yes, it's safe to remove the FOREGROUND_SERVICE permission from the AndroidManifest.xml if you do not need foreground services with your app, and that actually is the recommended approach with the latest version of the Android Beacon Library.

    <manifest ... xmlns:tools="http://schemas.android.com/tools">
        ...
        <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" tools:node="remove" />
        ...
    </manifest>
    

    Needing to do this is admittedly awkward. Some quick history: The permission was added to the library manifest when Google started requiring the permission for foreground services. This was done to make it easier for developers to use the built-in foreground service. When this change to the library was made, Google was not requiring justifications for the permission for submission to the Google Play Store, so there was no practical downside. As you point out, the new justification requirement changes that, but removing the permission from the library now would be a breaking change for many apps, so I am reluctant to do that before the next major 3.0 release.

    Addressing this problem is a good topic for discussion on an issue in the open source repo on GitHub. Any ideas are welcome.

    Full disclosure: I am the lead developer on the Android Beacon Library open source project.