Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Disconnect devices button doesn't disconnect #58

Open
beaufortfrancois opened this issue Jan 8, 2016 · 9 comments
Open

Disconnect devices button doesn't disconnect #58

beaufortfrancois opened this issue Jan 8, 2016 · 9 comments

Comments

@beaufortfrancois
Copy link
Member

Calling mGattServer.cancelConnection(device); doesn't disconnect device as I've observed in btmon and adb logs when tapping "Disconnect devices" button.
Moreover, onConnectionStateChange is not called which means "Devices connected" text is not updated.

@g-ortuno

@g-ortuno
Copy link
Contributor

Do you have some reproduction steps? What device did you connect with?

@beaufortfrancois
Copy link
Member Author

I'll be more detailed tomorrow.
My device is a Nexus 5X.

@beaufortfrancois
Copy link
Member Author

  1. [chromebook] Go to https://googlechrome.github.io/samples/web-bluetooth/battery-level.html
  2. [Nexus 5X] Open BLE Peripheral Simulator
  3. [Nexus 5X] Select "Battery"
  4. [chromebook] Click on "Get Bluetooth Device's Battery Level" button, pick device
  5. [chromebook] Battery level is read. It works!
  6. [Nexus 5X] Click on "Disconnect"
  7. [Nexus 5X] Device is disconnected. It works!
  8. [Nexus 5X] Move to background BLE Peripheral Simulator
  9. [Nexus 5X] Restore BLE Peripheral Simulator
  10. [chromebook] Click on "Get Bluetooth Device's Battery Level" button, pick device
  11. [chromebook] Battery level is read. It works!
  12. [Nexus 5X] Click on "Disconnect"
  13. [Nexus 5X] "Devices connected" count is not decreased. 😭

@beaufortfrancois
Copy link
Member Author

I'm still able to reproduce this sadly and I wish https://googlechrome.github.io/samples/web-bluetooth/device-disconnect.html would work with this app.

Code below isn't actually working as getConnectedDevices don't retrieve my connected BLE peripherals. I'm thinking about monitor connected & disconnected devices so that we can cancel connection manually instead.

  private void disconnectFromDevices() {
    Log.d(TAG, "Disconnecting devices...");
    for (BluetoothDevice device : mBluetoothManager.getConnectedDevices(
        BluetoothGattServer.GATT)) {
      Log.d(TAG, "Devices: " + device.getAddress() + " " + device.getName());
      mGattServer.cancelConnection(device);
    }
  }

WDYT @g-ortuno?

@g-ortuno
Copy link
Contributor

That's what we use to do but getConnectedDevices seemed like a better approach. We could work around the android bug but we should also report it.

@beaufortfrancois
Copy link
Member Author

It looks like getConnectedDevices has always been used. See ceadf8d#diff-9dee403cd7eefd5dbe7d5d5fe63816e2.
I'll definitely report this bug.

@beaufortfrancois
Copy link
Member Author

Looking at it more closely, I think that cancelConnection doesn't actually disconnect device. Calling getConnectedDevices() after that still returns the "cancelled connected devices".
This is why updateConnectedDevicesStatus should be updated as well.

@sonalchopra-vvdn
Copy link

cancelConnection doesn't really disconnect the device and it saved the connection state if we again go for ble connection. No Callback is received to central on calling above method.

@KrechkoMichael
Copy link

I faced with the same problem, cancelConnection() doesn't work. I have the issue when I want to connect with only one Central device, but if there are more devices ready to connect, Android generates few "onConnectionStateChanged" events before Advertising is really stopped. After that it's impossible to disconnect unwanted devices using cancelConnection()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants