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

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: agl comments 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
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_device_mac.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 d86e9f7794911a25bf09fa9d1fad7b1e10fc8dc9..4e4ca6431bebfecc47f1db275726866868109c78 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -9,8 +9,10 @@
#include "base/mac/mac_util.h"
#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_adapter_mac.h"
+#include "device/bluetooth/bluetooth_device.h"
using device::BluetoothDevice;
using device::BluetoothLowEnergyDeviceMac;
@@ -32,6 +34,8 @@ BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
NSDictionary* advertisementData,
int rssi) {
DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
+ identifier_ = GetPeripheralIdentifier(peripheral);
+ hash_address_ = GetPeripheralHashAddress(peripheral);
Update(peripheral, advertisementData, rssi);
}
@@ -58,7 +62,7 @@ void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral,
}
std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const {
- return GetPeripheralIdentifier(peripheral_);
+ return identifier_;
}
uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const {
@@ -66,7 +70,7 @@ uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const {
}
std::string BluetoothLowEnergyDeviceMac::GetAddress() const {
- return std::string();
+ return hash_address_;
}
BluetoothDevice::VendorIDSource BluetoothLowEnergyDeviceMac::GetVendorIDSource()
@@ -95,7 +99,7 @@ bool BluetoothLowEnergyDeviceMac::IsPaired() const {
}
bool BluetoothLowEnergyDeviceMac::IsConnected() const {
- return [peripheral_ isConnected];
+ return (GetPeripheralState() == CBPeripheralStateConnected);
}
bool BluetoothLowEnergyDeviceMac::IsConnectable() const {
@@ -209,3 +213,28 @@ std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(
NSString* uuidString = [uuid UUIDString];
return base::SysNSStringToUTF8(uuidString);
}
+
+// static
+std::string BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(
+ CBPeripheral* peripheral) {
+ const size_t kCanonicalAddressNumberOfBytes = 6;
+ char raw[kCanonicalAddressNumberOfBytes];
+ crypto::SHA256HashString(GetPeripheralIdentifier(peripheral), raw,
+ sizeof(raw));
+ std::string hash = base::HexEncode(raw, sizeof(raw));
+ return BluetoothDevice::CanonicalizeAddress(hash);
+}
+
+CBPeripheralState BluetoothLowEnergyDeviceMac::GetPeripheralState() const {
+ Class peripheral_class = NSClassFromString(@"CBPeripheral");
+ base::scoped_nsobject<NSMethodSignature> signature([[peripheral_class
+ instanceMethodSignatureForSelector:@selector(state)] retain]);
+ base::scoped_nsobject<NSInvocation> invocation(
+ [[NSInvocation invocationWithMethodSignature:signature] retain]);
+ [invocation setTarget:peripheral_];
+ [invocation setSelector:@selector(state)];
+ [invocation invoke];
+ CBPeripheralState state = CBPeripheralStateDisconnected;
+ [invocation getReturnValue:&state];
+ return state;
+}
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_device_mac.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698