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

Multiple connection and BLE notification callback in android on re-connection #246

Open
AnoopChatra opened this issue Aug 23, 2017 · 5 comments

Comments

@AnoopChatra
Copy link

commented Aug 23, 2017

The application is getting multiple connection call backs and redundant notifications after the re-connections.

Steps to reproduce

  1. Connect a BLE device with android application using :
    _adapter.ConnectToDeviceAsync(device, new ConnectParameters(true),
    reconnectCancelToken.Token);
    I have set the auto-connect parameter to true since i need the automatic re connection. Connection is successful, I will receive only one "BLE device connected" callback. All fine here.

2.Take the BLE device out of the bluetooth range. The BLE device disconnects from the app I receive only one "BLE device disconnected" callback . All fine here as well.

3.Bring the BLE device back in bluetooth range. App would automatically reconnects but I am getting 2
"BLE device connected" callbacks.

  1. Perform the step 2 and 3 for 'n' times then I am getting 'n' number of "connected and disconnected" callbacks. Multiple callback issue is observed in all sort of re connections.

  2. The same behavior is also observed with BLE notification callbacks.

I did some sort of debugging in Plugin.BLE.Android and I have some observations regarding the root cause of this problem -

  1. _gattCallback is one of the attribute of 'Device' class and it is been initialized in the constructor.

  2. _gattCallback is basically an instance of 'GattCallBack' which implements BluetoothGattCallback . So this instance contains the connection callback from android OS .

  3. _gattCallback should have initialized only once but when ever IDevice object is created new _gattCallback is getting created . usually in re-connection IDevice objects are initialized again.

  4. I believe this is the reason for multiple connection callback.

  5. We have the exact same problrm with BLE notification callbacks. Multiple notifications are revceived after reconnections.

  6. The BLE notification callbacks are also implemented in GattCallBack class(Ideally this call back should have implemented in a different class). So I believe this is the reason for multiple notification callback .

Expected behavior

Application should receive only one set of connection callbacks and only one set of BLE notifications.

Crashlog

Configuration

Version of the Plugin: 1.3.0 (Master branch)

Platform: Android 7.1

Device: Google Pixel

@smsissuechecker

This comment has been minimized.

Copy link

commented Aug 23, 2017

Hi @AnoopChatra,

I'm the friendly issue checker.
Thanks for using the issue template 🌟
I appreciate it very much. I'm sure, the maintainers of this repository will answer, soon.

@xabre

This comment has been minimized.

Copy link
Owner

commented Aug 29, 2017

@AnoopChatra You are right, this might happen. I have started working on the android auto connect #182 on a separate branch, but some stuff got in the way and I didn't get enough time to continue. This feature will only work reliably after the Android_AutoConect branch is implemented and merged.

@AnoopChatra

This comment has been minimized.

Copy link
Author

commented Sep 7, 2017

@xabre , when can we expect the stable release of 'Android_AutoConect branch' ?? We are highly dependant on Plugin BLE library. Could you please look in to the problem as soon as possible.

@xabre

This comment has been minimized.

Copy link
Owner

commented Sep 17, 2017

@AnoopChatra We will get to it as soon as we can, this is still an open source project for which we use our spare time to work on. If you can find an improvement/fix for this issue we can gladly merge you pull request :) Thanks

@AnoopChatra

This comment has been minimized.

Copy link
Author

commented Jan 18, 2018

@xabre , Is there any updates on the issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.