Port update_engine_client ResetStatus command to lib
This is the first step in getting update_engine_client completely off of
direct DBus calls
Test: Ran --reset_status command and verified update_engine received the
signal.
Bug: 26233663
Signed-off-by: Casey Dahlin <sadmac@google.com>
Change-Id: Iac54d890fd796f91a7813755d6061cf468255347
diff --git a/Android.mk b/Android.mk
index 2727a44..c9a2297 100644
--- a/Android.mk
+++ b/Android.mk
@@ -387,7 +387,8 @@
$(ue_common_shared_libraries) \
libdbus \
libbrillo-dbus \
- libchrome-dbus
+ libchrome-dbus \
+ libupdate_engine_client
LOCAL_SRC_FILES := \
update_engine_client.cc
include $(BUILD_EXECUTABLE)
diff --git a/client_library/client_impl.cc b/client_library/client_impl.cc
index 84ca184..3dba873 100644
--- a/client_library/client_impl.cc
+++ b/client_library/client_impl.cc
@@ -66,6 +66,10 @@
return StringToUpdateStatus(status_as_string, out_update_status);
}
+bool UpdateEngineClientImpl::ResetStatus() {
+ return proxy_->ResetStatus(nullptr);
+}
+
bool UpdateEngineClientImpl::SetTargetChannel(const string& in_target_channel) {
return proxy_->SetChannel(
in_target_channel,
diff --git a/client_library/client_impl.h b/client_library/client_impl.h
index e6194d2..912449f 100644
--- a/client_library/client_impl.h
+++ b/client_library/client_impl.h
@@ -44,6 +44,8 @@
std::string* out_new_version,
int64_t* out_new_size) override;
+ bool ResetStatus() override;
+
bool SetTargetChannel(const std::string& target_channel) override;
bool GetTargetChannel(std::string* out_channel) override;
diff --git a/client_library/include/update_engine/client.h b/client_library/include/update_engine/client.h
index b3cef66..3406ca6 100644
--- a/client_library/include/update_engine/client.h
+++ b/client_library/include/update_engine/client.h
@@ -66,6 +66,9 @@
std::string* out_new_version,
int64_t* out_new_size) = 0;
+ // Resets the status of the Update Engine
+ virtual bool ResetStatus() = 0;
+
// Changes the current channel of the device to the target channel.
virtual bool SetTargetChannel(const std::string& target_channel) = 0;
diff --git a/update_engine.gyp b/update_engine.gyp
index 97ed4c2..01d691d 100644
--- a/update_engine.gyp
+++ b/update_engine.gyp
@@ -285,10 +285,32 @@
'main.cc',
],
},
+ # update_engine client library.
+ {
+ 'target_name': 'libupdate_engine_client',
+ 'type': 'static_library',
+ 'variables': {
+ 'deps': [
+ 'dbus-1',
+ 'libupdate_engine-client',
+ ],
+ },
+ 'sources': [
+ 'client_library/client.cc',
+ 'client_library/client_impl.cc',
+ 'update_status_utils.cc',
+ ],
+ 'include_dirs': [
+ 'client_library/include',
+ ],
+ },
# update_engine console client.
{
'target_name': 'update_engine_client',
'type': 'executable',
+ 'dependencies': [
+ 'libupdate_engine_client',
+ ],
'variables': {
'exported_deps': [
'libupdate_engine-client',
diff --git a/update_engine_client.cc b/update_engine_client.cc
index b59f22f..1413806 100644
--- a/update_engine_client.cc
+++ b/update_engine_client.cc
@@ -18,6 +18,7 @@
#include <sysexits.h>
#include <unistd.h>
+#include <memory>
#include <string>
#include <base/bind.h>
@@ -27,10 +28,12 @@
#include <brillo/daemons/dbus_daemon.h>
#include <brillo/flag_helper.h>
#include <dbus/bus.h>
+#include <update_engine/client.h>
#include <update_engine/dbus-constants.h>
#include <update_engine/dbus-proxies.h>
using std::string;
+using std::unique_ptr;
using update_engine::kAttemptUpdateFlagNonInteractive;
using update_engine::kUpdateEngineServiceName;
@@ -42,7 +45,10 @@
class UpdateEngineClient : public brillo::DBusDaemon {
public:
- UpdateEngineClient(int argc, char** argv) : argc_(argc), argv_(argv) {}
+ UpdateEngineClient(int argc, char** argv) : argc_(argc), argv_(argv) {
+ client_ = update_engine::UpdateEngineClient::CreateInstance();
+ }
+
~UpdateEngineClient() override = default;
protected:
@@ -91,8 +97,6 @@
// The daemon should continue running for this to work.
void WatchForUpdates();
- void ResetStatus();
-
// Show the status of the update engine in stdout.
// Blocking call. Exits the program with error 1 in case of an error.
void ShowStatus();
@@ -171,6 +175,9 @@
int argc_;
char** argv_;
+ // Library-based client
+ unique_ptr<update_engine::UpdateEngineClient> client_;
+
// Tell whether the UpdateEngine service is available after startup.
bool service_is_available_{false};
@@ -240,11 +247,6 @@
base::Unretained(this)));
}
-void UpdateEngineClient::ResetStatus() {
- bool ret = proxy_->ResetStatus(nullptr);
- CHECK(ret) << "ResetStatus() failed.";
-}
-
void UpdateEngineClient::ShowStatus() {
int64_t last_checked_time = 0;
double progress = 0.0;
@@ -483,10 +485,16 @@
// Update the status if requested.
if (FLAGS_reset_status) {
LOG(INFO) << "Setting Update Engine status to idle ...";
- ResetStatus();
- LOG(INFO) << "ResetStatus succeeded; to undo partition table changes run:\n"
- "(D=$(rootdev -d) P=$(rootdev -s); cgpt p -i$(($(echo ${P#$D} "
- "| sed 's/^[^0-9]*//')-1)) $D;)";
+
+ if (client_->ResetStatus()) {
+ LOG(INFO) << "ResetStatus succeeded; to undo partition table changes "
+ "run:\n"
+ "(D=$(rootdev -d) P=$(rootdev -s); cgpt p -i$(($(echo "
+ "${P#$D} | sed 's/^[^0-9]*//')-1)) $D;)";
+ } else {
+ LOG(ERROR) << "ResetStatus failed";
+ return 1;
+ }
}
// Changes the current update over cellular network setting.