Test for developer images using crossystem.

Previously, testing for developer builds was done by checking for
the existence of the file /root/.dev_mode.  That file has been
deprecated for some time; the update engine is one of the last
hold-outs still using it.

This changes the IsOfficialBuild() test to use the crossystem
library to test for 'cros_debug' on the kernel command line.
Additionally, older callers that invoked the 'crossystem' command
as a subprocess have been converted to use the library instead

BUG=chromium:308678
TEST=run update_engine_client on a host without /root/.dev_mode.
TEST=unit tests
CQ-DEPEND=CL:175039

Change-Id: I7fd472e2f28f9c18d5fbdd3258632368f2b63313
Reviewed-on: https://chromium-review.googlesource.com/175050
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Commit-Queue: Richard Barnette <jrbarnette@chromium.org>
diff --git a/hardware.cc b/hardware.cc
index f04c340..6ab0f22 100644
--- a/hardware.cc
+++ b/hardware.cc
@@ -8,6 +8,7 @@
 #include <base/logging.h>
 #include <base/string_util.h>
 #include <rootdev/rootdev.h>
+#include <vboot/crossystem.h>
 
 #include "update_engine/subprocess.h"
 #include "update_engine/utils.h"
@@ -17,9 +18,6 @@
 
 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
@@ -38,37 +36,27 @@
 }
 
 bool Hardware::IsOfficialBuild() {
-  return !file_util::PathExists(FilePath(kDevImageMarker));
+  return VbGetSystemPropertyInt("debug_build") == 0;
 }
 
 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;
+  bool dev_mode = VbGetSystemPropertyInt("devsw_boot") != 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");
-  cmd.push_back(key);
+  char value_buffer[VB_MAX_STRING_PROPERTY];
 
-  string return_value;
-  bool success = Subprocess::SynchronousExec(cmd, &exit_code, &return_value);
-  if (success && !exit_code) {
+  const char *rv = VbGetSystemPropertyString(key.c_str(), value_buffer,
+                                             sizeof(value_buffer));
+  if (rv != NULL) {
+    string return_value(value_buffer);
     TrimWhitespaceASCII(return_value, TRIM_ALL, &return_value);
     return return_value;
   }
-  LOG(ERROR) << "Unable to read " << key << " (" << exit_code << ") "
-             << return_value;
+
+  LOG(ERROR) << "Unable to read crossystem key " << key;
   return "";
 }