From: Jakub Pawlowski Date: Wed, 17 May 2017 22:23:22 +0000 (-0700) Subject: Protect concurrent access to local state used during BLE scanning X-Git-Tag: android-x86-9.0-r1~473^2^2~20 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=235e738f20;p=android-x86%2Fsystem-bt.git 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) --- diff --git a/btif/src/btif_ble_scanner.cc b/btif/src/btif_ble_scanner.cc index 2e24ecc6d..162935b79 100644 --- a/btif/src/btif_ble_scanner.cc +++ b/btif/src/btif_ble_scanner.cc @@ -83,6 +83,7 @@ struct equal_to { namespace { +// all access to this variable should be done on the jni thread std::unordered_set p_dev_cb; void btif_gattc_add_remote_bdaddr(BD_ADDR p_bda, uint8_t addr_type) { @@ -258,15 +259,20 @@ class BleScannerInterfaceImpl : public BleScannerInterface { } void Scan(bool start) override { - if (!start) { - do_in_bta_thread(FROM_HERE, Bind(&BTA_DmBleObserve, false, 0, nullptr)); - return; - } - - btif_gattc_init_dev_cb(); - do_in_bta_thread(FROM_HERE, - Bind(&BTA_DmBleObserve, true, 0, - (tBTA_DM_SEARCH_CBACK*)bta_scan_results_cb)); + do_in_jni_thread(Bind( + [](bool start) { + if (!start) { + do_in_bta_thread(FROM_HERE, + Bind(&BTA_DmBleObserve, false, 0, nullptr)); + return; + } + + btif_gattc_init_dev_cb(); + do_in_bta_thread(FROM_HERE, + Bind(&BTA_DmBleObserve, true, 0, + (tBTA_DM_SEARCH_CBACK*)bta_scan_results_cb)); + }, + start)); } void ScanFilterParamSetup(