From bc9041a4c9bb21838ca07d8a83869aa2c659564c Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 2 Dec 2016 08:07:44 +0100 Subject: [PATCH] Pebble 2/LE: on connect wait 30s max and stop waiting immediately if a real PP connection got establish (ie write request on the gatt server) --- .../service/devices/pebble/ble/PebbleGATTServer.java | 3 +++ .../service/devices/pebble/ble/PebbleLESupport.java | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleGATTServer.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleGATTServer.java index a0136b4f..c818a956 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleGATTServer.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleGATTServer.java @@ -104,6 +104,9 @@ class PebbleGATTServer extends BluetoothGattServerCallback { return; } mPebbleLESupport.mIsConnected = true; + synchronized (mPebbleLESupport) { + mPebbleLESupport.notify(); + } LOG.info("write request: offset = " + offset + " value = " + GB.hexdump(value, 0, -1)); int header = value[0] & 0xff; int command = header & 7; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java index f896c340..fcc27415 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java @@ -36,9 +36,11 @@ public class PebbleLESupport { if (mPebbleGATTServer.initialize()) { mPebbleGATTClient = new PebbleGATTClient(this, context, mBtDevice); try { - Thread.sleep(6000); - if (mIsConnected) { - return; + synchronized (this) { + wait(30000); + if (mIsConnected) { + return; + } } } catch (InterruptedException ignored) { }