This should fix some connection problems #274

Some APIs have become synchronous, it seems, e.g.
connectGatt() -> onConnectionStateChanged() -> discoverServices() -> onServicesDiscovered()
appears to happen synchronously. So connectGatt() will not return before services are discovered!

So now we deal with this situation.
here
cpfeiffer 2016-05-26 19:03:38 +02:00
parent b0e0aec465
commit c360eb3392
2 changed files with 7 additions and 2 deletions

View File

@ -147,7 +147,6 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
}
private void gattServicesDiscovered(List<BluetoothGattService> discoveredGattServices) {
if (discoveredGattServices == null) {
return;
}
@ -180,7 +179,7 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
@Override
public void onServicesDiscovered(BluetoothGatt gatt) {
gattServicesDiscovered(getQueue().getSupportedGattServices());
gattServicesDiscovered(gatt.getServices());
initializeDevice(createTransactionBuilder("Initializing device")).queue(getQueue());
}

View File

@ -308,6 +308,12 @@ public final class BtLEQueue {
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
LOG.debug("connection state change, newState: " + newState + getStatusString(status));
synchronized (mGattMonitor) {
if (mBluetoothGatt == null) {
mBluetoothGatt = gatt;
}
}
if (!checkCorrectGattInstance(gatt, "connection state event")) {
return;
}