Chromium Code Reviews| 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..1d992cc3b23c5207e5785cf7b7d3493fc33f2333 100644 |
| --- a/device/bluetooth/bluetooth_adapter_mac.mm |
| +++ b/device/bluetooth/bluetooth_adapter_mac.mm |
| @@ -379,6 +379,8 @@ |
| } |
| void BluetoothAdapterMac::Init() { |
| + if (IsLowEnergyAvailable()) |
| + AddConnectedLowEnergyDevices(); |
| ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| PollAdapter(); |
| } |
| @@ -455,8 +457,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 +566,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 = |
|
jracle (use Gerrit)
2016/09/02 14:23:10
Still need to confirm this logic.
|
| + [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" |
|
jracle (use Gerrit)
2016/09/02 14:23:10
Passing nil in following line causes -Wnonnull to
|
| + // 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<CBPeripheral*>* 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)); |
| + } |
| } |
| } |