mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02: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:
+1
-2
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user