diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java index 63c1facf9..36948f70c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java @@ -104,7 +104,7 @@ public class BluetoothCommunicationService extends Service { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); sharedPrefs.edit().putString("last_device_address", btDeviceAddress).commit(); - if (btDeviceAddress != null && !isConnected()) { + if (btDeviceAddress != null && !isConnected() && !isConnecting()) { // currently only one thread allowed if (mGBDeviceIoThread != null) { mGBDeviceIoThread.quit(); @@ -201,6 +201,10 @@ public class BluetoothCommunicationService extends Service { return mGBDevice != null && mGBDevice.getState() == State.CONNECTED; } + private boolean isConnecting() { + return mGBDevice != null && mGBDevice.getState() == State.CONNECTING; + } + @Override public void onDestroy() { super.onDestroy(); 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 77dece7d3..8a769ae86 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleIoThread.java @@ -80,6 +80,7 @@ public class PebbleIoThread extends GBDeviceIoThread { protected boolean connect(String btDeviceAddress) { BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(btDeviceAddress); ParcelUuid uuids[] = btDevice.getUuids(); + GBDevice.State originalState = gbDevice.getState(); try { mBtSocket = btDevice.createRfcommSocketToServiceRecord(uuids[0].getUuid()); mBtSocket.connect(); @@ -87,7 +88,7 @@ public class PebbleIoThread extends GBDeviceIoThread { mmOutStream = mBtSocket.getOutputStream(); } catch (IOException e) { e.printStackTrace(); - gbDevice.setState(GBDevice.State.NOT_CONNECTED); + gbDevice.setState(originalState); mmInStream = null; mmOutStream = null; mBtSocket = null;