From fa3cd6192438c3ab29b82b638d5e1738f1438119 Mon Sep 17 00:00:00 2001 From: Aleksander Nowakowski Date: Tue, 18 Oct 2016 15:47:37 +0200 Subject: [PATCH] Comments regarding autoConnect updated --- .../android/nrftoolbox/profile/BleManager.java | 12 ++++++++++-- .../nrftoolbox/profile/BleManagerCallbacks.java | 4 +++- .../android/nrftoolbox/ble/BleManager.java | 12 ++++++++++-- .../android/nrftoolbox/ble/BleManagerCallbacks.java | 6 ++++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleManager.java index ad14a190..c285478f 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleManager.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleManager.java @@ -179,8 +179,16 @@ public abstract class BleManager implements ILogg protected abstract BleManagerGattCallback getGattCallback(); /** - * Returns whether to directly connect to the remote device (false) or to automatically connect as soon as the remote - * device becomes available (true). + * Returns whether to connect to the remote device just once (false) or to add the address to white list of devices + * that will be automatically connect as soon as they become available (true). In the latter case, if + * Bluetooth adapter is enabled, Android scans periodically for devices from the white list and if a advertising packet + * is received from such, it tries to connect to it. When the connection is lost, the system will keep trying to reconnect + * to it in. If true is returned, and the connection to the device is lost the {@link BleManagerCallbacks#onLinklossOccur(BluetoothDevice)} + * callback is called instead of {@link BleManagerCallbacks#onDeviceDisconnected(BluetoothDevice)}. + *

This feature works much better on newer Android phone models and many not work on older phones.

+ *

This method should only be used with bonded devices, as otherwise the device may change it's address. + * It will however work also with non-bonded devices with private static address. A connection attempt to + * a device with private resolvable address will fail.

* * @return autoConnect flag value */ diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleManagerCallbacks.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleManagerCallbacks.java index d03a06b7..6ba0a8fb 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleManagerCallbacks.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleManagerCallbacks.java @@ -52,7 +52,9 @@ public interface BleManagerCallbacks { /** * Called when the device has disconnected (when the callback returned - * {@link BluetoothGattCallback#onConnectionStateChange(BluetoothGatt, int, int)} with state DISCONNECTED. + * {@link BluetoothGattCallback#onConnectionStateChange(BluetoothGatt, int, int)} with state DISCONNECTED), + * but ONLY if the {@link BleManager#shouldAutoConnect()} method returned false for this device when it was connecting. + * Otherwise the {@link #onLinklossOccur(BluetoothDevice)} method will be called instead. * @param device the device that got disconnected */ void onDeviceDisconnected(final BluetoothDevice device); diff --git a/wear/src/main/java/no/nordicsemi/android/nrftoolbox/ble/BleManager.java b/wear/src/main/java/no/nordicsemi/android/nrftoolbox/ble/BleManager.java index 66affc62..92469db9 100644 --- a/wear/src/main/java/no/nordicsemi/android/nrftoolbox/ble/BleManager.java +++ b/wear/src/main/java/no/nordicsemi/android/nrftoolbox/ble/BleManager.java @@ -147,8 +147,16 @@ public class BleManager implements BleProfileApi { } /** - * Returns whether to directly connect to the remote device (false) or to automatically connect as soon as the remote - * device becomes available (true). + * Returns whether to connect to the remote device just once (false) or to add the address to white list of devices + * that will be automatically connect as soon as they become available (true). In the latter case, if + * Bluetooth adapter is enabled, Android scans periodically for devices from the white list and if a advertising packet + * is received from such, it tries to connect to it. When the connection is lost, the system will keep trying to reconnect + * to it in. If true is returned, and the connection to the device is lost the {@link BleManagerCallbacks#onLinklossOccur(BluetoothDevice)} + * callback is called instead of {@link BleManagerCallbacks#onDeviceDisconnected(BluetoothDevice)}. + *

This feature works much better on newer Android phone models and many not work on older phones.

+ *

This method should only be used with bonded devices, as otherwise the device may change it's address. + * It will however work also with non-bonded devices with private static address. A connection attempt to + * a device with private resolvable address will fail.

* * @return autoConnect flag value */ diff --git a/wear/src/main/java/no/nordicsemi/android/nrftoolbox/ble/BleManagerCallbacks.java b/wear/src/main/java/no/nordicsemi/android/nrftoolbox/ble/BleManagerCallbacks.java index 9846c037..9a513666 100644 --- a/wear/src/main/java/no/nordicsemi/android/nrftoolbox/ble/BleManagerCallbacks.java +++ b/wear/src/main/java/no/nordicsemi/android/nrftoolbox/ble/BleManagerCallbacks.java @@ -70,8 +70,10 @@ public interface BleManagerCallbacks { /** * Called when the device has disconnected (when the callback returned - * {@link BluetoothGattCallback#onConnectionStateChange(BluetoothGatt, int, int)} with state DISCONNECTED. - * @param device target device + * {@link BluetoothGattCallback#onConnectionStateChange(BluetoothGatt, int, int)} with state DISCONNECTED), + * but ONLY if the {@link BleManager#shouldAutoConnect()} method returned false for this device when it was connecting. + * Otherwise the {@link #onLinklossOccur(BluetoothDevice)} method will be called instead. + * @param device the device that got disconnected */ void onDeviceDisconnected(final BluetoothDevice device);