update_engine: Add option to turn on repeated updates from client.

Add `enable_repeated_updates` arg for update_engine_client which
used dbus method to turn on the repeated updates feature.

BUG=None
TEST=FEATURES=test emerge-hatch update_engine update_engine-client
TEST=update_engine_client --enable_feature=feature-repeated-updates
--disable_feature=feature-repeated-updates
TEST=update_engine_client --enable_feature=feature-repeated-updates
--update

Disallow-Recycled-Builds: all
Change-Id: I4f45265014641918789cd832309d83bc71bde3a5
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2650406
Tested-by: Vyshu Khota <vyshu@google.com>
Commit-Queue: Vyshu Khota <vyshu@google.com>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
diff --git a/client_library/client_dbus.cc b/client_library/client_dbus.cc
index 1e8b9e2..0684173 100644
--- a/client_library/client_dbus.cc
+++ b/client_library/client_dbus.cc
@@ -251,5 +251,10 @@
   return proxy_->GetLastAttemptError(last_attempt_error, nullptr);
 }
 
+bool DBusUpdateEngineClient::ToggleFeature(const std::string& feature,
+                                           bool enable) {
+  return proxy_->ToggleFeature(feature, enable, nullptr);
+}
+
 }  // namespace internal
 }  // namespace update_engine
diff --git a/client_library/client_dbus.h b/client_library/client_dbus.h
index f19555f..172fd3d 100644
--- a/client_library/client_dbus.h
+++ b/client_library/client_dbus.h
@@ -75,6 +75,8 @@
 
   bool GetChannel(std::string* out_channel) const override;
 
+  bool ToggleFeature(const std::string& feature, bool enable) override;
+
   bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
   bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
 
diff --git a/client_library/include/update_engine/client.h b/client_library/include/update_engine/client.h
index f734733..a6af9be 100644
--- a/client_library/include/update_engine/client.h
+++ b/client_library/include/update_engine/client.h
@@ -119,6 +119,8 @@
   // Get the last UpdateAttempt error code.
   virtual bool GetLastAttemptError(int32_t* last_attempt_error) const = 0;
 
+  virtual bool ToggleFeature(const std::string& feature, bool enable) = 0;
+
  protected:
   // Use CreateInstance().
   UpdateEngineClient() = default;
diff --git a/cros/update_engine_client.cc b/cros/update_engine_client.cc
index 6f20f11..e8139dc 100644
--- a/cros/update_engine_client.cc
+++ b/cros/update_engine_client.cc
@@ -286,6 +286,15 @@
               "Show the previous OS version used before the update reboot.");
   DEFINE_bool(last_attempt_error, false, "Show the last attempt error.");
   DEFINE_bool(eol_status, false, "Show the current end-of-life status.");
+  DEFINE_string(
+      enable_feature,
+      "",
+      "Give the name of the feature to enable, ex.\"feature-repeated-updates\" "
+      "to continue checking for updates while waiting for reboot.");
+  DEFINE_string(disable_feature,
+                "",
+                "Give the name of the feature to disable, "
+                "ex.\"feature-repeated-updates\".");
 
   // Boilerplate init commands.
   base::CommandLine::Init(argc_, argv_);
@@ -470,6 +479,29 @@
     }
   }
 
+  if (!FLAGS_enable_feature.empty() && !FLAGS_disable_feature.empty() &&
+      FLAGS_enable_feature == FLAGS_disable_feature) {
+    LOG(ERROR) << "Cannot both enable and disable feature: "
+               << FLAGS_disable_feature;
+    return 1;
+  }
+
+  if (!FLAGS_enable_feature.empty()) {
+    LOG(INFO) << "Requesting to enable feature " << FLAGS_enable_feature;
+    if (!client_->ToggleFeature(FLAGS_enable_feature, true)) {
+      LOG(ERROR) << "Enabling feature failed.";
+      return 1;
+    }
+  }
+
+  if (!FLAGS_disable_feature.empty()) {
+    LOG(INFO) << "Requesting to disable feature " << FLAGS_disable_feature;
+    if (!client_->ToggleFeature(FLAGS_disable_feature, false)) {
+      LOG(ERROR) << "Disabling feature failed.";
+      return 1;
+    }
+  }
+
   // Initiate an update check, if necessary.
   if (do_update_request) {
     LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored.";