diff --git a/mockrxandroidble/src/main/java/com/polidea/rxandroidble/mockrxandroidble/RxBleConnectionMock.java b/mockrxandroidble/src/main/java/com/polidea/rxandroidble/mockrxandroidble/RxBleConnectionMock.java index 45ac8d7e0..4bbfe3a40 100644 --- a/mockrxandroidble/src/main/java/com/polidea/rxandroidble/mockrxandroidble/RxBleConnectionMock.java +++ b/mockrxandroidble/src/main/java/com/polidea/rxandroidble/mockrxandroidble/RxBleConnectionMock.java @@ -42,6 +42,11 @@ public Observable requestMtu(int mtu) { return Observable.just(mtu); } + @Override + public void requestConnectionPriority(int priority) { + + } + @Override public Observable discoverServices() { return Observable.just(rxBleDeviceServices); diff --git a/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleConnection.java b/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleConnection.java index 44db6e3b6..dbb140418 100644 --- a/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleConnection.java +++ b/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleConnection.java @@ -17,6 +17,7 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; + import rx.Observable; /** @@ -48,13 +49,19 @@ public String toString() { } } + /** + * Request a connection priority update. + */ + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + void requestConnectionPriority(int priority); + /** * Performs GATT service discovery and emits discovered results. After service discovery you can walk through * {@link android.bluetooth.BluetoothGattService}s and {@link BluetoothGattCharacteristic}s. *

* Result of the discovery is cached internally so consecutive calls won't trigger BLE operation and can be * considered relatively lightweight. - * + *

* Uses default timeout of 20 seconds * * @return Observable emitting result a GATT service discovery. @@ -70,10 +77,10 @@ public String toString() { *

* Result of the discovery is cached internally so consecutive calls won't trigger BLE operation and can be * considered relatively lightweight. - * + *

* Timeouts after specified amount of time. * - * @param timeout multiplier of TimeUnit after which the discovery will timeout in case of no return values + * @param timeout multiplier of TimeUnit after which the discovery will timeout in case of no return values * @param timeUnit TimeUnit for the timeout * @return Observable emitting result a GATT service discovery. * @throws BleGattCannotStartException with {@link BleGattOperationType#SERVICE_DISCOVERY} type, when it wasn't possible to start @@ -88,7 +95,7 @@ public String toString() { * characteristic and the lifecycle of the notification will be shared among them. *

* Notification is automatically unregistered once this observable is unsubscribed. - * + *

* NOTE: due to stateful nature of characteristics if one will setupIndication() before setupNotification() * the notification will not be set up and will emit an BleCharacteristicNotificationOfOtherTypeAlreadySetException * @@ -97,7 +104,7 @@ public String toString() { * @throws BleCharacteristicNotFoundException if characteristic with given UUID hasn't been found. * @throws BleCannotSetCharacteristicNotificationException if setup process notification setup process fail. This may be an internal * reason or lack of permissions. - * @throws BleConflictingNotificationAlreadySetException if indication is already setup for this characteristic + * @throws BleConflictingNotificationAlreadySetException if indication is already setup for this characteristic */ Observable> setupNotification(@NonNull UUID characteristicUuid); @@ -118,7 +125,7 @@ public String toString() { * @return Observable emitting another observable when the notification setup is complete. * @throws BleCannotSetCharacteristicNotificationException if setup process notification setup process fail. This may be an internal * reason or lack of permissions. - * @throws BleConflictingNotificationAlreadySetException if indication is already setup for this characteristic + * @throws BleConflictingNotificationAlreadySetException if indication is already setup for this characteristic */ Observable> setupNotification(@NonNull BluetoothGattCharacteristic characteristic); @@ -137,7 +144,7 @@ public String toString() { * @throws BleCharacteristicNotFoundException if characteristic with given UUID hasn't been found. * @throws BleCannotSetCharacteristicNotificationException if setup process indication setup process fail. This may be an internal * reason or lack of permissions. - * @throws BleConflictingNotificationAlreadySetException if notification is already setup for this characteristic + * @throws BleConflictingNotificationAlreadySetException if notification is already setup for this characteristic */ Observable> setupIndication(@NonNull UUID characteristicUuid); @@ -158,7 +165,7 @@ public String toString() { * @return Observable emitting another observable when the indication setup is complete. * @throws BleCannotSetCharacteristicNotificationException if setup process indication setup process fail. This may be an internal * reason or lack of permissions. - * @throws BleConflictingNotificationAlreadySetException if notification is already setup for this characteristic + * @throws BleConflictingNotificationAlreadySetException if notification is already setup for this characteristic */ Observable> setupIndication(@NonNull BluetoothGattCharacteristic characteristic); @@ -192,8 +199,8 @@ public String toString() { * * @param characteristic Requested characteristic. * @return Observable emitting characteristic value or an error in case of failure. - * @throws BleGattCannotStartException if read operation couldn't be started for internal reason. - * @throws BleGattException if read operation failed + * @throws BleGattCannotStartException if read operation couldn't be started for internal reason. + * @throws BleGattException if read operation failed * @see #getCharacteristic(UUID) to obtain the characteristic. * @see #discoverServices() to obtain the characteristic. */ @@ -215,7 +222,6 @@ public String toString() { * by {@link BluetoothGattCharacteristic#getValue()} when this function is being called and reassigned at the time of internal execution * by {@link BluetoothGattCharacteristic#setValue(byte[])} *

- * @deprecated Use {@link #writeCharacteristic(BluetoothGattCharacteristic, byte[])} instead * * @param bluetoothGattCharacteristic Characteristic to write. Use {@link BluetoothGattCharacteristic#setValue(byte[])} to set value. * @return Observable emitting characteristic after write or an error in case of failure. @@ -223,6 +229,7 @@ public String toString() { * @throws BleGattException if write operation failed * @see #getCharacteristic(UUID) to obtain the characteristic. * @see #discoverServices() to obtain the characteristic. + * @deprecated Use {@link #writeCharacteristic(BluetoothGattCharacteristic, byte[])} instead */ @Deprecated Observable writeCharacteristic(@NonNull BluetoothGattCharacteristic bluetoothGattCharacteristic); @@ -231,7 +238,7 @@ public String toString() { * Performs GATT write operation on a given characteristic. * * @param bluetoothGattCharacteristic Characteristic to write. - * @param data the byte array to write + * @param data the byte array to write * @return Observable emitting written data or an error in case of failure. * @throws BleGattCannotStartException if write operation couldn't be started for internal reason. * @throws BleGattException if write operation failed @@ -243,9 +250,9 @@ public String toString() { /** * Performs GATT read operation on a descriptor from a characteristic with a given UUID from a service with a given UUID. * - * @param serviceUuid Requested {@link android.bluetooth.BluetoothGattService} UUID + * @param serviceUuid Requested {@link android.bluetooth.BluetoothGattService} UUID * @param characteristicUuid Requested {@link android.bluetooth.BluetoothGattCharacteristic} UUID - * @param descriptorUuid Requested {@link android.bluetooth.BluetoothGattDescriptor} UUID + * @param descriptorUuid Requested {@link android.bluetooth.BluetoothGattDescriptor} UUID * @return Observable emitting the descriptor value after read or an error in case of failure. * @throws BleGattCannotStartException if read operation couldn't be started for internal reason. * @throws BleGattException if read operation failed @@ -269,9 +276,9 @@ public String toString() { /** * Performs GATT write operation on a descriptor from a characteristic with a given UUID from a service with a given UUID. * - * @param serviceUuid Requested {@link android.bluetooth.BluetoothGattDescriptor} UUID + * @param serviceUuid Requested {@link android.bluetooth.BluetoothGattDescriptor} UUID * @param characteristicUuid Requested {@link android.bluetooth.BluetoothGattCharacteristic} UUID - * @param descriptorUuid Requested {@link android.bluetooth.BluetoothGattDescriptor} UUID + * @param descriptorUuid Requested {@link android.bluetooth.BluetoothGattDescriptor} UUID * @return Observable emitting the written descriptor value after write or an error in case of failure. * @throws BleGattCannotStartException if write operation couldn't be started for internal reason. * @throws BleGattException if write operation failed @@ -299,7 +306,7 @@ public String toString() { /** * Performs GATT request MTU - * + *

* Timeouts after 10 seconds. * * @return Observable emitting result the MTU requested. diff --git a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleConnectionImpl.java b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleConnectionImpl.java index 02d3877da..496c87205 100644 --- a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleConnectionImpl.java +++ b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleConnectionImpl.java @@ -81,6 +81,12 @@ private Observable privateRequestMtu(int mtu, long timeout, TimeUnit ti return newObservable; } + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + @Override + public void requestConnectionPriority(int priority) { + bluetoothGatt.requestConnectionPriority(priority); + } + @Override public Observable discoverServices() { return privateDiscoverServices(20, TimeUnit.SECONDS);