From f3f6f2b0e8a2bfdfecd4a973f46a568c09daa946 Mon Sep 17 00:00:00 2001 From: emawby Date: Tue, 3 Aug 2021 12:45:56 -0700 Subject: [PATCH] not firing willShowInForegroundHandler for restoring notifications --- .../java/com/onesignal/NotificationBundleProcessor.java | 2 +- .../onesignal/src/main/java/com/onesignal/OneSignal.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationBundleProcessor.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationBundleProcessor.java index 17878dcb86..2345c15f29 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationBundleProcessor.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationBundleProcessor.java @@ -146,7 +146,7 @@ private static int processJobForDisplay(OSNotificationController notificationCon if (doDisplay) { androidNotificationId = notificationJob.getAndroidId(); - if (fromBackgroundLogic && OneSignal.shouldFireForegroundHandlers()) { + if (fromBackgroundLogic && OneSignal.shouldFireForegroundHandlers(notificationJob)) { notificationController.setFromBackgroundLogic(false); OneSignal.fireForegroundHandlers(notificationController); // Notification will be processed by foreground user complete or timer complete diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java index 3019d7e216..9bf020dcaa 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java @@ -2299,7 +2299,7 @@ static void handleNotificationReceived(OSNotificationGenerationJob notificationJ *

* @see OSNotificationWillShowInForegroundHandler */ - static boolean shouldFireForegroundHandlers() { + static boolean shouldFireForegroundHandlers(OSNotificationGenerationJob notificationJob) { if (!isInForeground()) { OneSignal.onesignalLog(LOG_LEVEL.INFO, "App is in background, show notification"); return false; @@ -2310,6 +2310,12 @@ static boolean shouldFireForegroundHandlers() { return false; } + // Notification is restored. Don't fire for restored notifications. + if (notificationJob.isRestoring()) { + OneSignal.onesignalLog(LOG_LEVEL.INFO, "Not firing notificationWillShowInForegroundHandler for restored notifications"); + return false; + } + return true; }