From b608478adefc3d683f817ed59a83d667741249a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Mon, 23 Dec 2024 18:40:40 +0000 Subject: [PATCH] Garmin: Respect calendar sync setting --- .../devices/garmin/ProtocolBufferHandler.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/ProtocolBufferHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/ProtocolBufferHandler.java index 31a2bf3c2..8760371cf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/ProtocolBufferHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/ProtocolBufferHandler.java @@ -1,5 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SYNC_CALENDAR; + import android.content.Intent; import android.graphics.Bitmap; import android.location.Location; @@ -15,11 +17,13 @@ import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences; @@ -199,6 +203,20 @@ public class ProtocolBufferHandler implements MessageHandler { if (calendarService.hasCalendarRequest()) { GdiCalendarService.CalendarService.CalendarServiceRequest calendarServiceRequest = calendarService.getCalendarRequest(); + final boolean syncEnabled = GBApplication.getDeviceSpecificSharedPrefs(deviceSupport.getDevice().getAddress()) + .getBoolean(PREF_SYNC_CALENDAR, false); + + if (!syncEnabled) { + LOG.warn("Got calendar request, but calendar sync is disabled"); + return GdiSmartProto.Smart.newBuilder().setCalendarService( + GdiCalendarService.CalendarService.newBuilder().setCalendarResponse( + GdiCalendarService.CalendarService.CalendarServiceResponse.newBuilder() + .addAllCalendarEvent(Collections.emptyList()) + .setStatus(GdiCalendarService.CalendarService.CalendarServiceResponse.ResponseStatus.OK) + ) + ).build(); + } + CalendarManager upcomingEvents = new CalendarManager(deviceSupport.getContext(), deviceSupport.getDevice().getAddress()); List mEvents = upcomingEvents.getCalendarEventList(); List watchEvents = new ArrayList<>();