Commit bf569c8f authored by Oleh Lamzin's avatar Oleh Lamzin Committed by Commit Bot

[Telemetry SWX] Add bluetooth info

Add bluetooth info to the probe service.

Bug: b:158658869
Change-Id: Ic17d533e877dd1be3804587ca6126125dec7b869
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2275880
Commit-Queue: Oleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarMahmoud Gawad <mgawad@google.com>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarRoland Bock <rbock@google.com>
Cr-Commit-Position: refs/heads/master@{#786274}
parent ccb8622d
......@@ -30,6 +30,7 @@
// - BacklightInfo
// - FanInfo
// - StatefulPartitionInfo
// - BluetoothAdapterInfo
// 3) NonRemovableBlockDeviceInfo: use uint32 to store manufacturer_id instead
// of uint8 in case we want to extend manufacturer range.
// 4) LogicalCpuInfo:
......@@ -70,6 +71,7 @@ enum ProbeCategoryEnum {
kBacklight,
kFan,
kStatefulPartition,
kBluetooth,
};
// An enumeration of the different categories of errors that can occur when
......@@ -121,6 +123,13 @@ struct UInt64Value {
uint64 value;
};
// Optional bool field. Since primitives numeric types cannot be optional,
// wrap bool in a struct that can be nulled.
struct BoolValue {
// The value of the bool.
bool value;
};
// Information related to the main battery.
struct BatteryInfo {
// Cycle count.
......@@ -374,6 +383,27 @@ union StatefulPartitionResult {
ProbeError error;
};
// Information related to one of a device's Bluetooth adapters.
struct BluetoothAdapterInfo {
// The name of the adapter.
string? name;
// The MAC address of the adapter.
string? address;
// Indicates whether the adapter is on or off.
BoolValue? powered;
// The number of devices connected to this adapter.
UInt32Value? num_connected_devices;
};
// Bluetooth probe result. Can either be populated with the BluetoothAdapterInfo
// or an error retrieving the information.
union BluetoothResult {
// Valid BluetoothAdapterInfo.
array<BluetoothAdapterInfo> bluetooth_adapter_info;
// The error that occurred attempting to retrieve the BluetoothAdapterInfo.
ProbeError error;
};
// A collection of all the device's telemetry information that cros_healthd is
// capable of reporting. Note that every field in TelemetryInfo is nullable, and
// the response for a particular ProbeTelemetryInfo request will only contain
......@@ -411,4 +441,7 @@ struct TelemetryInfo {
// kStatefulPartition was included in the categories input to
// ProbeTelemetryInfo.
StatefulPartitionResult? stateful_partition_result;
// Information about the device's Bluetooth adapters and devices. Only present
// when kBluetooth was included in the categories input to ProbeTelemetryInfo.
BluetoothResult? bluetooth_result;
};
......@@ -36,6 +36,8 @@ cros_healthd::mojom::ProbeCategoryEnum Convert(
return cros_healthd::mojom::ProbeCategoryEnum::kFan;
case health::mojom::ProbeCategoryEnum::kStatefulPartition:
return cros_healthd::mojom::ProbeCategoryEnum::kStatefulPartition;
case health::mojom::ProbeCategoryEnum::kBluetooth:
return cros_healthd::mojom::ProbeCategoryEnum::kBluetooth;
}
NOTREACHED();
}
......@@ -274,6 +276,27 @@ health::mojom::StatefulPartitionResultPtr UncheckedConvertPtr(
NOTREACHED();
}
health::mojom::BluetoothAdapterInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::BluetoothAdapterInfoPtr input) {
return health::mojom::BluetoothAdapterInfo::New(
std::move(input->name), std::move(input->address),
Convert(input->powered), Convert(input->num_connected_devices));
}
health::mojom::BluetoothResultPtr UncheckedConvertPtr(
cros_healthd::mojom::BluetoothResultPtr input) {
switch (input->which()) {
case cros_healthd::mojom::BluetoothResult::Tag::BLUETOOTH_ADAPTER_INFO:
return health::mojom::BluetoothResult::NewBluetoothAdapterInfo(
ConvertPtrVector<health::mojom::BluetoothAdapterInfoPtr>(
std::move(input->get_bluetooth_adapter_info())));
case cros_healthd::mojom::BluetoothResult::Tag::ERROR:
return health::mojom::BluetoothResult::NewError(
ConvertPtr(std::move(input->get_error())));
}
NOTREACHED();
}
health::mojom::TelemetryInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::TelemetryInfoPtr input) {
return health::mojom::TelemetryInfo::New(
......@@ -285,7 +308,8 @@ health::mojom::TelemetryInfoPtr UncheckedConvertPtr(
ConvertPtr(std::move(input->memory_result)),
ConvertPtr(std::move(input->backlight_result)),
ConvertPtr(std::move(input->fan_result)),
ConvertPtr(std::move(input->stateful_partition_result)));
ConvertPtr(std::move(input->stateful_partition_result)),
ConvertPtr(std::move(input->bluetooth_result)));
}
} // namespace unchecked
......@@ -317,6 +341,10 @@ health::mojom::CpuArchitectureEnum Convert(
NOTREACHED();
}
health::mojom::BoolValuePtr Convert(bool input) {
return health::mojom::BoolValue::New(input);
}
health::mojom::DoubleValuePtr Convert(double input) {
return health::mojom::DoubleValue::New(input);
}
......
......@@ -97,6 +97,12 @@ health::mojom::StatefulPartitionInfoPtr UncheckedConvertPtr(
health::mojom::StatefulPartitionResultPtr UncheckedConvertPtr(
cros_healthd::mojom::StatefulPartitionResultPtr input);
health::mojom::BluetoothAdapterInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::BluetoothAdapterInfoPtr input);
health::mojom::BluetoothResultPtr UncheckedConvertPtr(
cros_healthd::mojom::BluetoothResultPtr input);
health::mojom::TelemetryInfoPtr UncheckedConvertPtr(
cros_healthd::mojom::TelemetryInfoPtr input);
......@@ -107,6 +113,8 @@ health::mojom::ErrorType Convert(cros_healthd::mojom::ErrorType type);
health::mojom::CpuArchitectureEnum Convert(
cros_healthd::mojom::CpuArchitectureEnum input);
health::mojom::BoolValuePtr Convert(bool input);
health::mojom::DoubleValuePtr Convert(double input);
health::mojom::Int64ValuePtr Convert(int64_t input);
......
......@@ -27,7 +27,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) {
health::mojom::ProbeCategoryEnum::kMemory,
health::mojom::ProbeCategoryEnum::kBacklight,
health::mojom::ProbeCategoryEnum::kFan,
health::mojom::ProbeCategoryEnum::kStatefulPartition};
health::mojom::ProbeCategoryEnum::kStatefulPartition,
health::mojom::ProbeCategoryEnum::kBluetooth};
EXPECT_THAT(
ConvertCategoryVector(kInput),
ElementsAre(
......@@ -39,7 +40,8 @@ TEST(ProbeServiceConvertors, ConvertCategoryVector) {
cros_healthd::mojom::ProbeCategoryEnum::kMemory,
cros_healthd::mojom::ProbeCategoryEnum::kBacklight,
cros_healthd::mojom::ProbeCategoryEnum::kFan,
cros_healthd::mojom::ProbeCategoryEnum::kStatefulPartition));
cros_healthd::mojom::ProbeCategoryEnum::kStatefulPartition,
cros_healthd::mojom::ProbeCategoryEnum::kBluetooth));
}
// Tests that |ConvertPtr| function returns nullptr if input is nullptr.
......@@ -67,6 +69,11 @@ TEST(ProbeServiceConvertors, ProbeErrorPtr) {
health::mojom::ErrorType::kFileReadError, kMsg));
}
TEST(ProbeServiceConvertors, BoolValue) {
EXPECT_EQ(Convert(false), health::mojom::BoolValue::New(false));
EXPECT_EQ(Convert(true), health::mojom::BoolValue::New(true));
}
TEST(ProbeServiceConvertors, DoubleValue) {
constexpr double kValue = 100500.500100;
EXPECT_EQ(Convert(kValue), health::mojom::DoubleValue::New(kValue));
......@@ -573,6 +580,60 @@ TEST(ProbeServiceConvertors, StatefulPartitionResultPtrError) {
EXPECT_TRUE(output->is_error());
}
TEST(ProbeServiceConvertors, BluetoothAdapterInfoPtr) {
constexpr char kName[] = "hci0";
constexpr char kAddress[] = "ab:cd:ef:12:34:56";
constexpr bool kPowered = true;
constexpr uint32_t kNumConnectedDevices = 3;
auto input = cros_healthd::mojom::BluetoothAdapterInfo::New();
input->name = kName;
input->address = kAddress;
input->powered = kPowered;
input->num_connected_devices = kNumConnectedDevices;
const auto output = ConvertPtr(std::move(input));
ASSERT_TRUE(output);
EXPECT_EQ(output->name, kName);
EXPECT_EQ(output->address, kAddress);
EXPECT_EQ(output->powered, health::mojom::BoolValue::New(kPowered));
EXPECT_EQ(output->num_connected_devices,
health::mojom::UInt32Value::New(kNumConnectedDevices));
}
TEST(ProbeServiceConvertors, BluetoothResultPtrInfo) {
constexpr char kName[] = "hci0";
cros_healthd::mojom::BluetoothResultPtr input;
{
auto info = cros_healthd::mojom::BluetoothAdapterInfo::New();
info->name = kName;
std::vector<cros_healthd::mojom::BluetoothAdapterInfoPtr> infos;
infos.push_back(std::move(info));
input = cros_healthd::mojom::BluetoothResult::NewBluetoothAdapterInfo(
std::move(infos));
}
const auto output = ConvertPtr(input.Clone());
ASSERT_TRUE(output);
ASSERT_TRUE(output->is_bluetooth_adapter_info());
const auto& bluetooth_adapter_info_output =
output->get_bluetooth_adapter_info();
ASSERT_EQ(bluetooth_adapter_info_output.size(), 1ULL);
ASSERT_TRUE(bluetooth_adapter_info_output[0]);
EXPECT_EQ(bluetooth_adapter_info_output[0]->name, kName);
}
TEST(ProbeServiceConvertors, BluetoothResultPtrError) {
const health::mojom::BluetoothResultPtr output =
ConvertPtr(cros_healthd::mojom::BluetoothResult::NewError(nullptr));
ASSERT_TRUE(output);
EXPECT_TRUE(output->is_error());
}
TEST(ProbeServiceConvertors, TelemetryInfoPtrHasBatteryResult) {
constexpr int64_t kCycleCount = 1;
......@@ -812,6 +873,7 @@ TEST(ProbeServiceConvertors, TelemetryInfoPtrWithNullFields) {
EXPECT_FALSE(telemetry_info_output->backlight_result);
EXPECT_FALSE(telemetry_info_output->fan_result);
EXPECT_FALSE(telemetry_info_output->stateful_partition_result);
EXPECT_FALSE(telemetry_info_output->bluetooth_result);
}
} // namespace probe_service_converters
......
......@@ -64,6 +64,7 @@ UNTRUSTED_TEST('UntustedRequestTelemetryInfo', async () => {
'backlightResult': null,
'batteryResult': null,
'blockDeviceResult': null,
'bluetoothResult': null,
'cpuResult': null,
'fanResult': null,
'memoryResult': null,
......
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