Commit 47113625 authored by Daniel Winkler's avatar Daniel Winkler Committed by Commit Bot

bluetooth: Always update discovery filter

Recent ChromeOS bluez-next uprev fixes a bug that clears a client's
discovery filter between discovery sessions. Now that it is fixed,
we must be sure the filter is refreshed to prevent lingering filters
from affecting client discovery.

BUG=b:157266509
TEST=ARC++ bluetooth tests that use LE filters

Change-Id: I06cf494a49d6bcf83370fbcb0f1d365a50e27560
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225278
Commit-Queue: Daniel Winkler <danielwinkler@google.com>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarMiao-chen Chou <mcchou@chromium.org>
Reviewed-by: default avatarSonny Sasaka <sonnysasaka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775182}
parent 038c592e
...@@ -1523,6 +1523,8 @@ void BluetoothAdapterBlueZ::UpdateFilter( ...@@ -1523,6 +1523,8 @@ void BluetoothAdapterBlueZ::UpdateFilter(
void BluetoothAdapterBlueZ::StartScanWithFilter( void BluetoothAdapterBlueZ::StartScanWithFilter(
std::unique_ptr<device::BluetoothDiscoveryFilter> discovery_filter, std::unique_ptr<device::BluetoothDiscoveryFilter> discovery_filter,
DiscoverySessionResultCallback callback) { DiscoverySessionResultCallback callback) {
DCHECK(discovery_filter.get());
if (!IsPresent()) { if (!IsPresent()) {
std::move(callback).Run( std::move(callback).Run(
true, UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT); true, UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT);
...@@ -1532,39 +1534,16 @@ void BluetoothAdapterBlueZ::StartScanWithFilter( ...@@ -1532,39 +1534,16 @@ void BluetoothAdapterBlueZ::StartScanWithFilter(
BLUETOOTH_LOG(EVENT) << __func__; BLUETOOTH_LOG(EVENT) << __func__;
auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback)); auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback));
SetDiscoveryFilter(
if (discovery_filter && !discovery_filter->IsDefault()) { std::move(discovery_filter),
std::unique_ptr<BluetoothDiscoveryFilter> df( base::BindRepeating(
new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_DUAL)); &BluetoothAdapterBlueZ::OnPreSetDiscoveryFilter,
df->CopyFrom(*discovery_filter);
SetDiscoveryFilter(
std::move(df),
base::BindRepeating(
&BluetoothAdapterBlueZ::OnPreSetDiscoveryFilter,
weak_ptr_factory_.GetWeakPtr(),
base::BindRepeating(copyable_callback, /*is_error=*/false,
UMABluetoothDiscoverySessionOutcome::SUCCESS),
base::BindRepeating(copyable_callback, true)),
base::BindOnce(
&BluetoothAdapterBlueZ::OnPreSetDiscoveryFilterError,
weak_ptr_factory_.GetWeakPtr(),
base::BindRepeating(copyable_callback, /*is_error=*/false,
UMABluetoothDiscoverySessionOutcome::SUCCESS),
base::BindOnce(copyable_callback, true)));
return;
}
// This is the first request to start device discovery.
bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StartDiscovery(
object_path_,
base::BindOnce(
&BluetoothAdapterBlueZ::OnStartDiscovery,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
base::BindRepeating(copyable_callback, /*is_error=*/false, base::BindRepeating(copyable_callback, /*is_error=*/false,
UMABluetoothDiscoverySessionOutcome::SUCCESS), UMABluetoothDiscoverySessionOutcome::SUCCESS),
base::BindRepeating(copyable_callback, true)), base::BindRepeating(copyable_callback, true)),
base::BindOnce( base::BindOnce(
&BluetoothAdapterBlueZ::OnStartDiscoveryError, &BluetoothAdapterBlueZ::OnPreSetDiscoveryFilterError,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
base::BindRepeating(copyable_callback, /*is_error=*/false, base::BindRepeating(copyable_callback, /*is_error=*/false,
UMABluetoothDiscoverySessionOutcome::SUCCESS), UMABluetoothDiscoverySessionOutcome::SUCCESS),
...@@ -1607,6 +1586,8 @@ void BluetoothAdapterBlueZ::SetDiscoveryFilter( ...@@ -1607,6 +1586,8 @@ void BluetoothAdapterBlueZ::SetDiscoveryFilter(
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter, std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const base::Closure& callback, const base::Closure& callback,
DiscoverySessionErrorCallback error_callback) { DiscoverySessionErrorCallback error_callback) {
DCHECK(discovery_filter.get());
if (!IsPresent()) { if (!IsPresent()) {
std::move(error_callback) std::move(error_callback)
.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); .Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED);
...@@ -1614,36 +1595,32 @@ void BluetoothAdapterBlueZ::SetDiscoveryFilter( ...@@ -1614,36 +1595,32 @@ void BluetoothAdapterBlueZ::SetDiscoveryFilter(
} }
bluez::BluetoothAdapterClient::DiscoveryFilter dbus_discovery_filter; bluez::BluetoothAdapterClient::DiscoveryFilter dbus_discovery_filter;
uint16_t pathloss;
int16_t rssi;
uint8_t transport;
std::set<device::BluetoothUUID> uuids;
if (discovery_filter->GetPathloss(&pathloss))
dbus_discovery_filter.pathloss = std::make_unique<uint16_t>(pathloss);
if (discovery_filter->GetRSSI(&rssi))
dbus_discovery_filter.rssi = std::make_unique<int16_t>(rssi);
transport = discovery_filter->GetTransport();
if (transport == device::BLUETOOTH_TRANSPORT_LE) {
dbus_discovery_filter.transport = std::make_unique<std::string>("le");
} else if (transport == device::BLUETOOTH_TRANSPORT_CLASSIC) {
dbus_discovery_filter.transport = std::make_unique<std::string>("bredr");
} else if (transport == device::BLUETOOTH_TRANSPORT_DUAL) {
dbus_discovery_filter.transport = std::make_unique<std::string>("auto");
}
if (discovery_filter.get() && !discovery_filter->IsDefault()) { discovery_filter->GetUUIDs(uuids);
uint16_t pathloss; if (uuids.size()) {
int16_t rssi; dbus_discovery_filter.uuids = std::make_unique<std::vector<std::string>>();
uint8_t transport;
std::set<device::BluetoothUUID> uuids;
if (discovery_filter->GetPathloss(&pathloss))
dbus_discovery_filter.pathloss.reset(new uint16_t(pathloss));
if (discovery_filter->GetRSSI(&rssi))
dbus_discovery_filter.rssi.reset(new int16_t(rssi));
transport = discovery_filter->GetTransport();
if (transport == device::BLUETOOTH_TRANSPORT_LE) {
dbus_discovery_filter.transport.reset(new std::string("le"));
} else if (transport == device::BLUETOOTH_TRANSPORT_CLASSIC) {
dbus_discovery_filter.transport.reset(new std::string("bredr"));
} else if (transport == device::BLUETOOTH_TRANSPORT_DUAL) {
dbus_discovery_filter.transport.reset(new std::string("auto"));
}
discovery_filter->GetUUIDs(uuids);
if (uuids.size()) {
dbus_discovery_filter.uuids = std::unique_ptr<std::vector<std::string>>(
new std::vector<std::string>);
for (const auto& it : uuids) for (const auto& it : uuids)
dbus_discovery_filter.uuids.get()->push_back(it.value()); dbus_discovery_filter.uuids.get()->push_back(it.value());
}
} }
auto copyable_error_callback = auto copyable_error_callback =
......
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