com.polidea.rxandroidble2.internal.connection.RxBleGattCallback Java Examples

The following examples show how to use com.polidea.rxandroidble2.internal.connection.RxBleGattCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DisconnectOperation.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Inject
DisconnectOperation(
        RxBleGattCallback rxBleGattCallback,
        BluetoothGattProvider bluetoothGattProvider,
        @Named(DeviceModule.MAC_ADDRESS) String macAddress,
        BluetoothManager bluetoothManager,
        @Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) Scheduler bluetoothInteractionScheduler,
        @Named(DeviceModule.DISCONNECT_TIMEOUT) TimeoutConfiguration timeoutConfiguration,
        ConnectionStateChangeListener connectionStateChangeListener) {
    this.rxBleGattCallback = rxBleGattCallback;
    this.bluetoothGattProvider = bluetoothGattProvider;
    this.macAddress = macAddress;
    this.bluetoothManager = bluetoothManager;
    this.bluetoothInteractionScheduler = bluetoothInteractionScheduler;
    this.timeoutConfiguration = timeoutConfiguration;
    this.connectionStateChangeListener = connectionStateChangeListener;
}
 
Example #2
Source File: ConnectOperation.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Inject
ConnectOperation(
        BluetoothDevice bluetoothDevice,
        BleConnectionCompat connectionCompat,
        RxBleGattCallback rxBleGattCallback,
        BluetoothGattProvider bluetoothGattProvider,
        @Named(CONNECT_TIMEOUT) TimeoutConfiguration connectTimeout,
        @Named(AUTO_CONNECT) boolean autoConnect,
        ConnectionStateChangeListener connectionStateChangedAction) {
    this.bluetoothDevice = bluetoothDevice;
    this.connectionCompat = connectionCompat;
    this.rxBleGattCallback = rxBleGattCallback;
    this.bluetoothGattProvider = bluetoothGattProvider;
    this.connectTimeout = connectTimeout;
    this.autoConnect = autoConnect;
    this.connectionStateChangedAction = connectionStateChangedAction;
}
 
Example #3
Source File: CharacteristicLongWriteOperation.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
CharacteristicLongWriteOperation(
        BluetoothGatt bluetoothGatt,
        RxBleGattCallback rxBleGattCallback,
        @Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) Scheduler bluetoothInteractionScheduler,
        @Named(ConnectionModule.OPERATION_TIMEOUT) TimeoutConfiguration timeoutConfiguration,
        BluetoothGattCharacteristic bluetoothGattCharacteristic,
        PayloadSizeLimitProvider batchSizeProvider,
        WriteOperationAckStrategy writeOperationAckStrategy,
        WriteOperationRetryStrategy writeOperationRetryStrategy,
        byte[] bytesToWrite) {
    this.bluetoothGatt = bluetoothGatt;
    this.rxBleGattCallback = rxBleGattCallback;
    this.bluetoothInteractionScheduler = bluetoothInteractionScheduler;
    this.timeoutConfiguration = timeoutConfiguration;
    this.bluetoothGattCharacteristic = bluetoothGattCharacteristic;
    this.batchSizeProvider = batchSizeProvider;
    this.writeOperationAckStrategy = writeOperationAckStrategy;
    this.writeOperationRetryStrategy = writeOperationRetryStrategy;
    this.bytesToWrite = bytesToWrite;
}
 
Example #4
Source File: OperationsProviderImpl.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Inject
OperationsProviderImpl(
        RxBleGattCallback rxBleGattCallback,
        BluetoothGatt bluetoothGatt,
        LoggerUtilBluetoothServices bleServicesLogger,
        @Named(ConnectionModule.OPERATION_TIMEOUT) TimeoutConfiguration timeoutConfiguration,
        @Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) Scheduler bluetoothInteractionScheduler,
        @Named(ClientComponent.NamedSchedulers.TIMEOUT) Scheduler timeoutScheduler,
        Provider<ReadRssiOperation> rssiReadOperationProvider) {
    this.rxBleGattCallback = rxBleGattCallback;
    this.bluetoothGatt = bluetoothGatt;
    this.bleServicesLogger = bleServicesLogger;
    this.timeoutConfiguration = timeoutConfiguration;
    this.bluetoothInteractionScheduler = bluetoothInteractionScheduler;
    this.timeoutScheduler = timeoutScheduler;
    this.rssiReadOperationProvider = rssiReadOperationProvider;
}
 
Example #5
Source File: ServiceDiscoveryOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
/**
 * Sometimes it happens that the {@link BluetoothGatt} will receive all {@link BluetoothGattService}'s,
 * {@link android.bluetooth.BluetoothGattCharacteristic}'s and {@link android.bluetooth.BluetoothGattDescriptor}
 * but it won't receive the final callback that the service discovery was completed. This is a potential workaround.
 * <p>
 * There is a change in Android 7.0.0_r1 where all data is received at once - in this situation returned services size will be always 0
 * https://android.googlesource.com/platform/frameworks/base/+/android-7.0.0_r1/core/java/android/bluetooth/BluetoothGatt.java#206
 * https://android.googlesource.com/platform/frameworks/base/+/android-6.0.1_r72/core/java/android/bluetooth/BluetoothGatt.java#205
 *
 * @param bluetoothGatt     the BluetoothGatt to use
 * @param rxBleGattCallback the RxBleGattCallback to use
 * @param timeoutScheduler  the Scheduler for timeout to use
 * @return Observable that may emit {@link RxBleDeviceServices} or {@link TimeoutException}
 */
@NonNull
@Override
protected Single<RxBleDeviceServices> timeoutFallbackProcedure(
        final BluetoothGatt bluetoothGatt,
        final RxBleGattCallback rxBleGattCallback,
        final Scheduler timeoutScheduler
) {
    return Single.defer(new Callable<SingleSource<? extends RxBleDeviceServices>>() {
        @Override
        public SingleSource<? extends RxBleDeviceServices> call() {
            final List<BluetoothGattService> services = bluetoothGatt.getServices();
            if (services.size() == 0) {
                // if after the timeout services are empty we have no other option to declare a failed discovery
                return Single.error(new BleGattCallbackTimeoutException(bluetoothGatt, BleGattOperationType.SERVICE_DISCOVERY));
            } else {
            /*
            it is observed that usually the Android OS is returning services, characteristics and descriptors in a short period of time
            if there are some services available we will wait for 5 more seconds just to be sure that
            the timeout was not triggered right in the moment of filling the services and then emit a value.
             */
                return Single
                        .timer(5, TimeUnit.SECONDS, timeoutScheduler)
                        .flatMap(new Function<Long, Single<RxBleDeviceServices>>() {
                            @Override
                            public Single<RxBleDeviceServices> apply(Long delayedSeconds) {
                                return Single.fromCallable(new Callable<RxBleDeviceServices>() {
                                    @Override
                                    public RxBleDeviceServices call() {
                                        return new RxBleDeviceServices(bluetoothGatt.getServices());
                                    }
                                });
                            }
                        });
            }
        }
    });
}
 
Example #6
Source File: JamBaseBluetoothService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Observable<Void> asObservable(BluetoothGatt bluetoothGatt,
                                     RxBleGattCallback rxBleGattCallback,
                                     Scheduler scheduler) throws Throwable {

    return Observable.fromCallable(() -> refreshDeviceCache(bluetoothGatt))
            .delay(delay_ms, TimeUnit.MILLISECONDS, Schedulers.computation())
            .subscribeOn(scheduler);
}
 
Example #7
Source File: Ob1G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Observable<Void> asObservable(BluetoothGatt bluetoothGatt,
                                     RxBleGattCallback rxBleGattCallback,
                                     Scheduler scheduler) throws Throwable {

    return Observable.fromCallable(() -> refreshDeviceCache(bluetoothGatt))
            .delay(delay_ms, TimeUnit.MILLISECONDS, Schedulers.computation())
            .subscribeOn(scheduler);
}
 
Example #8
Source File: Ob1G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Observable<Void> asObservable(BluetoothGatt bluetoothGatt,
                                     RxBleGattCallback rxBleGattCallback,
                                     Scheduler scheduler) throws Throwable {

    return Observable.fromCallable(() -> refreshDeviceCache(bluetoothGatt))
            .delay(delay_ms, TimeUnit.MILLISECONDS, Schedulers.computation())
            .subscribeOn(scheduler);
}
 
Example #9
Source File: JamBaseBluetoothService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Observable<Void> asObservable(BluetoothGatt bluetoothGatt,
                                     RxBleGattCallback rxBleGattCallback,
                                     Scheduler scheduler) throws Throwable {

    return Observable.fromCallable(() -> refreshDeviceCache(bluetoothGatt))
            .delay(delay_ms, TimeUnit.MILLISECONDS, Schedulers.computation())
            .subscribeOn(scheduler);
}
 
Example #10
Source File: Ob1G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Observable<Void> asObservable(BluetoothGatt bluetoothGatt,
                                     RxBleGattCallback rxBleGattCallback,
                                     Scheduler scheduler) throws Throwable {

    return Observable.fromCallable(() -> refreshDeviceCache(bluetoothGatt))
            .delay(delay_ms, TimeUnit.MILLISECONDS, Schedulers.computation())
            .subscribeOn(scheduler);
}
 
Example #11
Source File: Ob1G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Observable<Void> asObservable(BluetoothGatt bluetoothGatt,
                                     RxBleGattCallback rxBleGattCallback,
                                     Scheduler scheduler) throws Throwable {

    return Observable.fromCallable(() -> refreshDeviceCache(bluetoothGatt))
            .delay(delay_ms, TimeUnit.MILLISECONDS, Schedulers.computation())
            .subscribeOn(scheduler);
}
 
Example #12
Source File: MtuRequestOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Inject
MtuRequestOperation(
        RxBleGattCallback rxBleGattCallback,
        BluetoothGatt bluetoothGatt,
        TimeoutConfiguration timeoutConfiguration, int requestedMtu) {
    super(bluetoothGatt, rxBleGattCallback, BleGattOperationType.ON_MTU_CHANGED, timeoutConfiguration);
    mtu = requestedMtu;
}
 
Example #13
Source File: DescriptorWriteOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
protected Single<byte[]> getCallback(RxBleGattCallback rxBleGattCallback) {
    return rxBleGattCallback
            .getOnDescriptorWrite()
            .filter(descriptorPredicate(bluetoothGattDescriptor))
            .firstOrError()
            .map(getBytesFromAssociation());
}
 
Example #14
Source File: DescriptorWriteOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
DescriptorWriteOperation(RxBleGattCallback rxBleGattCallback,
                         BluetoothGatt bluetoothGatt,
                         @Named(ConnectionModule.OPERATION_TIMEOUT) TimeoutConfiguration timeoutConfiguration,
                         int bluetoothGattCharacteristicDefaultWriteType,
                         BluetoothGattDescriptor bluetoothGattDescriptor,
                         byte[] data) {
    super(bluetoothGatt, rxBleGattCallback, BleGattOperationType.DESCRIPTOR_WRITE, timeoutConfiguration);
    this.bluetoothGattCharacteristicDefaultWriteType = bluetoothGattCharacteristicDefaultWriteType;
    this.bluetoothGattDescriptor = bluetoothGattDescriptor;
    this.data = data;
}
 
Example #15
Source File: DescriptorReadOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
protected Single<ByteAssociation<BluetoothGattDescriptor>> getCallback(RxBleGattCallback rxBleGattCallback) {
    return rxBleGattCallback
            .getOnDescriptorRead()
            .filter(descriptorPredicate(bluetoothGattDescriptor))
            .firstOrError();
}
 
Example #16
Source File: DescriptorReadOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Inject
DescriptorReadOperation(RxBleGattCallback rxBleGattCallback, BluetoothGatt bluetoothGatt,
                        @Named(ConnectionModule.OPERATION_TIMEOUT) TimeoutConfiguration timeoutConfiguration,
                        BluetoothGattDescriptor descriptor) {
    super(bluetoothGatt, rxBleGattCallback, BleGattOperationType.DESCRIPTOR_READ, timeoutConfiguration);
    bluetoothGattDescriptor = descriptor;
}
 
Example #17
Source File: CharacteristicWriteOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
protected Single<byte[]> getCallback(RxBleGattCallback rxBleGattCallback) {
    return rxBleGattCallback
            .getOnCharacteristicWrite()
            .filter(characteristicUUIDPredicate(bluetoothGattCharacteristic.getUuid()))
            .firstOrError()
            .map(getBytesFromAssociation());
}
 
Example #18
Source File: SingleResponseOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
public SingleResponseOperation(BluetoothGatt bluetoothGatt,
                               RxBleGattCallback rxBleGattCallback,
                               BleGattOperationType gattOperationType,
                               TimeoutConfiguration timeoutConfiguration) {
    this.bluetoothGatt = bluetoothGatt;
    this.rxBleGattCallback = rxBleGattCallback;
    this.operationType = gattOperationType;
    this.timeoutConfiguration = timeoutConfiguration;
}
 
Example #19
Source File: SingleResponseOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
protected Single<T> timeoutFallbackProcedure(
        BluetoothGatt bluetoothGatt,
        RxBleGattCallback rxBleGattCallback,
        Scheduler timeoutScheduler
) {
    return Single.error(new BleGattCallbackTimeoutException(this.bluetoothGatt, operationType));
}
 
Example #20
Source File: ConnectionPriorityChangeOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Inject
ConnectionPriorityChangeOperation(
        RxBleGattCallback rxBleGattCallback,
        BluetoothGatt bluetoothGatt,
        TimeoutConfiguration timeoutConfiguration,
        int connectionPriority,
        TimeoutConfiguration successTimeoutConfiguration) {
    super(bluetoothGatt, rxBleGattCallback, BleGattOperationType.CONNECTION_PRIORITY_CHANGE, timeoutConfiguration);
    this.connectionPriority = connectionPriority;
    this.successTimeoutConfiguration = successTimeoutConfiguration;
}
 
Example #21
Source File: CharacteristicWriteOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
CharacteristicWriteOperation(RxBleGattCallback rxBleGattCallback, BluetoothGatt bluetoothGatt,
                             @Named(ConnectionModule.OPERATION_TIMEOUT) TimeoutConfiguration timeoutConfiguration,
                             BluetoothGattCharacteristic bluetoothGattCharacteristic,
                             byte[] data) {
    super(bluetoothGatt, rxBleGattCallback, BleGattOperationType.CHARACTERISTIC_WRITE, timeoutConfiguration);
    this.bluetoothGattCharacteristic = bluetoothGattCharacteristic;
    this.data = data;
}
 
Example #22
Source File: CharacteristicReadOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
protected Single<byte[]> getCallback(RxBleGattCallback rxBleGattCallback) {
    return rxBleGattCallback
            .getOnCharacteristicRead()
            .filter(characteristicUUIDPredicate(bluetoothGattCharacteristic.getUuid()))
            .firstOrError()
            .map(getBytesFromAssociation());
}
 
Example #23
Source File: ServiceDiscoveryOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
ServiceDiscoveryOperation(
        RxBleGattCallback rxBleGattCallback,
        BluetoothGatt bluetoothGatt,
        LoggerUtilBluetoothServices bleServicesLogger,
        TimeoutConfiguration timeoutConfiguration) {
    super(bluetoothGatt, rxBleGattCallback, BleGattOperationType.SERVICE_DISCOVERY, timeoutConfiguration);
    this.bluetoothGatt = bluetoothGatt;
    this.bleServicesLogger = bleServicesLogger;
}
 
Example #24
Source File: ServiceDiscoveryOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
protected Single<RxBleDeviceServices> getCallback(RxBleGattCallback rxBleGattCallback) {
    return rxBleGattCallback.getOnServicesDiscovered().firstOrError()
            .doOnSuccess(new Consumer<RxBleDeviceServices>() {
                @Override
                public void accept(RxBleDeviceServices rxBleDeviceServices) {
                    bleServicesLogger.log(rxBleDeviceServices, bluetoothGatt.getDevice());
                }
            });
}
 
Example #25
Source File: CharacteristicReadOperation.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
CharacteristicReadOperation(RxBleGattCallback rxBleGattCallback, BluetoothGatt bluetoothGatt,
                            @Named(ConnectionModule.OPERATION_TIMEOUT) TimeoutConfiguration timeoutConfiguration,
                            BluetoothGattCharacteristic bluetoothGattCharacteristic) {
    super(bluetoothGatt, rxBleGattCallback, BleGattOperationType.CHARACTERISTIC_READ, timeoutConfiguration);
    this.bluetoothGattCharacteristic = bluetoothGattCharacteristic;
}
 
Example #26
Source File: DisconnectOperation.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
DisconnectGattObservable(BluetoothGatt bluetoothGatt, RxBleGattCallback rxBleGattCallback, Scheduler disconnectScheduler) {
    this.bluetoothGatt = bluetoothGatt;
    this.rxBleGattCallback = rxBleGattCallback;
    this.disconnectScheduler = disconnectScheduler;
}
 
Example #27
Source File: MtuRequestOperation.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
protected Single<Integer> getCallback(RxBleGattCallback rxBleGattCallback) {
    return rxBleGattCallback.getOnMtuChanged().firstOrError();
}
 
Example #28
Source File: ReadRssiOperation.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Inject
ReadRssiOperation(RxBleGattCallback bleGattCallback, BluetoothGatt bluetoothGatt,
                  @Named(ConnectionModule.OPERATION_TIMEOUT) TimeoutConfiguration timeoutConfiguration) {
    super(bluetoothGatt, bleGattCallback, BleGattOperationType.READ_RSSI, timeoutConfiguration);
}
 
Example #29
Source File: ConnectionPriorityChangeOperation.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
protected Single<Long> getCallback(RxBleGattCallback rxBleGattCallback) {
    return Single.timer(successTimeoutConfiguration.timeout, successTimeoutConfiguration.timeoutTimeUnit,
            successTimeoutConfiguration.timeoutScheduler);
}
 
Example #30
Source File: ReadRssiOperation.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
protected Single<Integer> getCallback(RxBleGattCallback rxBleGattCallback) {
    return rxBleGattCallback.getOnRssiRead().firstOrError();
}