#include "device/bluetooth/bluetooth_adapter.h"
#include <memory>
#include <string>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/observer_list.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "components/device_event_log/device_event_log.h"
#include "device/bluetooth/bluetooth_common.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_discovery_session.h"
#include "device/bluetooth/bluetooth_discovery_session_outcome.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
#include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
#include "device/bluetooth/bluetooth_remote_gatt_service.h"
#include "device/bluetooth/public/cpp/bluetooth_address.h"
namespace device {
BluetoothAdapter::ServiceOptions::ServiceOptions() = default;
BluetoothAdapter::ServiceOptions::~ServiceOptions() = default;
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS) && \
!BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_WIN) && !BUILDFLAG(IS_LINUX)
scoped_refptr<BluetoothAdapter> BluetoothAdapter::CreateAdapter() {
return nullptr;
}
#endif
base::WeakPtr<BluetoothAdapter> BluetoothAdapter::GetWeakPtrForTesting() { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
void BluetoothAdapter::Shutdown() { … }
#endif
void BluetoothAdapter::AddObserver(BluetoothAdapter::Observer* observer) { … }
void BluetoothAdapter::RemoveObserver(BluetoothAdapter::Observer* observer) { … }
std::string BluetoothAdapter::GetSystemName() const { … }
bool BluetoothAdapter::HasObserver(BluetoothAdapter::Observer* observer) { … }
bool BluetoothAdapter::CanPower() const { … }
BluetoothAdapter::PermissionStatus BluetoothAdapter::GetOsPermissionStatus()
const { … }
void BluetoothAdapter::RequestSystemPermission(
BluetoothAdapter::RequestSystemPermissionCallback callback) { … }
void BluetoothAdapter::SetPowered(bool powered,
base::OnceClosure callback,
ErrorCallback error_callback) { … }
bool BluetoothAdapter::IsPeripheralRoleSupported() const { … }
std::unordered_map<BluetoothDevice*, BluetoothDevice::UUIDSet>
BluetoothAdapter::RetrieveGattConnectedDevicesWithDiscoveryFilter(
const BluetoothDiscoveryFilter& discovery_filter) { … }
void BluetoothAdapter::StartDiscoverySession(const std::string& client_name,
DiscoverySessionCallback callback,
ErrorCallback error_callback) { … }
void BluetoothAdapter::StartDiscoverySessionWithFilter(
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const std::string& client_name,
DiscoverySessionCallback callback,
ErrorCallback error_callback) { … }
void BluetoothAdapter::MaybeUpdateFilter(
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
DiscoverySessionResultCallback callback) { … }
void BluetoothAdapter::RemoveDiscoverySession(
BluetoothDiscoverySession* discovery_session,
base::OnceClosure callback,
DiscoverySessionErrorCallback error_callback) { … }
std::unique_ptr<BluetoothDiscoveryFilter>
BluetoothAdapter::GetMergedDiscoveryFilter() const { … }
BluetoothAdapter::DeviceList BluetoothAdapter::GetDevices() { … }
BluetoothAdapter::ConstDeviceList BluetoothAdapter::GetDevices() const { … }
BluetoothDevice* BluetoothAdapter::GetDevice(const std::string& address) { … }
const BluetoothDevice* BluetoothAdapter::GetDevice(
const std::string& address) const { … }
void BluetoothAdapter::AddPairingDelegate(
BluetoothDevice::PairingDelegate* pairing_delegate,
PairingDelegatePriority priority) { … }
void BluetoothAdapter::RemovePairingDelegate(
BluetoothDevice::PairingDelegate* pairing_delegate) { … }
BluetoothDevice::PairingDelegate* BluetoothAdapter::DefaultPairingDelegate() { … }
bool BluetoothAdapter::IsExtendedAdvertisementsAvailable() const { … }
std::vector<BluetoothAdvertisement*>
BluetoothAdapter::GetPendingAdvertisementsForTesting() const { … }
base::WeakPtr<BluetoothLocalGattService>
BluetoothAdapter::CreateLocalGattService(
const BluetoothUUID& uuid,
bool is_primary,
BluetoothLocalGattService::Delegate* delegate) { … }
void BluetoothAdapter::NotifyAdapterPresentChanged(bool present) { … }
void BluetoothAdapter::NotifyAdapterPoweredChanged(bool powered) { … }
void BluetoothAdapter::NotifyDeviceChanged(BluetoothDevice* device) { … }
void BluetoothAdapter::NotifyAdapterDiscoveryChangeCompletedForTesting() { … }
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
void BluetoothAdapter::NotifyDevicePairedChanged(BluetoothDevice* device,
bool new_paired_status) { … }
void BluetoothAdapter::NotifyDeviceConnectedStateChanged(
BluetoothDevice* device,
bool is_connected) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
void BluetoothAdapter::NotifyDeviceBatteryChanged(
BluetoothDevice* device,
BluetoothDevice::BatteryType type) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS)
void BluetoothAdapter::NotifyDeviceBondedChanged(BluetoothDevice* device,
bool new_bonded_status) {
for (auto& observer : observers_)
observer.DeviceBondedChanged(this, device, new_bonded_status);
}
void BluetoothAdapter::NotifyDeviceIsBlockedByPolicyChanged(
BluetoothDevice* device,
bool new_blocked_status) {
DCHECK_EQ(device->GetAdapter(), this);
for (auto& observer : observers_)
observer.DeviceBlockedByPolicyChanged(this, device, new_blocked_status);
}
void BluetoothAdapter::NotifyGattNeedsDiscovery(BluetoothDevice* device) {
for (auto& observer : observers_) {
observer.GattNeedsDiscovery(device);
}
}
#endif
void BluetoothAdapter::NotifyGattServiceAdded(
BluetoothRemoteGattService* service) { … }
void BluetoothAdapter::NotifyGattServiceRemoved(
BluetoothRemoteGattService* service) { … }
void BluetoothAdapter::NotifyGattServiceChanged(
BluetoothRemoteGattService* service) { … }
int BluetoothAdapter::NumDiscoverySessions() const { … }
int BluetoothAdapter::NumScanningDiscoverySessions() const { … }
void BluetoothAdapter::ClearAllDevices() { … }
void BluetoothAdapter::NotifyGattServicesDiscovered(BluetoothDevice* device) { … }
void BluetoothAdapter::NotifyGattDiscoveryComplete(
BluetoothRemoteGattService* service) { … }
void BluetoothAdapter::NotifyGattCharacteristicAdded(
BluetoothRemoteGattCharacteristic* characteristic) { … }
void BluetoothAdapter::NotifyGattCharacteristicRemoved(
BluetoothRemoteGattCharacteristic* characteristic) { … }
void BluetoothAdapter::NotifyGattDescriptorAdded(
BluetoothRemoteGattDescriptor* descriptor) { … }
void BluetoothAdapter::NotifyGattDescriptorRemoved(
BluetoothRemoteGattDescriptor* descriptor) { … }
void BluetoothAdapter::NotifyGattCharacteristicValueChanged(
BluetoothRemoteGattCharacteristic* characteristic,
const std::vector<uint8_t>& value) { … }
void BluetoothAdapter::NotifyGattDescriptorValueChanged(
BluetoothRemoteGattDescriptor* descriptor,
const std::vector<uint8_t>& value) { … }
#if BUILDFLAG(IS_CHROMEOS)
void BluetoothAdapter::
NotifyLowEnergyScanSessionHardwareOffloadingStatusChanged(
LowEnergyScanSessionHardwareOffloadingStatus status) {
for (auto& observer : observers_)
observer.LowEnergyScanSessionHardwareOffloadingStatusChanged(status);
}
#endif
BluetoothAdapter::SetPoweredCallbacks::SetPoweredCallbacks() = default;
BluetoothAdapter::SetPoweredCallbacks::~SetPoweredCallbacks() = default;
BluetoothAdapter::StartOrStopDiscoveryCallback::StartOrStopDiscoveryCallback(
base::OnceClosure start_callback,
ErrorCallback start_error_callback) { … }
BluetoothAdapter::StartOrStopDiscoveryCallback::StartOrStopDiscoveryCallback(
base::OnceClosure stop_callback,
DiscoverySessionErrorCallback stop_error_callback) { … }
BluetoothAdapter::StartOrStopDiscoveryCallback::
~StartOrStopDiscoveryCallback() = default;
BluetoothAdapter::BluetoothAdapter() { … }
BluetoothAdapter::~BluetoothAdapter() { … }
void BluetoothAdapter::RunPendingPowerCallbacks() { … }
void BluetoothAdapter::OnDiscoveryChangeComplete(
bool is_error,
UMABluetoothDiscoverySessionOutcome outcome) { … }
void BluetoothAdapter::UpdateDiscoveryState(bool is_error) { … }
void BluetoothAdapter::ProcessDiscoveryQueue() { … }
void BluetoothAdapter::NotifyDiscoveryError(CallbackQueue callback_queue) { … }
void BluetoothAdapter::MarkDiscoverySessionsAsInactive() { … }
void BluetoothAdapter::DeleteDeviceForTesting(const std::string& address) { … }
void BluetoothAdapter::RemoveTimedOutDevices() { … }
const base::TimeDelta BluetoothAdapter::timeoutSec = …;
}