Repository navigation
fix(messaging,android): ignore broadcasts that carry no message #18907
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
Open
Lyokone
wants to merge
2
commits into
main
Choose a base branch
from
fix/messaging-android-notification-dismiss
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
97 changes: 97 additions & 0 deletions
97
...test/java/io/flutter/plugins/firebase/messaging/FlutterFirebaseMessagingReceiverTest.java
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,97 @@ | ||
| // Copyright 2026, the Chromium project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| package io.flutter.plugins.firebase.messaging; | ||
|
|
||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertNull; | ||
|
|
||
| import android.content.Intent; | ||
| import android.os.Bundle; | ||
| import android.os.Parcelable; | ||
| import org.junit.Test; | ||
|
|
||
| public class FlutterFirebaseMessagingReceiverTest { | ||
| // The android.jar of unit tests keeps no extras, so this broadcast answers the reads the receiver | ||
| // makes itself: all its extras, the "wrapped_intent" one and the "message_type" one. | ||
| private static Intent broadcast( | ||
| final Bundle extras, final Parcelable wrappedIntent, final String messageType) { | ||
| return new Intent() { | ||
| @Override | ||
| public Bundle getExtras() { | ||
| return extras; | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings({"deprecation", "unchecked"}) | ||
| public <T extends Parcelable> T getParcelableExtra(String name) { | ||
| return "wrapped_intent".equals(name) ? (T) wrappedIntent : null; | ||
| } | ||
|
|
||
| @Override | ||
| public String getStringExtra(String name) { | ||
| return "message_type".equals(name) ? messageType : null; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private static Intent broadcast(Bundle extras, Parcelable wrappedIntent) { | ||
| return broadcast(extras, wrappedIntent, null); | ||
| } | ||
|
|
||
| private static Intent broadcastOfType(String messageType) { | ||
| return broadcast(new Bundle(), null, messageType); | ||
| } | ||
|
|
||
| @Test | ||
| public void readsTheMessageOfABroadcastWithExtras() { | ||
| assertNotNull( | ||
| FlutterFirebaseMessagingReceiver.remoteMessageFrom(broadcast(new Bundle(), null))); | ||
| } | ||
|
|
||
| @Test | ||
| public void ignoresABroadcastWrappingAnIntent() { | ||
| // What firebase-messaging's delete intent wraps when the user dismisses a notification. The | ||
| // android.jar of unit tests drops the action: any wrapped Intent is a notification event. | ||
| Intent dismissal = | ||
| broadcast(new Bundle(), new Intent("com.google.firebase.messaging.NOTIFICATION_DISMISS")); | ||
|
|
||
| assertNull(FlutterFirebaseMessagingReceiver.remoteMessageFrom(dismissal)); | ||
| } | ||
|
|
||
| @Test | ||
| public void ignoresABroadcastWithoutExtras() { | ||
| assertNull(FlutterFirebaseMessagingReceiver.remoteMessageFrom(broadcast(null, null))); | ||
| } | ||
|
|
||
| @Test | ||
| public void readsTheMessageWhenTheWrappedValueIsNotAnIntent() { | ||
| // CloudMessagingReceiver also reads only an Intent there as a notification event. | ||
| assertNotNull( | ||
| FlutterFirebaseMessagingReceiver.remoteMessageFrom(broadcast(new Bundle(), new Bundle()))); | ||
| } | ||
|
|
||
| @Test | ||
| public void readsTheMessageOfABroadcastOfTypeGcm() { | ||
| assertNotNull(FlutterFirebaseMessagingReceiver.remoteMessageFrom(broadcastOfType("gcm"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void ignoresADeletedMessagesBroadcast() { | ||
| // Like the broadcast FCM sends when it has deleted messages pending for the app. | ||
| assertNull( | ||
| FlutterFirebaseMessagingReceiver.remoteMessageFrom(broadcastOfType("deleted_messages"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void ignoresMessageTypesOtherThanGcm() { | ||
| // FirebaseMessagingService passes upstream message events to their own callbacks, and drops | ||
| // a type it does not know. | ||
| for (String messageType : new String[] {"send_event", "send_error", "unknown"}) { | ||
| assertNull( | ||
| messageType, | ||
| FlutterFirebaseMessagingReceiver.remoteMessageFrom(broadcastOfType(messageType))); | ||
| } | ||
| } | ||
| } |
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
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.