From 7e1700250f34faf83def39736e470260d45ac475 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 19 Jun 2015 12:34:33 +0200 Subject: [PATCH] Pebble: add dev option to force latest notification protocol usage When enabled it forces to use 3.x notifications on FW 3.x (2.x notifcations on FW 2.x) When disabled 2.x notification on FW 2.x and 1.x notifications on FW 2.x are used (which is recommended) This allows Pebble Time users to do further tests. --- .../gadgetbridge/pebble/PebbleIoThread.java | 4 ++++ .../gadgetbridge/pebble/PebbleProtocol.java | 21 +++++++++++++++---- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values/strings.xml | 4 ++++ app/src/main/res/xml/preferences.xml | 13 ++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleIoThread.java index 1854e025b..a6dfa41eb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleIoThread.java @@ -115,6 +115,10 @@ public class PebbleIoThread extends GBDeviceIoThread { mBtSocket = null; return false; } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + mPebbleProtocol.setForceProtocol(sharedPrefs.getBoolean("pebble_force_protocol", false)); + gbDevice.setState(GBDevice.State.CONNECTED); gbDevice.sendDeviceUpdateIntent(getContext()); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java index 82b7da35f..be741c313 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java @@ -165,6 +165,8 @@ public class PebbleProtocol extends GBDeviceProtocol { private static Random mRandom = new Random(); boolean isFw3x = false; + boolean mForceProtocol = false; + byte last_id = -1; private ArrayList tmpUUIDS = new ArrayList<>(); @@ -221,13 +223,16 @@ public class PebbleProtocol extends GBDeviceProtocol { ts += (SimpleTimeZone.getDefault().getOffset(ts)); ts /= 1000; - if (isFw3x) { + if (isFw3x && mForceProtocol) { String[] parts = {from, null, body}; return encodeBlobdbNotification((int) (ts & 0xffffffff), parts); - } else { + } else if (!isFw3x && !mForceProtocol) { String[] parts = {from, body, ts.toString()}; return encodeMessage(ENDPOINT_NOTIFICATION, NOTIFICATION_SMS, 0, parts); } + + String[] parts = {from, null, body}; + return encodeExtensibleNotification(mRandom.nextInt(), (int) (ts & 0xffffffff), parts); } @Override @@ -236,13 +241,16 @@ public class PebbleProtocol extends GBDeviceProtocol { ts += (SimpleTimeZone.getDefault().getOffset(ts)); ts /= 1000; - if (isFw3x) { + if (isFw3x && mForceProtocol) { String[] parts = {from, subject, body}; return encodeBlobdbNotification((int) (ts & 0xffffffff), parts); - } else { + } else if (!isFw3x && !mForceProtocol) { String[] parts = {from, body, ts.toString(), subject}; return encodeMessage(ENDPOINT_NOTIFICATION, NOTIFICATION_EMAIL, 0, parts); } + + String[] parts = {from, subject, body}; + return encodeExtensibleNotification(mRandom.nextInt(), (int) (ts & 0xffffffff), parts); } @Override @@ -913,4 +921,9 @@ public class PebbleProtocol extends GBDeviceProtocol { return cmd; } + + public void setForceProtocol(boolean force) { + LOG.info("setting force protocol to " + force); + mForceProtocol = force; + } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 1b61f9669..947f8f5f5 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -93,4 +93,5 @@ Anzahl der Vibrationen Log-Dateien schreiben (Neustart erforderlich) Schlafmonitor + Pebble Einstellungen diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e9f52eaee..088b793c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -42,6 +42,10 @@ Developer Options Mi Band address + Pebble Settings + Force Notification Protocol + This option forces using the latest notification protocol depending on the firmware version. ENABLE ONLY IF YOU KNOW WHAT YOU ARE DOING! + not connected connecting diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 274e8744d..8123d0479 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -59,6 +59,19 @@ + + + + +