Move IsOfficialBuild() and IsNormalBootMode() into HardwareInterface.

This makes the implementation of the two methods part of the
HardwareInterface, so that unit tests won't end up with meaningless
(and unpredictable) calls to the real functions.

BUG=None
TEST=unit tests

Change-Id: Ia23932634124987c1d6ff0683acb15cf4819bc5e
Reviewed-on: https://chromium-review.googlesource.com/175024
Reviewed-by: Chris Sosa <[email protected]>
Commit-Queue: Richard Barnette <[email protected]>
Tested-by: Richard Barnette <[email protected]>
diff --git a/hardware.cc b/hardware.cc
index a44edcf..f04c340 100644
--- a/hardware.cc
+++ b/hardware.cc
@@ -4,6 +4,7 @@
 
 #include "update_engine/hardware.h"
 
+#include <base/file_util.h>
 #include <base/logging.h>
 #include <base/string_util.h>
 #include <rootdev/rootdev.h>
@@ -16,6 +17,9 @@
 
 namespace chromeos_update_engine {
 
+static const char kDevImageMarker[] = "/root/.dev_mode";
+
+
 const string Hardware::BootDevice() {
   char boot_path[PATH_MAX];
   // Resolve the boot device path fully, including dereferencing
@@ -33,6 +37,25 @@
   return boot_path;
 }
 
+bool Hardware::IsOfficialBuild() {
+  return !file_util::PathExists(FilePath(kDevImageMarker));
+}
+
+bool Hardware::IsNormalBootMode() {
+  // 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("devsw_boot?1");
+
+  // Assume dev mode if the dev switch is set to 1 and there was no error
+  // executing crossystem. Assume normal mode otherwise.
+  bool success = Subprocess::SynchronousExec(cmd, &exit_code, NULL);
+  bool dev_mode = success && exit_code == 0;
+  LOG_IF(INFO, dev_mode) << "Booted in dev mode.";
+  return !dev_mode;
+}
+
 static string ReadValueFromCrosSystem(const string& key) {
   int exit_code = 0;
   vector<string> cmd(1, "/usr/bin/crossystem");