Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added requestConnectionPriority methods. #112

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public Observable<Integer> requestMtu(int mtu) {
return Observable.just(mtu);
}

@Override
public void requestConnectionPriority(int priority) {

}

@Override
public Observable<RxBleDeviceServices> discoverServices() {
return Observable.just(rxBleDeviceServices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.UUID;

import java.util.concurrent.TimeUnit;

import rx.Observable;

/**
Expand Down Expand Up @@ -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.
* <p>
* Result of the discovery is cached internally so consecutive calls won't trigger BLE operation and can be
* considered relatively lightweight.
*
* <p>
* Uses default timeout of 20 seconds
*
* @return Observable emitting result a GATT service discovery.
Expand All @@ -70,10 +77,10 @@ public String toString() {
* <p>
* Result of the discovery is cached internally so consecutive calls won't trigger BLE operation and can be
* considered relatively lightweight.
*
* <p>
* 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
Expand All @@ -88,7 +95,7 @@ public String toString() {
* characteristic and the lifecycle of the notification will be shared among them.
* <p>
* Notification is automatically unregistered once this observable is unsubscribed.
*
* <p>
* 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
*
Expand All @@ -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<Observable<byte[]>> setupNotification(@NonNull UUID characteristicUuid);

Expand All @@ -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<Observable<byte[]>> setupNotification(@NonNull BluetoothGattCharacteristic characteristic);

Expand All @@ -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<Observable<byte[]>> setupIndication(@NonNull UUID characteristicUuid);

Expand All @@ -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<Observable<byte[]>> setupIndication(@NonNull BluetoothGattCharacteristic characteristic);

Expand Down Expand Up @@ -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.
*/
Expand All @@ -215,14 +222,14 @@ 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[])}
* <p>
* @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.
* @throws BleGattCannotStartException if write operation couldn't be started for internal reason.
* @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<BluetoothGattCharacteristic> writeCharacteristic(@NonNull BluetoothGattCharacteristic bluetoothGattCharacteristic);
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -299,7 +306,7 @@ public String toString() {

/**
* Performs GATT request MTU
*
* <p>
* Timeouts after 10 seconds.
*
* @return Observable emitting result the MTU requested.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ private Observable<Integer> 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<RxBleDeviceServices> discoverServices() {
return privateDiscoverServices(20, TimeUnit.SECONDS);
Expand Down