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

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac.mm

Issue 2339253002: bluetooth: mac: add connected LE devices to chooser (Closed)
Patch Set: Cleanup Created 4 years, 2 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 unified diff | Download patch
OLDNEW
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 163 }
164 164
165 bool BluetoothAdapterMac::IsDiscovering() const { 165 bool BluetoothAdapterMac::IsDiscovering() const {
166 bool is_discovering = classic_discovery_manager_->IsDiscovering(); 166 bool is_discovering = classic_discovery_manager_->IsDiscovering();
167 if (IsLowEnergyAvailable()) 167 if (IsLowEnergyAvailable())
168 is_discovering = 168 is_discovering =
169 is_discovering || low_energy_discovery_manager_->IsDiscovering(); 169 is_discovering || low_energy_discovery_manager_->IsDiscovering();
170 return is_discovering; 170 return is_discovering;
171 } 171 }
172 172
173 void BluetoothAdapterMac::RetrievedConnectedPeripherals() {
ortuno 2016/10/06 02:22:07 +scheib for thoughts. Some context: We are adding
ortuno 2016/10/06 02:22:52 +scheib for realz
scheib 2016/10/06 21:01:34 RetrievedConnectedPeripherals seems to be incorrec
ortuno 2016/10/06 23:43:12 Right, but we still have the problem of providing
scheib 2016/10/07 17:08:00 This method doesn't return devices. It causes conn
ortuno 2016/10/10 02:57:22 The current method as is does not return devices b
jlebel 2016/10/13 15:29:02 Acknowledged.
174 // It is not possible to ask for all connected peripherals with
175 // -[CBCentralManager retrieveConnectedPeripheralsWithServices:] by passing
176 // nil. To try to get most of the peripherals, the search is done with
177 // Generic Access service.
178 CBUUID* genericAccessServiceUUID = [CBUUID UUIDWithString:@"1800"];
ortuno 2016/10/12 06:42:46 I've been thinking about this and I think we need
jlebel 2016/10/13 15:29:01 I've tried, and yes, the devices are filtered out
ortuno 2016/10/14 03:03:03 To summarize the problem: Peripherals returned by
scheib 2016/10/14 17:16:14 :( I'm a tad confused on if we have the UUIDs to
179 NSArray* connectedServices = @[ genericAccessServiceUUID ];
180 #pragma clang diagnostic push
181 #pragma clang diagnostic ignored "-Wpartial-availability"
182 // Can remove ignore -Wpartial-availability when 10.8 will not be supported
183 // anymore.
184 // TODO(crbug.com/653056)
185 NSArray* peripherals = [low_energy_central_manager_
186 retrieveConnectedPeripheralsWithServices:connectedServices];
187 #pragma clang diagnostic pop
188 for (CBPeripheral* peripheral in peripherals) {
189 LowEnergyDeviceUpdated(peripheral, nil /* advertisementData */,
190 0 /* rssi */);
191 }
192 }
193
173 BluetoothAdapter::UUIDList BluetoothAdapterMac::GetUUIDs() const { 194 BluetoothAdapter::UUIDList BluetoothAdapterMac::GetUUIDs() const {
174 NOTIMPLEMENTED(); 195 NOTIMPLEMENTED();
175 return UUIDList(); 196 return UUIDList();
176 } 197 }
177 198
178 void BluetoothAdapterMac::CreateRfcommService( 199 void BluetoothAdapterMac::CreateRfcommService(
179 const BluetoothUUID& uuid, 200 const BluetoothUUID& uuid,
180 const ServiceOptions& options, 201 const ServiceOptions& options,
181 const CreateServiceCallback& callback, 202 const CreateServiceCallback& callback,
182 const CreateServiceErrorCallback& error_callback) { 203 const CreateServiceErrorCallback& error_callback) {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 // hash the probability of this occuring with 10,000 devices 527 // hash the probability of this occuring with 10,000 devices
507 // simultaneously present is 1e-6 (see 528 // simultaneously present is 1e-6 (see
508 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We 529 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We
509 // ignore the second device by returning. 530 // ignore the second device by returning.
510 return; 531 return;
511 } 532 }
512 } 533 }
513 534
514 DCHECK(device_mac); 535 DCHECK(device_mac);
515 536
516 // Get Advertised UUIDs 537 if (advertisement_data) {
517 BluetoothDevice::UUIDList advertised_uuids; 538 // Get Advertised UUIDs
518 NSArray* service_uuids = 539 BluetoothDevice::UUIDList advertised_uuids;
519 [advertisement_data objectForKey:CBAdvertisementDataServiceUUIDsKey]; 540 NSArray* service_uuids =
520 for (CBUUID* uuid in service_uuids) { 541 [advertisement_data objectForKey:CBAdvertisementDataServiceUUIDsKey];
521 advertised_uuids.push_back(BluetoothUUID([[uuid UUIDString] UTF8String])); 542 for (CBUUID* uuid in service_uuids) {
543 advertised_uuids.push_back(BluetoothUUID([[uuid UUIDString] UTF8String]));
544 }
545 NSArray* overflow_service_uuids = [advertisement_data
546 objectForKey:CBAdvertisementDataOverflowServiceUUIDsKey];
547 for (CBUUID* uuid in overflow_service_uuids) {
548 advertised_uuids.push_back(BluetoothUUID([[uuid UUIDString] UTF8String]));
549 }
550
551 // Get Service Data.
552 BluetoothDevice::ServiceDataMap service_data_map;
553 NSDictionary* service_data =
554 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey];
555 for (CBUUID* uuid in service_data) {
556 NSData* data = [service_data objectForKey:uuid];
557 const uint8_t* bytes = static_cast<const uint8_t*>([data bytes]);
558 size_t length = [data length];
559 service_data_map.emplace(BluetoothUUID([[uuid UUIDString] UTF8String]),
560 std::vector<uint8_t>(bytes, bytes + length));
561 }
562
563 // Get Tx Power.
564 NSNumber* tx_power =
565 [advertisement_data objectForKey:CBAdvertisementDataTxPowerLevelKey];
566 int8_t clamped_tx_power = BluetoothDevice::ClampPower([tx_power intValue]);
567
568 device_mac->UpdateAdvertisementData(
569 BluetoothDevice::ClampPower(rssi), std::move(advertised_uuids),
570 std::move(service_data_map),
571 tx_power == nil ? nullptr : &clamped_tx_power);
522 } 572 }
523 NSArray* overflow_service_uuids = [advertisement_data
524 objectForKey:CBAdvertisementDataOverflowServiceUUIDsKey];
525 for (CBUUID* uuid in overflow_service_uuids) {
526 advertised_uuids.push_back(BluetoothUUID([[uuid UUIDString] UTF8String]));
527 }
528
529 // Get Service Data.
530 BluetoothDevice::ServiceDataMap service_data_map;
531 NSDictionary* service_data =
532 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey];
533 for (CBUUID* uuid in service_data) {
534 NSData* data = [service_data objectForKey:uuid];
535 const uint8_t* bytes = static_cast<const uint8_t*>([data bytes]);
536 size_t length = [data length];
537 service_data_map.emplace(BluetoothUUID([[uuid UUIDString] UTF8String]),
538 std::vector<uint8_t>(bytes, bytes + length));
539 }
540
541 // Get Tx Power.
542 NSNumber* tx_power =
543 [advertisement_data objectForKey:CBAdvertisementDataTxPowerLevelKey];
544 int8_t clamped_tx_power = BluetoothDevice::ClampPower([tx_power intValue]);
545
546 device_mac->UpdateAdvertisementData(
547 BluetoothDevice::ClampPower(rssi), std::move(advertised_uuids),
548 std::move(service_data_map),
549 tx_power == nil ? nullptr : &clamped_tx_power);
550 573
551 if (is_new_device) { 574 if (is_new_device) {
552 std::string device_address = 575 std::string device_address =
553 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 576 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
554 devices_.add(device_address, std::unique_ptr<BluetoothDevice>(device_mac)); 577 devices_.add(device_address, std::unique_ptr<BluetoothDevice>(device_mac));
555 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 578 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
556 DeviceAdded(this, device_mac)); 579 DeviceAdded(this, device_mac));
557 } else { 580 } else {
558 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 581 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
559 DeviceChanged(this, device_mac)); 582 DeviceChanged(this, device_mac));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 std::string device_address = 661 std::string device_address =
639 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 662 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
640 DevicesMap::const_iterator iter = devices_.find(device_address); 663 DevicesMap::const_iterator iter = devices_.find(device_address);
641 if (iter == devices_.end()) { 664 if (iter == devices_.end()) {
642 return nil; 665 return nil;
643 } 666 }
644 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 667 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
645 } 668 }
646 669
647 } // namespace device 670 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac.h ('k') | device/bluetooth/bluetooth_adapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698