Skip to content

Commit

Permalink
Add null checks, and improve swig error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
a-maurice committed Sep 3, 2024
1 parent c11a478 commit 851e2d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions messaging/src/FirebaseNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Firebase.Messaging {
/// implementation.
public sealed class AndroidNotificationParams {
internal static AndroidNotificationParams FromInternal(AndroidNotificationParamsInternal other) {
if (other == null) return null;

AndroidNotificationParams android = new AndroidNotificationParams();
android.ChannelId = other.channel_id;
return android;
Expand All @@ -45,6 +47,8 @@ public void Dispose(bool disposing) { }
/// library.
public sealed class FirebaseNotification {
internal static FirebaseNotification FromInternal(FirebaseNotificationInternal other) {
if (other == null) return null;

FirebaseNotification notification = new FirebaseNotification();
notification.Android = AndroidNotificationParams.FromInternal(other.android);
notification.Badge = other.badge;
Expand Down
6 changes: 5 additions & 1 deletion messaging/src/swig/messaging.i
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,22 @@ void SendPendingEvents() {
// messageReceivedDelegate.
[MonoPInvokeCallback(typeof(MessageReceivedDelegate))]
private static int MessageReceivedDelegateMethod(System.IntPtr message) {
int tookOwnership = 0;
return ExceptionAggregator.Wrap(() => {
// Use a local copy so another thread cannot unset this before we use it.
var handler = FirebaseMessagingInternal.MessageReceivedInternal;
if (handler != null) {
// Take ownership, and track it so that the caller of this knows, even
// if an exception is thrown, since the C# object will still delete it.
FirebaseMessageInternal messageInternal = new FirebaseMessageInternal(message, true);
tookOwnership = 1;
handler(null, new Firebase.Messaging.MessageReceivedEventArgs(
FirebaseMessage.FromInternal(messageInternal)));
messageInternal.Dispose();
return 1;
}
return 0;
}, 0);
}, tookOwnership);
}

// Called from ListenerImpl::TokenReceived() via the
Expand Down

0 comments on commit 851e2d5

Please sign in to comment.