summaryrefslogtreecommitdiff
path: root/update_engine_client_android.cc
diff options
context:
space:
mode:
authorAmin Hassani <ahassani@chromium.org>2020-09-16 11:19:28 -0700
committerAmin Hassani <ahassani@chromium.org>2020-09-17 10:17:36 -0700
commite53b39b8b9c5c0871841bbbb86f23657c0b7f91b (patch)
tree12746e5e7e4716ba7fc94d3ed5c1a36c4d47d474 /update_engine_client_android.cc
parenta02a1f1dc837f22226499d9856a949fb180d099a (diff)
parent9956320ffa4edb340d20bd7f3c852a9e87437bd3 (diff)
update_engine: Merge remote-tracking branch 'cros/upstream' into cros/master
Done with: git merge cros/upstream --commit -s recursive - Added EC key support and its unittests. - Resolved a conlict on error codes. Since Android versions are not uploading any UMA metrics, I gave the priority to the Android version Since they can't be changed. - Changed the openssl functions to get1 version (from get0) version because of a current issue with gale. Once the issue is resolved we need to change them back. - Some remaining styling issues fixed by clang-format BUG=b:163153182 TEST=CQ passes TEST=unittests Change-Id: Ib95034422b92433ce26e28336bc4806b34910d38
Diffstat (limited to 'update_engine_client_android.cc')
-rw-r--r--update_engine_client_android.cc61
1 files changed, 52 insertions, 9 deletions
diff --git a/update_engine_client_android.cc b/update_engine_client_android.cc
index 6863799f..1a68cf49 100644
--- a/update_engine_client_android.cc
+++ b/update_engine_client_android.cc
@@ -72,12 +72,15 @@ class UpdateEngineClientAndroid : public brillo::Daemon {
// Called whenever the UpdateEngine daemon dies.
void UpdateEngineServiceDied();
+ static std::vector<android::String16> ParseHeaders(const std::string& arg);
+
// Copy of argc and argv passed to main().
int argc_;
char** argv_;
android::sp<android::os::IUpdateEngine> service_;
android::sp<android::os::BnUpdateEngineCallback> callback_;
+ android::sp<android::os::BnUpdateEngineCallback> cleanup_callback_;
brillo::BinderWatcher binder_watcher_;
};
@@ -123,15 +126,16 @@ int UpdateEngineClientAndroid::OnInit() {
DEFINE_string(headers,
"",
"A list of key-value pairs, one element of the list per line. "
- "Used when --update is passed.");
+ "Used when --update or --allocate is passed.");
DEFINE_bool(verify,
false,
"Given payload metadata, verify if the payload is applicable.");
+ DEFINE_bool(allocate, false, "Given payload metadata, allocate space.");
DEFINE_string(metadata,
"/data/ota_package/metadata",
"The path to the update payload metadata. "
- "Used when --verify is passed.");
+ "Used when --verify or --allocate is passed.");
DEFINE_bool(suspend, false, "Suspend an ongoing update and exit.");
DEFINE_bool(resume, false, "Resume a suspended update.");
@@ -141,7 +145,10 @@ int UpdateEngineClientAndroid::OnInit() {
false,
"Follow status update changes until a final state is reached. "
"Exit status is 0 if the update succeeded, and 1 otherwise.");
-
+ DEFINE_bool(merge,
+ false,
+ "Wait for previous update to merge. "
+ "Only available after rebooting to new slot.");
// Boilerplate init commands.
base::CommandLine::Init(argc_, argv_);
brillo::FlagHelper::Init(argc_, argv_, "Android Update Engine Client");
@@ -200,6 +207,36 @@ int UpdateEngineClientAndroid::OnInit() {
return ExitWhenIdle(status);
}
+ if (FLAGS_allocate) {
+ auto headers = ParseHeaders(FLAGS_headers);
+ int64_t ret = 0;
+ Status status = service_->allocateSpaceForPayload(
+ android::String16{FLAGS_metadata.data(), FLAGS_metadata.size()},
+ headers,
+ &ret);
+ if (status.isOk()) {
+ if (ret == 0) {
+ LOG(INFO) << "Successfully allocated space for payload.";
+ } else {
+ LOG(INFO) << "Insufficient space; required " << ret << " bytes.";
+ }
+ } else {
+ LOG(INFO) << "Allocation failed.";
+ }
+ return ExitWhenIdle(status);
+ }
+
+ if (FLAGS_merge) {
+ // Register a callback object with the service.
+ cleanup_callback_ = new UECallback(this);
+ Status status = service_->cleanupSuccessfulUpdate(cleanup_callback_);
+ if (!status.isOk()) {
+ LOG(ERROR) << "Failed to call cleanupSuccessfulUpdate.";
+ return ExitWhenIdle(status);
+ }
+ keep_running = true;
+ }
+
if (FLAGS_follow) {
// Register a callback object with the service.
callback_ = new UECallback(this);
@@ -212,12 +249,7 @@ int UpdateEngineClientAndroid::OnInit() {
}
if (FLAGS_update) {
- std::vector<std::string> headers = base::SplitString(
- FLAGS_headers, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
- std::vector<android::String16> and_headers;
- for (const auto& header : headers) {
- and_headers.push_back(android::String16{header.data(), header.size()});
- }
+ auto and_headers = ParseHeaders(FLAGS_headers);
Status status = service_->applyPayload(
android::String16{FLAGS_payload.data(), FLAGS_payload.size()},
FLAGS_offset,
@@ -261,6 +293,17 @@ void UpdateEngineClientAndroid::UpdateEngineServiceDied() {
QuitWithExitCode(1);
}
+std::vector<android::String16> UpdateEngineClientAndroid::ParseHeaders(
+ const std::string& arg) {
+ std::vector<std::string> headers = base::SplitString(
+ arg, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
+ std::vector<android::String16> and_headers;
+ for (const auto& header : headers) {
+ and_headers.push_back(android::String16{header.data(), header.size()});
+ }
+ return and_headers;
+}
+
} // namespace internal
} // namespace chromeos_update_engine