From ee28ccd4fe37bc8190a0f0ac978999a60cbe022e Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 10 Feb 2017 23:06:34 +0100 Subject: [PATCH] Pebble: add a dev option to always and immediately ACK PebbleKit messages to the watch Might help #509 --- .../devices/pebble/PebbleIoThread.java | 1 + .../devices/pebble/PebbleKitSupport.java | 10 ++++++---- .../devices/pebble/PebbleProtocol.java | 19 +++++++++++++------ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/preferences.xml | 5 +++++ 5 files changed, 27 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 f4e6e31e9..35c1c2564 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 @@ -85,6 +85,7 @@ class PebbleIoThread extends GBDeviceIoThread { mBtAdapter = btAdapter; mPebbleSupport = pebbleSupport; mEnablePebblekit = prefs.getBoolean("pebble_enable_pebblekit", false); + mPebbleProtocol.setAlwaysACKPebbleKit(prefs.getBoolean("pebble_always_ack_pebblekit", false)); } private int readWithException(InputStream inputStream, byte[] buffer, int byteOffset, int byteCount) throws IOException { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleKitSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleKitSupport.java index 6d05dc8c2..2277d1ca2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleKitSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleKitSupport.java @@ -64,10 +64,12 @@ class PebbleKitSupport { break; case PEBBLEKIT_ACTION_APP_ACK: transaction_id = intent.getIntExtra("transaction_id", -1); - if (transaction_id >= 0 && transaction_id <= 255) { - mPebbleIoThread.write(mPebbleProtocol.encodeApplicationMessageAck(null, (byte) transaction_id)); - } else { - LOG.warn("illegal transaction id " + transaction_id); + if (!mPebbleProtocol.mAlwaysACKPebbleKit) { + if (transaction_id >= 0 && transaction_id <= 255) { + mPebbleIoThread.write(mPebbleProtocol.encodeApplicationMessageAck(null, (byte) transaction_id)); + } else { + LOG.warn("illegal transaction 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 772167a23..6d1e93c19 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 @@ -253,6 +253,7 @@ public class PebbleProtocol extends GBDeviceProtocol { private static final Random mRandom = new Random(); int mFwMajor = 3; + boolean mAlwaysACKPebbleKit = false; private boolean mForceProtocol = false; private GBDeviceEventScreenshot mDevEventScreenshot = null; private int mScreenshotRemaining = -1; @@ -1833,16 +1834,17 @@ public class PebbleProtocol extends GBDeviceProtocol { jsonArray.put(jsonObject); } - // 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); - */ + GBDeviceEventSendBytes sendBytesAck = null; + if (mAlwaysACKPebbleKit) { + // this is a hack we send an ack to the Pebble immediately because somebody said it helps some PebbleKit apps :P + 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}; + return new GBDeviceEvent[]{appMessage, sendBytesAck}; } byte[] encodeApplicationMessagePush(short endpoint, UUID uuid, ArrayList> pairs) { @@ -2584,6 +2586,11 @@ public class PebbleProtocol extends GBDeviceProtocol { mForceProtocol = force; } + void setAlwaysACKPebbleKit(boolean alwaysACKPebbleKit) { + LOG.info("setting always ACK Pebbleit to " + alwaysACKPebbleKit); + mAlwaysACKPebbleKit = alwaysACKPebbleKit; + } + private String getFixedString(ByteBuffer buf, int length) { byte[] tmp = new byte[length]; buf.get(tmp, 0, length); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 77484bacb..3bed06a37 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -149,6 +149,8 @@ If your Pebble 2/Pebble LE does not work as expected, try this setting to limit the MTU (valid range 20–512) Enable Watch App Logging Will cause logs from watch apps to be logged by Gadgetbridge (requires reconnect) + Prematurely ACK PebbleKit + Will cause messages that are sent to external 3rd party apps to be acknowledged always and immediately Reconnection Attempts diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index b44383c6b..d324fa3a1 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -386,6 +386,11 @@ android:key="pebble_enable_applogs" android:summary="@string/pref_summary_pebble_enable_applogs" android:title="@string/pref_title_pebble_enable_applogs" /> +