0

Revert "[Bluetooth] Wire filter in LE Scan API"

This reverts commit 908ba12207.

Reason for revert: Causes failures under MSan

Original change's description:
> [Bluetooth] Wire filter in LE Scan API
>
> This wires BluetoothAdapter::StartLowEnergyScanSession's filter argument
> down to Floss daemon's ScanFilter.
>
> Bug: b:217274013
>
> Change-Id: I7e5bd594b278297038f0e98b4a8b5d041881d2b4
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4064434
> Reviewed-by: Katherine Lai <laikatherine@chromium.org>
> Commit-Queue: Sonny Sasaka <sonnysasaka@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1079995}

Bug: b:217274013, chromium:1396871
Change-Id: I43f2bbadcbf9d4f0be1c04f368bb710bff54c2fa
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4081437
Owners-Override: Johann Koenig <johannkoenig@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Johann Koenig <johannkoenig@google.com>
Cr-Commit-Position: refs/heads/main@{#1080142}
This commit is contained in:
Johann Koenig
2022-12-07 02:25:43 +00:00
committed by Chromium LUCI CQ
parent a9e5b2ded3
commit b5bc3cb87c
5 changed files with 16 additions and 118 deletions

@ -1065,7 +1065,7 @@ BluetoothAdapterFloss::StartLowEnergyScanSession(
std::unique_ptr<device::BluetoothLowEnergyScanFilter> filter,
base::WeakPtr<device::BluetoothLowEnergyScanSession::Delegate> delegate) {
auto scan_session = std::make_unique<BluetoothLowEnergyScanSessionFloss>(
std::move(filter), delegate,
delegate,
base::BindOnce(&BluetoothAdapterFloss::OnLowEnergyScanSessionDestroyed,
weak_ptr_factory_.GetWeakPtr()));
FlossDBusManager::Get()->GetLEScanClient()->RegisterScanner(base::BindOnce(
@ -1112,7 +1112,7 @@ void BluetoothAdapterFloss::ScannerRegistered(device::BluetoothUUID uuid,
FlossDBusManager::Get()->GetLEScanClient()->StartScan(
base::BindOnce(&BluetoothAdapterFloss::OnStartScan,
weak_ptr_factory_.GetWeakPtr(), uuid, scanner_id),
scanner_id, ScanSettings{}, scanners_[uuid]->GetFlossScanFilter());
scanner_id, ScanSettings{}, absl::nullopt);
}
void BluetoothAdapterFloss::ScanResultReceived(ScanResult scan_result) {

@ -11,11 +11,9 @@
namespace floss {
BluetoothLowEnergyScanSessionFloss::BluetoothLowEnergyScanSessionFloss(
std::unique_ptr<device::BluetoothLowEnergyScanFilter> filter,
base::WeakPtr<device::BluetoothLowEnergyScanSession::Delegate> delegate,
base::OnceCallback<void(const std::string&)> destructor_callback)
: filter_(std::move(filter)),
delegate_(std::move(delegate)),
: delegate_(std::move(delegate)),
destructor_callback_(std::move(destructor_callback)) {}
BluetoothLowEnergyScanSessionFloss::~BluetoothLowEnergyScanSessionFloss() {
@ -76,28 +74,4 @@ void BluetoothLowEnergyScanSessionFloss::OnRegistered(
uuid_ = uuid;
}
absl::optional<ScanFilter>
BluetoothLowEnergyScanSessionFloss::GetFlossScanFilter() {
if (!filter_)
return absl::nullopt;
ScanFilter filter;
filter.rssi_high_threshold = filter_->device_found_rssi_threshold();
filter.rssi_low_threshold = filter_->device_lost_rssi_threshold();
filter.rssi_low_timeout = filter_->device_lost_timeout().InSeconds();
filter.rssi_sampling_period =
filter_->rssi_sampling_period().value().InMilliseconds() / 100;
for (auto& pattern : filter_->patterns()) {
ScanFilterPattern p;
p.start_position = pattern.start_position();
p.ad_type = static_cast<uint8_t>(pattern.data_type());
p.content = pattern.value();
filter.condition.patterns.push_back(p);
}
return filter;
}
} // namespace floss

@ -9,9 +9,7 @@
#include "base/memory/weak_ptr.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_export.h"
#include "device/bluetooth/bluetooth_low_energy_scan_filter.h"
#include "device/bluetooth/bluetooth_low_energy_scan_session.h"
#include "device/bluetooth/floss/floss_lescan_client.h"
namespace floss {
@ -19,7 +17,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyScanSessionFloss
: public device::BluetoothLowEnergyScanSession {
public:
BluetoothLowEnergyScanSessionFloss(
std::unique_ptr<device::BluetoothLowEnergyScanFilter> filter,
base::WeakPtr<device::BluetoothLowEnergyScanSession::Delegate> delegate,
base::OnceCallback<void(const std::string&)> destructor_callback);
~BluetoothLowEnergyScanSessionFloss() override;
@ -30,7 +27,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyScanSessionFloss
void OnDeviceLost(device::BluetoothDevice* device);
void OnRegistered(device::BluetoothUUID uuid);
uint8_t GetScannerId() { return scanner_id_; }
absl::optional<ScanFilter> GetFlossScanFilter();
base::WeakPtr<BluetoothLowEnergyScanSessionFloss> GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
@ -38,7 +34,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyScanSessionFloss
protected:
private:
std::unique_ptr<device::BluetoothLowEnergyScanFilter> filter_;
base::WeakPtr<device::BluetoothLowEnergyScanSession::Delegate> delegate_;
base::OnceCallback<void(const std::string&)> destructor_callback_;
device::BluetoothUUID uuid_;

@ -24,20 +24,10 @@ namespace floss {
const char kNoCallbackRegistered[] =
"org.chromium.bluetooth.Error.NoCallbackRegistered";
ScanFilterPattern::ScanFilterPattern() = default;
ScanFilterPattern::ScanFilterPattern(const ScanFilterPattern&) = default;
ScanFilterPattern::~ScanFilterPattern() = default;
ScanFilterCondition::ScanFilterCondition() = default;
ScanFilterCondition::ScanFilterCondition(const ScanFilterCondition&) = default;
ScanFilterCondition::~ScanFilterCondition() = default;
ScanFilter::ScanFilter() = default;
ScanFilter::ScanFilter(const ScanFilter&) = default;
ScanFilter::~ScanFilter() = default;
ScanResult::ScanResult() = default;
ScanResult::ScanResult(const ScanResult&) = default;
ScanResult::~ScanResult() = default;
std::unique_ptr<FlossLEScanClient> FlossLEScanClient::Create() {
@ -181,26 +171,14 @@ void FlossDBusClient::WriteDBusParam(dbus::MessageWriter* writer,
writer->CloseContainer(&array_writer);
}
template <>
void FlossDBusClient::WriteDBusParam(dbus::MessageWriter* writer,
const ScanFilterPattern& data) {
dbus::MessageWriter array_writer(nullptr);
writer->OpenArray("{sv}", &array_writer);
WriteDictEntry(&array_writer, "start_position", data.start_position);
WriteDictEntry(&array_writer, "ad_type", data.ad_type);
WriteDictEntry(&array_writer, "content", data.content);
writer->CloseContainer(&array_writer);
}
template <>
void FlossDBusClient::WriteDBusParam(dbus::MessageWriter* writer,
const ScanFilterCondition& data) {
dbus::MessageWriter array_writer(nullptr);
writer->OpenArray("{sv}", &array_writer);
WriteDictEntry(&array_writer, "patterns", data.patterns);
// TODO(b/217274013): Update fields here.
WriteDictEntry(&array_writer, "patterns", std::vector<uint8_t>());
writer->CloseContainer(&array_writer);
}
@ -211,15 +189,13 @@ void FlossDBusClient::WriteDBusParam(dbus::MessageWriter* writer,
dbus::MessageWriter array_writer(nullptr);
writer->OpenArray("{sv}", &array_writer);
WriteDictEntry(&array_writer, "rssi_high_threshold",
static_cast<uint8_t>(data.rssi_high_threshold));
WriteDictEntry(&array_writer, "rssi_low_threshold",
static_cast<uint8_t>(data.rssi_low_threshold));
WriteDictEntry(&array_writer, "rssi_low_timeout",
static_cast<uint8_t>(data.rssi_low_timeout));
// TODO(b/217274013): Update fields here.
WriteDictEntry(&array_writer, "rssi_high_threshold", static_cast<uint8_t>(3));
WriteDictEntry(&array_writer, "rssi_low_threshold", static_cast<uint8_t>(3));
WriteDictEntry(&array_writer, "rssi_low_timeout", static_cast<uint8_t>(3));
WriteDictEntry(&array_writer, "rssi_sampling_period",
static_cast<uint8_t>(data.rssi_sampling_period));
WriteDictEntry(&array_writer, "condition", data.condition);
static_cast<uint8_t>(3));
WriteDictEntry(&array_writer, "condition", ScanFilterCondition{});
writer->CloseContainer(&array_writer);
}

@ -33,58 +33,11 @@ const char kScannerCallbackInterfaceName[] =
// TODO(b/217274013): Update structs to support filtering
class ScanSettings {};
struct DEVICE_BLUETOOTH_EXPORT ScanFilterPattern {
// Specifies the starting byte position of the pattern immediately following
// AD Type.
uint8_t start_position;
class ScanFilterPattern {};
// Advertising Data type (https://www.bluetooth.com/specifications/assigned-numbers/).
uint8_t ad_type;
enum ScanFilterCondition {};
// The pattern to be matched for the specified AD Type within the
// advertisement packet from the specified starting byte.
std::vector<uint8_t> content;
ScanFilterPattern();
ScanFilterPattern(const ScanFilterPattern&);
~ScanFilterPattern();
};
struct DEVICE_BLUETOOTH_EXPORT ScanFilterCondition {
// Match by pattern anywhere in the advertisement data. Multiple patterns are
// "OR"-ed.
std::vector<ScanFilterPattern> patterns;
ScanFilterCondition();
ScanFilterCondition(const ScanFilterCondition&);
~ScanFilterCondition();
};
// Modeled based on MSFT HCI extension spec:
// https://learn.microsoft.com/en-us/windows-hardware/drivers/bluetooth/microsoft-defined-bluetooth-hci-commands-and-events#command_parameters-1
struct DEVICE_BLUETOOTH_EXPORT ScanFilter {
// Advertisements with RSSI above or equal this value is considered "found".
uint8_t rssi_high_threshold;
// Advertisements with RSSI below or equal this value (for a period of
// rssi_low_timeout) is considered "lost".
uint8_t rssi_low_threshold;
// Time in seconds over which the RSSI value should be below
// rssi_low_threshold before being considered "lost".
uint8_t rssi_low_timeout;
// Sampling interval in 100 milliseconds.
// i.e. The real sampling period in ms = rssi_sampling_period * 100.
uint8_t rssi_sampling_period;
//The condition to match advertisements with.
ScanFilterCondition condition;
ScanFilter();
ScanFilter(const ScanFilter&);
~ScanFilter();
};
class ScanFilter {};
struct DEVICE_BLUETOOTH_EXPORT ScanResult {
std::string name;