From 12bf3e43ca3b657f1795010083b18e72678c87a8 Mon Sep 17 00:00:00 2001 From: dakhnod Date: Sun, 20 Oct 2019 01:49:21 +0200 Subject: [PATCH] Fixed notification remove callback by looking up the original id --- .../externalevents/NotificationListener.java | 10 +++++----- .../freeyourgadget/gadgetbridge/util/LimitedQueue.java | 9 +++++++++ 2 files changed, 14 insertions(+), 5 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 d61b8bb0f..0befb6ec9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -629,6 +629,9 @@ public class NotificationListener extends NotificationListenerService { @Override public void onNotificationRemoved(StatusBarNotification sbn) { LOG.info("Notification removed: " + sbn.getPackageName()); + + int originalId = (int) mNotificationHandleLookup.lookupByValue(sbn.getPostTime()); + if (GBApplication.isRunningLollipopOrLater()) { LOG.info("Notification removed: " + sbn.getPackageName() + ", category: " + sbn.getNotification().category); if (Notification.CATEGORY_CALL.equals(sbn.getNotification().category) && activeCallPostTime == sbn.getPostTime()) { @@ -638,17 +641,14 @@ public class NotificationListener extends NotificationListenerService { GBApplication.deviceService().onSetCallState(callSpec); } } - // FIXME: DISABLED for now - /* if (shouldIgnore(sbn)) return; Prefs prefs = GBApplication.getPrefs(); - if (prefs.getBoolean("autoremove_notifications", false)) { + if (prefs.getBoolean("autoremove_notifications", true)) { LOG.info("notification removed, will ask device to delete it"); - GBApplication.deviceService().onDeleteNotification((int) sbn.getPostTime()); + GBApplication.deviceService().onDeleteNotification(originalId); } - */ } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LimitedQueue.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LimitedQueue.java index 1052532b1..e1250b57b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LimitedQueue.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LimitedQueue.java @@ -53,4 +53,13 @@ public class LimitedQueue { } return null; } + + synchronized public Object lookupByValue(Object value){ + for (Pair entry : list) { + if (value.equals(entry.second)) { + return entry.first; + } + } + return null; + } }