update_engine: Leverage install indication in StatusResult protobuf

Update engine will provide this install indication for signal listeners
(specifically dlcservice) and status requesters to indicate whether
update engine is in the process of installing or updating. With this,
dlcservice will can be altered to not probe update engine for status
during a DLC uninstall.

The update engine client is also updated when getting the status from
update engine by using KeyValueStore printouts now.

Old output:

  [0725/202915.815630:INFO:update_engine_client.cc(501)] Querying Update
  Engine status...
  LAST_CHECKED_TIME=1564102396
  PROGRESS=1.000000
  CURRENT_OP=UPDATE_STATUS_IDLE
  NEW_VERSION=12354.0.2019_07_19_1136
  NEW_SIZE=792

New output:

  [0726/173804.558077:INFO:update_engine_client.cc(490)] Querying Update
  Engine status...
  CURRENT_OPERATION=UPDATE_STATUS_IDLE
  IS_INSTALL=false
  LAST_CHECKED_TIME=1564187860
  NEW_SIZE=792
  NEW_VERSION=12369.0.2019_07_26_0904
  PROGRESS=1.0

BUG=chromium:871340
TEST=FEATURES="test" emerge-$BOARD update_engine update_engine-client system_api
TEST=/usr/bin/update_engine_client --status

Cq-Depend: chromium:1717661
Change-Id: Iaacea27e0fc0711200ec81fdebb7fef45f94af43
diff --git a/client_library/client_dbus.cc b/client_library/client_dbus.cc
index d046502..e2defe7 100644
--- a/client_library/client_dbus.cc
+++ b/client_library/client_dbus.cc
@@ -54,6 +54,7 @@
   out_status->new_version = status.new_version();
   out_status->new_size_bytes = status.new_size();
   out_status->status = static_cast<UpdateStatus>(status.current_operation());
+  out_status->is_install = status.is_install();
 }
 }  // namespace
 
diff --git a/client_library/include/update_engine/update_status.h b/client_library/include/update_engine/update_status.h
index 059181c..bc14e67 100644
--- a/client_library/include/update_engine/update_status.h
+++ b/client_library/include/update_engine/update_status.h
@@ -52,7 +52,7 @@
   // This value is exclusively used in Chrome. DO NOT define nor use it.
   // TODO(crbug.com/977320): Remove this value from chrome by refactoring the
   // Chrome code and evantually from here. This is not really an operation or
-  // state that the update engine stays on. This is the result of an internal
+  // state that the update_engine stays on. This is the result of an internal
   // failure and should be reflected differently.
   // ERROR = -1,
 };
@@ -71,19 +71,20 @@
 DECLARE_FLAGS_ENUM(UpdateAttemptFlags);
 
 struct UpdateEngineStatus {
-  // When the update_engine last checked for updates (time_t: seconds from unix
-  // epoch)
+  // Update engine last checked update (time_t: seconds from unix epoch).
   int64_t last_checked_time;
-  // the current status/operation of the update_engine
+  // Current status/operation of the update_engine.
   UpdateStatus status;
-  // the current product version (oem bundle id)
+  // Current product version (oem bundle id).
   std::string current_version;
-  // The current progress (0.0f-1.0f).
+  // Current progress (0.0f-1.0f).
   double progress;
-  // the size of the update (bytes)
+  // Size of the update in bytes.
   uint64_t new_size_bytes;
-  // the new product version
+  // New product version.
   std::string new_version;
+  // Indication of install for DLC(s).
+  bool is_install;
 };
 
 }  // namespace update_engine
diff --git a/dbus_service.cc b/dbus_service.cc
index 0cfe26b..b379603 100644
--- a/dbus_service.cc
+++ b/dbus_service.cc
@@ -47,6 +47,7 @@
   out_status->set_current_operation(static_cast<Operation>(ue_status.status));
   out_status->set_new_version(ue_status.new_version);
   out_status->set_new_size(ue_status.new_size_bytes);
+  out_status->set_is_install(ue_status.is_install);
 }
 }  // namespace
 
diff --git a/update_attempter.cc b/update_attempter.cc
index dc7a4b5..71463b5 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -1382,6 +1382,7 @@
   out_status->progress = download_progress_;
   out_status->new_size_bytes = new_payload_size_;
   out_status->new_version = new_version_;
+  out_status->is_install = is_install_;
   return true;
 }
 
diff --git a/update_engine_client.cc b/update_engine_client.cc
index 1b680d1..954e856 100644
--- a/update_engine_client.cc
+++ b/update_engine_client.cc
@@ -41,6 +41,7 @@
 
 using chromeos_update_engine::EolStatus;
 using chromeos_update_engine::ErrorCode;
+using chromeos_update_engine::UpdateEngineStatusToString;
 using chromeos_update_engine::UpdateStatusToString;
 using chromeos_update_engine::utils::ErrorCodeToString;
 using std::string;
@@ -138,12 +139,7 @@
 
 void WatchingStatusUpdateHandler::HandleStatusUpdate(
     const UpdateEngineStatus& status) {
-  LOG(INFO) << "Got status update:";
-  LOG(INFO) << "  last_checked_time: " << status.last_checked_time;
-  LOG(INFO) << "  progress: " << status.progress;
-  LOG(INFO) << "  current_operation: " << UpdateStatusToString(status.status);
-  LOG(INFO) << "  new_version: " << status.new_version;
-  LOG(INFO) << "  new_size: " << status.new_size_bytes;
+  LOG(INFO) << "Got status update: " << UpdateEngineStatusToString(status);
 }
 
 bool UpdateEngineClient::ShowStatus() {
@@ -161,14 +157,7 @@
         base::TimeDelta::FromSeconds(kShowStatusRetryIntervalInSeconds));
   }
 
-  printf("LAST_CHECKED_TIME=%" PRIi64
-         "\nPROGRESS=%f\nCURRENT_OP=%s\n"
-         "NEW_VERSION=%s\nNEW_SIZE=%" PRIi64 "\n",
-         status.last_checked_time,
-         status.progress,
-         UpdateStatusToString(status.status),
-         status.new_version.c_str(),
-         status.new_size_bytes);
+  printf("%s", UpdateEngineStatusToString(status).c_str());
 
   return true;
 }
diff --git a/update_status_utils.cc b/update_status_utils.cc
index f3917d1..b56d94a 100644
--- a/update_status_utils.cc
+++ b/update_status_utils.cc
@@ -16,8 +16,13 @@
 #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 {
@@ -52,4 +57,28 @@
   return nullptr;
 }
 
+string UpdateEngineStatusToString(const UpdateEngineStatus& status) {
+  KeyValueStore key_value_store;
+
+#if BASE_VER < 576279
+  key_value_store.SetString("LAST_CHECKED_TIME",
+                            base::Int64ToString(status.last_checked_time));
+  key_value_store.SetString("PROGRESS", base::DoubleToString(status.progress));
+  key_value_store.SetString("NEW_SIZE",
+                            base::Uint64ToString(status.new_size_bytes));
+#else
+  key_value_store.SetString("LAST_CHECKED_TIME",
+                            base::NumberToString(status.last_checked_time));
+  key_value_store.SetString("PROGRESS", base::NumberToString(status.progress));
+  key_value_store.SetString("NEW_SIZE",
+                            base::NumberToString(status.new_size_bytes));
+#endif
+  key_value_store.SetString("CURRENT_OPERATION",
+                            UpdateStatusToString(status.status));
+  key_value_store.SetString("NEW_VERSION", status.new_version);
+  key_value_store.SetBoolean("IS_INSTALL", status.is_install);
+
+  return key_value_store.SaveToString();
+}
+
 }  // namespace chromeos_update_engine
diff --git a/update_status_utils.h b/update_status_utils.h
index e3b8b43..1e3fdde 100644
--- a/update_status_utils.h
+++ b/update_status_utils.h
@@ -25,6 +25,9 @@
 
 const char* UpdateStatusToString(const update_engine::UpdateStatus& status);
 
+std::string UpdateEngineStatusToString(
+    const update_engine::UpdateEngineStatus& status);
+
 }  // namespace chromeos_update_engine
 
 #endif  // UPDATE_ENGINE_UPDATE_STATUS_UTILS_H_