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..62184a5cd51157e09ac1a8f079e4bd07a4935c18 |
--- /dev/null |
+++ b/chrome/browser/mac/hardware_utility.mm |
@@ -0,0 +1,73 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
Avi (use Gerrit)
2014/07/08 23:38:20
No (c), 2014.
erikchen
2014/07/09 00:18:57
Done.
|
+// 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> |
+ |
+namespace hardware_utility { |
+ |
+// Returns the Bluetooth driver's Link Management Protocol version. |
+// Returns -1 if no Bluetooth driver is present. |
+// Returns -2 on an unexpected error. |
+int GetBluetoothLMPVersion() { |
+ CFMutableDictionaryRef matching_dict = |
Avi (use Gerrit)
2014/07/08 23:32:03
base::ScopedCFTypeRef<CFMutableDictionaryRef>
erikchen
2014/07/09 00:18:57
That won't work, since IOServiceGetMatchingService
Avi (use Gerrit)
2014/07/09 01:54:05
On ScopedCFTypeRef, .Pass() is spelled .release()
Avi (use Gerrit)
2014/07/09 01:55:45
Actually, release() is a lot dumber than Pass(), b
erikchen
2014/07/09 02:04:21
Right you are. I made the incorrect assumption tha
Avi (use Gerrit)
2014/07/09 03:36:43
Yeah, it's a non-awesome name conflict.
|
+ IOServiceMatching("IOBluetoothHCIController"); |
+ if (!matching_dict) |
+ return -2; |
+ |
+ io_iterator_t iter; |
+ int kr = |
+ IOServiceGetMatchingServices(kIOMasterPortDefault, matching_dict, &iter); |
+ |
Avi (use Gerrit)
2014/07/08 23:32:03
Immediately after IOServiceGetMatchingServices, pu
erikchen
2014/07/09 00:18:57
Done.
|
+ if (kr != KERN_SUCCESS) |
+ return -1; |
+ |
+ int version = 0; |
+ bool success = false; |
+ io_service_t device; |
+ while ((device = IOIteratorNext(iter))) { |
Avi (use Gerrit)
2014/07/08 23:32:04
base::mac::ScopedIOObject<io_object_t>. See GetMAC
erikchen
2014/07/09 00:18:57
I copied the example, but used io_service_t as the
|
+ CFMutableDictionaryRef dict; |
+ kr = IORegistryEntryCreateCFProperties( |
+ device, &dict, kCFAllocatorDefault, kNilOptions); |
Avi (use Gerrit)
2014/07/08 23:32:03
Put the dictionary in base::ScopedCFTypeRef<CFMuta
erikchen
2014/07/09 00:18:57
Done.
|
+ if (kr != KERN_SUCCESS) { |
+ IOObjectRelease(device); |
+ continue; |
+ } |
+ |
+ // Check the properties for an LMP version. |
Avi (use Gerrit)
2014/07/08 23:32:46
Is there some documentation about LMP versions, an
erikchen
2014/07/09 00:18:57
Added the relevant links.
|
+ NSDictionary* objc_dict = static_cast<NSDictionary*>(dict); |
Avi (use Gerrit)
2014/07/08 23:32:04
base::mac::CFCast
Avi (use Gerrit)
2014/07/08 23:38:19
Sorry, CFToNSCast.
erikchen
2014/07/09 00:18:57
Done.
|
+ NSNumber* lmp_version = [objc_dict objectForKey:@"LMPVersion"]; |
Avi (use Gerrit)
2014/07/08 23:32:03
Use ObjCCast here and drop the class check on the
erikchen
2014/07/09 00:18:57
Done.
|
+ if (!lmp_version || ![lmp_version isKindOfClass:[NSNumber class]]) { |
+ CFRelease(dict); |
+ IOObjectRelease(device); |
+ continue; |
+ } |
+ |
+ // A bluetooth device with an LMP version has been found. Record the |
+ // highest version among all devices. |
+ success = true; |
+ version = MAX(version, [lmp_version intValue]); |
Avi (use Gerrit)
2014/07/08 23:32:03
std::max
erikchen
2014/07/09 00:18:56
Done.
|
+ CFRelease(dict); |
+ IOObjectRelease(device); |
+ } |
+ |
+ IOObjectRelease(iter); |
+ if (!success) |
+ return -2; |
+ |
+ return version; |
+} |
+ |
+BluetoothAvailability GetBluetoothAvailability() { |
+ int result = GetBluetoothLMPVersion(); |
Avi (use Gerrit)
2014/07/08 23:32:03
If this value will never change, you might as well
erikchen
2014/07/09 00:18:57
Done.
|
+ if (result < 0) |
+ return BLUETOOTH_NOT_AVAILABLE; |
+ if (result < 6) |
+ return BLUETOOTH_AVAILABLE_WITHOUT_LE; |
+ return BLUETOOTH_AVAILABLE_WITH_LE; |
+} |
+ |
+} // namespace hardware_utility |