From 5a9d1e23f5e31c2d6a25eb84c8b7b3352a4c48f9 Mon Sep 17 00:00:00 2001 From: t-m-w Date: Wed, 18 Nov 2020 12:55:03 -0800 Subject: [PATCH] Update Do Not Disturb support to allow priority notifications to break through. --- .../externalevents/NotificationListener.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 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 0d387cafd..d36a64fce 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -255,6 +255,11 @@ public class NotificationListener extends NotificationListenerService { @Override public void onNotificationPosted(StatusBarNotification sbn) { + onNotificationPosted(sbn, null); + } + + @Override + public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) { logNotification(sbn, true); notificationStack.remove(sbn.getPackageName()); @@ -269,17 +274,15 @@ public class NotificationListener extends NotificationListenerService { if (handleMediaSessionNotification(sbn)) return; - switch (GBApplication.getGrantedInterruptionFilter()) { - case NotificationManager.INTERRUPTION_FILTER_ALARMS: - case NotificationManager.INTERRUPTION_FILTER_NONE: - return; - case NotificationManager.INTERRUPTION_FILTER_PRIORITY: - // FIXME: Handle Reminders and Events if they are enabled in Do Not Disturb - return; - } - Prefs prefs = GBApplication.getPrefs(); if (GBApplication.isRunningLollipopOrLater()) { + if (prefs.getBoolean("notification_filter", false) && rankingMap != null) { + // Handle priority notifications for Do Not Disturb + Ranking ranking = new Ranking(); + if (rankingMap.getRanking(sbn.getKey(), ranking)) { + if (!ranking.matchesInterruptionFilter()) return; + } + } if (NotificationCompat.CATEGORY_CALL.equals(sbn.getNotification().category) && prefs.getBoolean("notification_support_voip_calls", false) && sbn.isOngoing()) {