Commit 959282b8 authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

cros_healthd: Add SmartBatteryInfo to cros_healthd_probe.mojom

Add SmartBatteryInfo to store Smart Battery information. Update
DeviceStatusCollector to correctly include this info in the
DeviceStatusReportRequest.

Bug: 1026848
Change-Id: I00951bc8c4ef7e2acdd5f5371108e3d10993f76f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2028261Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737534}
parent 482019aa
......@@ -145,6 +145,9 @@ const char kFirmwareNotParsed[] = "FirmwareNotParsed";
// File to look for firmware number in.
const char kPathFirmware[] = "/var/log/bios_info.txt";
// O°C in deciKelvin.
const unsigned int kZeroCInDeciKelvin = 2731;
// Helper function (invoked via blocking pool) to fetch information about
// mounted disks.
std::vector<em::VolumeInfo> GetVolumeInfo(
......@@ -792,18 +795,9 @@ class DeviceStatusCollectorState : public StatusCollectorState {
// Convert V to mV:
battery_info_out->set_design_min_voltage(
std::lround(battery_info->voltage_min_design * 1000));
if (battery_info->manufacture_date_smart > 0) {
// manufacture_date in (((year-1980) * 16 + month) * 32 + day) format.
int remainder = battery_info->manufacture_date_smart;
int day = remainder % 32;
remainder /= 32;
int month = remainder % 16;
remainder /= 16;
int year = remainder + 1980;
// set manufacture_date in yyyy-mm-dd format.
battery_info_out->set_manufacture_date(
base::StringPrintf("%04d-%02d-%02d", year, month, day));
}
const auto& smart_info = battery_info->smart_battery_info;
if (!smart_info.is_null())
battery_info_out->set_manufacture_date(smart_info->manufacture_date);
const auto& cpu_info = probe_result->cpu_info;
if (cpu_info.has_value()) {
for (const auto& cpu : cpu_info.value()) {
......@@ -1287,7 +1281,11 @@ void DeviceStatusCollector::SampleProbeData(
battery_sample.set_remaining_capacity(
std::lround(battery->charge_now * 1000));
// Convert 0.1 Kelvin to Celsius:
battery_sample.set_temperature((battery->temperature_smart - 2731) / 10);
const auto& smart_info = battery->smart_battery_info;
if (!smart_info.is_null()) {
battery_sample.set_temperature(
(smart_info->temperature - kZeroCInDeciKelvin) / 10);
}
sample->battery_samples[battery->model_name] = battery_sample;
}
......
......@@ -18,6 +18,7 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/optional.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
......@@ -104,6 +105,54 @@ namespace em = enterprise_management;
namespace {
// Test values for cros_healthd:
// Battery test values:
constexpr int kFakeBatteryCycleCount = 3;
constexpr int kExpectedBatteryVoltageNow = 12574; // (mV)
constexpr double kFakeBatteryVoltageNow =
kExpectedBatteryVoltageNow / 1000.0; // (V)
constexpr char kFakeBatteryVendor[] = "fake_battery_vendor";
constexpr char kFakeBatterySerial[] = "fake_battery_serial";
constexpr int kExpectedBatteryChargeFullDesign = 5275; // (mAh)
constexpr double kFakeBatteryChargeFullDesign =
kExpectedBatteryChargeFullDesign / 1000.0; // (Ah)
constexpr int kExpectedBatteryChargeFull = 5292; // (mAh)
constexpr double kFakeBatteryChargeFull =
kExpectedBatteryChargeFull / 1000.0; // (Ah)
constexpr int kExpectedBatteryVoltageMinDesign = 11550; // (mV)
constexpr double kFakeBatteryVoltageMinDesign =
kExpectedBatteryVoltageMinDesign / 1000.0; // (V)
constexpr char kFakeSmartBatteryManufactureDate[] = "2018-08-06";
constexpr int kFakeSmartBatteryTemperature = 3004;
constexpr char kFakeBatteryModel[] = "fake_battery_model";
constexpr int kExpectedBatteryChargeNow = 5281; // (mAh)
constexpr double kFakeBatteryChargeNow =
kExpectedBatteryChargeNow / 1000.0; // (Ah)
// Cached VPD test values:
constexpr char kFakeSkuNumber[] = "fake_sku_number";
// CPU test values:
constexpr char kFakeModelName[] = "fake_cpu_model_name";
constexpr chromeos::cros_healthd::mojom::CpuArchitectureEnum
kFakeMojoArchitecture =
chromeos::cros_healthd::mojom::CpuArchitectureEnum::kX86_64;
constexpr em::CpuInfo::Architecture kFakeProtoArchitecture =
em::CpuInfo::X86_64;
constexpr uint32_t kFakeMaxClockSpeed = 3400000;
// CPU Temperature test values:
constexpr char kFakeCpuLabel[] = "fake_cpu_label";
constexpr int kFakeCpuTemp = 91832;
constexpr int kFakeCpuTimestamp = 912;
// Storage test values:
constexpr char kFakeStoragePath[] = "fake_storage_path";
constexpr int kFakeStorageSize = 123;
constexpr char kFakeStorageType[] = "fake_storage_type";
constexpr uint8_t kFakeStorageManfid = 2;
constexpr char kFakeStorageName[] = "fake_storage_name";
constexpr int kFakeStorageSerial = 789;
// Timezone test values:
constexpr char kPosixTimezone[] = "MST7MDT,M3.2.0,M11.1.0";
constexpr char kTimezoneRegion[] = "America/Denver";
// Time delta representing 1 hour time interval.
constexpr TimeDelta kHour = TimeDelta::FromHours(1);
......@@ -375,30 +424,47 @@ void GetEmptyCrosHealthdData(
}
void GetFakeCrosHealthdData(
const chromeos::cros_healthd::mojom::BatteryInfo& battery_info,
const chromeos::cros_healthd::mojom::CachedVpdInfo& cached_vpd_info,
const chromeos::cros_healthd::mojom::NonRemovableBlockDeviceInfo&
storage_info,
const chromeos::cros_healthd::mojom::CpuInfo& cpu_info,
const chromeos::cros_healthd::mojom::TimezoneInfo& timezone_info,
const em::CPUTempInfo& cpu_sample,
const em::BatterySample& battery_sample,
policy::DeviceStatusCollector::CrosHealthdDataReceiver receiver) {
// Create fake TelemetryInfo.
chromeos::cros_healthd::mojom::SmartBatteryInfo smart_battery_info(
kFakeSmartBatteryManufactureDate, kFakeSmartBatteryTemperature);
chromeos::cros_healthd::mojom::BatteryInfo battery_info(
kFakeBatteryCycleCount, kFakeBatteryVoltageNow, kFakeBatteryVendor,
kFakeBatterySerial, kFakeBatteryChargeFullDesign, kFakeBatteryChargeFull,
kFakeBatteryVoltageMinDesign, kFakeBatteryModel, kFakeBatteryChargeNow,
smart_battery_info.Clone());
chromeos::cros_healthd::mojom::CachedVpdInfo cached_vpd_info(kFakeSkuNumber);
chromeos::cros_healthd::mojom::CpuInfo cpu_info(
kFakeModelName, kFakeMojoArchitecture, kFakeMaxClockSpeed);
std::vector<chromeos::cros_healthd::mojom::CpuInfoPtr> cpu_vector;
cpu_vector.push_back(cpu_info.Clone());
chromeos::cros_healthd::mojom::NonRemovableBlockDeviceInfo storage_info(
kFakeStoragePath, kFakeStorageSize, kFakeStorageType, kFakeStorageManfid,
kFakeStorageName, kFakeStorageSerial);
std::vector<chromeos::cros_healthd::mojom::NonRemovableBlockDeviceInfoPtr>
storage_vector;
storage_vector.push_back(storage_info.Clone());
base::Optional<std::vector<
chromeos::cros_healthd::mojom::NonRemovableBlockDeviceInfoPtr>>
block_device_info(std::move(storage_vector));
std::vector<chromeos::cros_healthd::mojom::CpuInfoPtr> cpu_vector;
cpu_vector.push_back(cpu_info.Clone());
chromeos::cros_healthd::mojom::TimezoneInfo timezone_info(kPosixTimezone,
kTimezoneRegion);
chromeos::cros_healthd::mojom::TelemetryInfo fake_info(
battery_info.Clone(), std::move(block_device_info),
cached_vpd_info.Clone(), std::move(cpu_vector), timezone_info.Clone());
// Create fake SampledData.
em::CPUTempInfo fake_cpu_temp_sample;
fake_cpu_temp_sample.set_cpu_label(kFakeCpuLabel);
fake_cpu_temp_sample.set_cpu_temp(kFakeCpuTemp);
fake_cpu_temp_sample.set_timestamp(kFakeCpuTimestamp);
em::BatterySample fake_battery_sample;
fake_battery_sample.set_voltage(kExpectedBatteryVoltageNow);
fake_battery_sample.set_remaining_capacity(kExpectedBatteryChargeNow);
fake_battery_sample.set_temperature(kFakeSmartBatteryTemperature);
auto sample = std::make_unique<policy::SampledData>();
sample->cpu_samples[cpu_sample.cpu_label()] = cpu_sample;
sample->battery_samples[battery_info.model_name] = battery_sample;
sample->cpu_samples[fake_cpu_temp_sample.cpu_label()] = fake_cpu_temp_sample;
sample->battery_samples[battery_info.model_name] = fake_battery_sample;
base::circular_deque<std::unique_ptr<policy::SampledData>> samples;
samples.push_back(std::move(sample));
......@@ -2426,86 +2492,9 @@ TEST_F(DeviceStatusCollectorTest, TestGraphicsStatus) {
TEST_F(DeviceStatusCollectorTest, TestCrosHealthdInfo) {
// Create a fake response from cros_healthd and populate it with some
// arbitrary values.
// Cached VPD test values.
constexpr char kFakeSkuNumber[] = "fake_sku_number";
// Storage test values.
constexpr char kFakeStoragePath[] = "fake_storage_path";
constexpr int kFakeStorageSize = 123;
constexpr char kFakeStorageType[] = "fake_storage_type";
constexpr uint8_t kFakeStorageManfid = 2;
constexpr char kFakeStorageName[] = "fake_storage_name";
constexpr int kFakeStorageSerial = 789;
// Battery test values.
constexpr int kFakeCycleCount = 3;
constexpr int kExpectedVoltageNow = 12574; // (mV)
constexpr double kFakeVoltageNow = kExpectedVoltageNow / 1000.0; // (V)
constexpr char kFakeBatteryVendor[] = "fake_battery_vendor";
constexpr char kFakeBatterySerial[] = "fake_battery_serial";
constexpr int kExpectedChargeFullDesign = 5275; // (mAh)
constexpr double kFakeChargeFullDesign =
kExpectedChargeFullDesign / 1000.0; // (Ah)
constexpr int kExpectedChargeFull = 5292; // (mAh)
constexpr double kFakeChargeFull = kExpectedChargeFull / 1000.0; // (Ah)
constexpr int kExpectedVoltageMinDesign = 11550; // (mV)
constexpr double kFakeVoltageMinDesign =
kExpectedVoltageMinDesign / 1000.0; // (V)
constexpr int kFakeManufactureDateSmart = 19718;
constexpr int kFakeTemperatureSmart = 3004;
constexpr char kFakeBatteryModel[] = "fake_battery_model";
constexpr int kExpectedChargeNow = 5281; // (mAh)
constexpr double kFakeChargeNow = kExpectedChargeNow / 1000.0; // (Ah)
// CPU test values.
constexpr char kFakeModelName[] = "fake_cpu_model_name";
constexpr chromeos::cros_healthd::mojom::CpuArchitectureEnum
kFakeMojoArchitecture =
chromeos::cros_healthd::mojom::CpuArchitectureEnum::kX86_64;
constexpr em::CpuInfo::Architecture kFakeProtoArchitecture =
em::CpuInfo::X86_64;
constexpr uint32_t kFakeMaxClockSpeed = 3400000;
// CPU Temperature test values.
constexpr char kFakeCpuLabel[] = "fake_cpu_label";
constexpr int kFakeCpuTemp = 91832;
constexpr int kFakeCpuTimestamp = 912;
// Timezone test values.
constexpr char kPosixTimezone[] = "MST7MDT,M3.2.0,M11.1.0";
constexpr char kTimezoneRegion[] = "America/Denver";
chromeos::cros_healthd::mojom::BatteryInfo battery_info(
kFakeCycleCount, kFakeVoltageNow, kFakeBatteryVendor, kFakeBatterySerial,
kFakeChargeFullDesign, kFakeChargeFull, kFakeVoltageMinDesign,
kFakeManufactureDateSmart, kFakeTemperatureSmart, kFakeBatteryModel,
kFakeChargeNow);
chromeos::cros_healthd::mojom::CachedVpdInfo cached_vpd_info(kFakeSkuNumber);
chromeos::cros_healthd::mojom::NonRemovableBlockDeviceInfo storage_info(
kFakeStoragePath, kFakeStorageSize, kFakeStorageType, kFakeStorageManfid,
kFakeStorageName, kFakeStorageSerial);
chromeos::cros_healthd::mojom::CpuInfo cpu_info(
kFakeModelName, kFakeMojoArchitecture, kFakeMaxClockSpeed);
chromeos::cros_healthd::mojom::TimezoneInfo timezone_info(kPosixTimezone,
kTimezoneRegion);
// Create a fake sample to test with.
em::CPUTempInfo fake_cpu_temp_sample;
fake_cpu_temp_sample.set_cpu_label(kFakeCpuLabel);
fake_cpu_temp_sample.set_cpu_temp(kFakeCpuTemp);
fake_cpu_temp_sample.set_timestamp(kFakeCpuTimestamp);
em::BatterySample fake_battery_sample;
// Convert from V to mV.
fake_battery_sample.set_voltage(kExpectedVoltageNow);
// Convert from Ah to mAh.
fake_battery_sample.set_remaining_capacity(kExpectedChargeNow);
fake_battery_sample.set_temperature(kFakeTemperatureSmart);
auto options = CreateEmptyDeviceStatusCollectorOptions();
options->cros_healthd_data_fetcher = base::BindRepeating(
&GetFakeCrosHealthdData, battery_info, cached_vpd_info, storage_info,
cpu_info, timezone_info, fake_cpu_temp_sample, fake_battery_sample);
options->cros_healthd_data_fetcher =
base::BindRepeating(&GetFakeCrosHealthdData);
RestartStatusCollector(std::move(options));
// If kReportDeviceCpuInfo, kReportDevicePowerStatus, and
......@@ -2547,18 +2536,18 @@ TEST_F(DeviceStatusCollectorTest, TestCrosHealthdInfo) {
const auto& battery = device_status_.power_status().batteries(0);
EXPECT_EQ(battery.serial(), kFakeBatterySerial);
EXPECT_EQ(battery.manufacturer(), kFakeBatteryVendor);
EXPECT_EQ(battery.design_capacity(), kExpectedChargeFullDesign);
EXPECT_EQ(battery.full_charge_capacity(), kExpectedChargeFull);
EXPECT_EQ(battery.cycle_count(), kFakeCycleCount);
EXPECT_EQ(battery.design_min_voltage(), kExpectedVoltageMinDesign);
EXPECT_EQ(battery.manufacture_date(), "2018-08-06");
EXPECT_EQ(battery.design_capacity(), kExpectedBatteryChargeFullDesign);
EXPECT_EQ(battery.full_charge_capacity(), kExpectedBatteryChargeFull);
EXPECT_EQ(battery.cycle_count(), kFakeBatteryCycleCount);
EXPECT_EQ(battery.design_min_voltage(), kExpectedBatteryVoltageMinDesign);
EXPECT_EQ(battery.manufacture_date(), kFakeSmartBatteryManufactureDate);
// Verify the battery sample data.
ASSERT_EQ(battery.samples_size(), 1);
const auto& battery_sample = battery.samples(0);
EXPECT_EQ(battery_sample.voltage(), kExpectedVoltageNow);
EXPECT_EQ(battery_sample.remaining_capacity(), kExpectedChargeNow);
EXPECT_EQ(battery_sample.temperature(), kFakeTemperatureSmart);
EXPECT_EQ(battery_sample.voltage(), kExpectedBatteryVoltageNow);
EXPECT_EQ(battery_sample.remaining_capacity(), kExpectedBatteryChargeNow);
EXPECT_EQ(battery_sample.temperature(), kFakeSmartBatteryTemperature);
// Verify the storage data.
ASSERT_TRUE(device_status_.has_storage_status());
......
......@@ -4,6 +4,7 @@
#include "chromeos/services/cros_healthd/public/cpp/service_connection.h"
#include <utility>
#include <vector>
#include "base/bind.h"
......@@ -81,13 +82,14 @@ MakeNonRemovableBlockDeviceInfo() {
}
mojom::BatteryInfoPtr MakeBatteryInfo() {
mojom::SmartBatteryInfoPtr smart_info = mojom::SmartBatteryInfo::New(
"2018-08-06" /* manufacture_date */, 981729 /* temperature */);
return mojom::BatteryInfo::New(
2 /* cycle_count */, 12.9 /* voltage_now */,
"battery_vendor" /* vendor */, "serial_number" /* serial_number */,
5.275 /* charge_full_design */, 5.292 /* charge_full */,
11.55 /* voltage_min_design */, 51785890 /* manufacture_date_smart */,
/*temperature smart=*/981729, /*model_name=*/"battery_model",
/*charge_now=*/5.123);
11.55 /* voltage_min_design */, "battery_model" /* model_name */,
5.123 /* charge_now */, std::move(smart_info));
}
mojom::CachedVpdInfoPtr MakeCachedVpdInfo() {
......
......@@ -27,6 +27,15 @@ enum ProbeCategoryEnum {
kTimezone,
};
// Information related to a Smart Battery, as defined in
// http://sbs-forum.org/specs/sbdat110.pdf.
struct SmartBatteryInfo {
// Manufacture date converted to yyyy-mm-dd format.
string manufacture_date;
// Temperature in 0.1K.
uint64 temperature;
};
// Information related to the main battery.
struct BatteryInfo {
// TODO(https://crbug.com/979245): Update "smart" cycle count.
......@@ -43,17 +52,13 @@ struct BatteryInfo {
double charge_full;
// Desired minimum output voltage (V)
double voltage_min_design;
// Smart Manufacture Date is defined in
// http://sbs-forum.org/specs/sbdat110.pdf. The value is calculated by
// ((year-1980) * 512 + month * 32 + day).
int64 manufacture_date_smart;
// Temperature in 0.1°K as Smart Battery Temperature defined in
// http://sbs-forum.org/specs/sbdat110.pdf
uint64 temperature_smart;
// Model name.
string model_name;
// Current battery charge (Ah)
double charge_now;
// Information related to a Smart Battery. Included when the main battery is a
// Smart Battery.
SmartBatteryInfo? smart_battery_info;
};
// Information related to a specific non-removable block device.
......
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