Fix Android Service not being disabled when set#3104
Merged
TheCodeTraveler merged 6 commits intoCommunityToolkit:mainfrom Feb 18, 2026
Merged
Fix Android Service not being disabled when set#3104TheCodeTraveler merged 6 commits intoCommunityToolkit:mainfrom
TheCodeTraveler merged 6 commits intoCommunityToolkit:mainfrom
Conversation
Refactored MediaElementOptions to remove the default true value for IsAndroidForegroundServiceEnabled, making it default to false. Removed the UpdateIsAndroidForegroundServiceEnabledWithUseMauiCommunityToolkitMediaElementParameter method and now use SetIsAndroidForegroundServiceEnabled directly. Updated AppBuilderExtensions and unit tests to reflect these changes and ensure correct behavior with the simplified property logic.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where setting IsAndroidForegroundServiceEnabled to false in MediaElement would still result in the Android Foreground Service being enabled. The root cause was twofold: the property defaulted to true, and the method that updated it used a logical OR assignment (|=) that prevented it from ever being set to false.
Changes:
- Removed erroneous default value (
= true) fromIsAndroidForegroundServiceEnabled, allowing it to default tofalse - Removed
UpdateIsAndroidForegroundServiceEnabledWithUseMauiCommunityToolkitMediaElementParametermethod that used|=operator - Changed
SetIsAndroidForegroundServiceEnabledvisibility frompublictointernalto prevent external misconfiguration - Simplified
AppBuilderExtensionsto callSetIsAndroidForegroundServiceEnableddirectly instead of using the removed method - Updated unit tests to reflect the new behavior
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| MediaElementOptions.shared.cs | Removed default true initialization and the problematic UpdateIsAndroidForegroundServiceEnabledWithUseMauiCommunityToolkitMediaElementParameter method; changed SetIsAndroidForegroundServiceEnabled to internal |
| AppBuilderExtensions.shared.cs | Simplified to call SetIsAndroidForegroundServiceEnabled directly with the parameter value |
| MediaElementOptionsTests.cs | Updated tests to verify the corrected behavior, removed tests for the deleted method |
pictos
previously approved these changes
Feb 18, 2026
This reverts commit cf7d7e3.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 11 comments.
Comments suppressed due to low confidence (1)
src/CommunityToolkit.Maui.UnitTests/Extensions/AppBuilderExtensionsTests.cs:269
- Test logic appears incorrect. The test calls SetIsAndroidForegroundServiceEnabled(false) on line 266, but then asserts that IsAndroidForegroundServiceEnabled should be true on line 269. Based on the PR description stating that SetIsAndroidForegroundServiceEnabled should directly set the value, this assertion should be false, or the method call on line 266 should be SetIsAndroidForegroundServiceEnabled(true) if the intention is to verify that the options callback overrides the parameter value.
TheCodeTraveler
approved these changes
Feb 18, 2026
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Android MediaSessionService was not being disabled when setting
IsAndroidForegroundServiceEnabledtofalse. This fixes it and removes setting the default value that was being set erroneously. It should never have been set. This is why the analyzer was created to verify that it was set and cause a build error message otherwise.Description of Change
Refactored MediaElementOptions to remove the default true value for IsAndroidForegroundServiceEnabled, making it default to false. Removed the UpdateIsAndroidForegroundServiceEnabledWithUseMauiCommunityToolkitMediaElementParameter method and now use SetIsAndroidForegroundServiceEnabled directly. Updated AppBuilderExtensions and unit tests to reflect these changes and ensure correct behavior with the simplified property logic.
Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
Please test and verify this works for more than just me :)