From f29995b571a9d25205fd172c3497ef567b91bbbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Fri, 8 Dec 2023 11:29:20 +0000 Subject: [PATCH] Zepp OS: Allow disabling app notifications per device --- .../devicesettings/DeviceSettingsPreferenceConst.java | 1 + .../devices/huami/Huami2021Coordinator.java | 1 + .../zeppos/services/ZeppOsNotificationService.java | 11 +++++++++++ app/src/main/res/values/strings.xml | 2 ++ .../res/xml/devicesettings_send_app_notifications.xml | 9 +++++++++ 5 files changed, 24 insertions(+) create mode 100644 app/src/main/res/xml/devicesettings_send_app_notifications.xml diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java index 83ed34fbd..219477d8d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java @@ -232,6 +232,7 @@ public class DeviceSettingsPreferenceConst { public static final String PREF_CASIO_ALERT_SMS = "casio_alert_sms"; public static final String PREF_AUTOREMOVE_MESSAGE = "autoremove_message"; + public static final String PREF_SEND_APP_NOTIFICATIONS = "send_app_notifications"; public static final String PREF_AUTOREMOVE_NOTIFICATIONS = "autoremove_notifications"; public static final String PREF_SCREEN_ON_ON_NOTIFICATIONS = "screen_on_on_notifications"; public static final String PREF_WORKOUT_KEEP_SCREEN_ON = "workout_keep_screen_on"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java index 33e16abc6..11749462b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java @@ -398,6 +398,7 @@ public abstract class Huami2021Coordinator extends HuamiCoordinator { settings.add(R.xml.devicesettings_sound_and_vibration); 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); settings.add(R.xml.devicesettings_canned_reply_16); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/services/ZeppOsNotificationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/services/ZeppOsNotificationService.java index b0e55b83f..715d7f1dd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/services/ZeppOsNotificationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/services/ZeppOsNotificationService.java @@ -31,6 +31,7 @@ import java.nio.charset.StandardCharsets; import java.util.Locale; 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.model.CallSpec; @@ -215,6 +216,11 @@ public class ZeppOsNotificationService extends AbstractZeppOsService { } public void sendNotification(final NotificationSpec notificationSpec) { + if (!getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS, true)) { + LOG.debug("App notifications disabled - ignoring"); + return; + } + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final String senderOrTitle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title); @@ -289,6 +295,11 @@ public class ZeppOsNotificationService extends AbstractZeppOsService { } public void deleteNotification(final int id) { + if (!getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS, true)) { + LOG.debug("App notifications disabled - ignoring delete"); + return; + } + LOG.info("Deleting notification {} from band", id); final ByteBuffer buf = ByteBuffer.allocate(12); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aa93dd155..c43545adc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -348,6 +348,8 @@ Notifications are automatically removed from the device when dismissed from the phone Screen On on Notifications Turn on the band\'s screen when a notification arrives + Send notifications + Send app notifications to the device Privacy mode Normal notifications Shift the notification text off-screen diff --git a/app/src/main/res/xml/devicesettings_send_app_notifications.xml b/app/src/main/res/xml/devicesettings_send_app_notifications.xml new file mode 100644 index 000000000..e6b5dab84 --- /dev/null +++ b/app/src/main/res/xml/devicesettings_send_app_notifications.xml @@ -0,0 +1,9 @@ + + + +