NordicSemiconductor / Android-BLE-Library

A library that makes working with Bluetooth LE on Android a pleasure. Seriously.
BSD 3-Clause "New" or "Revised" License
1.98k stars 413 forks source link

Provide access to cancelConnection so that a server can deny a client #551

Closed CyDragon80 closed 4 months ago

CyDragon80 commented 5 months ago

Stumbled across a situation where I want my server to block access to a client device but cannot find a way to disconnect it without first accepting it to build the managed connection. If there is a way I missed, please let me know. I can reflect into the library to get to cancelConnection for now but would be nice if there was legit access to it.

This is the basic scenario.

override fun onDeviceConnectedToServer(device: BluetoothDevice) {
    val address = device.address
    if (allowed(address)) {
        val newConnection = ...
        newConnection.useServer(this)
        newConnection.attachClientConnection(device)        
    } else {
        Log.d(TAG, "BLE connection blocked $address")
        cancelConnection(device)
    }
}
philips77 commented 4 months ago

LGTM