1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-30 16:56:22 +02:00

Pebble: fix some totaly obvious length calculation errors for actionable 3.x notifications

This commit is contained in:
Andreas Shimokawa 2015-07-21 21:55:00 +02:00
parent 3662f32dbf
commit 6c1e41b4ec

View File

@ -357,10 +357,11 @@ public class PebbleProtocol extends GBDeviceProtocol {
// Calculate length first // Calculate length first
final short BLOBDB_LENGTH = 23; final short BLOBDB_LENGTH = 23;
final short NOTIFICATION_PIN_LENGTH = 46; final short NOTIFICATION_PIN_LENGTH = 46;
final short ACTIONS_LENGTH = 17;
byte attributes_count = 0; byte attributes_count = 0;
int attributes_length = 0; short attributes_length = 0;
if (parts != null) { if (parts != null) {
for (String s : parts) { for (String s : parts) {
if (s == null || s.equals("")) { if (s == null || s.equals("")) {
@ -371,19 +372,21 @@ public class PebbleProtocol extends GBDeviceProtocol {
} }
} }
int length = BLOBDB_LENGTH + NOTIFICATION_PIN_LENGTH + attributes_length; short length = (short) (BLOBDB_LENGTH + NOTIFICATION_PIN_LENGTH + attributes_length);
short pin_length = (short) (NOTIFICATION_PIN_LENGTH + attributes_length);
byte actions_count = 0; byte actions_count = 0;
if (mForceProtocol) { if (mForceProtocol) {
actions_count = 1; actions_count = 1;
length += 13; // dismiss action length += ACTIONS_LENGTH; // dismiss action
pin_length += ACTIONS_LENGTH; // dismiss_action
} }
// Encode Prefix // Encode Prefix
ByteBuffer buf = ByteBuffer.allocate(length + LENGTH_PREFIX); ByteBuffer buf = ByteBuffer.allocate(length + LENGTH_PREFIX);
buf.order(ByteOrder.BIG_ENDIAN); buf.order(ByteOrder.BIG_ENDIAN);
buf.putShort((short) (length)); buf.putShort(length);
buf.putShort(ENDPOINT_BLOBDB); buf.putShort(ENDPOINT_BLOBDB);
buf.order(ByteOrder.LITTLE_ENDIAN); buf.order(ByteOrder.LITTLE_ENDIAN);
@ -396,7 +399,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
byte[] uuid_buf = new byte[16]; byte[] uuid_buf = new byte[16];
mRandom.nextBytes(uuid_buf); mRandom.nextBytes(uuid_buf);
buf.put(uuid_buf); // random UUID buf.put(uuid_buf); // random UUID
buf.putShort((short) (NOTIFICATION_PIN_LENGTH + attributes_length)); // length of the encapsulated data buf.putShort(pin_length); // length of the encapsulated data
// pin - 46 bytes // pin - 46 bytes
buf.put(uuid_buf); // random UUID buf.put(uuid_buf); // random UUID
@ -407,7 +410,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
buf.put((byte) 0x01); // type (0x01 = notification) buf.put((byte) 0x01); // type (0x01 = notification)
buf.putShort((short) 0x0010); // flags 0x0010 = read? buf.putShort((short) 0x0010); // flags 0x0010 = read?
buf.put((byte) 0x01); // layout (0x01 = default?) buf.put((byte) 0x01); // layout (0x01 = default?)
buf.putShort((short) attributes_length); // total length of all attributes in bytes buf.putShort(attributes_length); // total length of all attributes in bytes
buf.put(attributes_count); buf.put(attributes_count);
buf.put(actions_count); buf.put(actions_count);