question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RxBle is not show disconnected when BluetoothGatt: android.os.DeadObjectException is thrown

See original GitHub issue

Summary

CONNECTED state forever when BluetoothGatt: android.os.DeadObjectException is thrown

My code in below:

   private static final UUID characteristicUuid = UUID.fromString("25A80001-6478-11E6-BDF4-AD3BCC77759F");

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_example4);
        ButterKnife.bind(this);
        bleDevice = SampleApplication.getRxBleClient(this).getBleDevice(macAddress);
        connectionObservable = prepareConnectionObservable();
        bleDevice.observeConnectionStateChanges().subscribe(state -> {
            Log.i(getClass().getSimpleName(), "" + state.toString());
        });
        connect();
    }

    private Observable<RxBleConnection> prepareConnectionObservable() {
        return bleDevice
                .establishConnection(false)
                .takeUntil(disconnectTriggerSubject)
                .compose(bindUntilEvent(PAUSE))
                .compose(new ConnectionSharingAdapter());
    }

    @OnClick(R.id.connect)
    public void connect() {
        connectionObservable.flatMap(RxBleConnection::discoverServices)
                .flatMap(rxBleDeviceServices -> rxBleDeviceServices.getCharacteristic(characteristicUuid))
                .observeOn(AndroidSchedulers.mainThread())
                .doOnSubscribe(() -> Log.i(getClass().getSimpleName(), "start connect "))
                .subscribe(
                        characteristic -> {
                            Log.i(getClass().getSimpleName(), "Hey, connection has been established!");
                        },
                        this::onConnectionFailure,
                        this::onConnectionFinished
                );
    }

   @OnClick(R.id.dissconnect)
    public void triggerDisconnect() {
        disconnectTriggerSubject.onNext(null);
    }

     @OnClick(R.id.read_rssi)
    public void readRSSI() {
        if (bleDevice.getConnectionState() != RxBleConnection.RxBleConnectionState.CONNECTED) {
            return;
        }
        connectionObservable.flatMap(rxBleConnection -> rxBleConnection.readRssi())
                .subscribe(rssi -> {
                    Log.i(getClass().getSimpleName(), "RSSI = " + rssi);
                }, throwable -> {
                    Log.i(getClass().getSimpleName(), "Connection error: " + throwable);
                });
    }
  • Sometime, when Bluetooth in phone is crashed => I call readRSSI => BluetoothGatt: android.os.DeadObjectException is thrown. But RxBleDevice#getConnectionState() return RxBleConnectionState{CONNECTED}.
  • When call readRSSI again, BluetoothGatt: android.os.DeadObjectException still thown.
  • After, I call triggerDisconnect() method => connect() method=> try to readRSSI, and it work fine.

Actual result

BluetoothGatt: android.os.DeadObjectException is thown Please see log:

09-01 11:49:24.135 13204-13304/com.mysoftsource.vuzitech D/RxBle#Radio:   QUEUED RxBleRadioOperationReadRssi(28807445)
09-01 11:49:24.136 13204-13302/com.mysoftsource.vuzitech D/RxBle#Radio:  STARTED RxBleRadioOperationReadRssi(28807445)
09-01 11:49:24.138 13204-13204/com.mysoftsource.vuzitech D/BluetoothGatt: readRssi() - device: F7:A2:68:4B:DA:D3
09-01 11:49:24.139 13204-13204/com.mysoftsource.vuzitech E/BluetoothGatt: android.os.DeadObjectException
                                                                              at android.os.BinderProxy.transactNative(Native Method)
                                                                              at android.os.BinderProxy.transact(Binder.java:615)
                                                                              at android.bluetooth.IBluetoothGatt$Stub$Proxy.readRemoteRssi(IBluetoothGatt.java:1006)
                                                                              at android.bluetooth.BluetoothGatt.readRemoteRssi(BluetoothGatt.java:1121)
                                                                              at com.polidea.rxandroidble.internal.operations.RxBleRadioOperationReadRssi.startOperation(RxBleRadioOperationReadRssi.java:30)
                                                                              at com.polidea.rxandroidble.internal.RxBleSingleGattRadioOperation.protectedRun(RxBleSingleGattRadioOperation.java:56)
                                                                              at com.polidea.rxandroidble.internal.RxBleRadioOperation$1.call(RxBleRadioOperation.java:39)
                                                                              at com.polidea.rxandroidble.internal.RxBleRadioOperation$1.call(RxBleRadioOperation.java:35)
                                                                              at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:72)
                                                                              at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:32)
                                                                              at rx.Observable.unsafeSubscribe(Observable.java:10256)
                                                                              at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
                                                                              at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:107)
                                                                              at android.os.Handler.handleCallback(Handler.java:751)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                              at android.os.Looper.loop(Looper.java:154)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6126)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
09-01 11:49:24.141 13204-13302/com.mysoftsource.vuzitech D/RxBle#Radio: FINISHED RxBleRadioOperationReadRssi(28807445)
09-01 11:49:25.134 13204-13304/com.mysoftsource.vuzitech D/RxBle#Radio:   QUEUED RxBleRadioOperationReadRssi(189325052)
09-01 11:49:25.136 13204-13302/com.mysoftsource.vuzitech D/RxBle#Radio:  STARTED RxBleRadioOperationReadRssi(189325052)
09-01 11:49:25.138 13204-13204/com.mysoftsource.vuzitech D/BluetoothGatt: readRssi() - device: F7:A2:68:4B:DA:D3
09-01 11:49:25.140 13204-13204/com.mysoftsource.vuzitech E/BluetoothGatt: android.os.DeadObjectException
                                                                              at android.os.BinderProxy.transactNative(Native Method)
                                                                              at android.os.BinderProxy.transact(Binder.java:615)
                                                                              at android.bluetooth.IBluetoothGatt$Stub$Proxy.readRemoteRssi(IBluetoothGatt.java:1006)
                                                                              at android.bluetooth.BluetoothGatt.readRemoteRssi(BluetoothGatt.java:1121)
                                                                              at com.polidea.rxandroidble.internal.operations.RxBleRadioOperationReadRssi.startOperation(RxBleRadioOperationReadRssi.java:30)
                                                                              at com.polidea.rxandroidble.internal.RxBleSingleGattRadioOperation.protectedRun(RxBleSingleGattRadioOperation.java:56)
                                                                              at com.polidea.rxandroidble.internal.RxBleRadioOperation$1.call(RxBleRadioOperation.java:39)
                                                                              at com.polidea.rxandroidble.internal.RxBleRadioOperation$1.call(RxBleRadioOperation.java:35)
                                                                              at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:72)
                                                                              at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:32)
                                                                              at rx.Observable.unsafeSubscribe(Observable.java:10256)
                                                                              at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
                                                                              at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:107)
                                                                              at android.os.Handler.handleCallback(Handler.java:751)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                              at android.os.Looper.loop(Looper.java:154)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6126)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
09-01 11:49:25.141 13204-13302/com.mysoftsource.vuzitech D/RxBle#Radio: FINISHED RxBleRadioOperationReadRssi(189325052)

Expected result

When BluetoothGatt: android.os.DeadObjectException is thrown => call disconnect and shown DISCONNECTED state

Library version

1.3.3

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
dariuszseweryncommented, Sep 12, 2017

I will probably try to release it tomorrow.

0reactions
omeryounuscommented, Feb 11, 2020

I have seen this exception happening on some low end Android phones when calling gatt.disconnect method i:e - E/BluetoothGatt: android.os.DeadObjectException I am sure if there is any properly handling in library that would prevent it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RxBle is not show disconnected when BluetoothGatt: android ...
Summary CONNECTED state forever when BluetoothGatt: android.os.DeadObjectException is thrown My code in below: private static final UUID ...
Read more >
How to solve the BluetoothGatt : android.os ... - Stack Overflow
I solved this by disconnecting, closing the Gatt and stopping the service and then restart it again: mBluetoothLeService.disconnect(); ...
Read more >
BluetoothGatt - Android Developers
This class provides Bluetooth GATT functionality to enable communication with ... Health Device Profile (HDP) and MCAP protocol are no longer used.
Read more >
Bluetooth Low Energy: DeadObjectException at com.android ...
Hello! I have experienced a problem with Bluetooth Low-Energy. I am developing Android application which collects data from multiple BLE sensors.
Read more >
RxBLELibraries/RxAndroidBle - Gitter
Hello, I have a potentially silly question... After connecting to a BLE device, how do you disconnect? Unsubscribing the connection subscription seems to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found