Skip to content

Commit

Permalink
DeviceStatusCollector: Report system info using cros_healthd
Browse files Browse the repository at this point in the history
Now that cros_healthd collects system information, use it to fetch and
report this information in DeviceStatusCollector.

BUG=chromium:1057495
TEST=./out/Default/browser_tests --gtest_filter="DeviceStatusCollectorTest.*"
./out/Default/chromeos_components_unittests --gtest_filter=ProbeServiceConvertors.*

Change-Id: I401eadb02c39354d4308667e0f1c0cd24aa15481
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2271157
Commit-Queue: Kartik Hegde <khegde@chromium.org>
Reviewed-by: Oleh Lamzin <lamzin@google.com>
Reviewed-by: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789578}
  • Loading branch information
Kartik Hegde authored and Commit Bot committed Jul 17, 2020
1 parent de4f8c5 commit 5a68322
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ void OwnerSettingsServiceChromeOS::UpdateDeviceSettings(
// kReportDeviceVpdInfo
// kReportDeviceUsers
// kReportDeviceAppInfo
// kReportDeviceSystemInfo
// kServiceAccountIdentity
// kSystemTimezonePolicy
// kVariationsRestrictParameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,11 @@ void DecodeReportingPolicies(const em::ChromeDeviceSettingsProto& policy,
POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
base::Value(container.report_vpd_info()), nullptr);
}
if (container.has_report_system_info()) {
policies->Set(key::kReportDeviceSystemInfo, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
base::Value(container.report_system_info()), nullptr);
}
}

if (policy.has_device_heartbeat_settings()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,13 @@ class DeviceStatusCollectorState : public StatusCollectorState {

void FetchCrosHealthdData(
const policy::DeviceStatusCollector::CrosHealthdDataFetcher&
cros_healthd_data_fetcher) {
cros_healthd_data_fetcher,
bool report_system_info,
bool report_vpd_info) {
cros_healthd_data_fetcher.Run(
CrosHealthdCollectionMode::kFull,
base::BindOnce(&DeviceStatusCollectorState::OnCrosHealthdDataReceived,
this));
this, report_system_info, report_vpd_info));
}

void FetchEMMCLifeTime(
Expand Down Expand Up @@ -819,6 +821,8 @@ class DeviceStatusCollectorState : public StatusCollectorState {

// Stores the contents of |probe_result| and |samples| to |response_params_|.
void OnCrosHealthdDataReceived(
bool report_system_info,
bool report_vpd_info,
chromeos::cros_healthd::mojom::TelemetryInfoPtr probe_result,
const base::circular_deque<std::unique_ptr<SampledData>>& samples) {
namespace cros_healthd = chromeos::cros_healthd::mojom;
Expand Down Expand Up @@ -885,27 +889,6 @@ class DeviceStatusCollectorState : public StatusCollectorState {
}
}

// Process CachedVpdResult.
const auto& vpd_result = probe_result->vpd_result;
if (!vpd_result.is_null()) {
switch (vpd_result->which()) {
case cros_healthd::CachedVpdResult::Tag::ERROR: {
LOG(ERROR) << "cros_healthd: Error getting cached VPD info: "
<< vpd_result->get_error()->msg;
break;
}

case cros_healthd::CachedVpdResult::Tag::VPD_INFO: {
const auto& vpd_info = vpd_result->get_vpd_info();
em::SystemStatus* const system_status_out =
response_params_.device_status->mutable_system_status();
if (vpd_info->sku_number.has_value())
system_status_out->set_vpd_sku_number(vpd_info->sku_number.value());
break;
}
}
}

// Process BatteryResult.
const auto& battery_result = probe_result->battery_result;
if (!battery_result.is_null()) {
Expand Down Expand Up @@ -1140,6 +1123,62 @@ class DeviceStatusCollectorState : public StatusCollectorState {
}
}
}

// Process SystemResult.
const auto& system_result = probe_result->system_result;
if (!system_result.is_null()) {
switch (system_result->which()) {
case cros_healthd::SystemResult::Tag::ERROR: {
LOG(ERROR) << "cros_healthd: Error getting system info: "
<< system_result->get_error()->msg;
break;
}

case cros_healthd::SystemResult::Tag::SYSTEM_INFO: {
const auto& system_info = system_result->get_system_info();
em::SystemStatus* const system_status_out =
response_params_.device_status->mutable_system_status();
if (report_vpd_info) {
if (system_info->first_power_date.has_value()) {
system_status_out->set_first_power_date(
system_info->first_power_date.value());
}
if (system_info->manufacture_date.has_value()) {
system_status_out->set_manufacture_date(
system_info->manufacture_date.value());
}
if (system_info->product_sku_number.has_value()) {
system_status_out->set_vpd_sku_number(
system_info->product_sku_number.value());
}
}
if (report_system_info) {
system_status_out->set_marketing_name(system_info->marketing_name);
if (system_info->bios_version.has_value()) {
system_status_out->set_bios_version(
system_info->bios_version.value());
}
if (system_info->board_name.has_value()) {
system_status_out->set_board_name(
system_info->board_name.value());
}
if (system_info->board_version.has_value()) {
system_status_out->set_board_version(
system_info->board_version.value());
}
if (system_info->chassis_type) {
system_status_out->set_chassis_type(
system_info->chassis_type->value);
}
if (system_info->product_name.has_value()) {
system_status_out->set_product_name(
system_info->product_name.value());
}
}
break;
}
}
}
}

void OnEMMCLifetimeReceived(const em::DiskLifetimeEstimation& est) {
Expand Down Expand Up @@ -1328,6 +1367,8 @@ DeviceStatusCollector::DeviceStatusCollector(
chromeos::kReportDeviceVpdInfo, callback);
app_info_subscription_ = cros_settings_->AddSettingsObserver(
chromeos::kReportDeviceAppInfo, callback);
system_info_subscription_ = cros_settings_->AddSettingsObserver(
chromeos::kReportDeviceSystemInfo, callback);
stats_reporting_pref_subscription_ = cros_settings_->AddSettingsObserver(
chromeos::kStatsReportingPref, callback);

Expand Down Expand Up @@ -1480,6 +1521,10 @@ void DeviceStatusCollector::UpdateReportingSettings() {
&report_bluetooth_info_)) {
report_bluetooth_info_ = false;
}
if (!cros_settings_->GetBoolean(chromeos::kReportDeviceSystemInfo,
&report_system_info_)) {
report_system_info_ = false;
}
if (!cros_settings_->GetBoolean(chromeos::kReportDeviceFanInfo,
&report_fan_info_)) {
report_fan_info_ = false;
Expand Down Expand Up @@ -1771,8 +1816,8 @@ void DeviceStatusCollector::FetchCrosHealthdData(
SamplingProbeResultCallback completion_callback;
switch (mode) {
case CrosHealthdCollectionMode::kFull: {
if (report_vpd_info_)
categories_to_probe.push_back(ProbeCategoryEnum::kCachedVpdData);
if (report_vpd_info_ || report_system_info_)
categories_to_probe.push_back(ProbeCategoryEnum::kSystem);
if (report_storage_status_) {
categories_to_probe.push_back(
ProbeCategoryEnum::kNonRemovableBlockDevices);
Expand Down Expand Up @@ -1823,7 +1868,8 @@ void DeviceStatusCollector::OnProbeDataFetched(
bool DeviceStatusCollector::ShouldFetchCrosHealthdData() const {
return report_vpd_info_ || report_power_status_ || report_storage_status_ ||
report_cpu_info_ || report_timezone_info_ || report_memory_info_ ||
report_backlight_info_ || report_fan_info_ || report_bluetooth_info_;
report_backlight_info_ || report_fan_info_ || report_bluetooth_info_ ||
report_system_info_;
}

void DeviceStatusCollector::ReportingUsersChanged() {
Expand Down Expand Up @@ -2155,7 +2201,8 @@ bool DeviceStatusCollector::GetHardwareStatus(
state->FetchEMMCLifeTime(emmc_lifetime_fetcher_);

if (ShouldFetchCrosHealthdData()) {
state->FetchCrosHealthdData(cros_healthd_data_fetcher_);
state->FetchCrosHealthdData(cros_healthd_data_fetcher_, report_system_info_,
report_vpd_info_);
} else {
// Sample CPU temperature in a background thread.
state->SampleCPUTempInfo(cpu_temp_fetcher_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ class DeviceStatusCollector : public StatusCollector,
bool report_fan_info_ = false;
bool report_vpd_info_ = false;
bool report_app_info_ = false;
bool report_system_info_ = false;
bool stat_reporting_pref_ = false;

std::unique_ptr<chromeos::CrosSettings::ObserverSubscription>
Expand Down Expand Up @@ -495,6 +496,8 @@ class DeviceStatusCollector : public StatusCollector,
fan_info_subscription_;
std::unique_ptr<chromeos::CrosSettings::ObserverSubscription>
vpd_info_subscription_;
std::unique_ptr<chromeos::CrosSettings::ObserverSubscription>
system_info_subscription_;
std::unique_ptr<chromeos::CrosSettings::ObserverSubscription>
app_info_subscription_;
std::unique_ptr<chromeos::CrosSettings::ObserverSubscription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,16 @@ 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";
// System test values:
const char kFakeFirstPowerDate[] = "2020-40";
const char kFakeManufactureDate[] = "2019-01-01";
const char kFakeSkuNumber[] = "ABCD&^A";
constexpr char kFakeMarketingName[] = "Latitude 1234 Chromebook Enterprise";
constexpr char kFakeBiosVersion[] = "Google_BoardName.12200.68.0";
constexpr char kFakeBoardName[] = "BoardName";
constexpr char kFakeBoardVersion[] = "rev1234";
constexpr uint64_t kFakeChassisType = 9;
constexpr char kFakeProductName[] = "ProductName";
// CPU test values:
constexpr uint32_t kFakeNumTotalThreads = 8;
constexpr char kFakeModelName[] = "fake_cpu_model_name";
Expand Down Expand Up @@ -489,9 +497,13 @@ cros_healthd::NonRemovableBlockDeviceResultPtr CreateBlockDeviceResult() {
std::move(storage_vector));
}

cros_healthd::CachedVpdResultPtr CreateVpdResult() {
return cros_healthd::CachedVpdResult::NewVpdInfo(
cros_healthd::CachedVpdInfo::New(kFakeSkuNumber));
cros_healthd::SystemResultPtr CreateSystemResult() {
return cros_healthd::SystemResult::NewSystemInfo(
cros_healthd::SystemInfo::New(
kFakeFirstPowerDate, kFakeManufactureDate, kFakeSkuNumber,
kFakeMarketingName, kFakeBiosVersion, kFakeBoardName,
kFakeBoardVersion, cros_healthd::UInt64Value::New(kFakeChassisType),
kFakeProductName));
}

std::vector<cros_healthd::CpuCStateInfoPtr> CreateCStateInfo() {
Expand Down Expand Up @@ -594,7 +606,7 @@ void FetchFakeFullCrosHealthdData(
cros_healthd::TelemetryInfo fake_info;
fake_info.battery_result = CreateBatteryResult();
fake_info.block_device_result = CreateBlockDeviceResult();
fake_info.vpd_result = CreateVpdResult();
fake_info.system_result = CreateSystemResult();
fake_info.cpu_result = CreateCpuResult();
fake_info.timezone_result = CreateTimezoneResult();
fake_info.memory_result = CreateMemoryResult();
Expand Down Expand Up @@ -3032,6 +3044,8 @@ TEST_F(DeviceStatusCollectorTest, TestCrosHealthdInfo) {
chromeos::kReportDeviceFanInfo, false);
scoped_testing_cros_settings_.device_settings()->SetBoolean(
chromeos::kReportDeviceBluetoothInfo, false);
scoped_testing_cros_settings_.device_settings()->SetBoolean(
chromeos::kReportDeviceSystemInfo, false);
scoped_testing_cros_settings_.device_settings()->SetBoolean(
chromeos::kReportDeviceVpdInfo, false);
GetStatus();
Expand Down Expand Up @@ -3062,6 +3076,8 @@ TEST_F(DeviceStatusCollectorTest, TestCrosHealthdInfo) {
chromeos::kReportDeviceFanInfo, true);
scoped_testing_cros_settings_.device_settings()->SetBoolean(
chromeos::kReportDeviceBluetoothInfo, true);
scoped_testing_cros_settings_.device_settings()->SetBoolean(
chromeos::kReportDeviceSystemInfo, true);
scoped_testing_cros_settings_.device_settings()->SetBoolean(
chromeos::kReportDeviceVpdInfo, true);
GetStatus();
Expand Down Expand Up @@ -3114,9 +3130,20 @@ TEST_F(DeviceStatusCollectorTest, TestCrosHealthdInfo) {
EXPECT_EQ(disk.discard_time_seconds_since_last_boot(),
kFakeStorageDiscardTimeSeconds);

// Verify the Cached VPD.
// Verify the system info.
ASSERT_TRUE(device_status_.has_system_status());
EXPECT_EQ(device_status_.system_status().first_power_date(),
kFakeFirstPowerDate);
EXPECT_EQ(device_status_.system_status().manufacture_date(),
kFakeManufactureDate);
EXPECT_EQ(device_status_.system_status().vpd_sku_number(), kFakeSkuNumber);
EXPECT_EQ(device_status_.system_status().marketing_name(),
kFakeMarketingName);
EXPECT_EQ(device_status_.system_status().bios_version(), kFakeBiosVersion);
EXPECT_EQ(device_status_.system_status().board_name(), kFakeBoardName);
EXPECT_EQ(device_status_.system_status().board_version(), kFakeBoardVersion);
EXPECT_EQ(device_status_.system_status().chassis_type(), kFakeChassisType);
EXPECT_EQ(device_status_.system_status().product_name(), kFakeProductName);

// Verify the CPU data.
ASSERT_TRUE(device_status_.has_global_cpu_info());
Expand Down Expand Up @@ -3236,6 +3263,65 @@ TEST_F(DeviceStatusCollectorTest, TestPartialCrosHealthdInfo) {
EXPECT_EQ(device_status_.fan_info_size(), 0);
}

TEST_F(DeviceStatusCollectorTest, TestCrosHealthdVpdAndSystemInfo) {
// Create a fake response from cros_healthd and populate it with some
// arbitrary values.
auto options = CreateEmptyDeviceStatusCollectorOptions();
options->cros_healthd_data_fetcher =
base::BindRepeating(&FetchFakeFullCrosHealthdData);
RestartStatusCollector(std::move(options));

// If the ReportDeviceHardwareStatus policy is false, the policies
// corresponding to cros_healthd data are ignored. The policy is true by
// default, but set it explicitly to ensure the other policies are tested.
scoped_testing_cros_settings_.device_settings()->SetBoolean(
chromeos::kReportDeviceHardwareStatus, true);

// When the vpd reporting policy is turned on and the system reporting
// property is turned off, we only expect the protobuf to only have vpd info.
scoped_testing_cros_settings_.device_settings()->SetBoolean(
chromeos::kReportDeviceSystemInfo, false);
scoped_testing_cros_settings_.device_settings()->SetBoolean(
chromeos::kReportDeviceVpdInfo, true);
GetStatus();

// Verify the only vpd info is populated.
ASSERT_TRUE(device_status_.has_system_status());
EXPECT_EQ(device_status_.system_status().first_power_date(),
kFakeFirstPowerDate);
EXPECT_EQ(device_status_.system_status().manufacture_date(),
kFakeManufactureDate);
EXPECT_EQ(device_status_.system_status().vpd_sku_number(), kFakeSkuNumber);
ASSERT_FALSE(device_status_.system_status().has_marketing_name());
ASSERT_FALSE(device_status_.system_status().has_bios_version());
ASSERT_FALSE(device_status_.system_status().has_board_name());
ASSERT_FALSE(device_status_.system_status().has_board_version());
ASSERT_FALSE(device_status_.system_status().has_chassis_type());
ASSERT_FALSE(device_status_.system_status().has_product_name());

// When the system reporting policy is turned on and the vpd reporting policy
// is turned off, we expect the protobuf to have all system info except the
// subset of vpd info.
scoped_testing_cros_settings_.device_settings()->SetBoolean(
chromeos::kReportDeviceSystemInfo, true);
scoped_testing_cros_settings_.device_settings()->SetBoolean(
chromeos::kReportDeviceVpdInfo, false);
GetStatus();

// Verify all system info except vpd info exists.
ASSERT_TRUE(device_status_.has_system_status());
ASSERT_FALSE(device_status_.system_status().has_first_power_date());
ASSERT_FALSE(device_status_.system_status().has_manufacture_date());
ASSERT_FALSE(device_status_.system_status().has_vpd_sku_number());
EXPECT_EQ(device_status_.system_status().marketing_name(),
kFakeMarketingName);
EXPECT_EQ(device_status_.system_status().bios_version(), kFakeBiosVersion);
EXPECT_EQ(device_status_.system_status().board_name(), kFakeBoardName);
EXPECT_EQ(device_status_.system_status().board_version(), kFakeBoardVersion);
EXPECT_EQ(device_status_.system_status().chassis_type(), kFakeChassisType);
EXPECT_EQ(device_status_.system_status().product_name(), kFakeProductName);
}

TEST_F(DeviceStatusCollectorTest, GenerateAppInfo) {
const AccountId account_id(AccountId::FromUserEmail("user0@managed.com"));
MockRegularUserWithAffiliation(account_id, true);
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/chromeos/settings/device_settings_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const char* const kKnownSettings[] = {
kReportDeviceVersionInfo,
kReportDeviceVpdInfo,
kReportDeviceAppInfo,
kReportDeviceSystemInfo,
kReportOsUpdateStatus,
kReportRunningKioskApp,
kReportUploadFrequency,
Expand Down Expand Up @@ -625,6 +626,10 @@ void DecodeReportingPolicies(const em::ChromeDeviceSettingsProto& policy,
new_values_cache->SetBoolean(kReportDeviceVpdInfo,
reporting_policy.report_vpd_info());
}
if (reporting_policy.has_report_system_info()) {
new_values_cache->SetBoolean(kReportDeviceSystemInfo,
reporting_policy.report_system_info());
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions chrome/test/data/policy/policy_test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -5199,6 +5199,8 @@

"ReportDeviceVpdInfo": {},

"ReportDeviceSystemInfo": {},

"ReportUploadFrequency": {},

"DeviceAllowNewUsers": {},
Expand Down
Loading

0 comments on commit 5a68322

Please sign in to comment.