From 8131257750cec18d3bea36758fec10c54b239ae8 Mon Sep 17 00:00:00 2001 From: CyDragon80 Date: Sun, 31 Mar 2024 09:32:35 -0500 Subject: [PATCH] Provide access to cancelConnection so that a server can deny a device connection without creating a managed connection just to disconnect it --- .../main/java/no/nordicsemi/android/ble/BleServerManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ble/src/main/java/no/nordicsemi/android/ble/BleServerManager.java b/ble/src/main/java/no/nordicsemi/android/ble/BleServerManager.java index 6a533171..70692ba3 100644 --- a/ble/src/main/java/no/nordicsemi/android/ble/BleServerManager.java +++ b/ble/src/main/java/no/nordicsemi/android/ble/BleServerManager.java @@ -182,9 +182,11 @@ final void useConnection(@NonNull final BluetoothDevice device, final boolean au *

* As we're not calling {@link BluetoothGattServer#connect(BluetoothDevice, boolean)}, cancelling * the connection should not be required. On the other hand, perhaps we should call connect(..). + * Can also be called in onDeviceConnectedToServer to refuse a device connection without accepting it first. + * If you already have a managed connection and want to disconnect, you can use the disconnect request on the connection. * @param device The device to cancel connection to. */ - final void cancelConnection(@NonNull final BluetoothDevice device) { + protected final void cancelConnection(@NonNull final BluetoothDevice device) { if (server != null && (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || context.checkCallingOrSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED)) {