From b9999edf2a2634e0b4fb62c6526c60caa62718f9 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Mon, 29 Oct 2018 18:39:38 +0100 Subject: [PATCH] Ignore notifications that are older than the last forwarded one for the same source. This reuses the data structure populated to prevent overflow, but avoids to forward notifications that are older than the reference. --- .../externalevents/NotificationListener.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java index 0c03d5c15..89353f897 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -209,9 +209,12 @@ public class NotificationListener extends NotificationListenerService { String source = sbn.getPackageName().toLowerCase(); Notification notification = sbn.getNotification(); - if (notification.when < (sbn.getPostTime() - 1000)) { - LOG.info("NOT processing notification, too old. notification.when: " + notification.when + " post time: " + sbn.getPostTime() + " now: " + System.currentTimeMillis()); - return; + if (notificationTimes.containsKey(source)) { + long last_time = notificationTimes.get(source); + if (notification.when <= last_time) { + LOG.info("NOT processing notification, too old. notification.when: " + notification.when + " last notification for this source: " + last_time); + return; + } } NotificationSpec notificationSpec = new NotificationSpec(); notificationSpec.id = (int) sbn.getPostTime(); //FIXME: a truly unique id would be better