This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Android Secure DFU and bonds

We've been having issues getting DFU to complete consistently with Android devices when using a two-step DFU package (BL+SD and App). Some devices seem to have far less trouble than others. The newer Samsung devices tend to work pretty reliably for us, but Pixel devices are particularly bad.
We initate DFU through the DfuServiceInitiator and setKeepBond(true) and are using the SecureDfu implementation.
On all devices we tend to see pretty regular errors: DEVICE DISCONNECTED, GATT INVALID HANDLE, GATT WRITE NOT PERMIT. Often, retrying a couple of times will fix the problem but on the Pixel devices the GATT WRITE NOT PERMIT does not resolve itself. The only way we've been able to successfully fix it is to call the BluetoothDevice.removeBond() function via reflection.
After removing the bond we can pretty consistently initate the DFU of the bootloader. As the device switches from bootloader over to app we often start seeing the GATT WRITE NOT PERMIT errors again. If we removeBonds again
then we are able to successfully complete the DFU.
We also tried forcing a BluetoothGatt.refresh() (through reflection) to see if that resolved the issue but we didn't see any improved behavior. The only thing that lets us successfully DFU is removeBond().
How can we avoid removing the bonds every time we DFU?
We are using DFU library 1.7, and the issue happened with 1.6 as well. We notice that the latest nRF Connect app seems much more stable (often completes with clean logs), is it based on a newer library?
On the firmware side, we see this issue with SDK14 and SDK15, secure buttonless bootloader, with supports-bonds in app, and requires-bonds in bootloader.
Thanks,
Brian
Related