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 0db7131318d218b8003124231e7d7c87357608b6..59c370dd08e3fe67aa0e47a534d18e693d54468c 100644 |
| --- a/device/bluetooth/bluetooth_adapter_mac.mm |
| +++ b/device/bluetooth/bluetooth_adapter_mac.mm |
| @@ -31,6 +31,13 @@ |
| #include "device/bluetooth/bluetooth_low_energy_central_manager_delegate.h" |
| #include "device/bluetooth/bluetooth_socket_mac.h" |
| +@interface CBCentralManager (PartialAvailability) |
|
ortuno
2016/08/15 23:58:09
This doesn't seem to be a pattern we follow throug
jracle (use Gerrit)
2016/08/16 20:14:17
Actually, I think I've got it from a landed CL, bu
jlebel
2016/08/31 12:03:28
I think you can just #import <CoreBluetooth/CoreBl
jracle (use Gerrit)
2016/08/31 17:21:22
Indeed, as you state in other comment, that's a pa
|
| + |
| +- (NSArray<CBPeripheral*>*)retrieveConnectedPeripheralsWithServices: |
| + (NSArray<CBUUID*>*)serviceUUIDs; |
| + |
| +@end |
| + |
| namespace { |
| // The frequency with which to poll the adapter for updates. |
| @@ -375,6 +382,8 @@ |
| } |
| void BluetoothAdapterMac::Init() { |
| + if (IsLowEnergyAvailable()) |
| + AddConnectedLowEnergyDevices(); |
| ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| PollAdapter(); |
| } |
| @@ -451,8 +460,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, |
| @@ -523,10 +532,44 @@ |
| // 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 |
|
ortuno
2016/08/15 23:58:09
Could you add a link to some documentation that st
jracle (use Gerrit)
2016/08/16 20:14:17
I need to cross-check with Logitech guys who point
jracle (use Gerrit)
2016/08/17 21:21:15
While checking for official documentation, here is
|
| + // information service SDP entry. |
| + if (pnp_information) { |
| + ClassicDeviceAdded(device); |
| + } |
| + } |
| +} |
| + |
| +void BluetoothAdapterMac::AddConnectedLowEnergyDevices() { |
| + // Look for Device Information Service. BLE devices should advertise it. |
|
ortuno
2016/08/15 23:58:09
nit: Well if it's connected it's not really advert
jracle (use Gerrit)
2016/08/16 20:14:17
Indeed.. does 'implement' look better? ("Most BLE
|
| + CBUUID* device_information_uuid = [CBUUID UUIDWithString:@"180A"]; |
| + |
| + // 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 ]]; |
|
ortuno
2016/08/15 23:58:09
Just pass nil. There is no requirement that a devi
jracle (use Gerrit)
2016/08/16 20:14:17
Agree with you. Documentation says passing nil wil
|
| + |
| + 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_, |
|
ortuno
2016/08/15 23:58:09
We probably want to also start a service discovery
jracle (use Gerrit)
2016/08/16 20:14:17
I don't do it here, cause user will have to connec
|
| + DeviceAdded(this, device_mac)); |
| + } |
| } |
| } |