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 3bc426e6a45440211692b68e368565da68ece1ad..3925797a716643b337d8c79709804b10e75b8624 100644 |
| --- a/device/bluetooth/bluetooth_adapter_mac.mm |
| +++ b/device/bluetooth/bluetooth_adapter_mac.mm |
| @@ -73,6 +73,22 @@ BluetoothUUID BluetoothAdapterMac::BluetoothUUIDWithCBUUID(CBUUID* uuid) { |
| return device::BluetoothUUID(uuid_c_string); |
| } |
| +// static |
| +NSArray* BluetoothAdapterMac::CBUUIDArrayWithUUIDList( |
| + BluetoothDevice::UUIDList services_uuids) { |
| + NSMutableArray* services = nil; |
| + if (!services_uuids.empty()) { |
| + services = [NSMutableArray array]; |
| + for (auto& service_uuid : services_uuids) { |
| + NSString* uuidString = |
| + base::SysUTF8ToNSString(service_uuid.canonical_value().c_str()); |
| + CBUUID* uuid = [CBUUID UUIDWithString:uuidString]; |
| + [services addObject:uuid]; |
| + } |
| + } |
| + return [services copy]; |
| +} |
| + |
| BluetoothAdapterMac::BluetoothAdapterMac() |
| : BluetoothAdapter(), |
| classic_powered_(false), |
| @@ -170,6 +186,26 @@ bool BluetoothAdapterMac::IsDiscovering() const { |
| return is_discovering; |
| } |
| +void BluetoothAdapter::RetrievedConnectedPeripherals() { |
| + // It is not possible to ask for all connected peripherals with |
| + // -[CBCentralManager retrieveConnectedPeripheralsWithServices:] by passing |
| + // nil. To try to get most of the peripherals, the search is done with |
| + // Generic Access service. |
| + CBUUID* genericAccessServiceUUID = [CBUUID UUIDWithString:@"1800"]; |
| + NSArray* connectedServices = @[ genericAccessServiceUUID ]; |
| +#pragma clang diagnostic push |
| +#pragma clang diagnostic ignored "-Wpartial-availability" |
| + // Can remove ignore -Wpartial-availability when 10.8 will not be supported |
|
ortuno
2016/09/28 23:15:52
Is there an issue you could include with this comm
jlebel
2016/10/05 14:09:41
Done.
|
| + // anymore |
| + NSArray* peripherals = [low_energy_central_manager_ |
| + retrieveConnectedPeripheralsWithServices:connectedServices]; |
| +#pragma clang diagnostic pop |
| + for (CBPeripheral* peripheral in peripherals) { |
| + LowEnergyDeviceUpdated(peripheral, nil /* advertisementData */, |
|
ortuno
2016/09/28 23:15:52
LowEnergyDeviceUpdated is meant to be used when re
jlebel
2016/10/05 14:09:41
I don't know how to use the first part and the thi
|
| + 0 /* rssi */); |
| + } |
| +} |
| + |
| BluetoothAdapter::UUIDList BluetoothAdapterMac::GetUUIDs() const { |
| NOTIMPLEMENTED(); |
| return UUIDList(); |
| @@ -371,9 +407,10 @@ bool BluetoothAdapterMac::StartDiscovery( |
| if (transport & BLUETOOTH_TRANSPORT_LE) { |
| // Begin a low energy discovery session or update it if one is already |
| // running. |
| - if (IsLowEnergyAvailable()) |
| - low_energy_discovery_manager_->StartDiscovery( |
| - BluetoothDevice::UUIDList()); |
| + if (IsLowEnergyAvailable()) { |
| + NSArray* services = CBUUIDArrayWithUUIDList(BluetoothDevice::UUIDList()); |
|
ortuno
2016/09/28 23:15:52
This seems unrelated to this change.
jlebel
2016/10/05 14:09:41
Done.
|
| + low_energy_discovery_manager_->StartDiscovery(services); |
| + } |
| } |
| return true; |
| } |
| @@ -521,40 +558,42 @@ void BluetoothAdapterMac::LowEnergyDeviceUpdated( |
| DCHECK(device_mac); |
| - // Get Advertised UUIDs |
| - BluetoothDevice::UUIDList advertised_uuids; |
| - NSArray* service_uuids = |
| - [advertisement_data objectForKey:CBAdvertisementDataServiceUUIDsKey]; |
| - for (CBUUID* uuid in service_uuids) { |
| - advertised_uuids.push_back(BluetoothUUID([[uuid UUIDString] UTF8String])); |
| - } |
| - NSArray* overflow_service_uuids = [advertisement_data |
| - objectForKey:CBAdvertisementDataOverflowServiceUUIDsKey]; |
| - for (CBUUID* uuid in overflow_service_uuids) { |
| - advertised_uuids.push_back(BluetoothUUID([[uuid UUIDString] UTF8String])); |
| - } |
| + if (advertisement_data) { |
| + // Get Advertised UUIDs |
| + BluetoothDevice::UUIDList advertised_uuids; |
| + NSArray* service_uuids = |
| + [advertisement_data objectForKey:CBAdvertisementDataServiceUUIDsKey]; |
| + for (CBUUID* uuid in service_uuids) { |
| + advertised_uuids.push_back(BluetoothUUID([[uuid UUIDString] UTF8String])); |
| + } |
| + NSArray* overflow_service_uuids = [advertisement_data |
| + objectForKey:CBAdvertisementDataOverflowServiceUUIDsKey]; |
| + for (CBUUID* uuid in overflow_service_uuids) { |
| + advertised_uuids.push_back(BluetoothUUID([[uuid UUIDString] UTF8String])); |
| + } |
| - // Get Service Data. |
| - BluetoothDevice::ServiceDataMap service_data_map; |
| - NSDictionary* service_data = |
| - [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey]; |
| - for (CBUUID* uuid in service_data) { |
| - NSData* data = [service_data objectForKey:uuid]; |
| - const uint8_t* bytes = static_cast<const uint8_t*>([data bytes]); |
| - size_t length = [data length]; |
| - service_data_map.emplace(BluetoothUUID([[uuid UUIDString] UTF8String]), |
| - std::vector<uint8_t>(bytes, bytes + length)); |
| - } |
| + // Get Service Data. |
| + BluetoothDevice::ServiceDataMap service_data_map; |
| + NSDictionary* service_data = |
| + [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey]; |
| + for (CBUUID* uuid in service_data) { |
| + NSData* data = [service_data objectForKey:uuid]; |
| + const uint8_t* bytes = static_cast<const uint8_t*>([data bytes]); |
| + size_t length = [data length]; |
| + service_data_map.emplace(BluetoothUUID([[uuid UUIDString] UTF8String]), |
| + std::vector<uint8_t>(bytes, bytes + length)); |
| + } |
| - // Get Tx Power. |
| - NSNumber* tx_power = |
| - [advertisement_data objectForKey:CBAdvertisementDataTxPowerLevelKey]; |
| - int8_t clamped_tx_power = BluetoothDevice::ClampPower([tx_power intValue]); |
| + // Get Tx Power. |
| + NSNumber* tx_power = |
| + [advertisement_data objectForKey:CBAdvertisementDataTxPowerLevelKey]; |
| + int8_t clamped_tx_power = BluetoothDevice::ClampPower([tx_power intValue]); |
| - device_mac->UpdateAdvertisementData( |
| - BluetoothDevice::ClampPower(rssi), std::move(advertised_uuids), |
| - std::move(service_data_map), |
| - tx_power == nil ? nullptr : &clamped_tx_power); |
| + device_mac->UpdateAdvertisementData( |
| + BluetoothDevice::ClampPower(rssi), std::move(advertised_uuids), |
| + std::move(service_data_map), |
| + tx_power == nil ? nullptr : &clamped_tx_power); |
| + } |
| if (is_new_device) { |
| std::string device_address = |