mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-29 03:55:49 +01:00
Lefun: Limit notification length further
In addition to the 255 pieces limit, the band also uses a byte for total message length, so cap that too to not run over previous message data.
This commit is contained in:
parent
2c1167b1b3
commit
31078647b1
@ -37,6 +37,7 @@ public class NotificationCommand extends BaseCommand {
|
||||
public static final byte EXTENDED_SERVICE_TYPE_KAKAOTALK = 6;
|
||||
|
||||
public static final int MAX_PAYLOAD_LENGTH = 13;
|
||||
public static final int MAX_MESSAGE_LENGTH = 254;
|
||||
|
||||
private byte serviceType;
|
||||
private byte totalPieces;
|
||||
|
@ -59,20 +59,23 @@ public abstract class AbstractSendNotificationRequest extends Request {
|
||||
.getCharacteristic(LefunConstants.UUID_CHARACTERISTIC_LEFUN_WRITE);
|
||||
|
||||
List<NotificationCommand> commandList = new ArrayList<>();
|
||||
int charsWritten = 0;
|
||||
for (int i = 0; i < 0xff; ++i) {
|
||||
NotificationCommand cmd = new NotificationCommand();
|
||||
cmd.setServiceType(notificationType);
|
||||
cmd.setExtendedServiceType(extendedNotificationType);
|
||||
cmd.setCurrentPiece((byte) (i + 1));
|
||||
|
||||
int maxPayloadLength = NotificationCommand.MAX_PAYLOAD_LENGTH;
|
||||
if (reserveSpaceForExtended) maxPayloadLength -= 1;
|
||||
maxPayloadLength = Math.min(maxPayloadLength, buffer.limit() - buffer.position());
|
||||
maxPayloadLength = Math.min(maxPayloadLength, NotificationCommand.MAX_MESSAGE_LENGTH - charsWritten);
|
||||
if (maxPayloadLength == 0 && i != 0) break;
|
||||
|
||||
byte[] payload = new byte[maxPayloadLength];
|
||||
buffer.get(payload);
|
||||
|
||||
NotificationCommand cmd = new NotificationCommand();
|
||||
cmd.setServiceType(notificationType);
|
||||
cmd.setExtendedServiceType(extendedNotificationType);
|
||||
cmd.setCurrentPiece((byte) (i + 1));
|
||||
cmd.setPayload(payload);
|
||||
charsWritten += maxPayloadLength;
|
||||
|
||||
commandList.add(cmd);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user