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 2d01f8aa1..4363bb331 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -263,18 +263,24 @@ public class NotificationListener extends NotificationListenerService { logNotification(sbn, true); LOG.debug("notificationAppListIsBlackList: " + GBApplication.getPrefs().getString("notification_list_is_blacklist","true")); - notificationStack.remove(sbn.getPackageName()); notificationStack.add(sbn.getPackageName()); if (isServiceNotRunningAndShouldIgnoreNotifications()) return; + final Prefs prefs = GBApplication.getPrefs(); + final boolean mediaIgnoresAppList = prefs.getBoolean("notification_media_ignores_application_list", false); + + // If media notifications ignore app list, check them before + if (mediaIgnoresAppList && handleMediaSessionNotification(sbn)) return; + if (shouldIgnoreSource(sbn)) { LOG.debug("Ignoring notification source"); return; } - if (handleMediaSessionNotification(sbn)) return; + // If media notifications do NOT ignore app list, check them after + if (!mediaIgnoresAppList && handleMediaSessionNotification(sbn)) return; int dndSuppressed = 0; if (rankingMap != null) { @@ -285,7 +291,6 @@ public class NotificationListener extends NotificationListenerService { } } - Prefs prefs = GBApplication.getPrefs(); if (prefs.getBoolean("notification_filter", false) && dndSuppressed == 1) { return; } @@ -722,9 +727,17 @@ public class NotificationListener extends NotificationListenerService { notificationStack.remove(sbn.getPackageName()); if (isServiceNotRunningAndShouldIgnoreNotifications()) return; + + final Prefs prefs = GBApplication.getPrefs(); + final boolean mediaIgnoresAppList = prefs.getBoolean("notification_media_ignores_application_list", false); + + // If media notifications ignore app list, check them before + if (mediaIgnoresAppList && handleMediaSessionNotification(sbn)) return; + if (shouldIgnoreSource(sbn)) return; - if (handleMediaSessionNotification(sbn)) return; + // If media notifications do NOT ignore app list, check them after + if (!mediaIgnoresAppList && handleMediaSessionNotification(sbn)) return; if(Notification.CATEGORY_CALL.equals(sbn.getNotification().category) && activeCallPostTime == sbn.getPostTime()) { @@ -761,8 +774,8 @@ public class NotificationListener extends NotificationListenerService { // Send notification remove request to device List devices = GBApplication.app().getDeviceManager().getSelectedDevices(); for(GBDevice device : devices){ - Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(device.getAddress())); - if (prefs.getBoolean("autoremove_notifications", true)) { + Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(device.getAddress())); + if (devicePrefs.getBoolean("autoremove_notifications", true)) { for (int id : notificationsToRemove) { LOG.info("Notification " + id + " removed, will ask device to delete it"); GBApplication.deviceService().onDeleteNotification(id); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b90979b7c..4246016cc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -223,6 +223,8 @@ If available, send the long notification text to the device Do Not Disturb Block all notifications when Do Not Disturb is enabled on the phone + Media notifications ignore app list + Process media notifications before the app list. If this preference is unchecked, media applications need to be allowed in the application list for media controls to work on the device. Per application settings Use the Applications list to… Deny notifications from selected apps diff --git a/app/src/main/res/xml/notifications_preferences.xml b/app/src/main/res/xml/notifications_preferences.xml index 92f805745..e5217c9c7 100644 --- a/app/src/main/res/xml/notifications_preferences.xml +++ b/app/src/main/res/xml/notifications_preferences.xml @@ -104,6 +104,12 @@ android:key="notification_list_is_blacklist" android:summary="%s" android:title="@string/pref_title_notification_use_as" /> +