<NME> PlayTextNotificationRequest.java
<BEF> /*  Copyright (C) 2020-2021 Daniel Dakhno

    This file is part of Gadgetbridge.

    Gadgetbridge is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Gadgetbridge is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification;

import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;

public class PlayTextNotificationRequest extends PlayNotificationRequest {
    public PlayTextNotificationRequest(String packageName, String sender, String message, int messageId, FossilWatchAdapter adapter) {
        super(NotificationType.NOTIFICATION, 2, packageName, sender, message, messageId, adapter);
    }

    public PlayTextNotificationRequest(String packageName, FossilWatchAdapter adapter) {
        super(NotificationType.NOTIFICATION, 2, packageName, adapter);
    }
}

<MSG> Add support for native `Do Not Disturb` functionality on Fossil watches

<DFF> @@ -16,14 +16,15 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification;
 
+import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
 import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
 
 public class PlayTextNotificationRequest extends PlayNotificationRequest {
-    public PlayTextNotificationRequest(String packageName, String sender, String message, int messageId, FossilWatchAdapter adapter) {
-        super(NotificationType.NOTIFICATION, 2, packageName, sender, message, messageId, adapter);
+    public PlayTextNotificationRequest(String packageName, String sender, NotificationSpec notificationSpec, FossilWatchAdapter adapter) {
+        super(NotificationType.NOTIFICATION, 0x02 | notificationSpec.dndSuppressed, packageName, sender, notificationSpec.body, notificationSpec.getId(), adapter);
     }
 
     public PlayTextNotificationRequest(String packageName, FossilWatchAdapter adapter) {
-        super(NotificationType.NOTIFICATION, 2, packageName, adapter);
+        super(NotificationType.NOTIFICATION, 0x02, packageName, adapter);
     }
 }

{'commit': 'diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java\nindex 45c14acb7..3bab231c7 100644\n--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java\n+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java\n@@ -281,14 +281,19 @@ public class NotificationListener extends NotificationListenerService {\n \n         if (handleMediaSessionNotification(sbn)) return;\n \n+        int dndSuppressed = 0;\n+        if (GBApplication.isRunningLollipopOrLater() && rankingMap != null) {\n+            // Handle priority notifications for Do Not Disturb\n+            Ranking ranking = new Ranking();\n+            if (rankingMap.getRanking(sbn.getKey(), ranking)) {\n+                if (!ranking.matchesInterruptionFilter()) dndSuppressed = 1;\n+            }\n+        }\n+\n         Prefs prefs = GBApplication.getPrefs();\n         if (GBApplication.isRunningLollipopOrLater()) {\n-            if (prefs.getBoolean("notification_filter", false) && rankingMap != null) {\n-                // Handle priority notifications for Do Not Disturb\n-                Ranking ranking = new Ranking();\n-                if (rankingMap.getRanking(sbn.getKey(), ranking)) {\n-                    if (!ranking.matchesInterruptionFilter()) return;\n-                }\n+            if (prefs.getBoolean("notification_filter", false) && dndSuppressed == 1) {\n+                return;\n             }\n             if (NotificationCompat.CATEGORY_CALL.equals(sbn.getNotification().category)\n                     && prefs.getBoolean("notification_support_voip_calls", false)\n@@ -392,6 +397,7 @@ public class NotificationListener extends NotificationListenerService {\n         }\n \n         notificationSpec.attachedActions = new ArrayList<>();\n+        notificationSpec.dndSuppressed = dndSuppressed;\n \n         // DISMISS action\n         NotificationSpec.Action dismissAction = new NotificationSpec.Action();\ndiff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java\nindex fef80c875..9773147c9 100644\n--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java\n+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java\n@@ -155,7 +155,8 @@ public class GBDeviceService implements DeviceService {\n                 .putExtra(EXTRA_NOTIFICATION_SOURCENAME, notificationSpec.sourceName)\n                 .putExtra(EXTRA_NOTIFICATION_PEBBLE_COLOR, notificationSpec.pebbleColor)\n                 .putExtra(EXTRA_NOTIFICATION_SOURCEAPPID, notificationSpec.sourceAppId)\n-                .putExtra(EXTRA_NOTIFICATION_ICONID, notificationSpec.iconId);\n+                .putExtra(EXTRA_NOTIFICATION_ICONID, notificationSpec.iconId)\n+                .putExtra(EXTRA_NOTIFICATION_DNDSUPPRESSED, notificationSpec.dndSuppressed);\n         invokeService(intent);\n     }\n \ndiff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java\nindex fe36e40ca..95da94ec9 100644\n--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java\n+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java\n@@ -81,6 +81,7 @@ public interface DeviceService extends EventHandler {\n     String EXTRA_NOTIFICATION_ACTIONS = "notification_actions";\n     String EXTRA_NOTIFICATION_PEBBLE_COLOR = "notification_pebble_color";\n     String EXTRA_NOTIFICATION_ICONID = "notification_iconid";\n+    String EXTRA_NOTIFICATION_DNDSUPPRESSED = "notification_dndsuppressed";\n     String EXTRA_FIND_START = "find_start";\n     String EXTRA_VIBRATION_INTENSITY = "vibration_intensity";\n     String EXTRA_CALL_COMMAND = "call_command";\ndiff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationSpec.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationSpec.java\nindex fddaf6afd..6bfcf55dc 100644\n--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationSpec.java\n+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationSpec.java\n@@ -50,6 +50,8 @@ public class NotificationSpec {\n      */\n     public byte pebbleColor;\n \n+    public int dndSuppressed;\n+\n     public NotificationSpec() {\n         this.id = c.incrementAndGet();\n     }\ndiff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java\nindex d5494c081..c7e0f1013 100644\n--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java\n+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java\n@@ -157,6 +157,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUS\n import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_TRACKNR;\n import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_ACTIONS;\n import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_BODY;\n+import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_DNDSUPPRESSED;\n import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_FLAGS;\n import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_ICONID;\n import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_ID;\n@@ -413,6 +414,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere\n                 notificationSpec.flags = intent.getIntExtra(EXTRA_NOTIFICATION_FLAGS, 0);\n                 notificationSpec.sourceAppId = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCEAPPID);\n                 notificationSpec.iconId = intent.getIntExtra(EXTRA_NOTIFICATION_ICONID, 0);\n+                notificationSpec.dndSuppressed = intent.getIntExtra(EXTRA_NOTIFICATION_DNDSUPPRESSED, 0);\n \n                 if (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null) {\n                     GBApplication.getIDSenderLookup().add(notificationSpec.getId(), notificationSpec.phoneNumber);\ndiff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java\nindex 7a756713f..ee7dfedcb 100644\n--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java\n+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java\n@@ -1030,14 +1030,14 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {\n             for (NotificationHRConfiguration configuration : this.notificationConfigurations) {\n                 if (configuration.getPackageName().equals(sourceAppId)) {\n                     LOG.info("Package found in notificationConfigurations, using custom icon: " + sourceAppId);\n-                    queueWrite(new PlayTextNotificationRequest(sourceAppId, senderOrTitle, notificationSpec.body, notificationSpec.getId(), this));\n+                    queueWrite(new PlayTextNotificationRequest(sourceAppId, senderOrTitle, notificationSpec, this));\n                     packageFound = true;\n                 }\n             }\n \n             if(!packageFound) {\n                 LOG.info("Package not found in notificationConfigurations, using generic icon: " + sourceAppId);\n-                queueWrite(new PlayTextNotificationRequest("generic", senderOrTitle, notificationSpec.body, notificationSpec.getId(), this));\n+                queueWrite(new PlayTextNotificationRequest("generic", senderOrTitle, notificationSpec, this));\n             }\n         } catch (Exception e) {\n             LOG.error("Error while forwarding notification", e);\ndiff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/PlayTextNotificationRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/PlayTextNotificationRequest.java\nindex 80ae8cba7..c17b31eaf 100644\n--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/PlayTextNotificationRequest.java\n+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/PlayTextNotificationRequest.java\n@@ -16,14 +16,15 @@\n     along with this program.  If not, see <http://www.gnu.org/licenses/>. */\n package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification;\n \n+import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;\n import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;\n \n public class PlayTextNotificationRequest extends PlayNotificationRequest {\n-    public PlayTextNotificationRequest(String packageName, String sender, String message, int messageId, FossilWatchAdapter adapter) {\n-        super(NotificationType.NOTIFICATION, 2, packageName, sender, message, messageId, adapter);\n+    public PlayTextNotificationRequest(String packageName, String sender, NotificationSpec notificationSpec, FossilWatchAdapter adapter) {\n+        super(NotificationType.NOTIFICATION, 0x02 | notificationSpec.dndSuppressed, packageName, sender, notificationSpec.body, notificationSpec.getId(), adapter);\n     }\n \n     public PlayTextNotificationRequest(String packageName, FossilWatchAdapter adapter) {\n-        super(NotificationType.NOTIFICATION, 2, packageName, adapter);\n+        super(NotificationType.NOTIFICATION, 0x02, packageName, adapter);\n     }\n }\n', 'commit_subject': 'Add support for native `Do Not Disturb` functionality on Fossil watches', 'repo_name': 'Freeyourgadget/Gadgetbridge', 'committer': {'name': 'Gitea', 'email': '060b3b99f88e96085b4a68e095bc9e3d1d91e1bc@fake.local', 'time_sec': '1637684547', 'tz_offset': '60', 'date': {'seconds': '1637684547'}}, 'commit_tree': '6030d3fe84e8d89feabd09caab61605a6a345fef', 'commit_message': 'Add support for native `Do Not Disturb` functionality on Fossil watches\n', 'language_name': 'HTML', 'license': 'agpl-3.0', 'hunks': '@@ -16,14 +16,15 @@\n     along with this program.  If not, see <http://www.gnu.org/licenses/>. */\n package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification;\n \n+import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;\n import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;\n \n public class PlayTextNotificationRequest extends PlayNotificationRequest {\n-    public PlayTextNotificationRequest(String packageName, String sender, String message, int messageId, FossilWatchAdapter adapter) {\n-        super(NotificationType.NOTIFICATION, 2, packageName, sender, message, messageId, adapter);\n+    public PlayTextNotificationRequest(String packageName, String sender, NotificationSpec notificationSpec, FossilWatchAdapter adapter) {\n+        super(NotificationType.NOTIFICATION, 0x02 | notificationSpec.dndSuppressed, packageName, sender, notificationSpec.body, notificationSpec.getId(), adapter);\n     }\n \n     public PlayTextNotificationRequest(String packageName, FossilWatchAdapter adapter) {\n-        super(NotificationType.NOTIFICATION, 2, packageName, adapter);\n+        super(NotificationType.NOTIFICATION, 0x02, packageName, adapter);\n     }\n }\n', 'addition_count': 4, 'deletion_count': 3, 'src_file': 'a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/PlayTextNotificationRequest.java', 'tgt_file': 'b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/notification/PlayTextNotificationRequest.java', 'file_extension': '.java', 'before_file': '/*  Copyright (C) 2020-2021 Daniel Dakhno\n\n    This file is part of Gadgetbridge.\n\n    Gadgetbridge is free software: you can redistribute it and/or modify\n    it under the terms of the GNU Affero General Public License as published\n    by the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    Gadgetbridge is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU Affero General Public License for more details.\n\n    You should have received a copy of the GNU Affero General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>. */\npackage nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification;\n\nimport nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;\n\npublic class PlayTextNotificationRequest extends PlayNotificationRequest {\n    public PlayTextNotificationRequest(String packageName, String sender, String message, int messageId, FossilWatchAdapter adapter) {\n        super(NotificationType.NOTIFICATION, 2, packageName, sender, message, messageId, adapter);\n    }\n\n    public PlayTextNotificationRequest(String packageName, FossilWatchAdapter adapter) {\n        super(NotificationType.NOTIFICATION, 2, packageName, adapter);\n    }\n}\n', 'message': 'Add support for native `Do Not Disturb` functionality on Fossil watches\n', 'author_name': 'Gitea', 'lang': 'java'}