-
Notifications
You must be signed in to change notification settings - Fork 64
Fix foreground service type for Android 16 compatibility #153
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
Closed
MichaelUray
wants to merge
1
commit into
netbirdio:main
from
MichaelUray:fix/android16-foreground-service-type
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule netbird
updated
68 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🌐 Web query:
Android startForeground FOREGROUND_SERVICE_TYPE_SPECIAL_USE requirement API 34💡 Result:
On Android 14 / API 34 (i.e., when your app targets 34+), using
startForeground(..., FOREGROUND_SERVICE_TYPE_SPECIAL_USE)requires all of the following:<service>):The
<property>subtype/value is a free-form explanation intended for Google Play Console review when you usespecialUse. [1]Each FGS type has a corresponding permission, and on API 34+ missing the appropriate type permission can cause a
SecurityException. [2][3]startForeground():Use
FOREGROUND_SERVICE_TYPE_SPECIAL_USEwhen callingstartForeground(). [1]Note:
specialUsehas no runtime prerequisites (beyond the permissions + correct declarations above). [1]Sources
[1] Android Developers — Foreground service types (Special use)
[2] Android Developers — Changes to foreground services (Android 14 / API 34 requirements)
[3] Android Developers —
Manifest.permission.FOREGROUND_SERVICE_SPECIAL_USE(API 34)🏁 Script executed:
Repository: netbirdio/android-client
Length of output: 139
🏁 Script executed:
Repository: netbirdio/android-client
Length of output: 103
🏁 Script executed:
Repository: netbirdio/android-client
Length of output: 2611
🏁 Script executed:
Repository: netbirdio/android-client
Length of output: 1998
Critical:
startForeground()must use the 3-parameter overload with the service type.The manifest correctly declares
foregroundServiceType="specialUse"and includes the required permission. However,ForegroundNotification.javaline 51 calls the 2-parameterstartForeground(NOTIFICATION_ID, notification). Starting with Android 14 (API 34), when a foreground service declares aforegroundServiceTypein the manifest, thestartForeground()call must use the 3-parameter overload and pass the matching type constant. Failure to do so throwsInvalidForegroundServiceTypeExceptionat runtime.Update
ForegroundNotification.java:Diff
Additionally, the
<service>block inAndroidManifest.xmlis missing the required<property>element for special use justification. Add this inside the<service>tag (line 15–26):🤖 Prompt for AI Agents