From 8c8a74fcbfe861a683944b0f156a52b8b18852df Mon Sep 17 00:00:00 2001 From: Rickard Nord Date: Wed, 16 Nov 2022 16:52:26 +0100 Subject: [PATCH] fix: add 'Exported = false' to Service-attribute on PNMessagingService and Immutable flag to all pending intents --- .../DefaultPushNotificationHandler.android.cs | 8 ++++---- .../PNMessagingService.android.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Plugin.AzurePushNotification/DefaultPushNotificationHandler.android.cs b/src/Plugin.AzurePushNotification/DefaultPushNotificationHandler.android.cs index cffd1db..d1628f7 100644 --- a/src/Plugin.AzurePushNotification/DefaultPushNotificationHandler.android.cs +++ b/src/Plugin.AzurePushNotification/DefaultPushNotificationHandler.android.cs @@ -297,7 +297,7 @@ public virtual void OnReceived(IDictionary parameters) resultIntent.SetFlags(AzurePushNotificationManager.NotificationActivityFlags.Value); } int requestCode = new Java.Util.Random().NextInt(); - var pendingIntent = PendingIntent.GetActivity(context, requestCode, resultIntent,PendingIntentFlags.UpdateCurrent); + var pendingIntent = PendingIntent.GetActivity(context, requestCode, resultIntent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable); var chanId = AzurePushNotificationManager.DefaultNotificationChannelId; if (parameters.TryGetValue(ChannelIdKey, out object channelId) && channelId != null) @@ -318,7 +318,7 @@ public virtual void OnReceived(IDictionary parameters) notificationBuilder.SetLargeIcon(largeIconBitmap); } var deleteIntent = new Intent(context,typeof(PushNotificationDeletedReceiver)); - var pendingDeleteIntent = PendingIntent.GetBroadcast(context, requestCode, deleteIntent,PendingIntentFlags.CancelCurrent); + var pendingDeleteIntent = PendingIntent.GetBroadcast(context, requestCode, deleteIntent, PendingIntentFlags.CancelCurrent | PendingIntentFlags.Immutable); notificationBuilder.SetDeleteIntent(pendingDeleteIntent); if (Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.O) @@ -428,7 +428,7 @@ public virtual void OnReceived(IDictionary parameters) extras.PutString(ActionIdentifierKey, action.Id); actionIntent.PutExtras(extras); - pendingActionIntent = PendingIntent.GetActivity(context, aRequestCode, actionIntent, PendingIntentFlags.UpdateCurrent); + pendingActionIntent = PendingIntent.GetActivity(context, aRequestCode, actionIntent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable); } else @@ -436,7 +436,7 @@ public virtual void OnReceived(IDictionary parameters) actionIntent = new Intent(context, typeof(PushNotificationActionReceiver)); extras.PutString(ActionIdentifierKey, action.Id); actionIntent.PutExtras(extras); - pendingActionIntent = PendingIntent.GetBroadcast(context, aRequestCode, actionIntent, PendingIntentFlags.UpdateCurrent); + pendingActionIntent = PendingIntent.GetBroadcast(context, aRequestCode, actionIntent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable); } diff --git a/src/Plugin.AzurePushNotification/PNMessagingService.android.cs b/src/Plugin.AzurePushNotification/PNMessagingService.android.cs index b9145ae..383a570 100644 --- a/src/Plugin.AzurePushNotification/PNMessagingService.android.cs +++ b/src/Plugin.AzurePushNotification/PNMessagingService.android.cs @@ -2,13 +2,13 @@ using System.Linq; using Android.App; -using Android.Content; using Firebase.Messaging; namespace Plugin.AzurePushNotification { - [Service] + [Service(Exported = false)] [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })] + // ReSharper disable once InconsistentNaming public class PNMessagingService : FirebaseMessagingService { public override void OnMessageReceived(RemoteMessage message)