Re-land "Add ability to check /etc/lsb-release for HWID"
This reverts commit 33ab35b140d9d0da49d971cad26fb2f1b52215b0.
Add ability to check /etc/lsb-release for HWID
This is enabled by a compile-time option, only.
On certain boards HWID may not be available via normal means.
This functionality allows a compile-time choice to enable
behavior that will check /etc/lsb-release for an
HWID_OVERRIDE=<id> entry instead.
CQ-DEPEND=CL:186482
BUG=None
TEST=unit tests
Change-Id: I75a7bcf7219fbb19670647746735c814dacf7879
Reviewed-on: https://chromium-review.googlesource.com/187040
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Chris Masone <cmasone@chromium.org>
Tested-by: Chris Masone <cmasone@chromium.org>
diff --git a/hwid_override.cc b/hwid_override.cc
new file mode 100644
index 0000000..90e413b
--- /dev/null
+++ b/hwid_override.cc
@@ -0,0 +1,37 @@
+// Copyright (c) 2013 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.
+
+#include "update_engine/hwid_override.h"
+
+#include <map>
+#include <string>
+
+#include <base/basictypes.h>
+#include <base/file_path.h>
+#include <base/file_util.h>
+
+#include "update_engine/simple_key_value_store.h"
+
+using std::map;
+using std::string;
+
+namespace chromeos_update_engine {
+
+const char HwidOverride::kHwidOverrideKey[] = "HWID_OVERRIDE";
+
+HwidOverride::HwidOverride() {}
+
+HwidOverride::~HwidOverride() {}
+
+std::string HwidOverride::Read(const base::FilePath& root) {
+ base::FilePath kFile(root.value() + "/etc/lsb-release");
+ string file_data;
+ map<string, string> data;
+ if (file_util::ReadFileToString(kFile, &file_data)) {
+ data = simple_key_value_store::ParseString(file_data);
+ }
+ return data[kHwidOverrideKey];
+}
+
+} // namespace chromeos_update_engine