1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-10-02 11:17:00 +02:00

Bangle.js: Add message size limitation to Calendar and Messages - stops huge data streams being sent out esp for calendar events

This commit is contained in:
Gordon Williams 2023-05-19 10:44:01 +01:00
parent 0debd26a37
commit 757e36ebd6

View File

@ -1039,6 +1039,13 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
return result; return result;
} }
/// Crop a text string to ensure it's not longer than requested
public String cropToLength(String txt, int len) {
if (txt==null) return "";
if (txt.length()<=len) return txt;
return txt.substring(0,len-3)+"...";
}
@Override @Override
public void onNotification(NotificationSpec notificationSpec) { public void onNotification(NotificationSpec notificationSpec) {
if (notificationSpec.attachedActions!=null) if (notificationSpec.attachedActions!=null)
@ -1052,10 +1059,10 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
o.put("t", "notify"); o.put("t", "notify");
o.put("id", notificationSpec.getId()); o.put("id", notificationSpec.getId());
o.put("src", notificationSpec.sourceName); o.put("src", notificationSpec.sourceName);
o.put("title", renderUnicodeAsImage(notificationSpec.title)); o.put("title", renderUnicodeAsImage(cropToLength(notificationSpec.title,80)));
o.put("subject", renderUnicodeAsImage(notificationSpec.subject)); o.put("subject", renderUnicodeAsImage(cropToLength(notificationSpec.subject,80)));
o.put("body", renderUnicodeAsImage(notificationSpec.body)); o.put("body", renderUnicodeAsImage(cropToLength(notificationSpec.body, 400)));
o.put("sender", renderUnicodeAsImage(notificationSpec.sender)); o.put("sender", renderUnicodeAsImage(cropToLength(notificationSpec.sender,40)));
o.put("tel", notificationSpec.phoneNumber); o.put("tel", notificationSpec.phoneNumber);
uartTxJSON("onNotification", o); uartTxJSON("onNotification", o);
} catch (JSONException e) { } catch (JSONException e) {
@ -1255,15 +1262,15 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
public void onAddCalendarEvent(CalendarEventSpec calendarEventSpec) { public void onAddCalendarEvent(CalendarEventSpec calendarEventSpec) {
try { try {
JSONObject o = new JSONObject(); JSONObject o = new JSONObject();
o.put("t", "calendar"); //TODO implement command o.put("t", "calendar");
o.put("id", calendarEventSpec.id); o.put("id", calendarEventSpec.id);
o.put("type", calendarEventSpec.type); //implement this too? (sunrise and set) o.put("type", calendarEventSpec.type); //implement this too? (sunrise and set)
o.put("timestamp", calendarEventSpec.timestamp); o.put("timestamp", calendarEventSpec.timestamp);
o.put("durationInSeconds", calendarEventSpec.durationInSeconds); o.put("durationInSeconds", calendarEventSpec.durationInSeconds);
o.put("title", renderUnicodeAsImage(calendarEventSpec.title)); o.put("title", renderUnicodeAsImage(cropToLength(calendarEventSpec.title,40)));
o.put("description", renderUnicodeAsImage(calendarEventSpec.description)); o.put("description", renderUnicodeAsImage(cropToLength(calendarEventSpec.description,200)));
o.put("location", renderUnicodeAsImage(calendarEventSpec.location)); o.put("location", renderUnicodeAsImage(cropToLength(calendarEventSpec.location,40)));
o.put("calName", calendarEventSpec.calName); o.put("calName", cropToLength(calendarEventSpec.calName,20));
o.put("color", calendarEventSpec.color); o.put("color", calendarEventSpec.color);
o.put("allDay", calendarEventSpec.allDay); o.put("allDay", calendarEventSpec.allDay);
uartTxJSON("onAddCalendarEvent", o); uartTxJSON("onAddCalendarEvent", o);