1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-18 16:09:30 +01:00

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
This commit is contained in:
Daniele Gobbetti 2024-04-25 14:59:08 +02:00
parent 1dec34afea
commit 7700154b16
2 changed files with 49 additions and 14 deletions

View File

@ -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();
}

View File

@ -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;
}
}