From 38e234552db86c6adf571de8f0072318c32376d6 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 13 Jan 2017 08:16:33 +0100 Subject: [PATCH] Pebble: only ACK appmessages from pebble to pebblekit android apps after the app actually sent one --- .../service/devices/pebble/PebbleIoThread.java | 14 ++++++-------- .../service/devices/pebble/PebbleProtocol.java | 8 ++++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java index 923ee95cc..83e269124 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java @@ -117,24 +117,22 @@ class PebbleIoThread extends GBDeviceIoThread { try { JSONArray jsonArray = new JSONArray(jsonString); write(mPebbleProtocol.encodeApplicationMessageFromJSON(uuid, jsonArray)); - sendAppMessageAck(transaction_id); - + if (transaction_id >= 0 && transaction_id <= 255) { + sendAppMessageAck(transaction_id); + } } catch (JSONException e) { e.printStackTrace(); } break; case PEBBLEKIT_ACTION_APP_ACK: - // we do not get a uuid and cannot map a transaction id to it, so we ack in PebbleProtocol early - /* - uuid = (UUID) intent.getSerializableExtra("uuid"); - int transaction_id = intent.getIntExtra("transaction_id", -1); + transaction_id = intent.getIntExtra("transaction_id", -1); if (transaction_id >= 0 && transaction_id <= 255) { - write(mPebbleProtocol.encodeApplicationMessageAck(uuid, (byte) transaction_id)); + write(mPebbleProtocol.encodeApplicationMessageAck(null, (byte) transaction_id)); } else { LOG.warn("illegal transacktion id " + transaction_id); } - */ break; + } } }; 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 eff90ef32..121cbb44c 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 @@ -1698,6 +1698,9 @@ public class PebbleProtocol extends GBDeviceProtocol { } byte[] encodeApplicationMessageAck(UUID uuid, byte id) { + if (uuid == null) { + uuid = currentRunningApp; + } ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + 18); // +ACK buf.order(ByteOrder.BIG_ENDIAN); @@ -1829,14 +1832,15 @@ public class PebbleProtocol extends GBDeviceProtocol { } // this is a hack we send an ack to the Pebble immediately because we cannot map the transaction_id from the intent back to a uuid yet + /* GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes(); sendBytesAck.encodedBytes = encodeApplicationMessageAck(uuid, last_id); - + */ GBDeviceEventAppMessage appMessage = new GBDeviceEventAppMessage(); appMessage.appUUID = uuid; appMessage.id = last_id & 0xff; appMessage.message = jsonArray.toString(); - return new GBDeviceEvent[]{appMessage, sendBytesAck}; + return new GBDeviceEvent[]{appMessage}; } byte[] encodeApplicationMessagePush(short endpoint, UUID uuid, ArrayList> pairs) {