-
Notifications
You must be signed in to change notification settings - Fork 410
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
Fix crash when multiple Android Service are active #2418
base: main
Are you sure you want to change the base?
Conversation
@@ -18,15 +18,20 @@ | |||
namespace CommunityToolkit.Maui.Media.Services; | |||
|
|||
[SupportedOSPlatform("Android26.0")] | |||
[Service(Exported = false, Enabled = true, Name = "communityToolkit.maui.media.services", ForegroundServiceType = ForegroundService.TypeMediaPlayback)] | |||
[Service(Exported = false, Enabled = true, Name = "CommunityToolkit.Maui.Media.Services", ForegroundServiceType = ForegroundService.TypeMediaPlayback)] |
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.
Changing the case to uppercase will break older API's compatibility and prevent app from running on Android 23 or below. We only support android 26+ now on media element but I do want to point out this would break some current apps. Also changing this here requires changing the string in the manifest to match which has not been done.
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.
I really have no strong opinion on what naming convention should be done for android-net, but in native Android, it's package.name.ServiceName
but it can be addressed relatively in AndroidManifest.xml as .ServiceName
. Maybe we should follow that? I think it is still early for this library to think about the naming convention before the inconsistency spreads out even more, but if you think this is the convention we should follow moving forward, I'm happy to revert it.
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.
Thanks for your PR, but I can't see what I should review. Where's the actual fix for the issue?
Can you also revert all code style changes that you made and follow ours?
public const string ActionPlay = "MediaAction.play"; | ||
public const string ActionPause = "MediaAction.pause"; | ||
public const string ActionUpdateUI = "CommunityToolkit.Maui.Services.action.UPDATE_UI"; | ||
public const string ActionUpdatePlayer = "CommunityToolkit.Maui.Services.action.UPDATE_PLAYER"; | ||
public const string ActionRewind = "MediaAction.rewind"; | ||
public const string ActionFastForward = "MediaAction.fastForward"; |
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.
Why did you change the pattern? Can you revert and follow our pattern
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.
Isn't PascalCasing the standard convention in C# to name consts?
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.
@pictos I've left some comments on some of my code changes.
{ | ||
notification.AddAction(actionPlay); | ||
} | ||
notification.AddAction(actionNext); | ||
notification.Build(); |
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.
This is an immutable operation. It basically does nothing so I think it's better to remove it.
public const string ActionRewind = "MediaAction.rewind"; | ||
public const string ActionFastForward = "MediaAction.fastForward"; | ||
|
||
public const string NotificationChannelId = "Maui.MediaElement"; |
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.
I have introduced a constant to easily spot the notification ID of this control. I think it's important to keep track of notification ID as we introduce more foreground Android services since the same notification ID could not co-exist in the same Android application. I also think it's important to name them appropriately instead of just "1" as what was previously implemented.
public const string ActionFastForward = "MediaAction.fastForward"; | ||
|
||
public const string NotificationChannelId = "Maui.MediaElement"; | ||
public const string NotificationChannelName = "Transport Controls"; |
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.
I have also introduced a const for channel name so we can easily track it. This is a user facing text so I think it's better to name it appropriately instead of just "notification". I am not sure about the exact text to put but I think title casing is the norm.
public const string NotificationChannelId = "Maui.MediaElement"; | ||
public const string NotificationChannelName = "Transport Controls"; | ||
|
||
public const int NotificationId = 2024; |
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.
2024 I think is unique enough not to clash with other foreground service ID.
@@ -112,20 +117,15 @@ async ValueTask InitializeNotification(MediaSessionCompat mediaSession, Intent m | |||
var style = new AndroidX.Media.App.NotificationCompat.MediaStyle(); | |||
style.SetMediaSession(token); | |||
|
|||
if (Build.VERSION.SdkInt >= BuildVersionCodes.S) | |||
{ | |||
style.SetShowActionsInCompactView(0, 1, 2, 3); |
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.
I think this operation must be called after setting actions to the notification object, but it's empty at this point and it's the main reason for crash issues reported here. I have also tried including this after the notification action has been set but it just completely hides the buttons in the notification when I tested it so I think it's better to remove this until we have a better reason to keep it and have it implement properly.
Description of Change
Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information