-
Notifications
You must be signed in to change notification settings - Fork 495
Add support to make AndroidForegroundService optional to MediaElement #2658
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
Merged
TheCodeTraveler
merged 81 commits into
CommunityToolkit:main
from
ne0rrmatrix:MediaElementOptionService
Jan 29, 2026
Merged
Changes from 70 commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
14eab7b
Add support to make AndroidForegroundService optional to MediaElement
ne0rrmatrix 44a9928
Rename foreground service property for clarity
ne0rrmatrix c683d61
Update media playback service and permissions
ne0rrmatrix 0feee28
Add tests for AndroidForegroundService default behavior
ne0rrmatrix f6407f6
Set service on by default
ne0rrmatrix 63ad21b
Remove old intent filter that was added by accident
ne0rrmatrix 1e60956
Rename AndroidForegroundServiceEnabled property
ne0rrmatrix 5a3c0fe
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 904ae95
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix ea35514
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix cecaf32
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 178e8ae
Enable Android Foreground Service for MediaElement
ne0rrmatrix 25b22c6
Merge branch 'MediaElementOptionService' of https://github.com/ne0rrm…
ne0rrmatrix 1168302
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 838d9a5
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 7aba464
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix a83de86
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix ed62a22
Update src/CommunityToolkit.Maui.MediaElement/MediaElementOptions.sha…
ne0rrmatrix 84b337c
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 58e07a8
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix cb63525
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 54830f8
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 74dfd56
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix e205ac3
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 8599d5c
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 9b20b70
Refactor MediaElement Android Foreground Service config
ne0rrmatrix 0588103
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix ca6ec4a
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 7a4e51b
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix af24853
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix d00dcf7
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 747f95b
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix 4106c25
Switch to using using OptIn and move from options to builder to set s…
ne0rrmatrix 045e95f
Merge branch 'MediaElementOptionService' of https://github.com/ne0rrm…
ne0rrmatrix eeeba09
Fix tests
ne0rrmatrix 859eb74
Require enableForegroundService param for MediaElement init
ne0rrmatrix 349607a
Remove Analyzer and associated tests
ne0rrmatrix a783e5b
Update src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/MediaEl…
ne0rrmatrix 268abca
Update comment to add href to documentation for MediaElement when set…
ne0rrmatrix f6dc22a
Update URL to not be region specific
ne0rrmatrix 5b2e117
Update MediaElementOptions tests to reflect no default value for whet…
ne0rrmatrix 28f912a
Copilot Suggestion
ne0rrmatrix 9eb07b8
Copilot Sugestions and update test to remove setting default for Serv…
ne0rrmatrix 2094ae8
Update src/CommunityToolkit.Maui.UnitTests/BaseTest.cs
ne0rrmatrix 20c3af6
Copilot suggestions
ne0rrmatrix 483a6d7
C# standards
ne0rrmatrix dc491ba
Merge branch 'main' into MediaElementOptionService
bijington b4d1316
Add analyzer & generator for MediaElement Android service
ne0rrmatrix 95c5f87
Add analyzer & source generator for MediaElement Android svc
ne0rrmatrix cc72e22
Refactor analyzer/generator and modernize test suite
ne0rrmatrix 4ed9db2
Refactor: use array initializers for ImmutableArray<T>
ne0rrmatrix bd26839
Merge branch 'main' into MediaElementOptionService
ne0rrmatrix a2c4cf8
Move Analyzers to `CommunityToolkit.Maui.MediaElement.Analyzers`, Mov…
TheCodeTraveler 651c556
Use Resources.resx
TheCodeTraveler 5760099
Add `UseMauiCommunityToolkitMediaElement`, Move ndroidMediaElementSer…
TheCodeTraveler cce1507
Ensure isAndroidForegroundServiceEnabled overrides `options`
TheCodeTraveler 59dd64f
Add support for UseMauiCommunityToolkitMediaElement
TheCodeTraveler cc14c22
Add Unit Tests for UseMauiCommunityToolkitMediaElementTests
TheCodeTraveler 94e77d4
Update `UseCommunityToolkitMediaElementInitializationAnalyzerTests` t…
TheCodeTraveler 1b8c576
Ensure `DiagnosticSeverity.Error`
TheCodeTraveler 44778f0
Resolve Failing Unit Tests
TheCodeTraveler aa68ecf
Update CommunityToolkit.Maui.slnx
TheCodeTraveler 2455858
Update dotnet-build.yml
TheCodeTraveler 2f496d8
Update CommunityToolkit.Maui.slnx
TheCodeTraveler 40fc920
Add Benchmarks
TheCodeTraveler ea558f1
Make class `public`
TheCodeTraveler 70387b6
Add MediaElementOptions. UpdateIsAndroidForegroundServiceEnabledWithU…
TheCodeTraveler a8ad407
Add references to MediaElement Analyzers
TheCodeTraveler 18a04fa
Add Reference to MediaElement Analyzers
TheCodeTraveler c4d2c3a
Add Analyzers + Source Generators to NuGet Package
TheCodeTraveler be60504
Update `AndroidMediaElementForegroundServiceConfigurationGenerator` name
TheCodeTraveler 4fd4594
Rename to `*ForegroundService*`
TheCodeTraveler c9a6ad5
Update error message
TheCodeTraveler 5e15042
Update Analyzer Error Message
TheCodeTraveler aadeec0
Remove period from error message
TheCodeTraveler dc282ab
Remove Foreground Service Analyzer, Update AndroidMediaElemenForegrou…
TheCodeTraveler f49a25f
Revert changes
TheCodeTraveler c955ef9
Update MediaElementOptionsTests.cs
TheCodeTraveler aa9ffc2
Update readme.txt
TheCodeTraveler f77c334
Merge branch 'MediaElementOptionService' of https://github.com/ne0rrm…
TheCodeTraveler b553279
Update CommunityToolkit.Maui.slnx
bijington 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
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
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
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
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
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
38 changes: 19 additions & 19 deletions
38
samples/CommunityToolkit.Maui.Sample/Platforms/Android/AndroidManifest.xml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,25 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <application android:allowBackup="true" android:icon="@mipmap/appicon" android:enableOnBackInvokedCallback="true" android:hardwareAccelerated="true" | ||
| android:supportsRtl="true"> | ||
|
|
||
| <meta-data android:name="com.google.android.geo.API_KEY" android:value="PASTE-YOUR-API-KEY-HERE" /> | ||
| </application> | ||
|
|
||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
| <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
| <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
| android:supportsRtl="true"> | ||
|
|
||
| <!-- Samsung --> | ||
| <uses-permission android:name="com.sec.android.provider.badge.permission.READ"/> | ||
| <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/> | ||
| <!-- /Samsung --> | ||
| <meta-data android:name="com.google.android.geo.API_KEY" android:value="PASTE-YOUR-API-KEY-HERE" /> | ||
| </application> | ||
|
|
||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
| <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
| <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
|
|
||
| <!-- Samsung --> | ||
| <uses-permission android:name="com.sec.android.provider.badge.permission.READ"/> | ||
| <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/> | ||
| <!-- /Samsung --> | ||
|
|
||
| <uses-permission android:name="android.permission.RECORD_AUDIO"/> | ||
| <uses-permission android:name="android.permission.CAMERA"/> | ||
| <queries> | ||
| <intent> | ||
| <action android:name="android.intent.action.TTS_SERVICE"/> | ||
| </intent> | ||
| </queries> | ||
| <uses-permission android:name="android.permission.RECORD_AUDIO"/> | ||
| <uses-permission android:name="android.permission.CAMERA"/> | ||
| <queries> | ||
| <intent> | ||
| <action android:name="android.intent.action.TTS_SERVICE"/> | ||
| </intent> | ||
| </queries> | ||
| </manifest> |
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
27 changes: 27 additions & 0 deletions
27
...it.Maui.Analyzers.Benchmarks/AndroidMediaElementServiceConfigurationAnalyzerBenchmarks.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using BenchmarkDotNet.Attributes; | ||
| using CommunityToolkit.Maui.MediaElement.SourceGenerators.UnitTests.AndroidMediaElementServiceConfigurationAnalyzerTests; | ||
|
|
||
| namespace CommunityToolkit.Maui.Analyzers.Benchmarks; | ||
|
|
||
| public class AndroidMediaElementServiceConfigurationAnalyzerBenchmarks | ||
| { | ||
| static readonly AndroidMediaElementServiceConfigurationAnalyzer_CommonUsageTests androidMediaElementServiceConfigurationAnalyzer_CommonUsageTests = new(); | ||
|
|
||
| [Benchmark] | ||
| public Task WhenNoMediaElementOptions_ReportsNoDiagnostic() | ||
| { | ||
| return androidMediaElementServiceConfigurationAnalyzer_CommonUsageTests.Analyzer_WhenNoMediaElementOptions_ReportsNoDiagnostic(); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public Task WhenMethodInvokedWithTrue_ReportsDiagnostic() | ||
| { | ||
| return androidMediaElementServiceConfigurationAnalyzer_CommonUsageTests.Analyzer_WhenMethodInvokedWithTrue_ReportsDiagnostic(); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public Task WhenMultiplePropertiesSetToTrue_ReportsSingleDiagnostic() | ||
| { | ||
| return androidMediaElementServiceConfigurationAnalyzer_CommonUsageTests.Analyzer_WhenMultiplePropertiesSetToTrue_ReportsSingleDiagnostic(); | ||
| } | ||
| } |
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
217 changes: 217 additions & 0 deletions
217
...gurationAnalyzerTests/AndroidMediaElementServiceConfigurationAnalyzer_CommonUsageTests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| using CommunityToolkit.Maui.MediaElement.Analyzers; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.Testing; | ||
| using Xunit; | ||
|
|
||
| namespace CommunityToolkit.Maui.MediaElement.SourceGenerators.UnitTests.AndroidMediaElementServiceConfigurationAnalyzerTests; | ||
|
|
||
| public class AndroidMediaElementServiceConfigurationAnalyzer_CommonUsageTests : BaseAndroidMediaElementServiceConfigurationAnalyzerTest | ||
| { | ||
| [Fact] | ||
| public async Task Analyzer_WhenPropertySetToTrue_ReportsDiagnostic() | ||
| { | ||
| const string source = | ||
| /* language=C#-test */ | ||
| $$""" | ||
| using CommunityToolkit.Maui.Core; | ||
|
|
||
| namespace {{defaultTestNamespace}}; | ||
|
|
||
| public class MediaElementOptions | ||
| { | ||
| internal static bool {|#0:IsAndroidForegroundServiceEnabled|} { get; private set; } = true; | ||
| } | ||
| """; | ||
|
|
||
| var expectedDiagnostic = new DiagnosticResult(AndroidMediaElementServiceConfigurationAnalyzer.Rule) | ||
| .WithLocation(0) | ||
| .WithSeverity(DiagnosticSeverity.Error); | ||
|
|
||
| await VerifyAnalyzerAsync(source, expectedDiagnostic); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Analyzer_WhenMethodInvokedWithTrue_ReportsDiagnostic() | ||
| { | ||
| const string source = | ||
| /* language=C#-test */ | ||
| $$""" | ||
| using CommunityToolkit.Maui.Core; | ||
|
|
||
| namespace {{defaultTestNamespace}}; | ||
|
|
||
| public class MediaElementOptions | ||
| { | ||
| internal static bool IsAndroidForegroundServiceEnabled { get; private set; } = false; | ||
|
|
||
| public void SetIsAndroidForegroundServiceEnabled(bool isEnabled) | ||
| { | ||
| IsAndroidForegroundServiceEnabled = isEnabled; | ||
| } | ||
| } | ||
|
|
||
| public class TestConfiguration | ||
| { | ||
| public void Configure() | ||
| { | ||
| var options = new MediaElementOptions(); | ||
| options.SetIsAndroidForegroundServiceEnabled({|#0:true|}); | ||
| } | ||
| } | ||
| """; | ||
|
|
||
| var expectedDiagnostic = new DiagnosticResult(AndroidMediaElementServiceConfigurationAnalyzer.Rule) | ||
| .WithLocation(0) | ||
| .WithSeverity(DiagnosticSeverity.Error); | ||
|
|
||
| await VerifyAnalyzerAsync(source, expectedDiagnostic); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Analyzer_WhenPropertySetToFalse_ReportsNoDiagnostic() | ||
| { | ||
| const string source = | ||
| /* language=C#-test */ | ||
| $$""" | ||
| using CommunityToolkit.Maui.Core; | ||
|
|
||
| namespace {{defaultTestNamespace}}; | ||
|
|
||
| public class MediaElementOptions | ||
| { | ||
| internal static bool IsAndroidForegroundServiceEnabled { get; private set; } = false; | ||
| } | ||
| """; | ||
|
|
||
| await VerifyAnalyzerAsync(source); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Analyzer_WhenMethodInvokedWithFalse_ReportsNoDiagnostic() | ||
| { | ||
| const string source = | ||
| /* language=C#-test */ | ||
| $$""" | ||
| using CommunityToolkit.Maui.Core; | ||
|
|
||
| namespace {{defaultTestNamespace}}; | ||
|
|
||
| public class MediaElementOptions | ||
| { | ||
| internal static bool IsAndroidForegroundServiceEnabled { get; private set; } = false; | ||
|
|
||
| public void SetIsAndroidForegroundServiceEnabled(bool isEnabled) | ||
| { | ||
| IsAndroidForegroundServiceEnabled = isEnabled; | ||
| } | ||
| } | ||
|
|
||
| public class TestConfiguration | ||
| { | ||
| public void Configure() | ||
| { | ||
| var options = new MediaElementOptions(); | ||
| options.SetIsAndroidForegroundServiceEnabled(false); | ||
| } | ||
| } | ||
| """; | ||
|
|
||
| await VerifyAnalyzerAsync(source); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Analyzer_WhenNoMediaElementOptions_ReportsNoDiagnostic() | ||
| { | ||
| const string source = | ||
| /* language=C#-test */ | ||
| $$""" | ||
| using Microsoft.Maui.Controls; | ||
|
|
||
| namespace {{defaultTestNamespace}}; | ||
|
|
||
| public class {{defaultTestClassName}} : View | ||
| { | ||
| public string Text { get; set; } = ""; | ||
| } | ||
| """; | ||
|
|
||
| await VerifyAnalyzerAsync(source); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Analyzer_WhenPropertyHasNoInitializer_ReportsNoDiagnostic() | ||
| { | ||
| const string source = | ||
| /* language=C#-test */ | ||
| $$""" | ||
| using CommunityToolkit.Maui.Core; | ||
|
|
||
| namespace {{defaultTestNamespace}}; | ||
|
|
||
| public class MediaElementOptions | ||
| { | ||
| internal static bool IsAndroidForegroundServiceEnabled { get; private set; } | ||
| } | ||
| """; | ||
|
|
||
| await VerifyAnalyzerAsync(source); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Analyzer_WhenMethodInvokedWithVariable_ReportsNoDiagnostic() | ||
| { | ||
| const string source = | ||
| /* language=C#-test */ | ||
| $$""" | ||
| using CommunityToolkit.Maui.Core; | ||
|
|
||
| namespace {{defaultTestNamespace}}; | ||
|
|
||
| public class MediaElementOptions | ||
| { | ||
| internal static bool IsAndroidForegroundServiceEnabled { get; private set; } = false; | ||
|
|
||
| public void SetIsAndroidForegroundServiceEnabled(bool isEnabled) | ||
| { | ||
| IsAndroidForegroundServiceEnabled = isEnabled; | ||
| } | ||
| } | ||
|
|
||
| public class TestConfiguration | ||
| { | ||
| public void Configure() | ||
| { | ||
| var options = new MediaElementOptions(); | ||
| bool enableService = true; | ||
| options.SetIsAndroidForegroundServiceEnabled(enableService); | ||
| } | ||
| } | ||
| """; | ||
|
|
||
| await VerifyAnalyzerAsync(source); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Analyzer_WhenMultiplePropertiesSetToTrue_ReportsSingleDiagnostic() | ||
| { | ||
| const string source = | ||
| /* language=C#-test */ | ||
| $$""" | ||
| using CommunityToolkit.Maui.Core; | ||
|
|
||
| namespace {{defaultTestNamespace}}; | ||
|
|
||
| public class MediaElementOptions | ||
| { | ||
| internal static bool {|#0:IsAndroidForegroundServiceEnabled|} { get; private set; } = true; | ||
| internal static bool AnotherProperty { get; private set; } = true; | ||
| } | ||
| """; | ||
|
|
||
| var expectedDiagnostic = new DiagnosticResult(AndroidMediaElementServiceConfigurationAnalyzer.Rule) | ||
| .WithLocation(0) | ||
| .WithSeverity(DiagnosticSeverity.Error); | ||
|
|
||
| await VerifyAnalyzerAsync(source, expectedDiagnostic); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.