Skip to content
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

Enable conditional opt out of automatically posting notifications to system tray #3492

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ public void onSendError(@NonNull String msgId, @NonNull Exception exception) {}
public void onNewToken(@NonNull String token) {}
;

/**
* Called when this service is evaluating whether a given RemoteMessage should use standard
* behavior when it has a notification payload - that is, automatically show a Notification in the
* system tray and do not invoke {@link onMessageReceived} when the app is backgrounded.
*
* <p>A subclass can override this to return false for specific classes of messages if it wishes
* to suppress the default system tray behavior and handle display itself via onMessageReceived.
*
* @param message The messge object that has been parsed from an incoming push payload.
* @return True if default behavior should be used; false if no system tray Notification should be
* displayed and onMessageReceived should be invoked while backgrounded.
*/
public boolean shouldUseDefaultNotificationBehavior(@NonNull RemoteMessage message) {
return true;
}

/** @hide */
@Override
protected Intent getStartCommandIntent(Intent originalIntent) {
Expand Down Expand Up @@ -212,7 +228,8 @@ private void dispatchMessage(Intent intent) {
// First remove any parameters that shouldn't be passed to the app
// * The wakelock ID set by the WakefulBroadcastReceiver
data.remove("androidx.content.wakelockid");
if (NotificationParams.isNotification(data)) {
RemoteMessage message = new RemoteMessage(data);
if (shouldUseDefaultNotificationBehavior(message) && NotificationParams.isNotification(data)) {
NotificationParams params = new NotificationParams(data);

ExecutorService executor = FcmExecutors.newNetworkIOExecutor();
Expand All @@ -232,7 +249,7 @@ private void dispatchMessage(Intent intent) {
MessagingAnalytics.logNotificationForeground(intent);
Copy link
Author

Choose a reason for hiding this comment

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

at the moment the change will bypass this MessagingAnalytics call, but I think that's probably okay?

if someone uses this new API to bypass default notification logic, the implication is that it should be treated identically to a standard data message (including for analytics)

}
}
onMessageReceived(new RemoteMessage(data));
onMessageReceived(message);
}

private boolean alreadyReceivedMessage(String messageId) {
Expand Down
Loading