flutter_reactive_ble icon indicating copy to clipboard operation
flutter_reactive_ble copied to clipboard

Proper workflow for performing device bonding

Open jhewitt opened this issue 3 years ago • 18 comments
trafficstars

I originally added this to an existing issue but believe it warrants more visibility. In addition to the existing Android 12 and security patch problems reported in other issues, we need to determine when a device bonding process has completed based on our observations below. This is not a problem on all iOS versions tested to date. We are encountering this problem on a Pixel 5 running Android 12.2 with all security patches applied.

The device we are attempting to bond with requires a PIN code which Android and iOS manage themselves. We have permissions handled but need a way to determine when bonding has completed. How do we determine using this PUB when to request services and set up characteristic notifications? We are encountering the following error when attempting this following the connected event, this same workflow works properly on all iOS versions tested to date. Note the error response to discovering services:

D/BluetoothAdapter(32345): isLeEnabled(): ON I/flutter (32345): D BluetoothServiceImpl._connectDevice: connecting 68A I/flutter (32345): D SmartLinkRepositoryImpl.connect: connect to device D/BluetoothGatt(32345): connect() - device: 00:A0:50:3E:A6:8A, auto: false D/BluetoothGatt(32345): registerApp() D/BluetoothGatt(32345): registerApp() - UUID=affa0af0-9efb-4c48-bec6-c8036b673079 I/flutter (32345): D SmartLinkRepositoryImpl._connectAndSubscribeToConnectionState.: ble connect state: ConnectionStateUpdate(deviceId: 00:A0:50:3E:A6:8A, connectionState: DeviceConnectionState.connecting, failure: null) D/BluetoothGatt(32345): onClientRegistered() - status=0 clientIf=9 D/BluetoothGatt(32345): onClientConnectionState() - status=0 clientIf=9 device=00:A0:50:3E:A6:8A I/flutter (32345): D SmartLinkRepositoryImpl._connectAndSubscribeToConnectionState.: ble connect state: ConnectionStateUpdate(deviceId: 00:A0:50:3E:A6:8A, connectionState: DeviceConnectionState.connected, failure: null) I/flutter (32345): D SmartLinkRepositoryImpl._subscribeToCharacteristics: ble Discovering Services I/flutter (32345): D SmartLinkRepositoryImpl._subscribeToCharacteristics: ble Error: PlatformException(service_discovery_failure, Bonding is in progress wait for bonding to be finished before executing more operations on the device, null, null) D/BluetoothGatt(32345): onConnectionUpdated() - Device=00:A0:50:3E:A6:8A interval=6 latency=0 timeout=500 status=0 D/BluetoothGatt(32345): onConnectionUpdated() - Device=00:A0:50:3E:A6:8A interval=36 latency=0 timeout=500 status=0 D/BluetoothGatt(32345): onClientConnectionState() - status=0 clientIf=9 device=00:A0:50:3E:A6:8A D/BluetoothGatt(32345): close() D/BluetoothGatt(32345): unregisterApp() - mClientIf=9

Originally posted by @jhewitt in https://github.com/PhilipsHue/flutter_reactive_ble/issues/530#issuecomment-1062937242

jhewitt avatar Mar 09 '22 13:03 jhewitt

I should mention that we have used this PUB successfully on other projects for both iOS and Android with devices that utilize the 'Just Works' pairing workflow.

jhewitt avatar Mar 11 '22 16:03 jhewitt

Understandable request and I agree this difficult without a method that make sure bonding is there. iOS doesn't have a mechanism to determine the bonding state but android does have it. Maybe we should consider exposing an extra check specifically for android where you can request the bonding state of the device. @Taym95 it goes a bit against our philosophy of not introducing platform specific methods. What are your thoughts? This is not the first issue in this area and bonding on Android works very differently

remonh87 avatar Mar 12 '22 15:03 remonh87

iOS and Android handle the bonding process differently. Typically Just-Works bonding takes place when the central device accesses a secure characteristic, at which time the OS takes over and performs BMS handshaking with the peripheral. Both Android and iOS delay the read or write response until BMS completes. When a device has all characteristics defined as secure, or when comparison, passkey or out of band workflows are used; this occurs during the connection process and iOS delays reporting the connect event until BMS is complete. The Android Bluetooth stack does not delay reporting of the connect event.

jhewitt avatar Mar 12 '22 18:03 jhewitt

Encountering this exact problem. Older phone and Android version, but the description is the same. Adding this to bump the issue.

petemillermultimedia avatar Mar 01 '23 17:03 petemillermultimedia

Exact same issue on Android.

invented-pro avatar Sep 09 '23 15:09 invented-pro

I have this problem on Android as well. I can't find a workaround or anything I can do to get through this error.

pzehle avatar Oct 23 '23 12:10 pzehle

I'm running into this issue as well.

chris-otani avatar Nov 21 '23 18:11 chris-otani

Same issue, maybe someone found how to solve it?

AurimassKl avatar Jan 05 '24 11:01 AurimassKl

Bump. Pixel 3XL with Android 12 on board, the same issue.

enseitankad0 avatar Mar 22 '24 10:03 enseitankad0

I got the same issue with Android.

marioalemn avatar Mar 28 '24 12:03 marioalemn

I've got the same issue with android. I'm trying to use a work around with flutter MethodChannel function calls, but I still haven't got it working exactly how I would like.

rowdy15 avatar Apr 26 '24 12:04 rowdy15