system/bt
Revision | 235e738f20c7c3c52828ff7ec1789be7237b6999 (tree) |
---|---|
Zeit | 2017-05-18 15:26:18 |
Autor | Jakub Pawlowski <jpawlowski@goog...> |
Commiter | Jakub Pawlowski |
Protect concurrent access to local state used during BLE scanning
Make sure that all access happens on jni thread
Bug: 38298938
Test: Code compilation
Change-Id: I38246626d2c6390586b314b27889dd9ba905f406
(cherry picked from commit eb43e9cf12139aeb227e26a8201a80974129c553)
@@ -83,6 +83,7 @@ struct equal_to<bt_bdaddr_t> { | ||
83 | 83 | |
84 | 84 | namespace { |
85 | 85 | |
86 | +// all access to this variable should be done on the jni thread | |
86 | 87 | std::unordered_set<bt_bdaddr_t> p_dev_cb; |
87 | 88 | |
88 | 89 | void btif_gattc_add_remote_bdaddr(BD_ADDR p_bda, uint8_t addr_type) { |
@@ -258,15 +259,20 @@ class BleScannerInterfaceImpl : public BleScannerInterface { | ||
258 | 259 | } |
259 | 260 | |
260 | 261 | void Scan(bool start) override { |
261 | - if (!start) { | |
262 | - do_in_bta_thread(FROM_HERE, Bind(&BTA_DmBleObserve, false, 0, nullptr)); | |
263 | - return; | |
264 | - } | |
265 | - | |
266 | - btif_gattc_init_dev_cb(); | |
267 | - do_in_bta_thread(FROM_HERE, | |
268 | - Bind(&BTA_DmBleObserve, true, 0, | |
269 | - (tBTA_DM_SEARCH_CBACK*)bta_scan_results_cb)); | |
262 | + do_in_jni_thread(Bind( | |
263 | + [](bool start) { | |
264 | + if (!start) { | |
265 | + do_in_bta_thread(FROM_HERE, | |
266 | + Bind(&BTA_DmBleObserve, false, 0, nullptr)); | |
267 | + return; | |
268 | + } | |
269 | + | |
270 | + btif_gattc_init_dev_cb(); | |
271 | + do_in_bta_thread(FROM_HERE, | |
272 | + Bind(&BTA_DmBleObserve, true, 0, | |
273 | + (tBTA_DM_SEARCH_CBACK*)bta_scan_results_cb)); | |
274 | + }, | |
275 | + start)); | |
270 | 276 | } |
271 | 277 | |
272 | 278 | void ScanFilterParamSetup( |