Skip to content

Commit

Permalink
fix(messaging, android): repair crash handling remote notifications
Browse files Browse the repository at this point in the history
WritableNativeMap has a check to see if it is consumed or not when it is used,
to prevent resolving a Promise in native code then attempting to modify it.

We may use the same WritableNativeMap object twice though when handling deferred
initial notifications. Crash repair is to store a copy so the Maps are distinct
  • Loading branch information
mikehardy committed Apr 29, 2021
1 parent b972cb6 commit 6a30d4b
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void getInitialNotification(Promise promise) {
} else {
remoteMessageMap = ReactNativeFirebaseMessagingSerializer.remoteMessageToWritableMap(remoteMessage);
}
if (remoteMessageMap != null){
if (remoteMessageMap != null) {
promise.resolve(remoteMessageMap);
initialNotificationMap.put(messageId, true);
return;
Expand Down Expand Up @@ -228,9 +228,10 @@ public void onNewIntent(Intent intent) {
} else {
remoteMessageMap = ReactNativeFirebaseMessagingSerializer.remoteMessageToWritableMap(remoteMessage);
}

if (remoteMessageMap != null){
initialNotification = remoteMessageMap;

if (remoteMessageMap != null) {
// WritableNativeMap not be consumed twice. But it is resolved in future and in event below. Make a copy - issue #5231
initialNotification = remoteMessageMap.copy();
ReactNativeFirebaseMessagingReceiver.notifications.remove(messageId);

ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
Expand Down

1 comment on commit 6a30d4b

@vercel
Copy link

@vercel vercel bot commented on 6a30d4b Apr 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.