-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow adding foreground service types dynamically #1050
feat: allow adding foreground service types dynamically #1050
Conversation
I think that Notifee's AndroidManifest should not include: Since the foreground service could have other types and the resulting AndroidManifest would still have this permission |
the |
Yes But look at the following case. Only Location type is needed, so user add to his AndroidManifest: Permission request: And types replace: The problem here is that the resulting AndroidManifest will have both permission requirements: Which causes problems when uploading to the Play Store, since proof of the use of "FOREGROUND_SERVICE_DATA_SYNC" will be required, while this permission is not actually being used. The solution that comes to mind is:
|
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
@josegiufrida what you said makes a lot of sense to me.. I will update the docs accordingly in this PR |
The deadline for Android release to target SDK 34 is fast approaching (End of August). This PR is required for all notifee apps to run properly.
@josegiufrida Will this be enough of a fix for now until this PR is merged to be able to run on Android 14? |
How can we use this branch version of lib' until PR is merged ? |
it seems this one will not work when we start the foreground service from the background.
|
@zungx The error tells you that you dont have permissions to access microphone in the background! Set the foreground types based on what permissions you have |
Hey everyone 👋 - I'm looking into this at this very moment
But I like the fundamental approach - the basic idea of removing the current always-added foreground service type (which is illegal with new Android permission rules) and creating a new feature of optionally adding specific types is fundamentally sound, it looks like the right way to go So after a bit of cleanup etc this should be good to merge, hopefully pretty shortly 🚂 |
Hey @mikehardy , thanks a lot for checking this one, I think its best to update the default type to shortService It doesn't create a problem in google side as no permission is required for adding it. And I can remove the dataSync default. |
Based on the conversation that does seem like the best option, but I want to read all the related android developer documentation first Please don't worry about updating the PR for a moment - as maintainer I have permission to edit the PR and I am going to do so locally then push it, so as a collaboration item our changes may collide and I would clobber your changes - I don't want you to waste any time making changes that will be clobbered before I push to the PR :-) [update - nearly there - did the initial push that cleans up quite a few items, just a couple more to go + related pushes...] |
a bunch of non-standard formatting has crept in because we're not validating
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1050 +/- ##
==========================================
- Coverage 77.29% 77.08% -0.21%
==========================================
Files 32 32
Lines 1699 1727 +28
Branches 572 579 +7
==========================================
+ Hits 1313 1331 +18
- Misses 336 395 +59
+ Partials 50 1 -49 |
required for new foreground service symbols, which are required for Android 14 compatibility
BREAKING CHANGE: foreground service users must manually add Android permissions for Android 14+ requires android compileSdk of 34 or greater for new symbols to be available Android 14+ require foreground services to be strongly typed with specific permissions requested in the AndroidManifest and specified by the application. You are required to add the correct permission for the type of service you are using, and then declare it + justify the usage in the Google Play Store if you need foreground services
Android 15 adds a new foreground service type, it should be valid to use it in case people want to https://developer.android.com/about/versions/15/behavior-changes-15#mediaprocessing-fgs-type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright!
I want to be really quick to mention that the fundamental idea here (and the implementation of the actual feature) was sound and well done, huge thanks to @santhoshvai
I made a big pile of changes but they were all technicalities - lint formatting, minimizing the android build changes to be just a switch to the compileSdk (so as not to have scope creep here on the full set of changes there, they are non-trivial!), etc
Those ones I teased out into separate commits so that the main idea was in one commit and it was easy to see how it worked
I added one thing which is a new Android 15 foreground service type, as a follow-on commit
Allow adding foreground service types dynamically for Android 14 compatibility
Why ?
From Android 14 (API level 34) or higher, the operating system checks when you create a foreground service to make sure your app has all the appropriate permissions for that service type. For example, when you create a foreground service of type
microphone
, the operating system verifies that your app currently has theRECORD_AUDIO
permission. If you don't have that permission, the system throws aSecurityException
.How does this PR solve it?
To support this, a notification can now be created with
foregroundServiceTypes
property which specifies the types to be used while creating the service:If on runtime a new permission is granted from the user, the notification can be posted again (same notification id and channel id) with the new foregroundServiceTypes.
Fixes