I am communicating with a BLE device that sends me lots of data via one characteristic. The same Characteristic is used to send data to the device.
Inside Androids
In SDK27, the onNotify() callback function in BluetoothGatt.java was updated to call BOTH BluetoothGattCharacteristic.setValue() and BluetoothGattCallback.onCharacteristicChanged() in the Runnable's run().
This change allows us to force all calls to BluetoothGattCharacteristic.setValue() - both for our outbound writing to the characteristic and the inbound notifications - onto the same thread, which eliminates the race condition corrupting the BluetoothGattCharacteristic.mValue;
HandlerThreadHandler attached to your HandlerThreadHandler into BluetoothDevice.connectGatt() - congratulations, when a notify is received the setValue() and onCharacteristicChanged() will be called on your HandlerThread.setValue() and writeCharacteristic() to your HandlerThread via your HandlerNow all the function calls that were involved in the race condition are being executed on the same thread, eliminating the race condition.