Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 1216583003: Adding Hashed Address to BluetoothLowEnergyDeviceMac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@timeinfo
Patch Set: shortening a signature.. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_low_energy_device_mac.mm
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.mm b/device/bluetooth/bluetooth_low_energy_device_mac.mm
index cd2823c8a02d030c877d948d7ab7dcc88c747c78..d5d9e73a0b05d99c0c90050a2e127e29074f5488 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -8,7 +8,9 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/mac/sdk_forward_declarations.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/sys_string_conversions.h"
+#include "device/bluetooth/bluetooth_device.h"
using device::BluetoothDevice;
using device::BluetoothLowEnergyDeviceMac;
@@ -66,6 +68,8 @@ BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
CBPeripheral* peripheral,
NSDictionary* advertisementData,
int rssi) {
+ identifier_ = GetPeripheralIdentifier(peripheral);
+ hash_address_ = GetPeripheralHashAddress(peripheral);
Update(peripheral, advertisementData, rssi);
}
@@ -92,7 +96,7 @@ void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral,
}
std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const {
- return GetPeripheralIdentifier(peripheral_);
+ return identifier_;
}
uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const {
@@ -100,7 +104,7 @@ uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const {
}
std::string BluetoothLowEnergyDeviceMac::GetAddress() const {
- return std::string();
+ return hash_address_;
}
BluetoothDevice::VendorIDSource BluetoothLowEnergyDeviceMac::GetVendorIDSource()
@@ -129,6 +133,11 @@ bool BluetoothLowEnergyDeviceMac::IsPaired() const {
}
bool BluetoothLowEnergyDeviceMac::IsConnected() const {
+ // isConnected deprecated on OSX SDK >= 10.9, sending the state message is
+ // preferred.
+ if ([peripheral_ respondsToSelector:@selector(state)]) {
+ return ([peripheral_ state] == CBPeripheralStateConnected);
+ }
return [peripheral_ isConnected];
}
@@ -249,3 +258,13 @@ std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(
CFUUIDCreateString(NULL, [peripheral UUID]));
return SysCFStringRefToUTF8(str);
}
+
+std::string BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(
+ CBPeripheral* peripheral) {
+ const size_t kCanonicalAddressNumberOfBytes = 6;
+ char raw[kCanonicalAddressNumberOfBytes] = {0};
+ crypto::SHA256HashString(GetPeripheralIdentifier(peripheral), raw,
+ sizeof(raw));
+ std::string hash = base::HexEncode(raw, sizeof(raw));
+ return BluetoothDevice::CanonicalizeAddress(hash);
+}

Powered by Google App Engine
This is Rietveld 408576698