| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/ble/bluetooth_low_energy_connection.h" | 5 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 | 552 |
| 553 BluetoothDevice* BluetoothLowEnergyConnection::GetRemoteDevice() { | 553 BluetoothDevice* BluetoothLowEnergyConnection::GetRemoteDevice() { |
| 554 // It's not possible to simply use | 554 // It's not possible to simply use |
| 555 // |adapter_->GetDevice(GetDeviceAddress())| to find the device with MAC | 555 // |adapter_->GetDevice(GetDeviceAddress())| to find the device with MAC |
| 556 // address |GetDeviceAddress()|. For paired devices, | 556 // address |GetDeviceAddress()|. For paired devices, |
| 557 // BluetoothAdapter::GetDevice(XXX) searches for the temporary MAC address | 557 // BluetoothAdapter::GetDevice(XXX) searches for the temporary MAC address |
| 558 // XXX, whereas |GetDeviceAddress()| is the real MAC address. This is a | 558 // XXX, whereas |GetDeviceAddress()| is the real MAC address. This is a |
| 559 // bug in the way device::BluetoothAdapter is storing the devices (see | 559 // bug in the way device::BluetoothAdapter is storing the devices (see |
| 560 // crbug.com/497841). | 560 // crbug.com/497841). |
| 561 std::vector<BluetoothDevice*> devices = adapter_->GetDevices(); | 561 std::vector<BluetoothDevice*> devices = adapter_->GetDevices(); |
| 562 for (const auto& device : devices) { | 562 for (auto* device : devices) { |
| 563 if (device->GetAddress() == GetDeviceAddress()) | 563 if (device->GetAddress() == GetDeviceAddress()) |
| 564 return device; | 564 return device; |
| 565 } | 565 } |
| 566 | 566 |
| 567 return nullptr; | 567 return nullptr; |
| 568 } | 568 } |
| 569 | 569 |
| 570 BluetoothRemoteGattService* BluetoothLowEnergyConnection::GetRemoteService() { | 570 BluetoothRemoteGattService* BluetoothLowEnergyConnection::GetRemoteService() { |
| 571 BluetoothDevice* remote_device = GetRemoteDevice(); | 571 BluetoothDevice* remote_device = GetRemoteDevice(); |
| 572 if (!remote_device) { | 572 if (!remote_device) { |
| 573 PA_LOG(WARNING) << "Remote device not found."; | 573 PA_LOG(WARNING) << "Remote device not found."; |
| 574 return NULL; | 574 return NULL; |
| 575 } | 575 } |
| 576 if (remote_service_.id.empty()) { | 576 if (remote_service_.id.empty()) { |
| 577 std::vector<BluetoothRemoteGattService*> services = | 577 std::vector<BluetoothRemoteGattService*> services = |
| 578 remote_device->GetGattServices(); | 578 remote_device->GetGattServices(); |
| 579 for (const auto& service : services) | 579 for (auto* service : services) |
| 580 if (service->GetUUID() == remote_service_.uuid) { | 580 if (service->GetUUID() == remote_service_.uuid) { |
| 581 remote_service_.id = service->GetIdentifier(); | 581 remote_service_.id = service->GetIdentifier(); |
| 582 break; | 582 break; |
| 583 } | 583 } |
| 584 } | 584 } |
| 585 return remote_device->GetGattService(remote_service_.id); | 585 return remote_device->GetGattService(remote_service_.id); |
| 586 } | 586 } |
| 587 | 587 |
| 588 BluetoothRemoteGattCharacteristic* | 588 BluetoothRemoteGattCharacteristic* |
| 589 BluetoothLowEnergyConnection::GetGattCharacteristic( | 589 BluetoothLowEnergyConnection::GetGattCharacteristic( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 609 const uint32_t value) { | 609 const uint32_t value) { |
| 610 std::vector<uint8_t> bytes(4, 0); | 610 std::vector<uint8_t> bytes(4, 0); |
| 611 bytes[0] = static_cast<uint8_t>(value); | 611 bytes[0] = static_cast<uint8_t>(value); |
| 612 bytes[1] = static_cast<uint8_t>(value >> 8); | 612 bytes[1] = static_cast<uint8_t>(value >> 8); |
| 613 bytes[2] = static_cast<uint8_t>(value >> 16); | 613 bytes[2] = static_cast<uint8_t>(value >> 16); |
| 614 bytes[3] = static_cast<uint8_t>(value >> 24); | 614 bytes[3] = static_cast<uint8_t>(value >> 24); |
| 615 return bytes; | 615 return bytes; |
| 616 } | 616 } |
| 617 | 617 |
| 618 } // namespace proximity_auth | 618 } // namespace proximity_auth |
| OLD | NEW |