Move all blocking client calls to libupdate_engine_client

Change-Id: I27bc86ad2eef3a573c60fde1bb10b6b37af81c1c
Test: Affected commands continue to work
Bug: 26233663
Signed-off-by: Casey Dahlin <sadmac@google.com>
diff --git a/update_engine_client.cc b/update_engine_client.cc
index 52c2cd2..9294d36 100644
--- a/update_engine_client.cc
+++ b/update_engine_client.cc
@@ -102,30 +102,12 @@
   void WatchForUpdates();
 
   // Show the status of the update engine in stdout.
-  // Blocking call. Exits the program with error 1 in case of an error.
   bool ShowStatus();
 
   // Return whether we need to reboot. 0 if reboot is needed, 1 if an error
   // occurred, 2 if no reboot is needed.
   int GetNeedReboot();
 
-  void Rollback(bool rollback);
-  string GetRollbackPartition();
-
-  // Reboot the device if a reboot is needed.
-  // Blocking call. Ignores failures.
-  void RebootIfNeeded();
-
-  // Getter and setter for the updates over cellular connections.
-  // Blocking call. Exits the program with error 1 in case of an error.
-  void SetUpdateOverCellularPermission(bool allowed);
-  bool GetUpdateOverCellularPermission();
-
-  // Getter and setter for the updates from P2P permission.
-  // Blocking call. Exits the program with error 1 in case of an error.
-  void SetP2PUpdatePermission(bool enabled);
-  bool GetP2PUpdatePermission();
-
   // This is similar to watching for updates but rather than registering
   // a signal watch, actively poll the daemon just in case it stops
   // sending notifications.
@@ -136,9 +118,6 @@
                              const string& new_version,
                              int64_t new_size);
 
-  // Blocking call. Exits the program with error 1 in case of an error.
-  void ShowPrevVersion();
-
   // Blocks until a reboot is needed. If the reboot is needed, exits the program
   // with 0. Otherwise it exits the program with 1 if an error occurs before
   // the reboot is needed.
@@ -280,52 +259,6 @@
   return 2;
 }
 
-void UpdateEngineClient::Rollback(bool rollback) {
-  bool ret = proxy_->AttemptRollback(rollback, nullptr);
-  CHECK(ret) << "Rollback request failed.";
-}
-
-string UpdateEngineClient::GetRollbackPartition() {
-  string rollback_partition;
-  bool ret = proxy_->GetRollbackPartition(&rollback_partition, nullptr);
-  CHECK(ret) << "Error while querying rollback partition availabilty.";
-  return rollback_partition;
-}
-
-void UpdateEngineClient::RebootIfNeeded() {
-  bool ret = proxy_->RebootIfNeeded(nullptr);
-  if (!ret) {
-    // Reboot error code doesn't necessarily mean that a reboot
-    // failed. For example, D-Bus may be shutdown before we receive the
-    // result.
-    LOG(INFO) << "RebootIfNeeded() failure ignored.";
-  }
-}
-
-void UpdateEngineClient::SetUpdateOverCellularPermission(bool allowed) {
-  bool ret = proxy_->SetUpdateOverCellularPermission(allowed, nullptr);
-  CHECK(ret) << "Error setting the update over cellular setting.";
-}
-
-bool UpdateEngineClient::GetUpdateOverCellularPermission() {
-  bool allowed;
-  bool ret = proxy_->GetUpdateOverCellularPermission(&allowed, nullptr);
-  CHECK(ret) << "Error getting the update over cellular setting.";
-  return allowed;
-}
-
-void UpdateEngineClient::SetP2PUpdatePermission(bool enabled) {
-  bool ret = proxy_->SetP2PUpdatePermission(enabled, nullptr);
-  CHECK(ret) << "Error setting the peer-to-peer update setting.";
-}
-
-bool UpdateEngineClient::GetP2PUpdatePermission() {
-  bool enabled;
-  bool ret = proxy_->GetP2PUpdatePermission(&enabled, nullptr);
-  CHECK(ret) << "Error getting the peer-to-peer update setting.";
-  return enabled;
-}
-
 void UpdateEngineClient::OnUpdateCompleteCheck(
     int64_t /* last_checked_time */,
     double /* progress */,
@@ -350,17 +283,6 @@
                  base::Unretained(this)));
 }
 
-void UpdateEngineClient::ShowPrevVersion() {
-  string prev_version = nullptr;
-
-  bool ret = proxy_->GetPrevVersion(&prev_version, nullptr);;
-  if (!ret) {
-    LOG(ERROR) << "Error getting previous version.";
-  } else {
-    LOG(INFO) << "Previous version = " << prev_version;
-  }
-}
-
 void UpdateEngineClient::OnRebootNeededCheck(
     int64_t /* last_checked_time */,
     double /* progress */,
@@ -492,13 +414,22 @@
       LOG(ERROR) << "Unknown option: \"" << FLAGS_update_over_cellular
                  << "\". Please specify \"yes\" or \"no\".";
     } else {
-      SetUpdateOverCellularPermission(allowed);
+      if(!client_->SetUpdateOverCellularPermission(allowed)) {
+        LOG(ERROR) << "Error setting the update over cellular setting.";
+        return 1;
+      }
     }
   }
 
   // Show the current update over cellular network setting.
   if (FLAGS_show_update_over_cellular) {
-    bool allowed = GetUpdateOverCellularPermission();
+    bool allowed;
+
+    if (!client_->GetUpdateOverCellularPermission(&allowed)) {
+      LOG(ERROR) << "Error getting the update over cellular setting.";
+      return 1;
+    }
+
     LOG(INFO) << "Current update over cellular network setting: "
               << (allowed ? "ENABLED" : "DISABLED");
   }
@@ -515,13 +446,22 @@
       LOG(ERROR) << "Unknown option: \"" << FLAGS_p2p_update
                  << "\". Please specify \"yes\" or \"no\".";
     } else {
-      SetP2PUpdatePermission(enabled);
+      if (!client_->SetP2PUpdatePermission(enabled)) {
+        LOG(ERROR) << "Error setting the peer-to-peer update setting.";
+        return 1;
+      }
     }
   }
 
   // Show the rollback availability.
   if (FLAGS_can_rollback) {
-    string rollback_partition = GetRollbackPartition();
+    string rollback_partition;
+
+    if (!client_->GetRollbackPartition(&rollback_partition)) {
+      LOG(ERROR) << "Error while querying rollback partition availabilty.";
+      return 1;
+    }
+
     bool can_rollback = true;
     if (rollback_partition.empty()) {
       rollback_partition = "UNAVAILABLE";
@@ -538,7 +478,13 @@
 
   // Show the current P2P enabled setting.
   if (FLAGS_show_p2p_update) {
-    bool enabled = GetP2PUpdatePermission();
+    bool enabled;
+
+    if (!client_->GetP2PUpdatePermission(&enabled)) {
+      LOG(ERROR) << "Error getting the peer-to-peer update setting.";
+      return 1;
+    }
+
     LOG(INFO) << "Current update using P2P setting: "
               << (enabled ? "ENABLED" : "DISABLED");
   }
@@ -587,7 +533,10 @@
 
   if (FLAGS_rollback) {
     LOG(INFO) << "Requesting rollback.";
-    Rollback(FLAGS_powerwash);
+    if (!client_->Rollback(FLAGS_powerwash)) {
+      LOG(ERROR) << "Rollback request failed.";
+      return 1;
+    }
   }
 
   // Initiate an update check, if necessary.
@@ -640,12 +589,18 @@
 
   if (FLAGS_reboot) {
     LOG(INFO) << "Requesting a reboot...";
-    RebootIfNeeded();
+    client_->RebootIfNeeded();
     return 0;
   }
 
   if (FLAGS_prev_version) {
-    ShowPrevVersion();
+    string prev_version;
+
+    if (!client_->GetPrevVersion(&prev_version)) {
+      LOG(ERROR) << "Error getting previous version.";
+    } else {
+      LOG(INFO) << "Previous version = " << prev_version;
+    }
   }
 
   if (FLAGS_is_reboot_needed) {