Chromium Code Reviews| Index: components/arc/bluetooth/arc_bluetooth_bridge.cc |
| diff --git a/components/arc/bluetooth/arc_bluetooth_bridge.cc b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| index 3b8cf87ba4cd2e19c14df0cc88ef04ff501e8bc6..9d0e2274f2e0f3865b20f0ce8952bf694b3e797b 100644 |
| --- a/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| +++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| @@ -311,8 +311,7 @@ void ArcBluetoothBridge::OnInstanceClosed() { |
| bluetooth_adapter_->RemoveObserver(this); |
| } |
| -void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter, |
| - BluetoothDevice* device) { |
| +void ArcBluetoothBridge::SendDeviceData(const BluetoothDevice* device) const { |
|
Luis Héctor Chávez
2016/10/06 16:51:01
Maybe SendDevicePropertiesAndAdvData? SendDeviceIn
puthik_chromium
2016/10/06 18:29:30
SendDeviceInformation
|
| auto* bluetooth_instance = |
| arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound"); |
| if (!bluetooth_instance) |
| @@ -323,22 +322,29 @@ void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter, |
| bluetooth_instance->OnDeviceFound(std::move(properties)); |
| - auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| - "OnLEDeviceFound", kMinBtleVersion); |
| - if (!btle_instance) |
| - return; |
| if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) |
| return; |
| - mojom::BluetoothAddressPtr addr = |
| - mojom::BluetoothAddress::From(device->GetAddress()); |
| base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
| - mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| - GetAdvertisingData(device); |
| - btle_instance->OnLEDeviceFound(std::move(addr), |
| - rssi.value_or(mojom::kUnknownPower), |
| - std::move(adv_data)); |
| + mojom::BluetoothAddressPtr addr; |
| + |
| + // We only want to send updated advertise data to Android only when we are |
| + // scanning which is checked by the validity of rssi. Here are the 2 cases |
| + // that we don't want to send updated advertise data to Android. |
| + // 1) Cached found device and 2) rssi became invalid when we stop scanning. |
| + if (rssi.has_value()) { |
| + auto* btle_instance = |
| + arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| + "OnLEDeviceFound", kMinBtleVersion); |
| + if (!btle_instance) |
| + return; |
| + mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| + GetAdvertisingData(device); |
| + addr = mojom::BluetoothAddress::From(device->GetAddress()); |
| + btle_instance->OnLEDeviceFound(std::move(addr), rssi.value(), |
| + std::move(adv_data)); |
| + } |
| if (!device->IsConnected()) |
| return; |
| @@ -347,8 +353,15 @@ void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter, |
| OnGattConnectStateChanged(std::move(addr), true); |
| } |
| +void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter, |
| + BluetoothDevice* device) { |
| + SendDeviceData(device); |
| +} |
| + |
| void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter, |
| BluetoothDevice* device) { |
| + SendDeviceData(device); |
| + |
| if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) |
| return; |
| @@ -1704,7 +1717,7 @@ void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const { |
| mojo::Array<mojom::BluetoothPropertyPtr> |
| ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type, |
| - BluetoothDevice* device) const { |
| + const BluetoothDevice* device) const { |
| mojo::Array<mojom::BluetoothPropertyPtr> properties; |
| if (!device) { |
| @@ -1725,10 +1738,12 @@ ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type, |
| } |
| if (type == mojom::BluetoothPropertyType::ALL || |
| type == mojom::BluetoothPropertyType::UUIDS) { |
| - mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| BluetoothDevice::UUIDSet uuids = device->GetUUIDs(); |
| - btp->set_uuids(std::vector<BluetoothUUID>(uuids.begin(), uuids.end())); |
| - properties.push_back(std::move(btp)); |
| + if (uuids.size() > 0) { |
| + mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| + btp->set_uuids(std::vector<BluetoothUUID>(uuids.begin(), uuids.end())); |
| + properties.push_back(std::move(btp)); |
| + } |
| } |
| if (type == mojom::BluetoothPropertyType::ALL || |
| type == mojom::BluetoothPropertyType::CLASS_OF_DEVICE) { |
| @@ -1751,10 +1766,12 @@ ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type, |
| } |
| if (type == mojom::BluetoothPropertyType::ALL || |
| type == mojom::BluetoothPropertyType::REMOTE_RSSI) { |
| - mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
| - btp->set_remote_rssi(rssi.value_or(mojom::kUnknownPower)); |
| - properties.push_back(std::move(btp)); |
| + if (rssi.has_value()) { |
| + mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| + btp->set_remote_rssi(rssi.value()); |
| + properties.push_back(std::move(btp)); |
| + } |
| } |
| // TODO(smbarber): Add remote version info |
| @@ -1868,7 +1885,7 @@ ArcBluetoothBridge::GetAdapterProperties( |
| // UUID 128 bits. |
| // TODO(crbug.com/618442) Make Chrome expose missing data. |
| mojo::Array<mojom::BluetoothAdvertisingDataPtr> |
| -ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const { |
| +ArcBluetoothBridge::GetAdvertisingData(const BluetoothDevice* device) const { |
| mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; |
| // LocalName |
| @@ -1916,72 +1933,34 @@ ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const { |
| } |
| void ArcBluetoothBridge::SendCachedDevicesFound() const { |
| - // Send devices that have already been discovered, but aren't connected. |
| - auto* bluetooth_instance = |
| - arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound"); |
| - if (!bluetooth_instance) |
| - return; |
| - auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| - "OnLEDeviceFound", kMinBtleVersion); |
| + DCHECK(bluetooth_adapter_); |
| + // Send devices that have already been discovered, but aren't connected. |
| BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
| for (auto* device : devices) { |
| if (device->IsPaired()) |
| continue; |
| - mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| - GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| - |
| - bluetooth_instance->OnDeviceFound(std::move(properties)); |
| - |
| - if (btle_instance) { |
| - mojom::BluetoothAddressPtr addr = |
| - mojom::BluetoothAddress::From(device->GetAddress()); |
| - base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
| - mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| - GetAdvertisingData(device); |
| - btle_instance->OnLEDeviceFound(std::move(addr), |
| - rssi.value_or(mojom::kUnknownPower), |
| - std::move(adv_data)); |
| - } |
| + SendDeviceData(device); |
| } |
| } |
| void ArcBluetoothBridge::SendCachedPairedDevices() const { |
| DCHECK(bluetooth_adapter_); |
| - auto* bluetooth_instance = |
| - arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound"); |
| - if (!bluetooth_instance) |
| - return; |
| - auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| - "OnLEDeviceFound", kMinBtleVersion); |
| BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
| for (auto* device : devices) { |
| if (!device->IsPaired()) |
| continue; |
| - mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| - GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| - |
| - bluetooth_instance->OnDeviceFound(std::move(properties)); |
| - |
| - mojom::BluetoothAddressPtr addr = |
| - mojom::BluetoothAddress::From(device->GetAddress()); |
| - |
| - if (btle_instance) { |
| - base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
| - mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| - GetAdvertisingData(device); |
| - btle_instance->OnLEDeviceFound(addr->Clone(), |
| - rssi.value_or(mojom::kUnknownPower), |
| - std::move(adv_data)); |
| - } |
| + SendDeviceData(device); |
| // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING |
| // to make sure the bond state machine on Android is ready to take the |
| // pair-done event. Otherwise the pair-done event will be dropped as an |
| // invalid change of paired status. |
| + mojom::BluetoothAddressPtr addr = |
| + mojom::BluetoothAddress::From(device->GetAddress()); |
| OnPairing(addr->Clone()); |
| OnPairedDone(std::move(addr)); |
| } |