Use crossystem rather than cros_boot_mode.
Also, make the check for normal mode a bit more restrictive.
BUG=chromium-os:13283
TEST=unit tests, tested on device
Change-Id: I3ec8a4c5526208d6f050ec2e152604b2ead76f27
Review URL: http://codereview.chromium.org/6719012
diff --git a/SConstruct b/SConstruct
index dea012d..c6d357d 100644
--- a/SConstruct
+++ b/SConstruct
@@ -195,7 +195,6 @@
env['LIBS'] = Split("""base
bz2
- cros_boot_mode
crypto
curl
ext2fs
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index 7e67555..ece5a7d 100755
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -603,7 +603,7 @@
"errorcode=\"%d\"></o:event>\n",
OmahaEvent::kTypeDownloadComplete,
OmahaEvent::kResultError,
- kActionCodeError | kActionCodeBootModeFlag);
+ kActionCodeError);
EXPECT_NE(post_str.find(expected_event), string::npos);
EXPECT_EQ(post_str.find("o:updatecheck"), string::npos);
}
diff --git a/setup_dev_packages b/setup_dev_packages
index 8a9182c..64d063e 100755
--- a/setup_dev_packages
+++ b/setup_dev_packages
@@ -7,10 +7,10 @@
set -ex
sudo USE="-crash cros-debug" emerge -DNauv1 \
- chromeos-base/cros_boot_mode \
chromeos-base/hard-host-depends \
chromeos-base/libchrome \
chromeos-base/metrics \
+ chromeos-base/vboot_reference \
dev-cpp/gmock \
dev-cpp/gtest \
dev-util/bsdiff \
diff --git a/utils.cc b/utils.cc
index 502b0d1..e1256a7 100644
--- a/utils.cc
+++ b/utils.cc
@@ -25,7 +25,6 @@
#include <base/rand_util.h>
#include <base/string_util.h>
#include <base/logging.h>
-#include <cros_boot_mode/boot_mode.h>
#include <google/protobuf/stubs/common.h>
#include <rootdev/rootdev.h>
@@ -53,12 +52,18 @@
}
bool IsNormalBootMode() {
- cros_boot_mode::BootMode mode;
- mode.Initialize(false, // unsupported_is_developer
- true); // use_bootloader
- bool normal = mode.mode() == cros_boot_mode::BootMode::kNormal;
- LOG_IF(INFO, !normal) << "Boot mode not normal: " << mode.mode_text();
- return normal;
+ // 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);
+ bool dev_mode = success && exit_code == 0;
+ LOG_IF(INFO, dev_mode) << "Booted in dev mode.";
+ return !dev_mode;
}
bool WriteFile(const char* path, const char* data, int data_len) {
diff --git a/utils.h b/utils.h
index a17f241..fb30055 100644
--- a/utils.h
+++ b/utils.h
@@ -29,8 +29,8 @@
// otherwise.
bool IsOOBEComplete();
-// Returns true if the boot mode is normal, false otherwise (e.g., developer or
-// recovery).
+// Returns true if the boot mode is normal or if it's unable to determine the
+// boot mode. Returns false if the boot mode is developer.
bool IsNormalBootMode();
// Writes the data passed to path. The file at path will be overwritten if it
diff --git a/utils_unittest.cc b/utils_unittest.cc
index 0fda08f..67a14db 100644
--- a/utils_unittest.cc
+++ b/utils_unittest.cc
@@ -31,7 +31,7 @@
TEST(UtilsTest, IsNormalBootMode) {
// Pretty lame test...
- EXPECT_FALSE(utils::IsNormalBootMode());
+ EXPECT_TRUE(utils::IsNormalBootMode());
}
TEST(UtilsTest, NormalizePathTest) {