mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 10:05:49 +01:00
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) {
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user