removeBond() is called like removeBond().then(callback).enqueue() for checking the bond state after remove bond. and there are two different behaviors after that.
- sometimes
Connection state changed is logged and onServicesInvalidated is invoked, BOND_STATE_CHANGED is not logged and removeBond callback is not invoked.
V/nordic-lib: Removing bond information...
D/nordic-lib: device.removeBond() (hidden)
D/nordic-lib: [Callback] Connection state changed with status: 0 and new state: 0 (DISCONNECTED)
I/nordic-lib: Disconnected
D/nordic-lib: gatt.close()
D/ble-manager: onServicesInvalidated # self-defined ble manager
- sometimes
BOND_STATE_CHANGED is received and onServicesInvalidated is not invoked.
V/nordic-lib: Removing bond information...
D/nordic-lib: device.removeBond() (hidden)
D/nordic-lib: [Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_NONE (10)
I/nordic-lib: Bond information removed
D/nordic-lib: gatt.close()
D/viewmodel: removeBond callback:F2:0F:0E:FB:CD:DF state:10 # self-defined view model
in the 1st situation, though the removeBond callback is not invoked, we known the device is disconnected and can reconnect the device as designed.
in the 2nd situation, because gatt.close() is called but onServicesInvalidated() is not invoked, we don't known the device is actually disconnected, it leads to some mistake. we have to check connection state again in removeBond callback. I think it should not be a expected result.
after check the source code in nordic ble library, this problem may relate to issue #157. if i remove close() call in BleManagerHandler.java for #157, logs remain same when 1st situation occurs. but for the 2nd one, Connection state changed can be received and onServicesInvalidated is invoked, and the connection state can be well handled.
V/nordic-lib: Removing bond information...
D/nordic-lib: device.removeBond() (hidden)
D/nordic-lib: [Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_NONE (10)
I/nordic-lib: Bond information removed
D/viewmodel: removeBond callback:F2:0F:0E:FB:CD:DF state:10
D/nordic-lib: [Callback] Connection state changed with status: 0 and new state: 0 (DISCONNECTED)
I/nordic-lib: Disconnected
D/nordic-lib: gatt.close()
D/ble-manager: onServicesInvalidated
removeBond()is called likeremoveBond().then(callback).enqueue()for checking the bond state after remove bond. and there are two different behaviors after that.Connection state changedis logged andonServicesInvalidatedis invoked,BOND_STATE_CHANGEDis not logged and removeBond callback is not invoked.BOND_STATE_CHANGEDis received andonServicesInvalidatedis not invoked.in the 1st situation, though the removeBond callback is not invoked, we known the device is disconnected and can reconnect the device as designed.
in the 2nd situation, because
gatt.close()is called butonServicesInvalidated()is not invoked, we don't known the device is actually disconnected, it leads to some mistake. we have to check connection state again in removeBond callback. I think it should not be a expected result.after check the source code in nordic ble library, this problem may relate to issue #157. if i remove
close()call inBleManagerHandler.javafor #157, logs remain same when 1st situation occurs. but for the 2nd one,Connection state changedcan be received andonServicesInvalidatedis invoked, and the connection state can be well handled.