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

Fossil Hybrid HR: Correctly truncate notification body when too long

The original truncation code caused the null termination of the string
to be dropped, leading to several weird issues on the watch, including
empty notification bodies and firmware crashes.
This commit is contained in:
Arjan Schrijver 2022-12-21 23:16:11 +01:00
parent 824d75ccc0
commit 82b3e0d963

View File

@ -61,11 +61,11 @@ public abstract class PlayNotificationRequest extends FilePutRequest {
byte[] titleBytes = nullTerminatedTitle.getBytes(charsetUTF8);
String nullTerminatedSender = StringUtils.terminateNull(sender);
byte[] senderBytes = nullTerminatedSender.getBytes(charsetUTF8);
if (message.length() > 475) {
message = message.substring(0, 475);
}
String nullTerminatedMessage = StringUtils.terminateNull(message);
byte[] messageBytes = nullTerminatedMessage.getBytes(charsetUTF8);
if (messageBytes.length > 490) {
messageBytes = Arrays.copyOf(messageBytes, 475);
}
short mainBufferLength = (short) (lengthBufferLength + uidLength + appBundleCRCLength + titleBytes.length + senderBytes.length + messageBytes.length);
ByteBuffer mainBuffer = ByteBuffer.allocate(mainBufferLength);