Skip to content

Commit

Permalink
DeviceStatusCollector: report three new battery metrics
Browse files Browse the repository at this point in the history
Add current, technology and status to the battery metrics
already collected by DeviceStatusCollector. Of these three,
only technology is expected to change infrequently, so
sample current and status more frequently.

CrosHealthdServiceConnectionTest.ProbeTelemetryInfo

Bug: chromium:1053755
Test: DeviceStatusCollectorTest.TestCrosHealthdInfo and
Change-Id: I30f7abfcdd35e71972ce4f053b9433ba61f71cb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2064458
Reviewed-by: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Paul Moy <pmoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742770}
  • Loading branch information
Paul Moy authored and Commit Bot committed Feb 19, 2020
1 parent edc939e commit a2a90bd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ class DeviceStatusCollectorState : public StatusCollectorState {
battery_info_out->set_serial(battery_info->serial_number);
battery_info_out->set_manufacturer(battery_info->vendor);
battery_info_out->set_cycle_count(battery_info->cycle_count);
battery_info_out->set_technology(battery_info->technology);
// Convert Ah to mAh:
battery_info_out->set_design_capacity(
std::lround(battery_info->charge_full_design * 1000));
Expand Down Expand Up @@ -1293,6 +1294,9 @@ void DeviceStatusCollector::SampleProbeData(
// Convert Ah to mAh:
battery_sample.set_remaining_capacity(
std::lround(battery->charge_now * 1000));
// Convert A to mA:
battery_sample.set_current(std::lround(battery->current_now * 1000));
battery_sample.set_status(battery->status);
// Convert 0.1 Kelvin to Celsius:
const auto& smart_info = battery->smart_battery_info;
if (!smart_info.is_null()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ constexpr char kFakeBatteryModel[] = "fake_battery_model";
constexpr int kExpectedBatteryChargeNow = 5281; // (mAh)
constexpr double kFakeBatteryChargeNow =
kExpectedBatteryChargeNow / 1000.0; // (Ah)
constexpr int kExpectedBatteryCurrentNow = 87659; // (mA)
constexpr double kFakeBatteryCurrentNow =
kExpectedBatteryCurrentNow / 1000.0; // (A)
constexpr char kFakeBatteryTechnology[] = "fake_battery_technology";
constexpr char kFakeBatteryStatus[] = "fake_battery_status";
// Cached VPD test values:
constexpr char kFakeSkuNumber[] = "fake_sku_number";
// CPU test values:
Expand Down Expand Up @@ -432,6 +437,7 @@ void GetFakeCrosHealthdData(
kFakeBatteryCycleCount, kFakeBatteryVoltageNow, kFakeBatteryVendor,
kFakeBatterySerial, kFakeBatteryChargeFullDesign, kFakeBatteryChargeFull,
kFakeBatteryVoltageMinDesign, kFakeBatteryModel, kFakeBatteryChargeNow,
kFakeBatteryCurrentNow, kFakeBatteryTechnology, kFakeBatteryStatus,
smart_battery_info.Clone());
chromeos::cros_healthd::mojom::CachedVpdInfo cached_vpd_info(kFakeSkuNumber);
chromeos::cros_healthd::mojom::CpuInfo cpu_info(
Expand Down Expand Up @@ -462,6 +468,8 @@ void GetFakeCrosHealthdData(
fake_battery_sample.set_voltage(kExpectedBatteryVoltageNow);
fake_battery_sample.set_remaining_capacity(kExpectedBatteryChargeNow);
fake_battery_sample.set_temperature(kFakeSmartBatteryTemperature);
fake_battery_sample.set_current(kExpectedBatteryCurrentNow);
fake_battery_sample.set_status(kFakeBatteryStatus);
auto sample = std::make_unique<policy::SampledData>();
sample->cpu_samples[fake_cpu_temp_sample.cpu_label()] = fake_cpu_temp_sample;
sample->battery_samples[battery_info.model_name] = fake_battery_sample;
Expand Down Expand Up @@ -2544,13 +2552,16 @@ TEST_F(DeviceStatusCollectorTest, TestCrosHealthdInfo) {
EXPECT_EQ(battery.cycle_count(), kFakeBatteryCycleCount);
EXPECT_EQ(battery.design_min_voltage(), kExpectedBatteryVoltageMinDesign);
EXPECT_EQ(battery.manufacture_date(), kFakeSmartBatteryManufactureDate);
EXPECT_EQ(battery.technology(), kFakeBatteryTechnology);

// Verify the battery sample data.
ASSERT_EQ(battery.samples_size(), 1);
const auto& battery_sample = battery.samples(0);
EXPECT_EQ(battery_sample.voltage(), kExpectedBatteryVoltageNow);
EXPECT_EQ(battery_sample.remaining_capacity(), kExpectedBatteryChargeNow);
EXPECT_EQ(battery_sample.temperature(), kFakeSmartBatteryTemperature);
EXPECT_EQ(battery_sample.current(), kExpectedBatteryCurrentNow);
EXPECT_EQ(battery_sample.status(), kFakeBatteryStatus);

// Verify the storage data.
ASSERT_TRUE(device_status_.has_storage_status());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ mojom::BatteryInfoPtr MakeBatteryInfo() {
"battery_vendor" /* vendor */, "serial_number" /* serial_number */,
5.275 /* charge_full_design */, 5.292 /* charge_full */,
11.55 /* voltage_min_design */, "battery_model" /* model_name */,
5.123 /* charge_now */, std::move(smart_info));
5.123 /* charge_now */, 98.123 /* current_now */,
"battery_technology" /* technology */, "battery_status" /* status */,
std::move(smart_info));
}

mojom::CachedVpdInfoPtr MakeCachedVpdInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ struct BatteryInfo {
string model_name;
// Current battery charge (Ah)
double charge_now;
// Current battery current (A)
double current_now;
// Technology of the battery
string technology;
// Status of the battery
string status;
// Information related to a Smart Battery. Included when the main battery is a
// Smart Battery.
SmartBatteryInfo? smart_battery_info;
Expand Down
6 changes: 6 additions & 0 deletions components/policy/proto/device_management_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,10 @@ message BatterySample {
optional int32 discharge_rate = 5;
// Battery charge percentage
optional int32 charge_rate = 6;
// Battery current (mA)
optional int64 current = 7;
// Battery status read from sysfs
optional string status = 8;
}

// Status of the single battery
Expand All @@ -896,6 +900,8 @@ message BatteryInfo {
optional int32 design_min_voltage = 9;
// The date the battery was manufactured in yyyy-mm-dd format.
optional string manufacture_date = 10;
// Technology of the battery.
optional string technology = 11;
}

// Status of the power subsystem
Expand Down

0 comments on commit a2a90bd

Please sign in to comment.