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.
This commit is contained in:
parent
b0e0aec465
commit
c360eb3392
|
@ -147,7 +147,6 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
|
||||||
}
|
}
|
||||||
|
|
||||||
private void gattServicesDiscovered(List<BluetoothGattService> discoveredGattServices) {
|
private void gattServicesDiscovered(List<BluetoothGattService> discoveredGattServices) {
|
||||||
|
|
||||||
if (discoveredGattServices == null) {
|
if (discoveredGattServices == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +179,7 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServicesDiscovered(BluetoothGatt gatt) {
|
public void onServicesDiscovered(BluetoothGatt gatt) {
|
||||||
gattServicesDiscovered(getQueue().getSupportedGattServices());
|
gattServicesDiscovered(gatt.getServices());
|
||||||
initializeDevice(createTransactionBuilder("Initializing device")).queue(getQueue());
|
initializeDevice(createTransactionBuilder("Initializing device")).queue(getQueue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -308,6 +308,12 @@ public final class BtLEQueue {
|
||||||
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
|
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
|
||||||
LOG.debug("connection state change, newState: " + newState + getStatusString(status));
|
LOG.debug("connection state change, newState: " + newState + getStatusString(status));
|
||||||
|
|
||||||
|
synchronized (mGattMonitor) {
|
||||||
|
if (mBluetoothGatt == null) {
|
||||||
|
mBluetoothGatt = gatt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!checkCorrectGattInstance(gatt, "connection state event")) {
|
if (!checkCorrectGattInstance(gatt, "connection state event")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue