PhilipsHue / flutter_reactive_ble

Flutter library that handles BLE operations for multiple devices.
https://developers.meethue.com/
Other
661 stars 321 forks source link

Android low level library crash when the BLE device disconnects unexpectedly #860

Closed cmillauriaux closed 1 week ago

cmillauriaux commented 4 months ago

Describe the bug When I connect my Flutter application to a BLE object on battery, when the object runs out of battery and shuts down unexpectedly, the application crashes with a Java error stack

To Reproduce Steps to reproduce the behavior:

  1. Connect to one device using connectTo()
  2. subscribe to a protected characteristic
  3. BLE peripheral shutdown because it runs out of battery
  4. Observe a failure with exception
io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | com.polidea.rxandroidble2.exceptions.BleDisconnectedException: Disconnected from MAC='XX:XX:XX:XX:XX:XX' with status 133 (GATT_ERROR)
                                                                                                        at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
                                                                                                        at io.reactivex.internal.observers.LambdaObserver.onError(LambdaObserver.java:83)
                                                                                                        at io.reactivex.internal.operators.observable.ObservableRetryPredicate$RepeatObserver.onError(ObservableRetryPredicate.java:90)
                                                                                                        at io.reactivex.observers.SerializedObserver.onError(SerializedObserver.java:153)
                                                                                                        at io.reactivex.internal.operators.observable.ObservableDelay$DelayObserver$OnError.run(ObservableDelay.java:128)
                                                                                                        at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
                                                                                                        at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
                                                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                                                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
                                                                                                        at java.lang.Thread.run(Thread.java:919)
                                                                                                    Caused by: com.polidea.rxandroidble2.exceptions.BleDisconnectedException: Disconnected from MAC='XX:XX:XX:XX:XX:XX' with status 133 (GATT_ERROR)
                                                                                                        at com.polidea.rxandroidble2.internal.connection.RxBleGattCallback$2.onConnectionStateChange(RxBleGattCallback.java:81)
                                                                                                        at android.bluetooth.BluetoothGatt$1$4.run(BluetoothGatt.java:272)
                                                                                                        at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:780)
                                                                                                        at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:41)
                                                                                                        at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:267)
                                                                                                        at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:192)
                                                                                                        at android.os.Binder.execTransactInternal(Binder.java:1021)
                                                                                                        at android.os.Binder.execTransact(Binder.java:994)

Expected behavior A catchable error to close the connexion on Flutter side

Smartphone / tablet

Peripheral device

Giovanni-Fantin commented 3 weeks ago

@cmillauriaux have you found the solution? If not, I can help you

mbaz2 commented 1 week ago

@cmillauriaux have you tried what is suggested in the FAQ and still getting this?: https://pub.dev/packages/flutter_reactive_ble#faq

Taym95 commented 1 week ago

@cmillauriaux have you tried what is suggested in the FAQ and still getting this?: https://pub.dev/packages/flutter_reactive_ble#faq

Indeed to handle this exception check FAQ section.