1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-17 02:44:04 +02:00

Pebble: Proper fix for crash when no replies are set

Also:
- Support for multiple reply actions with canned replies (there must have been a crash before)
- When no replies are set use the firmware internal defaults

Fixes #1323
This commit is contained in:
Andreas Shimokawa 2018-11-08 08:36:37 +01:00
parent 8b3ba38344
commit 10b982f0ea

View File

@ -830,21 +830,26 @@ public class PebbleProtocol extends GBDeviceProtocol {
dismiss_action_id = 0x03; dismiss_action_id = 0x03;
actions_length += (short) (ACTION_LENGTH_MIN + dismiss_string.getBytes().length); actions_length += (short) (ACTION_LENGTH_MIN + dismiss_string.getBytes().length);
} }
if (attachedActions != null && attachedActions.size() > 0) {
for (Action act : attachedActions) {
actions_count++;
actions_length += (short) (ACTION_LENGTH_MIN + act.title.getBytes().length);
}
}
int replies_length = -1; int replies_length = 0;
if (cannedReplies != null && cannedReplies.length > 0) { if (cannedReplies != null && cannedReplies.length > 0) {
//do not increment actions_count! reply is an action and was already added above //do not increment actions_count! reply is an action and was already added above
for (String reply : cannedReplies) { for (String reply : cannedReplies) {
replies_length += reply.getBytes().length + 1; replies_length += reply.getBytes().length + 1;
} }
replies_length--;
//similarly, only the replies length has to be added, the length for the bare action was already added above //similarly, only the replies length has to be added, the length for the bare action was already added above
actions_length += (short) (replies_length + 3); // 3 = attribute id (byte) + length(short)
}
if (attachedActions != null && attachedActions.size() > 0) {
for (Action act : attachedActions) {
actions_count++;
actions_length += (short) (ACTION_LENGTH_MIN + act.title.getBytes().length);
if (act.isReply) {
actions_length += (short) replies_length + 3; // 3 = attribute id (byte) + length(short)
}
}
} }
byte attributes_count = 0; byte attributes_count = 0;
@ -969,21 +974,23 @@ public class PebbleProtocol extends GBDeviceProtocol {
buf.put((byte) 0x03); // reply action buf.put((byte) 0x03); // reply action
buf.put((byte) 0x02); // number attributes buf.put((byte) 0x02); // number attributes
} else { } else {
buf.put((byte) 0x02); // generic action, dismiss did not do anything buf.put((byte) 0x02); // generic action
buf.put((byte) 0x01); // number attributes buf.put((byte) 0x01); // number attributes
} }
buf.put((byte) 0x01); // attribute id (title) buf.put((byte) 0x01); // attribute id (title)
buf.putShort((short) act.title.getBytes().length); buf.putShort((short) act.title.getBytes().length);
buf.put(act.title.getBytes()); buf.put(act.title.getBytes());
if (act.isReply && cannedReplies != null && cannedReplies.length > 0) { if (act.isReply) {
buf.put((byte) 0x08); // canned replies buf.put((byte) 0x08); // canned replies
buf.putShort((short) replies_length); buf.putShort((short) replies_length);
for (int i = 0; i < cannedReplies.length - 1; i++) { if (cannedReplies != null && cannedReplies.length > 0) {
buf.put(cannedReplies[i].getBytes()); for (int i = 0; i < cannedReplies.length - 1; i++) {
buf.put((byte) 0x00); buf.put(cannedReplies[i].getBytes());
buf.put((byte) 0x00);
}
// last one must not be zero terminated, else we get an additional emply reply
buf.put(cannedReplies[cannedReplies.length - 1].getBytes());
} }
// last one must not be zero terminated, else we get an additional emply reply
buf.put(cannedReplies[cannedReplies.length - 1].getBytes());
} }
} }
} }