Loading system/btif/src/btif_ble_scanner.cc +6 −1 Original line number Diff line number Diff line Loading @@ -206,7 +206,8 @@ void bta_cback(tBTA_GATTC_EVT, tBTA_GATTC*) {} class BleScannerInterfaceImpl : public BleScannerInterface { ~BleScannerInterfaceImpl() override{}; void RegisterScanner(RegisterCallback cb) override { void RegisterScanner(const bluetooth::Uuid& app_uuid, RegisterCallback cb) override { do_in_main_thread(FROM_HERE, Bind( [](RegisterCallback cb) { Loading Loading @@ -333,6 +334,10 @@ class BleScannerInterfaceImpl : public BleScannerInterface { SyncLostCb lost_cb) override {} void StopSync(uint16_t handle) override {} void RegisterCallbacks(ScanningCallbacks* callbacks) { // For GD only } }; BleScannerInterface* btLeScannerInstance = nullptr; Loading system/gd/hci/le_scanning_manager.cc +9 −0 Original line number Diff line number Diff line Loading @@ -207,6 +207,10 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback } } void register_scanning_callback(ScanningCallback* scanning_callbacks) { scanning_callbacks_ = scanning_callbacks; } void OnPause() override { cached_registered_callback_ = registered_callback_; stop_scan(common::Bind(&impl::ack_pause, common::Unretained(this)), true); Loading Loading @@ -236,6 +240,7 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback hci::LeScanningInterface* le_scanning_interface_; hci::LeAddressManager* le_address_manager_; bool address_manager_registered = false; ScanningCallback* scanning_callbacks_ = nullptr; uint32_t interval_ms_{1000}; uint16_t window_ms_{1000}; Loading Loading @@ -306,5 +311,9 @@ void LeScanningManager::StopScan(common::Callback<void()> on_stopped) { GetHandler()->Post(common::Bind(&impl::stop_scan, common::Unretained(pimpl_.get()), on_stopped, false)); } void LeScanningManager::RegisterScanningCallback(ScanningCallback* scanning_callback) { CallOn(pimpl_.get(), &impl::register_scanning_callback, scanning_callback); } } // namespace hci } // namespace bluetooth system/gd/hci/le_scanning_manager.h +23 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "common/callback.h" #include "hci/hci_packets.h" #include "hci/le_report.h" #include "hci/uuid.h" #include "module.h" namespace bluetooth { Loading @@ -33,6 +34,26 @@ class LeScanningManagerCallbacks { virtual os::Handler* Handler() = 0; }; class ScanningCallback { public: virtual ~ScanningCallback() = default; virtual void OnScannerRegistered(const bluetooth::hci::Uuid app_uuid, uint8_t scanner_id, uint8_t status) = 0; virtual void OnScanResult( uint16_t event_type, uint8_t addr_type, Address* bda, uint8_t primary_phy, uint8_t secondary_phy, uint8_t advertising_sid, int8_t tx_power, int8_t rssi, uint16_t periodic_adv_int, std::vector<uint8_t> adv_data) = 0; virtual void OnTrackAdvFoundLost() = 0; virtual void OnBatchScanReports( int client_if, int status, int report_format, int num_records, std::vector<uint8_t> data) = 0; }; class LeScanningManager : public bluetooth::Module { public: LeScanningManager(); Loading @@ -41,6 +62,8 @@ class LeScanningManager : public bluetooth::Module { void StopScan(common::Callback<void()> on_stopped); void RegisterScanningCallback(ScanningCallback* scanning_callback); static const ModuleFactory Factory; protected: Loading system/include/hardware/ble_scanner.h +27 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #ifndef ANDROID_INCLUDE_BLE_SCANNER_H #define ANDROID_INCLUDE_BLE_SCANNER_H #include <bluetooth/uuid.h> #include <stdint.h> #include <vector> #include "bt_common_types.h" Loading Loading @@ -50,6 +51,28 @@ typedef struct { track_adv_event_callback track_adv_event_cb; } btgatt_scanner_callbacks_t; /** * LE Scanning related callbacks invoked from from the Bluetooth native stack * All callbacks are invoked on the JNI thread */ class ScanningCallbacks { public: virtual ~ScanningCallbacks() = default; virtual void OnScannerRegistered(const bluetooth::Uuid app_uuid, uint8_t scannerId, uint8_t status) = 0; virtual void OnScanResult(uint16_t event_type, uint8_t addr_type, RawAddress* bda, uint8_t primary_phy, uint8_t secondary_phy, uint8_t advertising_sid, int8_t tx_power, int8_t rssi, uint16_t periodic_adv_int, std::vector<uint8_t> adv_data) = 0; virtual void OnTrackAdvFoundLost( btgatt_track_adv_info_t* p_adv_track_info) = 0; virtual void OnBatchScanReports(int client_if, int status, int report_format, int num_records, std::vector<uint8_t> data) = 0; }; class BleScannerInterface { public: virtual ~BleScannerInterface() = default; Loading @@ -71,7 +94,8 @@ class BleScannerInterface { uint8_t /* action */, uint8_t /* status */)>; /** Registers a scanner with the stack */ virtual void RegisterScanner(RegisterCallback) = 0; virtual void RegisterScanner(const bluetooth::Uuid& app_uuid, RegisterCallback) = 0; /** Unregister a scanner from the stack */ virtual void Unregister(int scanner_id) = 0; Loading Loading @@ -128,6 +152,8 @@ class BleScannerInterface { uint16_t timeout, StartSyncCb start_cb, SyncReportCb report_cb, SyncLostCb lost_cb) = 0; virtual void StopSync(uint16_t handle) = 0; virtual void RegisterCallbacks(ScanningCallbacks* callbacks) = 0; }; #endif /* ANDROID_INCLUDE_BLE_SCANNER_H */ No newline at end of file system/main/shim/le_scanning_manager.cc +35 −3 Original line number Diff line number Diff line Loading @@ -20,17 +20,26 @@ #include <base/bind.h> #include <base/threading/thread.h> #include <hardware/bluetooth.h> #include <stdio.h> #include <unordered_set> class BleScannerInterfaceImpl : public BleScannerInterface { #include "btif_common.h" #include "gd/hci/address.h" #include "gd/hci/le_scanning_manager.h" #include "main/shim/entry.h" class BleScannerInterfaceImpl : public BleScannerInterface, public bluetooth::hci::ScanningCallback { public: ~BleScannerInterfaceImpl() override{}; void Init() { bluetooth::shim::GetScanning()->RegisterScanningCallback(this); } /** Registers a scanner with the stack */ void RegisterScanner(RegisterCallback) { void RegisterScanner(const bluetooth::Uuid& uuid, RegisterCallback) { LOG(INFO) << __func__ << " in shim layer"; } Loading Loading @@ -104,6 +113,25 @@ class BleScannerInterfaceImpl : public BleScannerInterface { LOG(INFO) << __func__ << " in shim layer"; // This function doesn't implement in the old stack } void RegisterCallbacks(ScanningCallbacks* callbacks) { LOG(INFO) << __func__ << " in shim layer"; scanning_callbacks_ = callbacks; } void OnScannerRegistered(const bluetooth::hci::Uuid app_uuid, uint8_t scanner_id, uint8_t status){}; void OnScanResult(uint16_t event_type, uint8_t addr_type, bluetooth::hci::Address* bda, uint8_t primary_phy, uint8_t secondary_phy, uint8_t advertising_sid, int8_t tx_power, int8_t rssi, uint16_t periodic_adv_int, std::vector<uint8_t> adv_data){}; void OnTrackAdvFoundLost(){}; void OnBatchScanReports(int client_if, int status, int report_format, int num_records, std::vector<uint8_t> data){}; ScanningCallbacks* scanning_callbacks_; }; BleScannerInterfaceImpl* bt_le_scanner_instance = nullptr; Loading @@ -114,3 +142,7 @@ BleScannerInterface* bluetooth::shim::get_ble_scanner_instance() { } return bt_le_scanner_instance; } void bluetooth::shim::init_scanning_manager() { bt_le_scanner_instance->Init(); } No newline at end of file Loading
system/btif/src/btif_ble_scanner.cc +6 −1 Original line number Diff line number Diff line Loading @@ -206,7 +206,8 @@ void bta_cback(tBTA_GATTC_EVT, tBTA_GATTC*) {} class BleScannerInterfaceImpl : public BleScannerInterface { ~BleScannerInterfaceImpl() override{}; void RegisterScanner(RegisterCallback cb) override { void RegisterScanner(const bluetooth::Uuid& app_uuid, RegisterCallback cb) override { do_in_main_thread(FROM_HERE, Bind( [](RegisterCallback cb) { Loading Loading @@ -333,6 +334,10 @@ class BleScannerInterfaceImpl : public BleScannerInterface { SyncLostCb lost_cb) override {} void StopSync(uint16_t handle) override {} void RegisterCallbacks(ScanningCallbacks* callbacks) { // For GD only } }; BleScannerInterface* btLeScannerInstance = nullptr; Loading
system/gd/hci/le_scanning_manager.cc +9 −0 Original line number Diff line number Diff line Loading @@ -207,6 +207,10 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback } } void register_scanning_callback(ScanningCallback* scanning_callbacks) { scanning_callbacks_ = scanning_callbacks; } void OnPause() override { cached_registered_callback_ = registered_callback_; stop_scan(common::Bind(&impl::ack_pause, common::Unretained(this)), true); Loading Loading @@ -236,6 +240,7 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback hci::LeScanningInterface* le_scanning_interface_; hci::LeAddressManager* le_address_manager_; bool address_manager_registered = false; ScanningCallback* scanning_callbacks_ = nullptr; uint32_t interval_ms_{1000}; uint16_t window_ms_{1000}; Loading Loading @@ -306,5 +311,9 @@ void LeScanningManager::StopScan(common::Callback<void()> on_stopped) { GetHandler()->Post(common::Bind(&impl::stop_scan, common::Unretained(pimpl_.get()), on_stopped, false)); } void LeScanningManager::RegisterScanningCallback(ScanningCallback* scanning_callback) { CallOn(pimpl_.get(), &impl::register_scanning_callback, scanning_callback); } } // namespace hci } // namespace bluetooth
system/gd/hci/le_scanning_manager.h +23 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "common/callback.h" #include "hci/hci_packets.h" #include "hci/le_report.h" #include "hci/uuid.h" #include "module.h" namespace bluetooth { Loading @@ -33,6 +34,26 @@ class LeScanningManagerCallbacks { virtual os::Handler* Handler() = 0; }; class ScanningCallback { public: virtual ~ScanningCallback() = default; virtual void OnScannerRegistered(const bluetooth::hci::Uuid app_uuid, uint8_t scanner_id, uint8_t status) = 0; virtual void OnScanResult( uint16_t event_type, uint8_t addr_type, Address* bda, uint8_t primary_phy, uint8_t secondary_phy, uint8_t advertising_sid, int8_t tx_power, int8_t rssi, uint16_t periodic_adv_int, std::vector<uint8_t> adv_data) = 0; virtual void OnTrackAdvFoundLost() = 0; virtual void OnBatchScanReports( int client_if, int status, int report_format, int num_records, std::vector<uint8_t> data) = 0; }; class LeScanningManager : public bluetooth::Module { public: LeScanningManager(); Loading @@ -41,6 +62,8 @@ class LeScanningManager : public bluetooth::Module { void StopScan(common::Callback<void()> on_stopped); void RegisterScanningCallback(ScanningCallback* scanning_callback); static const ModuleFactory Factory; protected: Loading
system/include/hardware/ble_scanner.h +27 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #ifndef ANDROID_INCLUDE_BLE_SCANNER_H #define ANDROID_INCLUDE_BLE_SCANNER_H #include <bluetooth/uuid.h> #include <stdint.h> #include <vector> #include "bt_common_types.h" Loading Loading @@ -50,6 +51,28 @@ typedef struct { track_adv_event_callback track_adv_event_cb; } btgatt_scanner_callbacks_t; /** * LE Scanning related callbacks invoked from from the Bluetooth native stack * All callbacks are invoked on the JNI thread */ class ScanningCallbacks { public: virtual ~ScanningCallbacks() = default; virtual void OnScannerRegistered(const bluetooth::Uuid app_uuid, uint8_t scannerId, uint8_t status) = 0; virtual void OnScanResult(uint16_t event_type, uint8_t addr_type, RawAddress* bda, uint8_t primary_phy, uint8_t secondary_phy, uint8_t advertising_sid, int8_t tx_power, int8_t rssi, uint16_t periodic_adv_int, std::vector<uint8_t> adv_data) = 0; virtual void OnTrackAdvFoundLost( btgatt_track_adv_info_t* p_adv_track_info) = 0; virtual void OnBatchScanReports(int client_if, int status, int report_format, int num_records, std::vector<uint8_t> data) = 0; }; class BleScannerInterface { public: virtual ~BleScannerInterface() = default; Loading @@ -71,7 +94,8 @@ class BleScannerInterface { uint8_t /* action */, uint8_t /* status */)>; /** Registers a scanner with the stack */ virtual void RegisterScanner(RegisterCallback) = 0; virtual void RegisterScanner(const bluetooth::Uuid& app_uuid, RegisterCallback) = 0; /** Unregister a scanner from the stack */ virtual void Unregister(int scanner_id) = 0; Loading Loading @@ -128,6 +152,8 @@ class BleScannerInterface { uint16_t timeout, StartSyncCb start_cb, SyncReportCb report_cb, SyncLostCb lost_cb) = 0; virtual void StopSync(uint16_t handle) = 0; virtual void RegisterCallbacks(ScanningCallbacks* callbacks) = 0; }; #endif /* ANDROID_INCLUDE_BLE_SCANNER_H */ No newline at end of file
system/main/shim/le_scanning_manager.cc +35 −3 Original line number Diff line number Diff line Loading @@ -20,17 +20,26 @@ #include <base/bind.h> #include <base/threading/thread.h> #include <hardware/bluetooth.h> #include <stdio.h> #include <unordered_set> class BleScannerInterfaceImpl : public BleScannerInterface { #include "btif_common.h" #include "gd/hci/address.h" #include "gd/hci/le_scanning_manager.h" #include "main/shim/entry.h" class BleScannerInterfaceImpl : public BleScannerInterface, public bluetooth::hci::ScanningCallback { public: ~BleScannerInterfaceImpl() override{}; void Init() { bluetooth::shim::GetScanning()->RegisterScanningCallback(this); } /** Registers a scanner with the stack */ void RegisterScanner(RegisterCallback) { void RegisterScanner(const bluetooth::Uuid& uuid, RegisterCallback) { LOG(INFO) << __func__ << " in shim layer"; } Loading Loading @@ -104,6 +113,25 @@ class BleScannerInterfaceImpl : public BleScannerInterface { LOG(INFO) << __func__ << " in shim layer"; // This function doesn't implement in the old stack } void RegisterCallbacks(ScanningCallbacks* callbacks) { LOG(INFO) << __func__ << " in shim layer"; scanning_callbacks_ = callbacks; } void OnScannerRegistered(const bluetooth::hci::Uuid app_uuid, uint8_t scanner_id, uint8_t status){}; void OnScanResult(uint16_t event_type, uint8_t addr_type, bluetooth::hci::Address* bda, uint8_t primary_phy, uint8_t secondary_phy, uint8_t advertising_sid, int8_t tx_power, int8_t rssi, uint16_t periodic_adv_int, std::vector<uint8_t> adv_data){}; void OnTrackAdvFoundLost(){}; void OnBatchScanReports(int client_if, int status, int report_format, int num_records, std::vector<uint8_t> data){}; ScanningCallbacks* scanning_callbacks_; }; BleScannerInterfaceImpl* bt_le_scanner_instance = nullptr; Loading @@ -114,3 +142,7 @@ BleScannerInterface* bluetooth::shim::get_ble_scanner_instance() { } return bt_le_scanner_instance; } void bluetooth::shim::init_scanning_manager() { bt_le_scanner_instance->Init(); } No newline at end of file