Add helper to convert strings to UpdateStatus values

This is useful for decyphering the statuses returned over
the DBus interface.

Bug: 24547247
Test: mmm system/update_engine; emerge-panther update_engine

Change-Id: Ifce74450209a7e7cb632c2fee7b54364ffaf3ff5
diff --git a/update_status_utils.cc b/update_status_utils.cc
index c1504fd..ff039b8 100644
--- a/update_status_utils.cc
+++ b/update_status_utils.cc
@@ -50,4 +50,40 @@
   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::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;
+  }
+  return false;
+}
+
 }  // namespace chromeos_update_engine
diff --git a/update_status_utils.h b/update_status_utils.h
index 8a07ebe..78d3530 100644
--- a/update_status_utils.h
+++ b/update_status_utils.h
@@ -17,12 +17,17 @@
 #ifndef CLIENT_LIBRARY_UPDATE_STATUS_TO_STRING_H_
 #define CLIENT_LIBRARY_UPDATE_STATUS_TO_STRING_H_
 
+#include <string>
+
 #include "update_engine/update_status.h"
 
 namespace chromeos_update_engine {
 
 const char* UpdateStatusToString(const update_engine::UpdateStatus& status);
 
+bool StringToUpdateStatus(const std::string& update_status_as_string,
+                          update_engine::UpdateStatus* status);
+
 }  // namespace chromeos_update_engine
 
 #endif  // CLIENT_LIBRARY_UPDATE_STATUS_TO_STRING_H_