summaryrefslogtreecommitdiff
path: root/update_status_utils.cc
diff options
context:
space:
mode:
authorTianjie <xunchang@google.com>2020-06-19 00:22:59 -0700
committerTianjie <xunchang@google.com>2020-07-06 11:24:36 -0700
commit55abd3cbae6bd150b3534728a63befd1cadd6c5e (patch)
tree0077b57b1ef96c194380908311ce2a993fb1a89c /update_status_utils.cc
parent99d570d67bd5dab11de321068c4002ab76ae774a (diff)
parent694eeb0dece40f88e11ece3a776d995d855be79b (diff)
Merge remote-tracking branch 'aosp/upstream-master' into merge
It's a merge from chrome OS with some reverts. 1. the fd watcher change, because the libbrillo version isn't compatible in aosp. commit 6955bcc4ffe4cc9d62a88186b9a7e75d095a7897 commit 493fecb3f48c8478fd3ef244d631d857730dd14d 2. two libcurl unittest. Because the RunOnce() of the fake message loop seems to have different behavior in aosp. commit d3d84218cafbc1a95e7d6bbb775b495d1bebf4d2 Put preprocessor guards to use the old code in aosp. And we can switch to the new code in the other path after adopting the new libbrillo & libchrome. Test: unit tests pass, apply an OTA Change-Id: Id613599834b0f44f92841dbeae6303601db5490d
Diffstat (limited to 'update_status_utils.cc')
-rw-r--r--update_status_utils.cc76
1 files changed, 37 insertions, 39 deletions
diff --git a/update_status_utils.cc b/update_status_utils.cc
index 11fd2995..a702c61a 100644
--- a/update_status_utils.cc
+++ b/update_status_utils.cc
@@ -16,12 +16,32 @@
#include "update_engine/update_status_utils.h"
#include <base/logging.h>
+#include <base/strings/string_number_conversions.h>
+#include <brillo/key_value_store.h>
#include <update_engine/dbus-constants.h>
+using brillo::KeyValueStore;
+using std::string;
+using update_engine::UpdateEngineStatus;
using update_engine::UpdateStatus;
namespace chromeos_update_engine {
+namespace {
+
+// Note: Do not change these, autotest depends on these string variables being
+// exactly these matches.
+const char kCurrentOp[] = "CURRENT_OP";
+const char kIsInstall[] = "IS_INSTALL";
+const char kIsEnterpriseRollback[] = "IS_ENTERPRISE_ROLLBACK";
+const char kLastCheckedTime[] = "LAST_CHECKED_TIME";
+const char kNewSize[] = "NEW_SIZE";
+const char kNewVersion[] = "NEW_VERSION";
+const char kProgress[] = "PROGRESS";
+const char kWillPowerwashAfterReboot[] = "WILL_POWERWASH_AFTER_REBOOT";
+
+} // namespace
+
const char* UpdateStatusToString(const UpdateStatus& status) {
switch (status) {
case UpdateStatus::IDLE:
@@ -54,45 +74,23 @@ const char* UpdateStatusToString(const UpdateStatus& status) {
return nullptr;
}
-bool StringToUpdateStatus(const std::string& s, UpdateStatus* status) {
- if (s == update_engine::kUpdateStatusIdle) {
- *status = UpdateStatus::IDLE;
- return true;
- } else if (s == update_engine::kUpdateStatusCheckingForUpdate) {
- *status = UpdateStatus::CHECKING_FOR_UPDATE;
- return true;
- } else if (s == update_engine::kUpdateStatusUpdateAvailable) {
- *status = UpdateStatus::UPDATE_AVAILABLE;
- return true;
- } else if (s == update_engine::kUpdateStatusNeedPermissionToUpdate) {
- *status = UpdateStatus::NEED_PERMISSION_TO_UPDATE;
- return true;
- } else if (s == update_engine::kUpdateStatusDownloading) {
- *status = UpdateStatus::DOWNLOADING;
- return true;
- } else if (s == update_engine::kUpdateStatusVerifying) {
- *status = UpdateStatus::VERIFYING;
- return true;
- } else if (s == update_engine::kUpdateStatusFinalizing) {
- *status = UpdateStatus::FINALIZING;
- return true;
- } else if (s == update_engine::kUpdateStatusUpdatedNeedReboot) {
- *status = UpdateStatus::UPDATED_NEED_REBOOT;
- return true;
- } else if (s == update_engine::kUpdateStatusReportingErrorEvent) {
- *status = UpdateStatus::REPORTING_ERROR_EVENT;
- return true;
- } else if (s == update_engine::kUpdateStatusAttemptingRollback) {
- *status = UpdateStatus::ATTEMPTING_ROLLBACK;
- return true;
- } else if (s == update_engine::kUpdateStatusDisabled) {
- *status = UpdateStatus::DISABLED;
- return true;
- } else if (s == update_engine::kUpdateStatusCleanupPreviousUpdate) {
- *status = UpdateStatus::CLEANUP_PREVIOUS_UPDATE;
- return true;
- }
- return false;
+string UpdateEngineStatusToString(const UpdateEngineStatus& status) {
+ KeyValueStore key_value_store;
+
+ key_value_store.SetString(kLastCheckedTime,
+ base::NumberToString(status.last_checked_time));
+ key_value_store.SetString(kProgress, base::NumberToString(status.progress));
+ key_value_store.SetString(kNewSize,
+ base::NumberToString(status.new_size_bytes));
+ key_value_store.SetString(kCurrentOp, UpdateStatusToString(status.status));
+ key_value_store.SetString(kNewVersion, status.new_version);
+ key_value_store.SetBoolean(kIsEnterpriseRollback,
+ status.is_enterprise_rollback);
+ key_value_store.SetBoolean(kIsInstall, status.is_install);
+ key_value_store.SetBoolean(kWillPowerwashAfterReboot,
+ status.will_powerwash_after_reboot);
+
+ return key_value_store.SaveToString();
}
} // namespace chromeos_update_engine