| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/bluetooth/bluetooth_adapter_mac.h" | 5 #include "device/bluetooth/bluetooth_adapter_mac.h" |
| 6 | 6 |
| 7 #import <IOBluetooth/objc/IOBluetoothDevice.h> | 7 #import <IOBluetooth/objc/IOBluetoothDevice.h> |
| 8 #import <IOBluetooth/objc/IOBluetoothHostController.h> | 8 #import <IOBluetooth/objc/IOBluetoothHostController.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 538 |
| 539 DCHECK(device_mac); | 539 DCHECK(device_mac); |
| 540 VLOG(3) << *device_mac << ": Device updated with " | 540 VLOG(3) << *device_mac << ": Device updated with " |
| 541 << base::SysNSStringToUTF8([advertisement_data description]); | 541 << base::SysNSStringToUTF8([advertisement_data description]); |
| 542 | 542 |
| 543 // Get Advertised UUIDs | 543 // Get Advertised UUIDs |
| 544 BluetoothDevice::UUIDList advertised_uuids; | 544 BluetoothDevice::UUIDList advertised_uuids; |
| 545 NSArray* service_uuids = | 545 NSArray* service_uuids = |
| 546 [advertisement_data objectForKey:CBAdvertisementDataServiceUUIDsKey]; | 546 [advertisement_data objectForKey:CBAdvertisementDataServiceUUIDsKey]; |
| 547 for (CBUUID* uuid in service_uuids) { | 547 for (CBUUID* uuid in service_uuids) { |
| 548 advertised_uuids.push_back(BluetoothUUID([[uuid UUIDString] UTF8String])); | 548 advertised_uuids.push_back( |
| 549 BluetoothAdapterMac::BluetoothUUIDWithCBUUID(uuid)); |
| 549 } | 550 } |
| 550 NSArray* overflow_service_uuids = [advertisement_data | 551 NSArray* overflow_service_uuids = [advertisement_data |
| 551 objectForKey:CBAdvertisementDataOverflowServiceUUIDsKey]; | 552 objectForKey:CBAdvertisementDataOverflowServiceUUIDsKey]; |
| 552 for (CBUUID* uuid in overflow_service_uuids) { | 553 for (CBUUID* uuid in overflow_service_uuids) { |
| 553 advertised_uuids.push_back(BluetoothUUID([[uuid UUIDString] UTF8String])); | 554 advertised_uuids.push_back( |
| 555 BluetoothAdapterMac::BluetoothUUIDWithCBUUID(uuid)); |
| 554 } | 556 } |
| 555 | 557 |
| 556 // Get Service Data. | 558 // Get Service Data. |
| 557 BluetoothDevice::ServiceDataMap service_data_map; | 559 BluetoothDevice::ServiceDataMap service_data_map; |
| 558 NSDictionary* service_data = | 560 NSDictionary* service_data = |
| 559 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey]; | 561 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey]; |
| 560 for (CBUUID* uuid in service_data) { | 562 for (CBUUID* uuid in service_data) { |
| 561 NSData* data = [service_data objectForKey:uuid]; | 563 NSData* data = [service_data objectForKey:uuid]; |
| 562 const uint8_t* bytes = static_cast<const uint8_t*>([data bytes]); | 564 const uint8_t* bytes = static_cast<const uint8_t*>([data bytes]); |
| 563 size_t length = [data length]; | 565 size_t length = [data length]; |
| 564 service_data_map.emplace(BluetoothUUID([[uuid UUIDString] UTF8String]), | 566 service_data_map.emplace(BluetoothAdapterMac::BluetoothUUIDWithCBUUID(uuid), |
| 565 std::vector<uint8_t>(bytes, bytes + length)); | 567 std::vector<uint8_t>(bytes, bytes + length)); |
| 566 } | 568 } |
| 567 | 569 |
| 568 // Get Tx Power. | 570 // Get Tx Power. |
| 569 NSNumber* tx_power = | 571 NSNumber* tx_power = |
| 570 [advertisement_data objectForKey:CBAdvertisementDataTxPowerLevelKey]; | 572 [advertisement_data objectForKey:CBAdvertisementDataTxPowerLevelKey]; |
| 571 int8_t clamped_tx_power = BluetoothDevice::ClampPower([tx_power intValue]); | 573 int8_t clamped_tx_power = BluetoothDevice::ClampPower([tx_power intValue]); |
| 572 | 574 |
| 573 device_mac->UpdateAdvertisementData( | 575 device_mac->UpdateAdvertisementData( |
| 574 BluetoothDevice::ClampPower(rssi), std::move(advertised_uuids), | 576 BluetoothDevice::ClampPower(rssi), std::move(advertised_uuids), |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 // hash the probability of this occuring with 10,000 devices | 749 // hash the probability of this occuring with 10,000 devices |
| 748 // simultaneously present is 1e-6 (see | 750 // simultaneously present is 1e-6 (see |
| 749 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We | 751 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We |
| 750 // ignore the second device by returning. | 752 // ignore the second device by returning. |
| 751 return true; | 753 return true; |
| 752 } | 754 } |
| 753 return false; | 755 return false; |
| 754 } | 756 } |
| 755 | 757 |
| 756 } // namespace device | 758 } // namespace device |
| OLD | NEW |