From 7ffcc44378e9226955cc5582b76e3ac88e68768c Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 14 Nov 2017 22:28:54 +0100 Subject: [PATCH] Pebble: fix nasty crash when appmessage id is > 127 This is a regression since Gadgetbridge 0.22.0 Potentially fixes the following: - #868 - #876 - #884 NOTE: Java has no unisgned, java has no unsigned, java has no unsigned. Java has no unisgned, java has no unsigned, java has no unsigned. Java has no unisgned, java has no unsigned, java has no unsigned. --- .../gadgetbridge/service/devices/pebble/PebbleProtocol.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index 3a06615d8..e9d6a21dd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -1986,7 +1986,7 @@ public class PebbleProtocol extends GBDeviceProtocol { } } - idLookup[last_id] = ext_id; + idLookup[last_id & 0xff] = ext_id; return buf.array(); } @@ -2633,14 +2633,14 @@ public class PebbleProtocol extends GBDeviceProtocol { LOG.info("got APPLICATIONMESSAGE/LAUNCHER (EP " + endpoint + ") NACK"); } GBDeviceEventAppMessage evtAppMessage = null; - if (endpoint == ENDPOINT_APPLICATIONMESSAGE && idLookup[last_id] != null) { + if (endpoint == ENDPOINT_APPLICATIONMESSAGE && idLookup[last_id & 0xff] != null) { evtAppMessage = new GBDeviceEventAppMessage(); if (pebbleCmd == APPLICATIONMESSAGE_ACK) { evtAppMessage.type = GBDeviceEventAppMessage.TYPE_ACK; } else { evtAppMessage.type = GBDeviceEventAppMessage.TYPE_NACK; } - evtAppMessage.id = idLookup[last_id]; + evtAppMessage.id = idLookup[last_id & 0xff]; evtAppMessage.appUUID = currentRunningApp; } devEvts = new GBDeviceEvent[]{evtAppMessage};