Commit b92204cd authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Chromium LUCI CQ

[CrOS PhoneHub] Add logging to help debug BLE scans

We've seen some intermittent connectivity issues where BLE scans do not
pick up advertisements sent by the phone. However, it's hard for us to
tell what service data is being scanned so that we can match this logged
data up with bug reports on the phone.

This CL logs this metadata during BLE scans.

Bug: 1164572
Change-Id: Icefbd5624a7c5987db944883d1e77d6530951f31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626316Reviewed-by: default avatarJosh Nohle <nohle@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843034}
parent 1ee6e780
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chromeos/components/multidevice/logging/logging.h" #include "chromeos/components/multidevice/logging/logging.h"
#include "chromeos/components/multidevice/remote_device_ref.h" #include "chromeos/components/multidevice/remote_device_ref.h"
...@@ -78,6 +80,14 @@ BleScannerImpl::~BleScannerImpl() { ...@@ -78,6 +80,14 @@ BleScannerImpl::~BleScannerImpl() {
} }
void BleScannerImpl::HandleScanRequestChange() { void BleScannerImpl::HandleScanRequestChange() {
if (GetAllDeviceIdPairs().empty()) {
PA_LOG(INFO) << "No devices to scan for";
} else {
PA_LOG(INFO) << "Scanning for: "
<< bluetooth_helper_->ExpectedServiceDataToString(
GetAllDeviceIdPairs());
}
UpdateDiscoveryStatus(); UpdateDiscoveryStatus();
} }
...@@ -258,17 +268,15 @@ void BleScannerImpl::HandlePotentialScanResult( ...@@ -258,17 +268,15 @@ void BleScannerImpl::HandlePotentialScanResult(
} }
// Prepare a hex string of |service_data|. // Prepare a hex string of |service_data|.
std::stringstream ss; std::string hex_service_data = base::StrCat(
ss << "0x" << std::hex; {"0x", base::HexEncode(service_data.data(), service_data.size())});
for (const auto& character : service_data)
ss << static_cast<uint32_t>(character);
if (results.empty()) { if (results.empty()) {
PA_LOG(WARNING) << "BleScannerImpl::HandleDeviceUpdated(): Received scan " PA_LOG(WARNING) << "BleScannerImpl::HandleDeviceUpdated(): Received scan "
<< "result from device with ID \"" << "result from device with ID \""
<< potential_result.first.GetTruncatedDeviceIdForLogs() << potential_result.first.GetTruncatedDeviceIdForLogs()
<< "\", but it did not correspond to an active scan " << "\", but it did not correspond to an active scan "
<< "request. Service data: " << ss.str() << "request. Service data: " << hex_service_data
<< ", Background advertisement: " << ", Background advertisement: "
<< (potential_result.second ? "true" : "false"); << (potential_result.second ? "true" : "false");
return; return;
...@@ -277,7 +285,7 @@ void BleScannerImpl::HandlePotentialScanResult( ...@@ -277,7 +285,7 @@ void BleScannerImpl::HandlePotentialScanResult(
PA_LOG(INFO) << "BleScannerImpl::HandleDeviceUpdated(): Received scan result " PA_LOG(INFO) << "BleScannerImpl::HandleDeviceUpdated(): Received scan result "
<< "from device with ID \"" << "from device with ID \""
<< potential_result.first.GetTruncatedDeviceIdForLogs() << "\"" << potential_result.first.GetTruncatedDeviceIdForLogs() << "\""
<< ". Service data: " << ss.str() << ". Service data: " << hex_service_data
<< ", Background advertisement: " << ", Background advertisement: "
<< (potential_result.second ? "true" : "false"); << (potential_result.second ? "true" : "false");
......
...@@ -50,6 +50,11 @@ class BluetoothHelper { ...@@ -50,6 +50,11 @@ class BluetoothHelper {
virtual std::string GetBluetoothPublicAddress( virtual std::string GetBluetoothPublicAddress(
const std::string& device_id) = 0; const std::string& device_id) = 0;
// Prints a string containing the expected service data for the provided
// device IDs.
virtual std::string ExpectedServiceDataToString(
const DeviceIdPairSet& device_id_pair_set) = 0;
protected: protected:
BluetoothHelper(); BluetoothHelper();
......
...@@ -140,6 +140,40 @@ std::string BluetoothHelperImpl::GetBluetoothPublicAddress( ...@@ -140,6 +140,40 @@ std::string BluetoothHelperImpl::GetBluetoothPublicAddress(
return std::string(); return std::string();
} }
std::string BluetoothHelperImpl::ExpectedServiceDataToString(
const DeviceIdPairSet& device_id_pair_set) {
std::stringstream ss;
for (const DeviceIdPair& pair : device_id_pair_set) {
ss << "{Device ID: "
<< multidevice::RemoteDeviceRef::TruncateDeviceIdForLogs(
pair.remote_device_id())
<< " - ";
base::Optional<multidevice::RemoteDeviceRef> device =
remote_device_cache_->GetRemoteDevice(
base::nullopt /* instance_id */,
pair.remote_device_id() /* legacy_device_id */);
if (!device) {
ss << "<missing metadata>},";
continue;
}
std::vector<DataWithTimestamp> data_for_device =
background_eid_generator_->GenerateNearestEids(
multidevice::ToCryptAuthSeedList(device->beacon_seeds()));
if (data_for_device.empty()) {
ss << "[]},";
continue;
}
ss << DataWithTimestamp::ToDebugString(data_for_device) << "},";
}
return ss.str();
}
base::Optional<BluetoothHelper::DeviceWithBackgroundBool> base::Optional<BluetoothHelper::DeviceWithBackgroundBool>
BluetoothHelperImpl::PerformIdentifyRemoteDevice( BluetoothHelperImpl::PerformIdentifyRemoteDevice(
const std::string& service_data, const std::string& service_data,
......
...@@ -58,6 +58,8 @@ class BluetoothHelperImpl : public BluetoothHelper { ...@@ -58,6 +58,8 @@ class BluetoothHelperImpl : public BluetoothHelper {
const std::string& service_data, const std::string& service_data,
const DeviceIdPairSet& device_id_pair_set) override; const DeviceIdPairSet& device_id_pair_set) override;
std::string GetBluetoothPublicAddress(const std::string& device_id) override; std::string GetBluetoothPublicAddress(const std::string& device_id) override;
std::string ExpectedServiceDataToString(
const DeviceIdPairSet& device_id_pair_set) override;
base::Optional<BluetoothHelper::DeviceWithBackgroundBool> base::Optional<BluetoothHelper::DeviceWithBackgroundBool>
PerformIdentifyRemoteDevice( PerformIdentifyRemoteDevice(
......
...@@ -68,6 +68,12 @@ std::string FakeBluetoothHelper::GetBluetoothPublicAddress( ...@@ -68,6 +68,12 @@ std::string FakeBluetoothHelper::GetBluetoothPublicAddress(
return device_id_to_bluetooth_public_address_map_[device_id]; return device_id_to_bluetooth_public_address_map_[device_id];
} }
std::string FakeBluetoothHelper::ExpectedServiceDataToString(
const DeviceIdPairSet& device_id_pair_set) {
// Stub implementation.
return std::string();
}
} // namespace secure_channel } // namespace secure_channel
} // namespace chromeos } // namespace chromeos
...@@ -49,6 +49,8 @@ class FakeBluetoothHelper : public BluetoothHelper { ...@@ -49,6 +49,8 @@ class FakeBluetoothHelper : public BluetoothHelper {
const std::string& service_data, const std::string& service_data,
const DeviceIdPairSet& device_id_pair_set) override; const DeviceIdPairSet& device_id_pair_set) override;
std::string GetBluetoothPublicAddress(const std::string& device_id) override; std::string GetBluetoothPublicAddress(const std::string& device_id) override;
std::string ExpectedServiceDataToString(
const DeviceIdPairSet& device_id_pair_set) override;
std::unordered_map<DeviceIdPair, DataWithTimestamp, DeviceIdPairHash> std::unordered_map<DeviceIdPair, DataWithTimestamp, DeviceIdPairHash>
device_id_pair_to_service_data_map_; device_id_pair_to_service_data_map_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment