NordicSemiconductor / Android-BLE-Library

A library that makes working with Bluetooth LE on Android a pleasure. Seriously.
BSD 3-Clause "New" or "Revised" License
2.03k stars 417 forks source link

Write progress callback gets wrong values #496

Closed piefel closed 1 year ago

piefel commented 1 year ago

I use writeCharacteristic() and the default splitter with split() taking a WriteProgressCallback. The latter gets called with incorrect values.

With ble-ktx:2.4.1, the index started at 1, probably unintentionally. My guess is that WriteRequest::notifyPacketSent is the place. The callback is called, then the count is incremented, but since the callback is posted to the handler, it gets the new value.

With ble-ktx:2.6.1 (don’t know where it started exactly) the index is still off by one, but now the data is wrong, too. It does not show the values that were actually transmitted, but some data that happen to be in some buffer, which is actually the next chunk by that time. I lose the first chunk of data in my logs, I get the last chunk twice.

philips77 commented 1 year ago

Thank you for the bug report. We'll look into it. Sorry for the late response.

philips77 commented 1 year ago

Hi, I pushed a fix. I tried to find the reason of why you'd experience such behavior, and the only thing I can see is that the callback were posted on a handler looper, and could have values updated. The fix above stores the current values and makes sure they are returned.