From e46ea03693d59e0eb1d762de62dfc2a4e369d0d4 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Thu, 25 Apr 2024 14:59:08 +0200 Subject: [PATCH] Garmin: calendar integration improvements use the protobuf fields described in the documentation[0] build the message according to the requested fields [0] https://gadgetbridge.org/internals/specifics/garmin-protocol/#calendarevent --- .../devices/garmin/ProtocolBufferHandler.java | 38 +++++++++++++------ .../gdi_calendar_service.proto | 25 ++++++++++-- 2 files changed, 49 insertions(+), 14 deletions(-) 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 b6e1e4ea8..0d8dc5922 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 @@ -3,7 +3,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin; import com.google.protobuf.InvalidProtocolBufferException; import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -157,16 +156,33 @@ public class ProtocolBufferHandler implements MessageHandler { LOG.debug("CalendarService Skipping event {} that is out of requested time range", mEvt.getTitle()); continue; } + if (!calendarServiceRequest.getIncludeAllDay() && mEvt.isAllDay()) { + LOG.debug("CalendarService Skipping event {} that is AllDay", mEvt.getTitle()); + continue; + } - watchEvents.add(GdiCalendarService.CalendarService.CalendarEvent.newBuilder() - .setTitle(mEvt.getTitle()) + if (watchEvents.size() >= calendarServiceRequest.getMaxEvents() * 2) { //NOTE: Tested with values higher than double of the reported max without issues + LOG.debug("Reached the maximum number of events supported by the watch"); + break; + } + + final GdiCalendarService.CalendarService.CalendarEvent.Builder event = GdiCalendarService.CalendarService.CalendarEvent.newBuilder() + .setTitle(mEvt.getTitle().substring(0, Math.min(mEvt.getTitle().length(), calendarServiceRequest.getMaxTitleLength()))) .setAllDay(mEvt.isAllDay()) - .setBegin(mEvt.getBeginSeconds()) - .setEnd(mEvt.getEndSeconds()) - .setLocation(StringUtils.defaultString(mEvt.getLocation())) - .setDescription(StringUtils.defaultString(mEvt.getDescription())) - .build() - ); + .setStartDate(mEvt.getBeginSeconds()) + .setEndDate(mEvt.getEndSeconds()); + + if (calendarServiceRequest.getIncludeLocation() && mEvt.getLocation() != null) { + event.setLocation(mEvt.getLocation().substring(0, Math.min(mEvt.getLocation().length(), calendarServiceRequest.getMaxLocationLength()))); + } + + if (calendarServiceRequest.getIncludeDescription() && mEvt.getDescription() != null) { + event.setDescription(mEvt.getDescription().substring(0, Math.min(mEvt.getDescription().length(), calendarServiceRequest.getMaxDescriptionLength()))); + } + if (calendarServiceRequest.getIncludeOrganizer() && mEvt.getOrganizer() != null) { + event.setDescription(mEvt.getOrganizer().substring(0, Math.min(mEvt.getOrganizer().length(), calendarServiceRequest.getMaxOrganizerLength()))); + } + watchEvents.add(event.build()); } LOG.debug("CalendarService Sending {} events to watch", watchEvents.size()); @@ -174,7 +190,7 @@ public class ProtocolBufferHandler implements MessageHandler { GdiCalendarService.CalendarService.newBuilder().setCalendarResponse( GdiCalendarService.CalendarService.CalendarServiceResponse.newBuilder() .addAllCalendarEvent(watchEvents) - .setUnknown(1) + .setStatus(GdiCalendarService.CalendarService.CalendarServiceResponse.ResponseStatus.OK) ) ).build(); } @@ -182,7 +198,7 @@ public class ProtocolBufferHandler implements MessageHandler { return GdiSmartProto.Smart.newBuilder().setCalendarService( GdiCalendarService.CalendarService.newBuilder().setCalendarResponse( GdiCalendarService.CalendarService.CalendarServiceResponse.newBuilder() - .setUnknown(0) + .setStatus(GdiCalendarService.CalendarService.CalendarServiceResponse.ResponseStatus.UNKNOWN_RESPONSE_STATUS) ) ).build(); } diff --git a/app/src/main/proto/garmin_vivomovehr/gdi_calendar_service.proto b/app/src/main/proto/garmin_vivomovehr/gdi_calendar_service.proto index ceeb01176..ac3ea2e12 100644 --- a/app/src/main/proto/garmin_vivomovehr/gdi_calendar_service.proto +++ b/app/src/main/proto/garmin_vivomovehr/gdi_calendar_service.proto @@ -11,19 +11,38 @@ message CalendarService { message CalendarServiceRequest { optional uint32 begin = 1; optional uint32 end = 2; + optional bool include_organizer = 3 [default = false]; + optional bool include_title = 4 [default = true]; + optional bool include_location = 5 [default = true]; + optional bool include_description = 6 [default = false]; + optional bool include_start_date = 7 [default = true]; + optional bool include_end_date = 8 [default = false]; + optional bool include_all_day = 9 [default = false]; + optional uint32 max_organizer_length = 10; + optional uint32 max_title_length = 11; + optional uint32 max_location_length = 12; + optional uint32 max_description_length = 13; + optional uint32 max_events = 14; } message CalendarServiceResponse { - optional uint32 unknown = 1; + enum ResponseStatus { + UNKNOWN_RESPONSE_STATUS = 0; + OK = 1; + INVALID_DATE_RANGE = 2; + } + optional ResponseStatus status = 1; repeated CalendarEvent calendar_event = 2; } message CalendarEvent { + optional string organizer = 1; optional string title = 2; optional string location = 3 [default = ""]; optional string description = 4 [default = ""]; - optional uint32 begin = 5; - optional uint32 end = 6; + optional uint32 start_date = 5; + optional uint32 end_date = 6; optional bool all_day = 7; + repeated uint32 reminder_time_in_secs = 8; } } \ No newline at end of file