Chromium Code Reviews
Descriptionbluetooth: Post a task when sending GATT events to simulate another thread.
On Android, Bluetooth GATT events arrive on a different thread so we post
them on the UI thread when they arrive. There have been a couple of bugs
where multiple events arrive at the same time so when the task on the
UI thread runs, it runs with invalid information.
To simulate this behavior we wrap ThreadUtils in ThreadUtilsWrapper and
in tests always post a task. For example:
SimulateGattCharacteristicValueChanged(std::vector<uint8_t>({1, 2}));
SimulateGattCharacteristicValueChanged(std::vector<uint8_t>({2, 1}));
base::RunLoop().RunUntilIdle();
In this case the first SimulateGattCharacteristicValueChanged() sets
characteristic's value to {1, 2} then posts a task to notify the clients.
Then the second SimulateGattCharacteristicValueChanged() gets called and
sets the characteritic's value to {2, 1} and posts a task to notify the
clients. When the first posted task runs it sees the value is {2, 1} and
notifies of this value. Which is incorrect.
The first of a set of patches to fix race conditions in Android:
[1] Post a task when sending GATT events. (This patch).
[2.1] Close and null out BluetoothGatt on the UI Thread http://crrev.com/2702163002
[2.2] Copy characteristic's value before posting task http://crrev.com/2707823002
BUG=691407
Review-Url: https://codereview.chromium.org/2708513002
Cr-Commit-Position: refs/heads/master@{#455034}
Committed: https://chromium.googlesource.com/chromium/src/+/9409d055c1933a95f40b7fb2ff08fa26a97f4e08
Patch Set 1 #
Total comments: 2
Patch Set 2 : Remove unnecessary if statement #Dependent Patchsets: Messages
Total messages: 19 (13 generated)
|