AU: Use crossystem hwid to obtain the hardware class.
This is more portable than reading the HWID from the ACPI file and should work
on ARM.
BUG=chromium-os:15255
TEST=unit tests, ran AU on Cr-48, checked the Omaha update check request
Change-Id: I8a2750140da7da99c217a6976f46b1b226696276
Reviewed-on: http://gerrit.chromium.org/gerrit/1078
Tested-by: Darin Petkov <[email protected]>
Reviewed-by: Thieu Le <[email protected]>
diff --git a/omaha_request_params.cc b/omaha_request_params.cc
index f4f8fb2..0f5af5b 100644
--- a/omaha_request_params.cc
+++ b/omaha_request_params.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,7 +13,6 @@
#include <vector>
#include <base/file_util.h>
-#include <base/string_util.h>
#include "update_engine/simple_key_value_store.h"
#include "update_engine/utils.h"
@@ -35,8 +34,6 @@
const char* const OmahaRequestParams::kUpdateUrl(
"https://tools.google.com/service/update2");
-static const char kHWIDPath[] = "/sys/devices/platform/chromeos_acpi/HWID";
-
OmahaRequestDeviceParams::OmahaRequestDeviceParams() :
force_lock_down_(false),
forced_lock_down_(false) {}
@@ -61,7 +58,7 @@
"",
&chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack,
true); // stateful_override
- hardware_class = GetHardwareClass();
+ hardware_class = utils::GetHardwareClass();
struct stat stbuf;
// Deltas are only okay if the /.nodelta file does not exist. If we don't
@@ -165,16 +162,6 @@
return ret;
}
-string OmahaRequestDeviceParams::GetHardwareClass() const {
- string hwid;
- if (!file_util::ReadFileToString(FilePath(root_ + kHWIDPath), &hwid)) {
- LOG(ERROR) << "Unable to determine the system hardware qualification ID.";
- return "";
- }
- TrimWhitespaceASCII(hwid, TRIM_ALL, &hwid);
- return hwid;
-}
-
bool OmahaRequestDeviceParams::ShouldLockDown() const {
if (force_lock_down_) {
return forced_lock_down_;
diff --git a/omaha_request_params.h b/omaha_request_params.h
index 7864370..edaba67 100644
--- a/omaha_request_params.h
+++ b/omaha_request_params.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -121,10 +121,6 @@
// Gets the machine type (e.g. "i686").
std::string GetMachineType() const;
- // Returns the hardware qualification ID of the system, or empty
- // string if the HWID is unavailable.
- std::string GetHardwareClass() const;
-
// When reading files, prepend root_ to the paths. Useful for testing.
std::string root_;
diff --git a/omaha_request_params_unittest.cc b/omaha_request_params_unittest.cc
index 3bf4ebc..458f582 100644
--- a/omaha_request_params_unittest.cc
+++ b/omaha_request_params_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -239,19 +239,6 @@
EXPECT_FALSE(out.delta_okay);
}
-TEST_F(OmahaRequestDeviceParamsTest, HardwareClassTest) {
- string test_class = " \t sample hardware class \n ";
- FilePath hwid_path(kTestDir + "/sys/devices/platform/chromeos_acpi/HWID");
- ASSERT_TRUE(file_util::CreateDirectory(hwid_path.DirName()));
- ASSERT_EQ(test_class.size(),
- file_util::WriteFile(hwid_path,
- test_class.data(),
- test_class.size()));
- OmahaRequestParams out;
- EXPECT_TRUE(DoTest(&out, "", ""));
- EXPECT_EQ("sample hardware class", out.hardware_class);
-}
-
TEST_F(OmahaRequestDeviceParamsTest, OverrideTest) {
ASSERT_TRUE(WriteFileString(
kTestDir + "/etc/lsb-release",
diff --git a/utils.cc b/utils.cc
index 9c05a25..bcf34d5 100644
--- a/utils.cc
+++ b/utils.cc
@@ -66,6 +66,23 @@
return !dev_mode;
}
+string GetHardwareClass() {
+ // TODO(petkov): Convert to a library call once a crossystem library is
+ // available (crosbug.com/13291).
+ int exit_code = 0;
+ vector<string> cmd(1, "/usr/bin/crossystem");
+ cmd.push_back("hwid");
+
+ string hwid;
+ bool success = Subprocess::SynchronousExec(cmd, &exit_code, &hwid);
+ if (success && !exit_code) {
+ TrimWhitespaceASCII(hwid, TRIM_ALL, &hwid);
+ return hwid;
+ }
+ LOG(ERROR) << "Unable to read HWID (" << exit_code << ") " << hwid;
+ return "";
+}
+
bool WriteFile(const char* path, const char* data, int data_len) {
DirectFileWriter writer;
TEST_AND_RETURN_FALSE_ERRNO(0 == writer.Open(path,
diff --git a/utils.h b/utils.h
index fb30055..7b39cd4 100644
--- a/utils.h
+++ b/utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -33,6 +33,9 @@
// boot mode. Returns false if the boot mode is developer.
bool IsNormalBootMode();
+// Returns the HWID or an empty string on error.
+std::string GetHardwareClass();
+
// Writes the data passed to path. The file at path will be overwritten if it
// exists. Returns true on success, false otherwise.
bool WriteFile(const char* path, const char* data, int data_len);