-
Notifications
You must be signed in to change notification settings - Fork 447
Open
Description
Hi
Has anyone encountered this issue where a connected BLE device, such as a heart rate monitor, cannot be fully disconnected when a GATT server is running? The BluetoothManager.getConnectionState() function still returns CONNECTED, even though DISCONNECTED is received in BluetoothGattCallback.onConnectionStateChange(). Is there any impact when calling server.cancelConnection(device) in BluetoothGattServerCallback.onConnectionStateChange() after receiving the DISCONNECTED status?
BleServerManager.java
public void onConnectionStateChange(@NonNull final BluetoothDevice device, final int status, final int newState) {
if (newState == BluetoothGatt.STATE_CONNECTED) {
log(Log.INFO, "[Server] " + device.getAddress() + " is now connected");
if (serverObserver != null)
serverObserver.onDeviceConnectedToServer(device);
} else if (newState == BluetoothGatt.STATE_DISCONNECTED) {
if (status == BluetoothGatt.GATT_SUCCESS) {
log(Log.INFO, "[Server] " + device.getAddress() + " is disconnected");
} else {
log(Log.WARN, "[Server] " + device.getAddress() + " has disconnected connected with status: " + status);
}
server.cancelConnection(device); // <- add this line
final BleManagerHandler handler = getRequestHandler(device);
if (handler != null && handler.bluetoothGatt == null) {
// There is no client connection to the device.
// We have to notify disconnection manually.
handler.notifyDeviceDisconnected(device, status);
}
if (serverObserver != null)
serverObserver.onDeviceDisconnectedFromServer(device);
}
}Metadata
Metadata
Assignees
Labels
No labels