Commit 00d48218 authored by Tiansong Cui's avatar Tiansong Cui Committed by Commit Bot

[Chromecast][BLE] Implement SetScanParameters

Bug: internal b/140961065
Test: build and run, check HCI logs
Change-Id: I1fe5abbd21168b864b7d82e632a5c55f5927802d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1815724Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Commit-Queue: Tiansong Cui <tiansong@google.com>
Auto-Submit: Tiansong Cui <tiansong@google.com>
Cr-Commit-Position: refs/heads/master@{#699533}
parent 4191bf16
...@@ -63,6 +63,12 @@ class LeScanManager { ...@@ -63,6 +63,12 @@ class LeScanManager {
virtual void ClearScanResults() = 0; virtual void ClearScanResults() = 0;
virtual void PauseScan() {}
virtual void RestartScan() {}
virtual void SetScanParameters(int scan_interval_ms, int scan_window_ms) {}
protected: protected:
LeScanManager() = default; LeScanManager() = default;
virtual ~LeScanManager() = default; virtual ~LeScanManager() = default;
......
...@@ -117,6 +117,7 @@ void LeScanManagerImpl::ClearScanResults() { ...@@ -117,6 +117,7 @@ void LeScanManagerImpl::ClearScanResults() {
void LeScanManagerImpl::PauseScan() { void LeScanManagerImpl::PauseScan() {
MAKE_SURE_IO_THREAD(PauseScan); MAKE_SURE_IO_THREAD(PauseScan);
if (scan_handle_ids_.empty()) { if (scan_handle_ids_.empty()) {
LOG(ERROR) << "Can't pause scan, no scan handle";
return; return;
} }
...@@ -128,6 +129,7 @@ void LeScanManagerImpl::PauseScan() { ...@@ -128,6 +129,7 @@ void LeScanManagerImpl::PauseScan() {
void LeScanManagerImpl::RestartScan() { void LeScanManagerImpl::RestartScan() {
MAKE_SURE_IO_THREAD(RestartScan); MAKE_SURE_IO_THREAD(RestartScan);
if (scan_handle_ids_.empty()) { if (scan_handle_ids_.empty()) {
LOG(ERROR) << "Can't restart scan, no scan handle";
return; return;
} }
...@@ -136,6 +138,18 @@ void LeScanManagerImpl::RestartScan() { ...@@ -136,6 +138,18 @@ void LeScanManagerImpl::RestartScan() {
} }
} }
void LeScanManagerImpl::SetScanParameters(int scan_interval_ms,
int scan_window_ms) {
MAKE_SURE_IO_THREAD(SetScanParameters, scan_interval_ms, scan_window_ms);
if (!le_scanner_->SetScanParameters(scan_interval_ms, scan_window_ms)) {
LOG(ERROR) << "Failed to set scan parameters";
}
LOG(INFO) << __func__ << " scan_interval: " << scan_interval_ms
<< "ms scan_window: " << scan_window_ms << "ms";
}
void LeScanManagerImpl::OnScanResult( void LeScanManagerImpl::OnScanResult(
const bluetooth_v2_shlib::LeScanner::ScanResult& scan_result_shlib) { const bluetooth_v2_shlib::LeScanner::ScanResult& scan_result_shlib) {
LeScanResult scan_result; LeScanResult scan_result;
......
...@@ -42,9 +42,9 @@ class LeScanManagerImpl : public LeScanManager, ...@@ -42,9 +42,9 @@ class LeScanManagerImpl : public LeScanManager,
GetScanResultsCallback cb, GetScanResultsCallback cb,
base::Optional<ScanFilter> service_uuid = base::nullopt) override; base::Optional<ScanFilter> service_uuid = base::nullopt) override;
void ClearScanResults() override; void ClearScanResults() override;
void PauseScan() override;
void PauseScan(); void RestartScan() override;
void RestartScan(); void SetScanParameters(int scan_interval_ms, int scan_window_ms) override;
private: private:
class ScanHandleImpl; class ScanHandleImpl;
......
...@@ -17,6 +17,7 @@ class LeScannerImpl { ...@@ -17,6 +17,7 @@ class LeScannerImpl {
virtual void SetDelegate(LeScanner::Delegate* delegate) = 0; virtual void SetDelegate(LeScanner::Delegate* delegate) = 0;
virtual bool StartScan() = 0; virtual bool StartScan() = 0;
virtual bool StopScan() = 0; virtual bool StopScan() = 0;
virtual bool SetScanParameters(int scan_interval_ms, int scan_window_ms) = 0;
}; };
} // namespace bluetooth_v2_shlib } // namespace bluetooth_v2_shlib
......
...@@ -19,6 +19,7 @@ class MockLeScanner : public LeScannerImpl { ...@@ -19,6 +19,7 @@ class MockLeScanner : public LeScannerImpl {
MOCK_METHOD1(SetDelegate, void(LeScanner::Delegate* delegate)); MOCK_METHOD1(SetDelegate, void(LeScanner::Delegate* delegate));
MOCK_METHOD0(StartScan, bool()); MOCK_METHOD0(StartScan, bool());
MOCK_METHOD0(StopScan, bool()); MOCK_METHOD0(StopScan, bool());
MOCK_METHOD2(SetScanParameters, bool(int, int));
}; };
inline MockLeScanner::MockLeScanner() = default; inline MockLeScanner::MockLeScanner() = default;
......
...@@ -41,6 +41,9 @@ class CHROMECAST_EXPORT LeScanner { ...@@ -41,6 +41,9 @@ class CHROMECAST_EXPORT LeScanner {
static bool StartScan(); static bool StartScan();
static bool StopScan(); static bool StopScan();
static bool SetScanParameters(int scan_interval_ms, int scan_window_ms)
__attribute__((__weak__));
}; };
inline LeScanner::ScanResult::ScanResult() = default; inline LeScanner::ScanResult::ScanResult() = default;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment