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/client_library/client_impl.cc b/client_library/client_impl.cc
index af9cb05..7b80025 100644
--- a/client_library/client_impl.cc
+++ b/client_library/client_impl.cc
@@ -66,6 +66,44 @@
return StringToUpdateStatus(status_as_string, out_update_status);
}
+bool UpdateEngineClientImpl::SetUpdateOverCellularPermission(bool allowed) {
+ return proxy_->SetUpdateOverCellularPermission(allowed, nullptr);
+}
+
+bool UpdateEngineClientImpl::GetUpdateOverCellularPermission(bool *allowed) {
+ return proxy_->GetUpdateOverCellularPermission(allowed, nullptr);
+}
+
+bool UpdateEngineClientImpl::SetP2PUpdatePermission(bool enabled) {
+ return proxy_->SetP2PUpdatePermission(enabled, nullptr);
+}
+
+bool UpdateEngineClientImpl::GetP2PUpdatePermission(bool* enabled) {
+ return proxy_->GetP2PUpdatePermission(enabled, nullptr);
+}
+
+bool UpdateEngineClientImpl::Rollback(bool powerwash) {
+ return proxy_->AttemptRollback(powerwash, nullptr);
+}
+
+bool UpdateEngineClientImpl::GetRollbackPartition(string* rollback_partition) {
+ return proxy_->GetRollbackPartition(rollback_partition, nullptr);
+}
+
+bool UpdateEngineClientImpl::GetPrevVersion(string* prev_version) {
+ return proxy_->GetPrevVersion(prev_version, nullptr);
+}
+
+void UpdateEngineClientImpl::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.";
+ }
+}
+
bool UpdateEngineClientImpl::ResetStatus() {
return proxy_->ResetStatus(nullptr);
}
diff --git a/client_library/client_impl.h b/client_library/client_impl.h
index c55f753..8c11ac2 100644
--- a/client_library/client_impl.h
+++ b/client_library/client_impl.h
@@ -44,6 +44,20 @@
std::string* out_new_version,
int64_t* out_new_size) override;
+ bool SetUpdateOverCellularPermission(bool allowed) override;
+ bool GetUpdateOverCellularPermission(bool* allowed) override;
+
+ bool SetP2PUpdatePermission(bool enabled) override;
+ bool GetP2PUpdatePermission(bool* enabled) override;
+
+ bool Rollback(bool powerwash) override;
+
+ bool GetRollbackPartition(std::string* rollback_partition) override;
+
+ void RebootIfNeeded() override;
+
+ bool GetPrevVersion(std::string* prev_version);
+
bool ResetStatus() override;
bool SetTargetChannel(const std::string& target_channel,
diff --git a/client_library/include/update_engine/client.h b/client_library/include/update_engine/client.h
index ffc4a8b..604cc5a 100644
--- a/client_library/include/update_engine/client.h
+++ b/client_library/include/update_engine/client.h
@@ -66,6 +66,27 @@
std::string* out_new_version,
int64_t* out_new_size) = 0;
+ // Getter and setter for the updates over cellular connections.
+ virtual bool SetUpdateOverCellularPermission(bool allowed) = 0;
+ virtual bool GetUpdateOverCellularPermission(bool* allowed) = 0;
+
+ // Getter and setter for the updates from P2P permission.
+ virtual bool SetP2PUpdatePermission(bool enabled) = 0;
+ virtual bool GetP2PUpdatePermission(bool* enabled) = 0;
+
+ // Attempt a rollback. Set 'powerwash' to reset the device while rolling
+ // back.
+ virtual bool Rollback(bool powerwash) = 0;
+
+ // Get the rollback partition if available. Gives empty string if not.
+ virtual bool GetRollbackPartition(std::string* rollback_partition) = 0;
+
+ // Reboot the system if needed.
+ virtual void RebootIfNeeded() = 0;
+
+ // Get the previous version
+ virtual bool GetPrevVersion(std::string* prev_version) = 0;
+
// Resets the status of the Update Engine
virtual bool ResetStatus() = 0;
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) {