diff --git a/clevertap-core/src/main/java/com/clevertap/android/sdk/AnalyticsManager.java b/clevertap-core/src/main/java/com/clevertap/android/sdk/AnalyticsManager.java index 5b66da21d..7690674d2 100644 --- a/clevertap-core/src/main/java/com/clevertap/android/sdk/AnalyticsManager.java +++ b/clevertap-core/src/main/java/com/clevertap/android/sdk/AnalyticsManager.java @@ -60,11 +60,11 @@ public class AnalyticsManager extends BaseAnalyticsManager { private final InAppResponse inAppResponse; - private final HashMap notificationIdTagMap = new HashMap<>(); + private final HashMap notificationIdTagMap = new HashMap<>(); private final Object notificationMapLock = new Object(); - private final HashMap notificationViewedIdTagMap = new HashMap<>(); + private final HashMap notificationViewedIdTagMap = new HashMap<>(); AnalyticsManager(Context context, CleverTapInstanceConfig config, @@ -1163,18 +1163,41 @@ private void _pushMultiValue(ArrayList originalValues, String key, Strin } } - private boolean checkDuplicateNotificationIds(Bundle extras, HashMap notificationTagMap, - int interval) { + private boolean checkDuplicateNotificationIds( + Bundle extras, + HashMap notificationTagMap, + int interval + ) { synchronized (notificationMapLock) { // default to false; only return true if we are sure we've seen this one before boolean isDupe = false; try { - String notificationIdTag = extras.getString(Constants.NOTIFICATION_ID_TAG); + + // This flag is used so that we can release in phased manner, eventually the check has to go away. + Object doDedupeCheck = extras.get(Constants.WZRK_DEDUPE); + + boolean check = false; + if (doDedupeCheck != null) { + if (doDedupeCheck instanceof String) { + check = "true".equalsIgnoreCase((String) doDedupeCheck); + } + if (doDedupeCheck instanceof Boolean) { + check = (Boolean) doDedupeCheck; + } + } + + String notificationIdTag; + if (check) { + notificationIdTag = extras.getString(Constants.WZRK_PUSH_ID); + } else { + notificationIdTag = extras.getString(Constants.NOTIFICATION_ID_TAG); + } + long now = System.currentTimeMillis(); if (notificationTagMap.containsKey(notificationIdTag)) { long timestamp; // noinspection ConstantConditions - timestamp = (Long) notificationTagMap.get(notificationIdTag); + timestamp = notificationTagMap.get(notificationIdTag); // same notificationId within time internal treat as dupe if (now - timestamp < interval) { isDupe = true; diff --git a/clevertap-core/src/main/java/com/clevertap/android/sdk/Constants.java b/clevertap-core/src/main/java/com/clevertap/android/sdk/Constants.java index e33557d89..804610337 100644 --- a/clevertap-core/src/main/java/com/clevertap/android/sdk/Constants.java +++ b/clevertap-core/src/main/java/com/clevertap/android/sdk/Constants.java @@ -249,6 +249,7 @@ public interface Constants { String KEY_ENCRYPTION_LEVEL = "encryptionLevel"; String KEY_ENCRYPTION_FLAG_STATUS = "encryptionFlagStatus"; String WZRK_PUSH_ID = "wzrk_pid"; + String WZRK_DEDUPE = "wzrk_dd"; String WZRK_PUSH_SILENT = "wzrk_pn_s"; String EXTRAS_FROM = "extras_from"; String NOTIF_MSG = "nm";