| Index: device/bluetooth/bluetooth_adapter_mac.mm
|
| diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
|
| index 1690da6559fe9582cecaba733cc476a6c4d7d763..2abbc4f7a05e317c00e37f1e94cae50c84e51d52 100644
|
| --- a/device/bluetooth/bluetooth_adapter_mac.mm
|
| +++ b/device/bluetooth/bluetooth_adapter_mac.mm
|
| @@ -57,8 +57,12 @@
|
| base::WeakPtr<BluetoothAdapterMac> BluetoothAdapterMac::CreateAdapterForTest(
|
| std::string name,
|
| std::string address,
|
| - scoped_refptr<base::SequencedTaskRunner> ui_task_runner) {
|
| + scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
|
| + CBCentralManager* central_manager) {
|
| BluetoothAdapterMac* adapter = new BluetoothAdapterMac();
|
| + if (central_manager) {
|
| + adapter->SetCentralManagerForTesting(central_manager);
|
| + }
|
| adapter->InitForTest(ui_task_runner);
|
| adapter->name_ = name;
|
| adapter->address_ = address;
|
| @@ -379,12 +383,16 @@
|
| }
|
|
|
| void BluetoothAdapterMac::Init() {
|
| + if (IsLowEnergyAvailable())
|
| + AddConnectedLowEnergyDevices();
|
| ui_task_runner_ = base::ThreadTaskRunnerHandle::Get();
|
| PollAdapter();
|
| }
|
|
|
| void BluetoothAdapterMac::InitForTest(
|
| scoped_refptr<base::SequencedTaskRunner> ui_task_runner) {
|
| + if (IsLowEnergyAvailable())
|
| + AddConnectedLowEnergyDevices();
|
| ui_task_runner_ = ui_task_runner;
|
| }
|
|
|
| @@ -455,8 +463,8 @@
|
| // is fixed.
|
| tracked_objects::ScopedTracker tracking_profile6(
|
| FROM_HERE_WITH_EXPLICIT_FUNCTION(
|
| - "461181 BluetoothAdapterMac::PollAdapter::AddPairedDevices"));
|
| - AddPairedDevices();
|
| + "461181 BluetoothAdapterMac::PollAdapter::AddPairedClassicDevices"));
|
| + AddPairedClassicDevices();
|
|
|
| ui_task_runner_->PostDelayedTask(
|
| FROM_HERE,
|
| @@ -564,10 +572,47 @@
|
| // TODO(krstnmnlsn): Implement. crbug.com/511025
|
| void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {}
|
|
|
| -void BluetoothAdapterMac::AddPairedDevices() {
|
| - // Add any new paired devices.
|
| +void BluetoothAdapterMac::AddPairedClassicDevices() {
|
| for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) {
|
| - ClassicDeviceAdded(device);
|
| + IOBluetoothSDPServiceRecord* pnp_information =
|
| + [device getServiceRecordForUUID:
|
| + [IOBluetoothSDPUUID
|
| + uuid16:kBluetoothSDPUUID16ServiceClassPnPInformation]];
|
| +
|
| + // IOBluetoothDevice instance is a Bluetooth Classic device if it has a PNP
|
| + // information service SDP entry.
|
| + if (pnp_information) {
|
| + ClassicDeviceAdded(device);
|
| + }
|
| + }
|
| +}
|
| +
|
| +void BluetoothAdapterMac::AddConnectedLowEnergyDevices() {
|
| + // Look for Device Information Service. BLE devices should implement it.
|
| + CBUUID* device_information_uuid = [CBUUID UUIDWithString:@"180A"];
|
| +
|
| +#pragma clang diagnostic push
|
| +#pragma clang diagnostic ignored "-Wpartial-availability"
|
| + // This list of devices contain both devices that are connected by other apps
|
| + // or by system. In that case, user will need to connect peripheral using
|
| + // CBCentralManager's connectPeripheral:options: method.
|
| + NSArray* connected_peripherals = [low_energy_central_manager_
|
| + retrieveConnectedPeripheralsWithServices:@[ device_information_uuid ]];
|
| +#pragma clang diagnostic pop
|
| +
|
| + for (CBPeripheral* peripheral in connected_peripherals) {
|
| + BluetoothLowEnergyDeviceMac* device_mac =
|
| + GetBluetoothLowEnergyDeviceMac(peripheral);
|
| +
|
| + if (!device_mac) {
|
| + device_mac = new BluetoothLowEnergyDeviceMac(this, peripheral);
|
| + std::string device_address =
|
| + BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
|
| + devices_.add(device_address,
|
| + std::unique_ptr<BluetoothDevice>(device_mac));
|
| + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
|
| + DeviceAdded(this, device_mac));
|
| + }
|
| }
|
| }
|
|
|
|
|