From 6479cc3bb0a2283bfbaaf41290da51d27b5200f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Fri, 8 Dec 2023 11:39:53 +0000 Subject: [PATCH] Xiaomi: Allow disabling app notifications per device --- .../devices/xiaomi/XiaomiCoordinator.java | 1 + .../xiaomi/services/XiaomiNotificationService.java | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiCoordinator.java index ec5413ed1..a31a237ee 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiCoordinator.java @@ -390,6 +390,7 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator { settings.add(R.xml.devicesettings_display_caller); settings.add(R.xml.devicesettings_vibrationpatterns); settings.add(R.xml.devicesettings_donotdisturb_withauto_and_always); + settings.add(R.xml.devicesettings_send_app_notifications); settings.add(R.xml.devicesettings_screen_on_on_notifications); settings.add(R.xml.devicesettings_autoremove_notifications); if (getCannedRepliesSlotCount(device) > 0) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiNotificationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiNotificationService.java index 91da93302..a2da9e080 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiNotificationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiNotificationService.java @@ -35,6 +35,7 @@ import java.util.Locale; import java.util.Queue; import nodomain.freeyourgadget.gadgetbridge.BuildConfig; +import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventNotificationControl; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences; @@ -117,6 +118,11 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements } public void onNotification(final NotificationSpec notificationSpec) { + if (!getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS, true)) { + LOG.debug("App notifications disabled - ignoring"); + return; + } + final XiaomiProto.Notification3.Builder notification3 = XiaomiProto.Notification3.newBuilder() .setId(notificationSpec.getId()) .setUnknown4("") // ? @@ -175,6 +181,11 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements } public void onDeleteNotification(final int id) { + if (!getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS, true)) { + LOG.debug("App notifications disabled - ignoring delete"); + return; + } + // TODO }