From bdf403210ec82180435c950906e8de369dc586da Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 28 Oct 2016 00:00:47 +0200 Subject: [PATCH 1/3] Pebble: Fix configuration of certain pebble apps for appkeys with index 0 it was assumed they were not found becaus JSONObject.getOpt() returns 0 if not found. Use the getOpt() method variant with a fallback parameter instead and set that to -1 fixes the problem. (Also fixes a missing debug output) Fixes #419 --- .../activities/ExternalPebbleJSActivity.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java index ed9ed508..44d5d93a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java @@ -161,23 +161,22 @@ public class ExternalPebbleJSActivity extends GBActivity { @JavascriptInterface public void sendAppMessage(String msg) { - LOG.debug("from WEBVIEW: ", msg); + LOG.debug("from WEBVIEW: " + msg); JSONObject knownKeys = getAppConfigurationKeys(); try { JSONObject in = new JSONObject(msg); JSONObject out = new JSONObject(); String inKey, outKey; - boolean passKey = false; + boolean passKey; for (Iterator key = in.keys(); key.hasNext(); ) { passKey = false; inKey = key.next(); outKey = null; - int pebbleAppIndex = knownKeys.optInt(inKey); - if (pebbleAppIndex != 0) { + int pebbleAppIndex = knownKeys.optInt(inKey, -1); + if (pebbleAppIndex != -1) { passKey = true; outKey = String.valueOf(pebbleAppIndex); - } else { //do not discard integer keys (see https://developer.pebble.com/guides/communication/using-pebblekit-js/ ) Scanner scanner = new Scanner(inKey); @@ -187,7 +186,7 @@ public class ExternalPebbleJSActivity extends GBActivity { } } - if (passKey && outKey != null) { + if (passKey) { Object obj = in.get(inKey); if (obj instanceof Boolean) { obj = ((Boolean) obj) ? "true" : "false"; From d6b9e6d64b9c60e23c1b5ed093d65f5a9046f1a4 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 28 Oct 2016 00:32:45 +0200 Subject: [PATCH 2/3] Pebble: Support sending byte arrays from app configuration data Also add debug output if trying to encode unknown classes in PebbleProtocol (Fixes #421) --- .../service/devices/pebble/PebbleProtocol.java | 3 +++ .../service/devices/pebble/PebbleSupport.java | 9 +++++++++ 2 files changed, 12 insertions(+) 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 a2a7e73f..57c58b70 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 @@ -1645,6 +1645,9 @@ public class PebbleProtocol extends GBDeviceProtocol { } else if (pair.second instanceof byte[]) { length += ((byte[]) pair.second).length; } + else { + LOG.warn("unknown type: " + pair.second.getClass().toString()); + } } ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java index a6beb9ff..dcf14ada 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java @@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble; import android.net.Uri; import android.util.Pair; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -59,6 +60,14 @@ public class PebbleSupport extends AbstractSerialDeviceSupport { while (keysIterator.hasNext()) { String keyStr = keysIterator.next(); Object object = json.get(keyStr); + if (object instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) object; + byte[] byteArray = new byte[jsonArray.length()]; + for (int i = 0; i < jsonArray.length(); i++) { + byteArray[i] = ((Integer) jsonArray.get(i)).byteValue(); + } + object = byteArray; + } pairs.add(new Pair<>(Integer.parseInt(keyStr), object)); } getDeviceIOThread().write(((PebbleProtocol) getDeviceProtocol()).encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, uuid, pairs)); From 9a41d4d7a2dd1cf70e85789084b66290750ae205 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 28 Oct 2016 00:51:29 +0200 Subject: [PATCH 3/3] bump version, update changelog --- CHANGELOG.md | 5 +++++ app/build.gradle | 4 ++-- app/src/main/res/xml/changelog_master.xml | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6719b89..85bd2d5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ###Changelog +####Version 0.13.7 +* Pebble: Fix configuration of certain pebble apps (eg. QR Generator, Squared 4.0) +* Mi Band: allow to delete Mi Band address from development settings +* Mi Band 2: Some initial hacky support for hr readings (Debug activity only) + ####Version 0.13.6 * Mi Band 2: Support for multiple alarms (3 at the moment) * Mi Band 2: Fix for alarms not working when just one is enabled diff --git a/app/build.gradle b/app/build.gradle index 824a9efb..cddd9398 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,8 +26,8 @@ android { targetSdkVersion 23 // note: always bump BOTH versionCode and versionName! - versionName "0.13.6" - versionCode 68 + versionName "0.13.7" + versionCode 69 } buildTypes { release { diff --git a/app/src/main/res/xml/changelog_master.xml b/app/src/main/res/xml/changelog_master.xml index 6459f604..f778baba 100644 --- a/app/src/main/res/xml/changelog_master.xml +++ b/app/src/main/res/xml/changelog_master.xml @@ -1,5 +1,10 @@ + + Pebble: Fix configuration of certain pebble apps (eg. QR Generator, Squared 4.0) + Mi Band: allow to delete Mi Band address from development settings + Mi Band 2: Some initial hacky support for hr readings (Debug activity only) + Mi Band 2: Support multiple alarms (3 at the moment) Mi Band 2: Fix for alarms not working when just one is enabled