Commit ba7954e5 authored by Martin Kreichgauer's avatar Martin Kreichgauer Committed by Commit Bot

bluetooth: add BluetoothAdapter::IsPeripheralRoleSupported()

It appears that on Windows, Bluetooth hardware does not generally
support the BLE peripheral role (i.e. BLE advertisements). Add a method
to BluetoothAdapter that returns the
BluetoothAdapter.IsPeripheralRoleSupported property [0] on WinRT and
true everywhere else, so that client code can detect these cases.

[0]
https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.bluetoothadapter.isperipheralrolesupported

Bug: 1069140
Change-Id: If8f2f448f30db6aaf720c10e00391dea3f65944e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2152892
Commit-Queue: Martin Kreichgauer <martinkr@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759836}
parent d64470ed
......@@ -91,6 +91,11 @@ void BluetoothAdapter::SetPowered(bool powered,
set_powered_callbacks_->error_callback = error_callback;
}
bool BluetoothAdapter::IsPeripheralRoleSupported() const {
// TODO(crbug/1071595): Implement this for more platforms.
return true;
}
std::unordered_map<BluetoothDevice*, BluetoothDevice::UUIDSet>
BluetoothAdapter::RetrieveGattConnectedDevicesWithDiscoveryFilter(
const BluetoothDiscoveryFilter& discovery_filter) {
......
......@@ -433,6 +433,9 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
const base::Closure& callback,
const ErrorCallback& error_callback);
// Indicates whether the adapter support the LowEnergy peripheral role.
virtual bool IsPeripheralRoleSupported() const;
// Indicates whether the adapter radio is discoverable.
virtual bool IsDiscoverable() const = 0;
......
......@@ -765,6 +765,7 @@ TEST_F(BluetoothTest, MAYBE_ConstructFakeAdapter) {
EXPECT_TRUE(adapter_->CanPower());
EXPECT_TRUE(adapter_->IsPresent());
EXPECT_TRUE(adapter_->IsPowered());
EXPECT_TRUE(adapter_->IsPeripheralRoleSupported());
EXPECT_FALSE(adapter_->IsDiscoverable());
EXPECT_FALSE(adapter_->IsDiscovering());
}
......
......@@ -533,6 +533,16 @@ bool BluetoothAdapterWinrt::IsPowered() const {
return GetState(radio_.Get()) == RadioState_On;
}
bool BluetoothAdapterWinrt::IsPeripheralRoleSupported() const {
boolean supported = false;
HRESULT hr = adapter_->get_IsPeripheralRoleSupported(&supported);
if (FAILED(hr)) {
BLUETOOTH_LOG(ERROR) << "Getting IsPeripheralRoleSupported failed: "
<< logging::SystemErrorCodeToString(hr);
}
return supported;
}
bool BluetoothAdapterWinrt::IsDiscoverable() const {
NOTIMPLEMENTED();
return false;
......
......@@ -43,6 +43,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterWinrt : public BluetoothAdapter {
bool IsPresent() const override;
bool CanPower() const override;
bool IsPowered() const override;
bool IsPeripheralRoleSupported() const override;
bool IsDiscoverable() const override;
void SetDiscoverable(bool discoverable,
const base::Closure& callback,
......
......@@ -73,7 +73,8 @@ HRESULT FakeBluetoothAdapterWinrt::get_IsLowEnergySupported(boolean* value) {
HRESULT FakeBluetoothAdapterWinrt::get_IsPeripheralRoleSupported(
boolean* value) {
return E_NOTIMPL;
*value = true;
return S_OK;
}
HRESULT FakeBluetoothAdapterWinrt::get_IsCentralRoleSupported(boolean* value) {
......
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