public class RxBleConnectionImpl extends java.lang.Object implements RxBleConnection
RxBleConnection.ConnectionPriority, RxBleConnection.Connector, RxBleConnection.LongWriteOperationBuilder, RxBleConnection.RxBleConnectionState, RxBleConnection.WriteOperationAckStrategy, RxBleConnection.WriteOperationRetryStrategyGATT_MTU_MAXIMUM, GATT_MTU_MINIMUM, GATT_READ_MTU_OVERHEAD, GATT_WRITE_MTU_OVERHEAD| Constructor and Description |
|---|
RxBleConnectionImpl(ConnectionOperationQueue operationQueue,
RxBleGattCallback gattCallback,
android.bluetooth.BluetoothGatt bluetoothGatt,
com.polidea.rxandroidble2.internal.connection.ServiceDiscoveryManager serviceDiscoveryManager,
com.polidea.rxandroidble2.internal.connection.NotificationAndIndicationManager notificationIndicationManager,
com.polidea.rxandroidble2.internal.connection.MtuProvider mtuProvider,
com.polidea.rxandroidble2.internal.connection.DescriptorWriter descriptorWriter,
OperationsProvider operationProvider,
<any> longWriteOperationBuilderProvider,
Scheduler callbackScheduler,
IllegalOperationChecker illegalOperationChecker) |
| Modifier and Type | Method and Description |
|---|---|
RxBleConnection.LongWriteOperationBuilder |
createNewLongWriteBuilder()
Returns a LongWriteOperationBuilder used for creating atomic write operations divided into multiple writes.
|
<any> |
discoverServices()
Performs GATT service discovery and emits discovered results.
|
<any> |
discoverServices(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Performs GATT service discovery and emits discovered results.
|
<any> |
getCharacteristic(java.util.UUID characteristicUuid)
Deprecated.
|
int |
getMtu()
Get currently negotiated MTU value.
|
<any> |
observeConnectionParametersUpdates()
Allows observing of connection parameters updates.
|
<T> <any> |
queue(RxBleCustomOperation<T> operation)
This method requires deep knowledge of RxAndroidBLE internals.
|
<T> <any> |
queue(RxBleCustomOperation<T> operation,
Priority priority)
This method requires deep knowledge of RxAndroidBLE internals.
|
<any> |
readCharacteristic(android.bluetooth.BluetoothGattCharacteristic characteristic)
Performs GATT read operation on a given characteristic.
|
<any> |
readCharacteristic(java.util.UUID characteristicUuid)
Performs GATT read operation on a characteristic with given UUID.
|
<any> |
readDescriptor(android.bluetooth.BluetoothGattDescriptor descriptor)
Performs GATT read operation on a descriptor from a characteristic with a given UUID from a service with a given UUID.
|
<any> |
readDescriptor(java.util.UUID serviceUuid,
java.util.UUID characteristicUuid,
java.util.UUID descriptorUuid)
Performs GATT read operation on a descriptor from a characteristic with a given UUID from a service with a given UUID.
|
<any> |
readRssi()
Performs GATT read rssi operation.
|
Completable |
requestConnectionPriority(int connectionPriority,
long delay,
java.util.concurrent.TimeUnit timeUnit)
Performs a GATT request connection priority operation, which requests a connection parameter
update on the remote device.
|
<any> |
requestMtu(int mtu)
Performs GATT MTU (Maximum Transfer Unit) request.
|
<any> |
setupIndication(android.bluetooth.BluetoothGattCharacteristic characteristic) |
<any> |
setupIndication(android.bluetooth.BluetoothGattCharacteristic characteristic,
NotificationSetupMode setupMode)
Setup characteristic indication in order to receive callbacks when given characteristic has been changed.
|
<any> |
setupIndication(java.util.UUID characteristicUuid) |
<any> |
setupIndication(java.util.UUID characteristicUuid,
NotificationSetupMode setupMode)
Setup characteristic indication in order to receive callbacks when given characteristic has been changed.
|
<any> |
setupNotification(android.bluetooth.BluetoothGattCharacteristic characteristic) |
<any> |
setupNotification(android.bluetooth.BluetoothGattCharacteristic characteristic,
NotificationSetupMode setupMode)
Setup characteristic notification in order to receive callbacks when given characteristic has been changed.
|
<any> |
setupNotification(java.util.UUID characteristicUuid) |
<any> |
setupNotification(java.util.UUID characteristicUuid,
NotificationSetupMode setupMode)
Setup characteristic notification in order to receive callbacks when given characteristic has been changed.
|
<any> |
writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic characteristic,
byte[] data)
Performs GATT write operation on a given characteristic.
|
<any> |
writeCharacteristic(java.util.UUID characteristicUuid,
byte[] data)
Performs GATT write operation on a characteristic with given UUID.
|
Completable |
writeDescriptor(android.bluetooth.BluetoothGattDescriptor bluetoothGattDescriptor,
byte[] data)
Performs GATT write operation on a given descriptor.
|
Completable |
writeDescriptor(java.util.UUID serviceUuid,
java.util.UUID characteristicUuid,
java.util.UUID descriptorUuid,
byte[] data)
Performs GATT write operation on a descriptor from a characteristic with a given UUID from a service with a given UUID.
|
public RxBleConnectionImpl(ConnectionOperationQueue operationQueue, RxBleGattCallback gattCallback, android.bluetooth.BluetoothGatt bluetoothGatt, com.polidea.rxandroidble2.internal.connection.ServiceDiscoveryManager serviceDiscoveryManager, com.polidea.rxandroidble2.internal.connection.NotificationAndIndicationManager notificationIndicationManager, com.polidea.rxandroidble2.internal.connection.MtuProvider mtuProvider, com.polidea.rxandroidble2.internal.connection.DescriptorWriter descriptorWriter, OperationsProvider operationProvider, <any> longWriteOperationBuilderProvider, Scheduler callbackScheduler, IllegalOperationChecker illegalOperationChecker)
public RxBleConnection.LongWriteOperationBuilder createNewLongWriteBuilder()
RxBleConnectionRxBleConnection.writeCharacteristic(UUID, byte[]) should be sufficient.createNewLongWriteBuilder in interface RxBleConnectionpublic Completable requestConnectionPriority(int connectionPriority,
long delay,
java.util.concurrent.TimeUnit timeUnit)
RxBleConnection
Tells Android to request an update of connection interval and slave latency parameters.
Using BluetoothGatt.CONNECTION_PRIORITY_HIGH will increase transmission speed and
battery drainage, if accepted by the device, compared to BluetoothGatt.CONNECTION_PRIORITY_BALANCED,
while using BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER will cause higher latencies
and save battery, if accepted by the device, compared to BluetoothGatt.CONNECTION_PRIORITY_BALANCED.
By default connection is balanced.
NOTE: Till API 26 (8.0) there was no method like `BluetoothGattCallback.onConnectionPriorityChanged()`. It was not possible to know
if the request was successful (accepted by the peripheral). This also causes the need of specifying when the request is considered
finished (parameter delay and timeUnit). Since API 26 the mentioned callback is hidden, yet possible to use. It is not used to
automatically complete this request due to Android OS changing connection parameters on its own. It is not possible to determine
which callback is actually finishing the request nor if the Android OS will not change the parameters right after the request.
If access to the callback is a must for your implementation you may achieve it by
RxBleGattCallback.setHiddenNativeCallback(HiddenBluetoothGattCallback) via RxBleConnection.queue(RxBleCustomOperation) and create
a custom request connection priority operation.
As of Lollipop the connection parameters are:
* BluetoothGatt.CONNECTION_PRIORITY_BALANCED: min interval 30 ms, max interval 50 ms, slave latency 0
* BluetoothGatt.CONNECTION_PRIORITY_HIGH: min interval 7.5 ms, max interval 10ms, slave latency 0
* BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER: min interval 100ms, max interval 125 ms, slave latency 2
Returned completable completes after the specified delay if and only if
BluetoothGatt.requestConnectionPriority(int) has returned true.
requestConnectionPriority in interface RxBleConnectionconnectionPriority - requested connection prioritydelay - delay after which operation is assumed to be successful (must be shorter than 30 seconds)timeUnit - time unit of the delaypublic <any> requestMtu(int mtu)
RxBleConnectionrequestMtu in interface RxBleConnectionpublic int getMtu()
RxBleConnectiongetMtu in interface RxBleConnectionpublic <any> discoverServices()
RxBleConnectionBluetoothGattServices and BluetoothGattCharacteristics.
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
discoverServices in interface RxBleConnectionpublic <any> discoverServices(long timeout,
java.util.concurrent.TimeUnit timeUnit)
RxBleConnectionBluetoothGattServices and BluetoothGattCharacteristics.
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.
discoverServices in interface RxBleConnectiontimeout - multiplier of TimeUnit after which the discovery will timeout in case of no return valuestimeUnit - TimeUnit for the timeout@Deprecated public <any> getCharacteristic(java.util.UUID characteristicUuid)
RxBleConnectiongetCharacteristic in interface RxBleConnectioncharacteristicUuid - Requested characteristic UUID.public <any> setupNotification(java.util.UUID characteristicUuid)
setupNotification in interface RxBleConnectionwith default setup mode.public <any> setupNotification(android.bluetooth.BluetoothGattCharacteristic characteristic)
setupNotification in interface RxBleConnectionwith default setup mode.public <any> setupNotification(java.util.UUID characteristicUuid,
NotificationSetupMode setupMode)
RxBleConnectionNotification 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
setupNotification in interface RxBleConnectioncharacteristicUuid - Characteristic UUID for notification setup.setupMode - Configures how the notification is set up. For available modes see NotificationSetupMode.public <any> setupNotification(android.bluetooth.BluetoothGattCharacteristic characteristic,
NotificationSetupMode setupMode)
RxBleConnectionNotification 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
The characteristic can be retrieved from RxBleDeviceServices emitted from
RxBleConnection.discoverServices()
setupNotification in interface RxBleConnectioncharacteristic - Characteristic for notification setup.setupMode - Configures how the notification is set up. For available modes see NotificationSetupMode.public <any> setupIndication(java.util.UUID characteristicUuid)
setupIndication in interface RxBleConnectionwith default setup mode.public <any> setupIndication(android.bluetooth.BluetoothGattCharacteristic characteristic)
setupIndication in interface RxBleConnectionwith default setup mode.public <any> setupIndication(java.util.UUID characteristicUuid,
NotificationSetupMode setupMode)
RxBleConnectionIndication is automatically unregistered once this observable is unsubscribed.
NOTE: due to stateful nature of characteristics if one will setupNotification() before setupIndication() the indication will not be set up and will emit an BleCharacteristicNotificationOfOtherTypeAlreadySetException
setupIndication in interface RxBleConnectioncharacteristicUuid - Characteristic UUID for indication setup.setupMode - Configures how the notification is set up. For available modes see NotificationSetupMode.public <any> setupIndication(android.bluetooth.BluetoothGattCharacteristic characteristic,
NotificationSetupMode setupMode)
RxBleConnectionIndication is automatically unregistered once this observable is unsubscribed.
NOTE: due to stateful nature of characteristics if one will setupNotification() before setupIndication() the indication will not be set up and will emit an BleCharacteristicNotificationOfOtherTypeAlreadySetException
The characteristic can be retrieved from RxBleDeviceServices emitted from
RxBleConnection.discoverServices()
setupIndication in interface RxBleConnectioncharacteristic - Characteristic for indication setup.setupMode - Configures how the notification is set up. For available modes see NotificationSetupMode.public <any> readCharacteristic(java.util.UUID characteristicUuid)
RxBleConnectionreadCharacteristic in interface RxBleConnectioncharacteristicUuid - Requested characteristic UUID.public <any> readCharacteristic(android.bluetooth.BluetoothGattCharacteristic characteristic)
RxBleConnectionreadCharacteristic in interface RxBleConnectioncharacteristic - Requested characteristic.to obtain the characteristic.,
to obtain the characteristic.public <any> writeCharacteristic(java.util.UUID characteristicUuid,
byte[] data)
RxBleConnectionwriteCharacteristic in interface RxBleConnectioncharacteristicUuid - Requested characteristic UUID.public <any> writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic characteristic,
byte[] data)
RxBleConnectionwriteCharacteristic in interface RxBleConnectioncharacteristic - Characteristic to write.data - the byte array to writeto obtain the characteristic.,
to obtain the characteristic.public <any> readDescriptor(java.util.UUID serviceUuid,
java.util.UUID characteristicUuid,
java.util.UUID descriptorUuid)
RxBleConnectionreadDescriptor in interface RxBleConnectionserviceUuid - Requested BluetoothGattService UUIDcharacteristicUuid - Requested BluetoothGattCharacteristic UUIDdescriptorUuid - Requested BluetoothGattDescriptor UUIDto obtain the characteristic.,
to obtain the characteristic.public <any> readDescriptor(android.bluetooth.BluetoothGattDescriptor descriptor)
RxBleConnectionreadDescriptor in interface RxBleConnectiondescriptor - Requested BluetoothGattDescriptorto obtain the characteristic from which you can get the {@link BluetoothGattDescriptor}.,
to obtain the {@link BluetoothGattDescriptor}.public Completable writeDescriptor(java.util.UUID serviceUuid,
java.util.UUID characteristicUuid,
java.util.UUID descriptorUuid,
byte[] data)
RxBleConnectionwriteDescriptor in interface RxBleConnectionserviceUuid - Requested BluetoothGattDescriptor UUIDcharacteristicUuid - Requested BluetoothGattCharacteristic UUIDdescriptorUuid - Requested BluetoothGattDescriptor UUIDpublic Completable writeDescriptor(android.bluetooth.BluetoothGattDescriptor bluetoothGattDescriptor,
byte[] data)
RxBleConnectionwriteDescriptor in interface RxBleConnectionbluetoothGattDescriptor - Requested BluetoothGattDescriptorto obtain the characteristic.,
to obtain the characteristic.public <any> readRssi()
RxBleConnectionreadRssi in interface RxBleConnectionpublic <any> observeConnectionParametersUpdates()
RxBleConnectionBluetoothGattCallback and will not work on lower API levels at all.
The system does change the parameters on its own at the beginning of connection (i.e. to speed up service discovery process).
The parameters may be further changed by using RxBleConnection.requestConnectionPriority(int, long, TimeUnit).observeConnectionParametersUpdates in interface RxBleConnectionpublic <T> <any> queue(RxBleCustomOperation<T> operation)
RxBleConnection
Queue an operation for future execution. The method accepts a RxBleCustomOperation concrete implementation
and will queue it inside connection operation queue. When ready to execute, the Observable returned
by the RxBleCustomOperation.asObservable(BluetoothGatt, RxBleGattCallback, Scheduler) will be
subscribed to.
Every event emitted by the Observable returned by
RxBleCustomOperation.asObservable(BluetoothGatt, RxBleGattCallback, Scheduler) will be forwarded
to the Observable returned by this method.
You must ensure the custom operation's Observable does terminate either via onCompleted
or onError(Throwable). Otherwise, the internal queue orchestrator will wait forever for
your Observable to complete. Normal queue processing will be resumed after the Observable
returned by RxBleCustomOperation.asObservable(BluetoothGatt, RxBleGattCallback, Scheduler)
completes.
The operation will be added to the queue using a Priority.NORMAL
priority.
queue in interface RxBleConnectionT - The type returned by the RxBleCustomOperation instance.operation - The custom operation to queue.public <T> <any> queue(RxBleCustomOperation<T> operation, Priority priority)
RxBleConnection
Queue an operation for future execution. The method accepts a RxBleCustomOperation concrete implementation
and will queue it inside connection operation queue. When ready to execute, the Observable returned
by the RxBleCustomOperation.asObservable(BluetoothGatt, RxBleGattCallback, Scheduler) will be
subscribed to.
Every event emitted by the Observable returned by
RxBleCustomOperation.asObservable(BluetoothGatt, RxBleGattCallback, Scheduler) will be forwarded
to the Observable returned by this method.
You must ensure the custom operation's Observable does terminate either via onCompleted
or onError(Throwable). Otherwise, the internal queue orchestrator will wait forever for
your Observable to complete. Normal queue processing will be resumed after the Observable
returned by RxBleCustomOperation.asObservable(BluetoothGatt, RxBleGattCallback, Scheduler)
completes.
queue in interface RxBleConnectionT - The type returned by the RxBleCustomOperation instance.operation - The custom operation to queue.priority - Priority affected to this operation