1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-28 18:49:56 +02:00

Stop LE scan before connecting to discovered device

See #278
This commit is contained in:
Erik Johansson
2018-06-14 21:56:52 +02:00
parent ffa25af1bc
commit a4a27d2f7e

View File

@@ -409,6 +409,7 @@ public abstract class BluetoothCommunication {
return;
}
synchronized (lock) {
stopLeScan();
connectGatt(device);
}
}
@@ -455,15 +456,20 @@ public abstract class BluetoothCommunication {
}
}
private void stopLeScan() {
if (leScanCallback != null) {
Timber.d("Stopping LE scan");
btAdapter.stopLeScan(leScanCallback);
leScanCallback = null;
}
}
/**
* Disconnect from a Bluetooth device
*/
public void disconnect(boolean doCleanup) {
synchronized (lock) {
if (leScanCallback != null) {
btAdapter.stopLeScan(leScanCallback);
leScanCallback = null;
}
stopLeScan();
if (bluetoothGatt == null) {
return;
@@ -563,10 +569,7 @@ public abstract class BluetoothCommunication {
if (newState == BluetoothProfile.STATE_CONNECTED) {
synchronized (lock) {
if (leScanCallback != null) {
btAdapter.stopLeScan(leScanCallback);
leScanCallback = null;
}
stopLeScan();
}
connectionEstablished = true;