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

Unified Diff: chrome/browser/mac/hardware_utility.mm

Issue 374203004: mac: Add metrics to record Bluetooth availability and capabilities. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase against origin/master Created 6 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: chrome/browser/mac/hardware_utility.mm
diff --git a/chrome/browser/mac/hardware_utility.mm b/chrome/browser/mac/hardware_utility.mm
new file mode 100644
index 0000000000000000000000000000000000000000..57b3bc3415b96c28168003c47298166cc4b6e099
--- /dev/null
+++ b/chrome/browser/mac/hardware_utility.mm
@@ -0,0 +1,79 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/mac/hardware_utility.h"
+
+#import <Foundation/Foundation.h>
+#include <IOKit/IOKitLib.h>
+
+#include "base/mac/foundation_util.h"
+#include "base/mac/scoped_ioobject.h"
+
+namespace hardware_utility {
+
+// Returns the Bluetooth driver's Link Management Protocol version.
+// Returns -1 if no Bluetooth driver is present.
Mark Mentovai 2014/07/09 17:53:00 Use constants for these.
erikchen 2014/07/09 20:14:42 Done.
+// Returns -2 on an unexpected error.
+int GetBluetoothLMPVersion() {
Mark Mentovai 2014/07/09 17:53:00 Put this in an unnamed namespace.
erikchen 2014/07/09 20:14:42 Done.
+ base::ScopedCFTypeRef<CFMutableDictionaryRef> matching_dict(
+ IOServiceMatching("IOBluetoothHCIController"));
+ if (!matching_dict)
+ return -2;
+
+ // IOServiceGetMatchingServices takes ownership of matching_dict.
+ io_iterator_t iter;
+ int kr = IOServiceGetMatchingServices(
+ kIOMasterPortDefault, matching_dict.release(), &iter);
+ if (kr != KERN_SUCCESS)
+ return -1;
+ base::mac::ScopedIOObject<io_iterator_t> scoped_iter(iter);
+
+ int version = 0;
+ bool success = false;
+ base::mac::ScopedIOObject<io_service_t> device;
+ while (device.reset(IOIteratorNext(scoped_iter.get())), device) {
+ CFMutableDictionaryRef dict;
+ kr = IORegistryEntryCreateCFProperties(
+ device, &dict, kCFAllocatorDefault, kNilOptions);
+ if (kr != KERN_SUCCESS)
+ continue;
+ base::ScopedCFTypeRef<CFMutableDictionaryRef> scoped_dict(dict);
+
+ // Check the LMP version.
+ // See the following link for the relationship between LMP version and
+ // Bluetooth Core Specification version.
+ // https://www.bluetooth.org/en-us/specification/assigned-numbers/link-manager
+ // Bluetooth Low Energy is available in Bluetooth Core Specification
+ // Version 4.0+.
Mark Mentovai 2014/07/09 17:53:00 As I understand it, Bluetooth 4.0 allows devices t
erikchen 2014/07/09 20:14:42 Hm. Right you are. I spent some time looking int
+ // http://en.wikipedia.org/wiki/Bluetooth_low_energy
+ NSDictionary* objc_dict = base::mac::CFToNSCast(scoped_dict.get());
+ NSNumber* lmp_version =
+ base::mac::ObjCCast<NSNumber>([objc_dict objectForKey:@"LMPVersion"]);
+ if (!lmp_version)
+ continue;
+
+ // A bluetooth device with an LMP version has been found. Record the
+ // highest version among all devices.
+ success = true;
+ version = std::max(version, [lmp_version intValue]);
+ }
+
+ if (!success)
+ return -2;
+
+ return version;
+}
+
+BluetoothAvailability GetBluetoothAvailability() {
+ static int result = GetBluetoothLMPVersion();
+ if (result == -2)
+ return BLUETOOTH_AVAILABILITY_ERROR;
+ if (result == -1)
+ return BLUETOOTH_NOT_AVAILABLE;
+ if (result < 6)
+ return BLUETOOTH_AVAILABLE_WITHOUT_LE;
+ return BLUETOOTH_AVAILABLE_WITH_LE;
+}
+
+} // namespace hardware_utility

Powered by Google App Engine
This is Rietveld 408576698