Commit 1e8e0fc1 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS PhoneHub] Update BleScanner to support multiple mediums

BleScanner scans for incoming BLE advertisements but only notifies
observers of results once they have been filtered by parameters provided
by clients. Before this CL, a filter consisted of a DeviceIdPair and a
ConnectionRole.

We will be utilizing BleScanner for Phone Hub, so now it must also
filter by ConnectionMedium. Since ConnectionAttemptDetails objects
consist of a DeviceIdPair, a ConnectionMedium, and a ConnectionRole
(i.e., exactly what we need), this CL change the type of the scan filter
parameters with ConnectionAttemptDetails.

A TODO is added in ble_scanner_impl.cc to reflect the fact that we must
now include the medium as part of the filtering process. This is left
for a follow-up CL.

Bug: 1106937
Change-Id: I251fe812b87145ae9861140af7021dfe2530084b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392954
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#805187}
parent 363a2cc1
...@@ -237,8 +237,9 @@ void BleConnectionManagerImpl::PerformAttemptBleInitiatorConnection( ...@@ -237,8 +237,9 @@ void BleConnectionManagerImpl::PerformAttemptBleInitiatorConnection(
device_id_pair.remote_device_id(), ConnectionRole::kInitiatorRole); device_id_pair.remote_device_id(), ConnectionRole::kInitiatorRole);
ble_advertiser_->AddAdvertisementRequest(device_id_pair, connection_priority); ble_advertiser_->AddAdvertisementRequest(device_id_pair, connection_priority);
ble_scanner_->AddScanFilter( ble_scanner_->AddScanRequest(ConnectionAttemptDetails(
BleScanner::ScanFilter(device_id_pair, ConnectionRole::kInitiatorRole)); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kInitiatorRole));
} }
void BleConnectionManagerImpl::PerformUpdateBleInitiatorConnectionPriority( void BleConnectionManagerImpl::PerformUpdateBleInitiatorConnectionPriority(
...@@ -269,8 +270,9 @@ void BleConnectionManagerImpl::PerformCancelBleInitiatorConnectionAttempt( ...@@ -269,8 +270,9 @@ void BleConnectionManagerImpl::PerformCancelBleInitiatorConnectionAttempt(
return; return;
ble_advertiser_->RemoveAdvertisementRequest(device_id_pair); ble_advertiser_->RemoveAdvertisementRequest(device_id_pair);
ble_scanner_->RemoveScanFilter( ble_scanner_->RemoveScanRequest(ConnectionAttemptDetails(
BleScanner::ScanFilter(device_id_pair, ConnectionRole::kInitiatorRole)); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kInitiatorRole));
} }
void BleConnectionManagerImpl::PerformAttemptBleListenerConnection( void BleConnectionManagerImpl::PerformAttemptBleListenerConnection(
...@@ -282,8 +284,9 @@ void BleConnectionManagerImpl::PerformAttemptBleListenerConnection( ...@@ -282,8 +284,9 @@ void BleConnectionManagerImpl::PerformAttemptBleListenerConnection(
StartConnectionAttemptTimerMetricsIfNecessary( StartConnectionAttemptTimerMetricsIfNecessary(
device_id_pair.remote_device_id(), ConnectionRole::kListenerRole); device_id_pair.remote_device_id(), ConnectionRole::kListenerRole);
ble_scanner_->AddScanFilter( ble_scanner_->AddScanRequest(ConnectionAttemptDetails(
BleScanner::ScanFilter(device_id_pair, ConnectionRole::kListenerRole)); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kListenerRole));
} }
void BleConnectionManagerImpl::PerformUpdateBleListenerConnectionPriority( void BleConnectionManagerImpl::PerformUpdateBleListenerConnectionPriority(
...@@ -309,8 +312,9 @@ void BleConnectionManagerImpl::PerformCancelBleListenerConnectionAttempt( ...@@ -309,8 +312,9 @@ void BleConnectionManagerImpl::PerformCancelBleListenerConnectionAttempt(
if (notifying_remote_device_id_ == device_id_pair.remote_device_id()) if (notifying_remote_device_id_ == device_id_pair.remote_device_id())
return; return;
ble_scanner_->RemoveScanFilter( ble_scanner_->RemoveScanRequest(ConnectionAttemptDetails(
BleScanner::ScanFilter(device_id_pair, ConnectionRole::kListenerRole)); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kListenerRole));
} }
void BleConnectionManagerImpl::OnAdvertisingSlotEnded( void BleConnectionManagerImpl::OnAdvertisingSlotEnded(
......
...@@ -420,13 +420,15 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test { ...@@ -420,13 +420,15 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test {
if (expected_to_add_request) { if (expected_to_add_request) {
EXPECT_EQ(connection_priority, EXPECT_EQ(connection_priority,
*fake_ble_advertiser()->GetPriorityForRequest(device_id_pair)); *fake_ble_advertiser()->GetPriorityForRequest(device_id_pair));
EXPECT_TRUE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_TRUE(fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
device_id_pair, ConnectionRole::kInitiatorRole))); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kInitiatorRole)));
} else { } else {
EXPECT_FALSE( EXPECT_FALSE(
fake_ble_advertiser()->GetPriorityForRequest(device_id_pair)); fake_ble_advertiser()->GetPriorityForRequest(device_id_pair));
EXPECT_FALSE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_FALSE(fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
device_id_pair, ConnectionRole::kInitiatorRole))); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kInitiatorRole)));
} }
} }
...@@ -443,13 +445,15 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test { ...@@ -443,13 +445,15 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test {
if (expected_to_update_priority) { if (expected_to_update_priority) {
EXPECT_EQ(connection_priority, EXPECT_EQ(connection_priority,
*fake_ble_advertiser()->GetPriorityForRequest(device_id_pair)); *fake_ble_advertiser()->GetPriorityForRequest(device_id_pair));
EXPECT_TRUE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_TRUE(fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
device_id_pair, ConnectionRole::kInitiatorRole))); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kInitiatorRole)));
} else { } else {
EXPECT_FALSE( EXPECT_FALSE(
fake_ble_advertiser()->GetPriorityForRequest(device_id_pair)); fake_ble_advertiser()->GetPriorityForRequest(device_id_pair));
EXPECT_FALSE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_FALSE(fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
device_id_pair, ConnectionRole::kInitiatorRole))); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kInitiatorRole)));
} }
} }
...@@ -458,8 +462,9 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test { ...@@ -458,8 +462,9 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test {
ConnectionRole::kInitiatorRole); ConnectionRole::kInitiatorRole);
manager_->CancelBleInitiatorConnectionAttempt(device_id_pair); manager_->CancelBleInitiatorConnectionAttempt(device_id_pair);
EXPECT_FALSE(fake_ble_advertiser()->GetPriorityForRequest(device_id_pair)); EXPECT_FALSE(fake_ble_advertiser()->GetPriorityForRequest(device_id_pair));
EXPECT_FALSE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_FALSE(fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
device_id_pair, ConnectionRole::kInitiatorRole))); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kInitiatorRole)));
} }
void AttemptBleListenerConnection(const DeviceIdPair& device_id_pair, void AttemptBleListenerConnection(const DeviceIdPair& device_id_pair,
...@@ -481,11 +486,13 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test { ...@@ -481,11 +486,13 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test {
should_cancel_attempt_on_failure)); should_cancel_attempt_on_failure));
if (expected_to_add_request) { if (expected_to_add_request) {
EXPECT_TRUE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_TRUE(fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
device_id_pair, ConnectionRole::kListenerRole))); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kListenerRole)));
} else { } else {
EXPECT_FALSE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_FALSE(fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
device_id_pair, ConnectionRole::kListenerRole))); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kListenerRole)));
} }
} }
...@@ -500,11 +507,13 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test { ...@@ -500,11 +507,13 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test {
connection_priority); connection_priority);
if (expected_to_update_priority) { if (expected_to_update_priority) {
EXPECT_TRUE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_TRUE(fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
device_id_pair, ConnectionRole::kListenerRole))); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kListenerRole)));
} else { } else {
EXPECT_FALSE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_FALSE(fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
device_id_pair, ConnectionRole::kListenerRole))); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kListenerRole)));
} }
} }
...@@ -512,8 +521,9 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test { ...@@ -512,8 +521,9 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test {
RemoveFromRemoteDeviceIdToMetadataMap(device_id_pair, RemoveFromRemoteDeviceIdToMetadataMap(device_id_pair,
ConnectionRole::kListenerRole); ConnectionRole::kListenerRole);
manager_->CancelBleListenerConnectionAttempt(device_id_pair); manager_->CancelBleListenerConnectionAttempt(device_id_pair);
EXPECT_FALSE(fake_ble_scanner()->HasScanFilter( EXPECT_FALSE(fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
BleScanner::ScanFilter(device_id_pair, ConnectionRole::kListenerRole))); device_id_pair, ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kListenerRole)));
} }
void SimulateBleSlotEnding(const DeviceIdPair& device_id_pair, void SimulateBleSlotEnding(const DeviceIdPair& device_id_pair,
...@@ -562,7 +572,7 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test { ...@@ -562,7 +572,7 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test {
.empty()); .empty());
EXPECT_TRUE( EXPECT_TRUE(
fake_ble_scanner() fake_ble_scanner()
->GetAllScanFiltersForRemoteDevice(remote_device.GetDeviceId()) ->GetAllScanRequestsForRemoteDevice(remote_device.GetDeviceId())
.empty()); .empty());
FakeSecureChannelConnection* last_created_secure_channel = FakeSecureChannelConnection* last_created_secure_channel =
...@@ -637,14 +647,18 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test { ...@@ -637,14 +647,18 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test {
EXPECT_EQ(std::get<2>(tuple), EXPECT_EQ(std::get<2>(tuple),
*fake_ble_advertiser()->GetPriorityForRequest( *fake_ble_advertiser()->GetPriorityForRequest(
std::get<0>(tuple))); std::get<0>(tuple)));
EXPECT_TRUE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_TRUE(
std::get<0>(tuple), ConnectionRole::kInitiatorRole))); fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
std::get<0>(tuple), ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kInitiatorRole)));
break; break;
} }
case ConnectionRole::kListenerRole: { case ConnectionRole::kListenerRole: {
EXPECT_TRUE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_TRUE(
std::get<0>(tuple), ConnectionRole::kListenerRole))); fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
std::get<0>(tuple), ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kListenerRole)));
break; break;
} }
} }
...@@ -680,14 +694,18 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test { ...@@ -680,14 +694,18 @@ class SecureChannelBleConnectionManagerImplTest : public testing::Test {
EXPECT_EQ(std::get<2>(tuple), EXPECT_EQ(std::get<2>(tuple),
*fake_ble_advertiser()->GetPriorityForRequest( *fake_ble_advertiser()->GetPriorityForRequest(
std::get<0>(tuple))); std::get<0>(tuple)));
EXPECT_TRUE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_TRUE(
std::get<0>(tuple), ConnectionRole::kInitiatorRole))); fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
std::get<0>(tuple), ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kInitiatorRole)));
break; break;
} }
case ConnectionRole::kListenerRole: { case ConnectionRole::kListenerRole: {
EXPECT_TRUE(fake_ble_scanner()->HasScanFilter(BleScanner::ScanFilter( EXPECT_TRUE(
std::get<0>(tuple), ConnectionRole::kListenerRole))); fake_ble_scanner()->HasScanRequest(ConnectionAttemptDetails(
std::get<0>(tuple), ConnectionMedium::kBluetoothLowEnergy,
ConnectionRole::kListenerRole)));
break; break;
} }
} }
......
...@@ -17,30 +17,31 @@ BleScanner::BleScanner() = default; ...@@ -17,30 +17,31 @@ BleScanner::BleScanner() = default;
BleScanner::~BleScanner() = default; BleScanner::~BleScanner() = default;
void BleScanner::AddScanFilter(const ScanFilter& scan_filter) { void BleScanner::AddScanRequest(const ConnectionAttemptDetails& scan_request) {
if (base::Contains(scan_filters_, scan_filter)) { if (base::Contains(scan_requests_, scan_request)) {
PA_LOG(ERROR) << "BleScanner::AddScanFilter(): Tried to add a scan filter " PA_LOG(ERROR) << "BleScanner::AddScanRequest(): Tried to add a scan "
<< "which already existed. Filter: " << scan_filter; << "request which already existed: " << scan_request;
NOTREACHED(); NOTREACHED();
} }
scan_filters_.insert(scan_filter); scan_requests_.insert(scan_request);
HandleScanFilterChange(); HandleScanRequestChange();
} }
void BleScanner::RemoveScanFilter(const ScanFilter& scan_filter) { void BleScanner::RemoveScanRequest(
if (!base::Contains(scan_filters_, scan_filter)) { const ConnectionAttemptDetails& scan_request) {
PA_LOG(ERROR) << "BleScanner::RemoveScanFilter(): Tried to remove a scan " if (!base::Contains(scan_requests_, scan_request)) {
<< "filter which was not present. Filter: " << scan_filter; PA_LOG(ERROR) << "BleScanner::RemoveScanRequest(): Tried to remove a scan "
<< "request which was not present: " << scan_request;
NOTREACHED(); NOTREACHED();
} }
scan_filters_.erase(scan_filter); scan_requests_.erase(scan_request);
HandleScanFilterChange(); HandleScanRequestChange();
} }
bool BleScanner::HasScanFilter(const ScanFilter& scan_filter) { bool BleScanner::HasScanRequest(const ConnectionAttemptDetails& scan_request) {
return base::Contains(scan_filters_, scan_filter); return base::Contains(scan_requests_, scan_request);
} }
void BleScanner::AddObserver(Observer* observer) { void BleScanner::AddObserver(Observer* observer) {
...@@ -53,8 +54,8 @@ void BleScanner::RemoveObserver(Observer* observer) { ...@@ -53,8 +54,8 @@ void BleScanner::RemoveObserver(Observer* observer) {
DeviceIdPairSet BleScanner::GetAllDeviceIdPairs() { DeviceIdPairSet BleScanner::GetAllDeviceIdPairs() {
DeviceIdPairSet set; DeviceIdPairSet set;
for (const auto& scan_filter : scan_filters_) for (const auto& scan_request : scan_requests_)
set.insert(scan_filter.first); set.insert(scan_request.device_id_pair());
return set; return set;
} }
...@@ -68,13 +69,6 @@ void BleScanner::NotifyReceivedAdvertisementFromDevice( ...@@ -68,13 +69,6 @@ void BleScanner::NotifyReceivedAdvertisementFromDevice(
} }
} }
std::ostream& operator<<(std::ostream& stream,
const BleScanner::ScanFilter& scan_filter) {
stream << "{device_id_pair: " << scan_filter.first
<< ", connection_role: " << scan_filter.second << "}";
return stream;
}
} // namespace secure_channel } // namespace secure_channel
} // namespace chromeos } // namespace chromeos
...@@ -13,19 +13,21 @@ ...@@ -13,19 +13,21 @@
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/observer_list_types.h" #include "base/observer_list_types.h"
#include "chromeos/components/multidevice/remote_device_ref.h" #include "chromeos/components/multidevice/remote_device_ref.h"
#include "chromeos/services/secure_channel/connection_attempt_details.h"
#include "chromeos/services/secure_channel/connection_role.h" #include "chromeos/services/secure_channel/connection_role.h"
#include "chromeos/services/secure_channel/device_id_pair.h" #include "chromeos/services/secure_channel/device_id_pair.h"
namespace device { namespace device {
class BluetoothDevice; class BluetoothDevice;
} } // namespace device
namespace chromeos { namespace chromeos {
namespace secure_channel { namespace secure_channel {
// Performs BLE scans and notifies its delegate when an advertisement has been // Performs BLE scans and notifies its delegate when an advertisement has been
// received from a remote device. // received from a remote device. This class allows clients to specify what type
// of connection they are scanning for and filters results accordingly.
class BleScanner { class BleScanner {
public: public:
class Observer : public base::CheckedObserver { class Observer : public base::CheckedObserver {
...@@ -39,19 +41,17 @@ class BleScanner { ...@@ -39,19 +41,17 @@ class BleScanner {
virtual ~BleScanner(); virtual ~BleScanner();
using ScanFilter = std::pair<DeviceIdPair, ConnectionRole>; // Adds a scan request for the provided ConnectionAttemptDetails. If no scan
// requests were previously present, adding a scan request will start a BLE
// discovery session.
void AddScanRequest(const ConnectionAttemptDetails& scan_request);
// Adds a scan filter for the provided ScanFilter. If no scan filters were // Removes a scan request for the provided ConnectionAttemptDetails. If this
// previously present, adding a scan filter will start a BLE discovery session // function removes the only remaining request, the ongoing BLE discovery
// and attempt to create a connection. // session will stop.
void AddScanFilter(const ScanFilter& scan_filter); void RemoveScanRequest(const ConnectionAttemptDetails& scan_request);
// Removes a scan filter for the provided ScanFilter. If this function bool HasScanRequest(const ConnectionAttemptDetails& scan_request);
// removes the only remaining filter, the ongoing BLE discovery session will
// stop.
void RemoveScanFilter(const ScanFilter& scan_filter);
bool HasScanFilter(const ScanFilter& scan_filter);
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
...@@ -59,10 +59,12 @@ class BleScanner { ...@@ -59,10 +59,12 @@ class BleScanner {
protected: protected:
BleScanner(); BleScanner();
virtual void HandleScanFilterChange() = 0; virtual void HandleScanRequestChange() = 0;
bool should_discovery_session_be_active() { return !scan_filters_.empty(); } bool should_discovery_session_be_active() { return !scan_requests_.empty(); }
const base::flat_set<ScanFilter>& scan_filters() { return scan_filters_; } const base::flat_set<ConnectionAttemptDetails>& scan_requests() {
return scan_requests_;
}
DeviceIdPairSet GetAllDeviceIdPairs(); DeviceIdPairSet GetAllDeviceIdPairs();
void NotifyReceivedAdvertisementFromDevice( void NotifyReceivedAdvertisementFromDevice(
...@@ -73,14 +75,11 @@ class BleScanner { ...@@ -73,14 +75,11 @@ class BleScanner {
private: private:
base::ObserverList<Observer> observer_list_; base::ObserverList<Observer> observer_list_;
base::flat_set<ScanFilter> scan_filters_; base::flat_set<ConnectionAttemptDetails> scan_requests_;
DISALLOW_COPY_AND_ASSIGN(BleScanner); DISALLOW_COPY_AND_ASSIGN(BleScanner);
}; };
std::ostream& operator<<(std::ostream& stream,
const BleScanner::ScanFilter& scan_filter);
} // namespace secure_channel } // namespace secure_channel
} // namespace chromeos } // namespace chromeos
......
...@@ -77,7 +77,7 @@ BleScannerImpl::~BleScannerImpl() { ...@@ -77,7 +77,7 @@ BleScannerImpl::~BleScannerImpl() {
adapter_->RemoveObserver(this); adapter_->RemoveObserver(this);
} }
void BleScannerImpl::HandleScanFilterChange() { void BleScannerImpl::HandleScanRequestChange() {
UpdateDiscoveryStatus(); UpdateDiscoveryStatus();
} }
...@@ -206,7 +206,7 @@ void BleScannerImpl::HandleDeviceUpdated( ...@@ -206,7 +206,7 @@ void BleScannerImpl::HandleDeviceUpdated(
service_data_str, GetAllDeviceIdPairs()); service_data_str, GetAllDeviceIdPairs());
// There was service data for the ProximityAuth UUID, but it did not apply to // There was service data for the ProximityAuth UUID, but it did not apply to
// any active scan filters. The advertisement was likely from a nearby device // any active scan requests. The advertisement was likely from a nearby device
// attempting a ProximityAuth connection for another account. // attempting a ProximityAuth connection for another account.
if (!potential_result) if (!potential_result)
return; return;
...@@ -225,18 +225,20 @@ void BleScannerImpl::HandlePotentialScanResult( ...@@ -225,18 +225,20 @@ void BleScannerImpl::HandlePotentialScanResult(
? ConnectionRole::kListenerRole ? ConnectionRole::kListenerRole
: ConnectionRole::kInitiatorRole; : ConnectionRole::kInitiatorRole;
// Check to see if a corresponding scan filter exists. At this point, it is // Check to see if a corresponding scan request exists. At this point, it is
// possible that a scan result was received for the correct DeviceIdPair but // possible that a scan result was received for the correct DeviceIdPair but
// incorrect ConnectionRole. // incorrect ConnectionRole.
bool does_corresponding_scan_filter_exist = false; bool does_corresponding_scan_request_exist = false;
for (const auto& scan_filter : scan_filters()) { for (const auto& scan_request : scan_requests()) {
if (scan_filter.first.remote_device_id() != if (scan_request.remote_device_id() !=
potential_result.first.GetDeviceId()) { potential_result.first.GetDeviceId()) {
continue; continue;
} }
if (scan_filter.second == connection_role) { // TODO(khorimoto): Also handle Nearby cases; currently, it is assumed that
does_corresponding_scan_filter_exist = true; // only BLE scan results are handled.
if (scan_request.connection_role() == connection_role) {
does_corresponding_scan_request_exist = true;
break; break;
} }
} }
...@@ -247,12 +249,12 @@ void BleScannerImpl::HandlePotentialScanResult( ...@@ -247,12 +249,12 @@ void BleScannerImpl::HandlePotentialScanResult(
for (const auto& character : service_data) for (const auto& character : service_data)
ss << static_cast<uint32_t>(character); ss << static_cast<uint32_t>(character);
if (!does_corresponding_scan_filter_exist) { if (!does_corresponding_scan_request_exist) {
PA_LOG(WARNING) << "BleScannerImpl::HandleDeviceUpdated(): Received scan " PA_LOG(WARNING) << "BleScannerImpl::HandleDeviceUpdated(): Received scan "
<< "result from device with ID \"" << "result from device with ID \""
<< potential_result.first.GetTruncatedDeviceIdForLogs() << potential_result.first.GetTruncatedDeviceIdForLogs()
<< "\", but it did not correspond to an active scan " << "\", but it did not correspond to an active scan "
<< "filter. Service data: " << ss.str() << "request. Service data: " << ss.str()
<< ", Background advertisement: " << ", Background advertisement: "
<< (potential_result.second ? "true" : "false"); << (potential_result.second ? "true" : "false");
return; return;
......
...@@ -70,7 +70,7 @@ class BleScannerImpl : public BleScanner, ...@@ -70,7 +70,7 @@ class BleScannerImpl : public BleScanner,
scoped_refptr<device::BluetoothAdapter> adapter); scoped_refptr<device::BluetoothAdapter> adapter);
// BleScanner: // BleScanner:
void HandleScanFilterChange() override; void HandleScanRequestChange() override;
// device::BluetoothAdapter::Observer: // device::BluetoothAdapter::Observer:
void DeviceAdvertisementReceived(device::BluetoothAdapter* adapter, void DeviceAdvertisementReceived(device::BluetoothAdapter* adapter,
......
...@@ -12,19 +12,19 @@ FakeBleScanner::FakeBleScanner() = default; ...@@ -12,19 +12,19 @@ FakeBleScanner::FakeBleScanner() = default;
FakeBleScanner::~FakeBleScanner() = default; FakeBleScanner::~FakeBleScanner() = default;
std::vector<BleScanner::ScanFilter> std::vector<ConnectionAttemptDetails>
FakeBleScanner::GetAllScanFiltersForRemoteDevice( FakeBleScanner::GetAllScanRequestsForRemoteDevice(
const std::string& remote_device_id) { const std::string& remote_device_id) {
std::vector<ScanFilter> all_scan_filters_for_remote_device; std::vector<ConnectionAttemptDetails> all_scan_requests_for_remote_device;
for (const auto& scan_filter : scan_filters()) { for (const auto& scan_request : scan_requests()) {
if (scan_filter.first.remote_device_id() == remote_device_id) if (scan_request.remote_device_id() == remote_device_id)
all_scan_filters_for_remote_device.push_back(scan_filter); all_scan_requests_for_remote_device.push_back(scan_request);
} }
return all_scan_filters_for_remote_device; return all_scan_requests_for_remote_device;
} }
void FakeBleScanner::HandleScanFilterChange() { void FakeBleScanner::HandleScanRequestChange() {
++num_scan_filter_changes_handled_; ++num_scan_request_changes_handled_;
} }
FakeBleScannerObserver::FakeBleScannerObserver() = default; FakeBleScannerObserver::FakeBleScannerObserver() = default;
......
...@@ -22,21 +22,21 @@ class FakeBleScanner : public BleScanner { ...@@ -22,21 +22,21 @@ class FakeBleScanner : public BleScanner {
FakeBleScanner(); FakeBleScanner();
~FakeBleScanner() override; ~FakeBleScanner() override;
size_t num_scan_filter_changes_handled() const { size_t num_scan_request_changes_handled() const {
return num_scan_filter_changes_handled_; return num_scan_request_changes_handled_;
} }
std::vector<ScanFilter> GetAllScanFiltersForRemoteDevice( std::vector<ConnectionAttemptDetails> GetAllScanRequestsForRemoteDevice(
const std::string& remote_device_id); const std::string& remote_device_id);
// Public for testing. // Public for testing.
using BleScanner::scan_filters;
using BleScanner::NotifyReceivedAdvertisementFromDevice; using BleScanner::NotifyReceivedAdvertisementFromDevice;
using BleScanner::scan_requests;
private: private:
void HandleScanFilterChange() override; void HandleScanRequestChange() override;
size_t num_scan_filter_changes_handled_ = 0u; size_t num_scan_request_changes_handled_ = 0u;
DISALLOW_COPY_AND_ASSIGN(FakeBleScanner); DISALLOW_COPY_AND_ASSIGN(FakeBleScanner);
}; };
......
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