1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-24 14:00:48 +02:00

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
This commit is contained in:
Andreas Shimokawa 2016-10-28 00:00:47 +02:00
parent d3571d53b2
commit bdf403210e

View File

@ -161,23 +161,22 @@ public class ExternalPebbleJSActivity extends GBActivity {
@JavascriptInterface @JavascriptInterface
public void sendAppMessage(String msg) { public void sendAppMessage(String msg) {
LOG.debug("from WEBVIEW: ", msg); LOG.debug("from WEBVIEW: " + msg);
JSONObject knownKeys = getAppConfigurationKeys(); JSONObject knownKeys = getAppConfigurationKeys();
try { try {
JSONObject in = new JSONObject(msg); JSONObject in = new JSONObject(msg);
JSONObject out = new JSONObject(); JSONObject out = new JSONObject();
String inKey, outKey; String inKey, outKey;
boolean passKey = false; boolean passKey;
for (Iterator<String> key = in.keys(); key.hasNext(); ) { for (Iterator<String> key = in.keys(); key.hasNext(); ) {
passKey = false; passKey = false;
inKey = key.next(); inKey = key.next();
outKey = null; outKey = null;
int pebbleAppIndex = knownKeys.optInt(inKey); int pebbleAppIndex = knownKeys.optInt(inKey, -1);
if (pebbleAppIndex != 0) { if (pebbleAppIndex != -1) {
passKey = true; passKey = true;
outKey = String.valueOf(pebbleAppIndex); outKey = String.valueOf(pebbleAppIndex);
} else { } else {
//do not discard integer keys (see https://developer.pebble.com/guides/communication/using-pebblekit-js/ ) //do not discard integer keys (see https://developer.pebble.com/guides/communication/using-pebblekit-js/ )
Scanner scanner = new Scanner(inKey); 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); Object obj = in.get(inKey);
if (obj instanceof Boolean) { if (obj instanceof Boolean) {
obj = ((Boolean) obj) ? "true" : "false"; obj = ((Boolean) obj) ? "true" : "false";