1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-29 12:05:53 +01:00

Huami: fix reminder message encoding

Potentially fixes #3548
This commit is contained in:
MrYoranimo 2024-02-05 18:28:14 +01:00 committed by José Rebelo
parent 78c10c3da9
commit 4edea1ed96

View File

@ -1083,8 +1083,9 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
return;
}
final ByteBuffer buf = ByteBuffer.allocate(14 + reminder.getMessage().getBytes().length);
buf.order(ByteOrder.LITTLE_ENDIAN);
final byte[] reminderMessage = StringUtils.truncate(reminder.getMessage(), coordinator.getMaximumReminderMessageLength())
.getBytes(StandardCharsets.UTF_8);
final ByteBuffer buf = ByteBuffer.allocate(14 + reminderMessage.length).order(ByteOrder.LITTLE_ENDIAN);
buf.put((byte) 0x0B);
buf.put((byte) (position & 0xFF));
@ -1119,16 +1120,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
buf.put(BLETypeConversions.shortCalendarToRawBytes(cal));
buf.put((byte) 0x00);
if (reminder.getMessage().getBytes().length > coordinator.getMaximumReminderMessageLength()) {
LOG.warn("The reminder message length {} is longer than {}, will be truncated",
reminder.getMessage().getBytes().length,
coordinator.getMaximumReminderMessageLength()
);
buf.put(Arrays.copyOf(reminder.getMessage().getBytes(), coordinator.getMaximumReminderMessageLength()));
} else {
buf.put(reminder.getMessage().getBytes());
}
buf.put(reminderMessage);
buf.put((byte) 0x00);
writeToChunked(builder, 2, buf.array());