Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2016 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
| 17 | #include <sysexits.h> |
| 18 | #include <unistd.h> |
| 19 | |
Kelvin Zhang | 8ddadd3 | 2023-12-12 12:54:30 -0800 | [diff] [blame] | 20 | #include <chrono> |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <base/bind.h> |
| 25 | #include <base/callback.h> |
| 26 | #include <base/command_line.h> |
| 27 | #include <base/logging.h> |
| 28 | #include <base/strings/string_split.h> |
| 29 | #include <binder/IServiceManager.h> |
Alex Deymo | 2130ee0 | 2016-02-02 18:35:50 -0800 | [diff] [blame] | 30 | #include <binderwrapper/binder_wrapper.h> |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 31 | #include <brillo/binder_watcher.h> |
| 32 | #include <brillo/daemons/daemon.h> |
| 33 | #include <brillo/flag_helper.h> |
| 34 | #include <brillo/message_loops/message_loop.h> |
| 35 | #include <brillo/syslog_logging.h> |
| 36 | #include <utils/String16.h> |
| 37 | #include <utils/StrongPointer.h> |
| 38 | |
| 39 | #include "android/os/BnUpdateEngineCallback.h" |
| 40 | #include "android/os/IUpdateEngine.h" |
| 41 | #include "update_engine/client_library/include/update_engine/update_status.h" |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 42 | #include "update_engine/common/error_code.h" |
Alex Deymo | e88e9fe | 2016-02-03 16:38:00 -0800 | [diff] [blame] | 43 | #include "update_engine/common/error_code_utils.h" |
Alex Deymo | 2130ee0 | 2016-02-02 18:35:50 -0800 | [diff] [blame] | 44 | #include "update_engine/update_status_utils.h" |
Kelvin Zhang | be1c180 | 2021-06-21 10:03:36 -0400 | [diff] [blame] | 45 | #include "utils/String8.h" |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 46 | |
| 47 | using android::binder::Status; |
| 48 | |
| 49 | namespace chromeos_update_engine { |
| 50 | namespace internal { |
| 51 | |
| 52 | class UpdateEngineClientAndroid : public brillo::Daemon { |
| 53 | public: |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 54 | UpdateEngineClientAndroid(int argc, char** argv) : argc_(argc), argv_(argv) {} |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 55 | |
| 56 | int ExitWhenIdle(const Status& status); |
| 57 | int ExitWhenIdle(int return_code); |
| 58 | |
| 59 | private: |
| 60 | class UECallback : public android::os::BnUpdateEngineCallback { |
| 61 | public: |
Alex Deymo | e88e9fe | 2016-02-03 16:38:00 -0800 | [diff] [blame] | 62 | explicit UECallback(UpdateEngineClientAndroid* client) : client_(client) {} |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 63 | |
| 64 | // android::os::BnUpdateEngineCallback overrides. |
| 65 | Status onStatusUpdate(int status_code, float progress) override; |
| 66 | Status onPayloadApplicationComplete(int error_code) override; |
| 67 | |
| 68 | private: |
| 69 | UpdateEngineClientAndroid* client_; |
| 70 | }; |
| 71 | |
| 72 | int OnInit() override; |
| 73 | |
Alex Deymo | 2130ee0 | 2016-02-02 18:35:50 -0800 | [diff] [blame] | 74 | // Called whenever the UpdateEngine daemon dies. |
| 75 | void UpdateEngineServiceDied(); |
Kelvin Zhang | be1c180 | 2021-06-21 10:03:36 -0400 | [diff] [blame] | 76 | // Register callback to watch for death notification from update_engine. |
| 77 | void RegisterDeathNotification(); |
Alex Deymo | 2130ee0 | 2016-02-02 18:35:50 -0800 | [diff] [blame] | 78 | |
Yifan Hong | 82cd9d3 | 2020-01-10 14:40:25 -0800 | [diff] [blame] | 79 | static std::vector<android::String16> ParseHeaders(const std::string& arg); |
| 80 | |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 81 | // Copy of argc and argv passed to main(). |
| 82 | int argc_; |
| 83 | char** argv_; |
| 84 | |
| 85 | android::sp<android::os::IUpdateEngine> service_; |
| 86 | android::sp<android::os::BnUpdateEngineCallback> callback_; |
Yifan Hong | 40bb0d0 | 2020-02-24 17:33:14 -0800 | [diff] [blame] | 87 | android::sp<android::os::BnUpdateEngineCallback> cleanup_callback_; |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 88 | |
| 89 | brillo::BinderWatcher binder_watcher_; |
| 90 | }; |
| 91 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 92 | Status UpdateEngineClientAndroid::UECallback::onStatusUpdate(int status_code, |
| 93 | float progress) { |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 94 | update_engine::UpdateStatus status = |
| 95 | static_cast<update_engine::UpdateStatus>(status_code); |
| 96 | LOG(INFO) << "onStatusUpdate(" << UpdateStatusToString(status) << " (" |
| 97 | << status_code << "), " << progress << ")"; |
| 98 | return Status::ok(); |
| 99 | } |
| 100 | |
| 101 | Status UpdateEngineClientAndroid::UECallback::onPayloadApplicationComplete( |
| 102 | int error_code) { |
| 103 | ErrorCode code = static_cast<ErrorCode>(error_code); |
Alex Deymo | e88e9fe | 2016-02-03 16:38:00 -0800 | [diff] [blame] | 104 | LOG(INFO) << "onPayloadApplicationComplete(" << utils::ErrorCodeToString(code) |
| 105 | << " (" << error_code << "))"; |
Sen Jiang | 02c4942 | 2017-10-31 15:14:11 -0700 | [diff] [blame] | 106 | client_->ExitWhenIdle( |
| 107 | (code == ErrorCode::kSuccess || code == ErrorCode::kUpdatedButNotActive) |
| 108 | ? EX_OK |
| 109 | : 1); |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 110 | return Status::ok(); |
| 111 | } |
| 112 | |
Kelvin Zhang | be1c180 | 2021-06-21 10:03:36 -0400 | [diff] [blame] | 113 | constexpr auto&& UNSPECIFIED_FLAG = "unspecified"; |
| 114 | |
| 115 | void UpdateEngineClientAndroid::RegisterDeathNotification() { |
| 116 | // When following updates status changes, exit if the update_engine daemon |
| 117 | // dies. |
| 118 | android::BinderWrapper::Create(); |
| 119 | android::BinderWrapper::Get()->RegisterForDeathNotifications( |
| 120 | android::os::IUpdateEngine::asBinder(service_), |
Kelvin Zhang | 2f6c25a | 2023-07-05 12:49:34 -0700 | [diff] [blame] | 121 | [this]() { UpdateEngineServiceDied(); }); |
Kelvin Zhang | be1c180 | 2021-06-21 10:03:36 -0400 | [diff] [blame] | 122 | } |
| 123 | |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 124 | int UpdateEngineClientAndroid::OnInit() { |
| 125 | int ret = Daemon::OnInit(); |
| 126 | if (ret != EX_OK) |
| 127 | return ret; |
| 128 | |
| 129 | DEFINE_bool(update, false, "Start a new update, if no update in progress."); |
| 130 | DEFINE_string(payload, |
| 131 | "http://127.0.0.1:8080/payload", |
| 132 | "The URI to the update payload to use."); |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 133 | DEFINE_int64(offset, |
| 134 | 0, |
Alex Deymo | 95b8f24 | 2016-01-28 16:06:57 -0800 | [diff] [blame] | 135 | "The offset in the payload where the CrAU update starts. " |
| 136 | "Used when --update is passed."); |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 137 | DEFINE_int64(size, |
| 138 | 0, |
Alex Deymo | 95b8f24 | 2016-01-28 16:06:57 -0800 | [diff] [blame] | 139 | "The size of the CrAU part of the payload. If 0 is passed, it " |
| 140 | "will be autodetected. Used when --update is passed."); |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 141 | DEFINE_string(headers, |
| 142 | "", |
Alex Deymo | 95b8f24 | 2016-01-28 16:06:57 -0800 | [diff] [blame] | 143 | "A list of key-value pairs, one element of the list per line. " |
Yifan Hong | 82cd9d3 | 2020-01-10 14:40:25 -0800 | [diff] [blame] | 144 | "Used when --update or --allocate is passed."); |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 145 | |
Sen Jiang | 6f67d56 | 2018-09-19 14:55:50 -0700 | [diff] [blame] | 146 | DEFINE_bool(verify, |
| 147 | false, |
| 148 | "Given payload metadata, verify if the payload is applicable."); |
Yifan Hong | 82cd9d3 | 2020-01-10 14:40:25 -0800 | [diff] [blame] | 149 | DEFINE_bool(allocate, false, "Given payload metadata, allocate space."); |
Sen Jiang | 6f67d56 | 2018-09-19 14:55:50 -0700 | [diff] [blame] | 150 | DEFINE_string(metadata, |
| 151 | "/data/ota_package/metadata", |
| 152 | "The path to the update payload metadata. " |
Yifan Hong | 82cd9d3 | 2020-01-10 14:40:25 -0800 | [diff] [blame] | 153 | "Used when --verify or --allocate is passed."); |
Sen Jiang | 6f67d56 | 2018-09-19 14:55:50 -0700 | [diff] [blame] | 154 | |
Kelvin Zhang | be1c180 | 2021-06-21 10:03:36 -0400 | [diff] [blame] | 155 | DEFINE_string(switch_slot, |
| 156 | UNSPECIFIED_FLAG, |
| 157 | "Perform just the slow switching part of OTA. " |
| 158 | "Used to revert a slot switch or re-do slot switch. Valid " |
| 159 | "values are 'true' and 'false'"); |
Kelvin Zhang | 0aaa736 | 2024-11-15 16:09:22 -0800 | [diff] [blame] | 160 | DEFINE_string( |
| 161 | trigger_postinstall, |
| 162 | UNSPECIFIED_FLAG, |
| 163 | "Only run postinstall sciprts. And only run postinstall script for the " |
| 164 | "specified partition. Example: \"system\", \"product\""); |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 165 | DEFINE_bool(suspend, false, "Suspend an ongoing update and exit."); |
| 166 | DEFINE_bool(resume, false, "Resume a suspended update."); |
| 167 | DEFINE_bool(cancel, false, "Cancel the ongoing update and exit."); |
Alex Deymo | 3b678db | 2016-02-09 11:50:06 -0800 | [diff] [blame] | 168 | DEFINE_bool(reset_status, false, "Reset an already applied update and exit."); |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 169 | DEFINE_bool(follow, |
| 170 | false, |
| 171 | "Follow status update changes until a final state is reached. " |
| 172 | "Exit status is 0 if the update succeeded, and 1 otherwise."); |
Yifan Hong | e5a8f23 | 2020-01-16 09:37:16 -0800 | [diff] [blame] | 173 | DEFINE_bool(merge, |
| 174 | false, |
| 175 | "Wait for previous update to merge. " |
| 176 | "Only available after rebooting to new slot."); |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 177 | // Boilerplate init commands. |
| 178 | base::CommandLine::Init(argc_, argv_); |
| 179 | brillo::FlagHelper::Init(argc_, argv_, "Android Update Engine Client"); |
| 180 | if (argc_ == 1) { |
| 181 | LOG(ERROR) << "Nothing to do. Run with --help for help."; |
| 182 | return 1; |
| 183 | } |
| 184 | |
| 185 | // Ensure there are no positional arguments. |
| 186 | const std::vector<std::string> positional_args = |
| 187 | base::CommandLine::ForCurrentProcess()->GetArgs(); |
| 188 | if (!positional_args.empty()) { |
| 189 | LOG(ERROR) << "Found a positional argument '" << positional_args.front() |
| 190 | << "'. If you want to pass a value to a flag, pass it as " |
| 191 | "--flag=value."; |
| 192 | return 1; |
| 193 | } |
| 194 | |
| 195 | bool keep_running = false; |
Alex Deymo | 95224dd | 2016-01-29 11:18:35 -0800 | [diff] [blame] | 196 | brillo::InitLog(brillo::kLogToStderr); |
Alex Deymo | 2130ee0 | 2016-02-02 18:35:50 -0800 | [diff] [blame] | 197 | |
| 198 | // Initialize a binder watcher early in the process before any interaction |
| 199 | // with the binder driver. |
| 200 | binder_watcher_.Init(); |
| 201 | |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 202 | android::status_t status = android::getService( |
| 203 | android::String16("android.os.UpdateEngineService"), &service_); |
| 204 | if (status != android::OK) { |
| 205 | LOG(ERROR) << "Failed to get IUpdateEngine binder from service manager: " |
| 206 | << Status::fromStatusT(status).toString8(); |
Alex Deymo | 2130ee0 | 2016-02-02 18:35:50 -0800 | [diff] [blame] | 207 | return ExitWhenIdle(1); |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Kelvin Zhang | c56afa3 | 2021-08-13 12:32:31 -0700 | [diff] [blame] | 210 | // Other commands, such as |setShouldSwitchSlotOnReboot|, might rely on the |
| 211 | // follow behavior, so created callback before running these commands. |
| 212 | if (FLAGS_follow) { |
| 213 | // Register a callback object with the service. |
| 214 | callback_ = new UECallback(this); |
Kelvin Zhang | 2f6c25a | 2023-07-05 12:49:34 -0700 | [diff] [blame] | 215 | bool bound = false; |
Kelvin Zhang | c56afa3 | 2021-08-13 12:32:31 -0700 | [diff] [blame] | 216 | if (!service_->bind(callback_, &bound).isOk() || !bound) { |
| 217 | LOG(ERROR) << "Failed to bind() the UpdateEngine daemon."; |
| 218 | return 1; |
| 219 | } |
| 220 | keep_running = true; |
| 221 | } |
| 222 | |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 223 | if (FLAGS_suspend) { |
| 224 | return ExitWhenIdle(service_->suspend()); |
| 225 | } |
| 226 | |
| 227 | if (FLAGS_resume) { |
| 228 | return ExitWhenIdle(service_->resume()); |
| 229 | } |
| 230 | |
| 231 | if (FLAGS_cancel) { |
| 232 | return ExitWhenIdle(service_->cancel()); |
| 233 | } |
| 234 | |
Alex Deymo | 3b678db | 2016-02-09 11:50:06 -0800 | [diff] [blame] | 235 | if (FLAGS_reset_status) { |
| 236 | return ExitWhenIdle(service_->resetStatus()); |
| 237 | } |
| 238 | |
Kelvin Zhang | 0aaa736 | 2024-11-15 16:09:22 -0800 | [diff] [blame] | 239 | if (FLAGS_trigger_postinstall != UNSPECIFIED_FLAG) { |
| 240 | return ExitWhenIdle(service_->triggerPostinstall( |
| 241 | android::String16(FLAGS_trigger_postinstall.c_str()))); |
| 242 | } |
| 243 | |
Kelvin Zhang | be1c180 | 2021-06-21 10:03:36 -0400 | [diff] [blame] | 244 | if (FLAGS_switch_slot != UNSPECIFIED_FLAG) { |
| 245 | if (FLAGS_switch_slot != "true" && FLAGS_switch_slot != "false") { |
| 246 | LOG(ERROR) << "--switch_slot should be either true or false, got " |
| 247 | << FLAGS_switch_slot; |
| 248 | return 1; |
| 249 | } |
| 250 | const bool should_switch = FLAGS_switch_slot == "true"; |
| 251 | ::android::binder::Status status; |
| 252 | if (should_switch) { |
| 253 | status = service_->setShouldSwitchSlotOnReboot( |
| 254 | android::String16(FLAGS_metadata.c_str(), FLAGS_metadata.size())); |
Kelvin Zhang | c56afa3 | 2021-08-13 12:32:31 -0700 | [diff] [blame] | 255 | if (!FLAGS_follow) { |
| 256 | return ExitWhenIdle(status); |
| 257 | } |
Kelvin Zhang | be1c180 | 2021-06-21 10:03:36 -0400 | [diff] [blame] | 258 | } else { |
Kelvin Zhang | c56afa3 | 2021-08-13 12:32:31 -0700 | [diff] [blame] | 259 | // resetShouldSwitchSlotOnReboot() is a synchronous call, no need to |
| 260 | // follow |
Kelvin Zhang | be1c180 | 2021-06-21 10:03:36 -0400 | [diff] [blame] | 261 | status = service_->resetShouldSwitchSlotOnReboot(); |
Kelvin Zhang | c56afa3 | 2021-08-13 12:32:31 -0700 | [diff] [blame] | 262 | return ExitWhenIdle(status); |
Kelvin Zhang | be1c180 | 2021-06-21 10:03:36 -0400 | [diff] [blame] | 263 | } |
Kelvin Zhang | be1c180 | 2021-06-21 10:03:36 -0400 | [diff] [blame] | 264 | } |
| 265 | |
Sen Jiang | 6f67d56 | 2018-09-19 14:55:50 -0700 | [diff] [blame] | 266 | if (FLAGS_verify) { |
| 267 | bool applicable = false; |
| 268 | Status status = service_->verifyPayloadApplicable( |
| 269 | android::String16{FLAGS_metadata.data(), FLAGS_metadata.size()}, |
| 270 | &applicable); |
| 271 | LOG(INFO) << "Payload is " << (applicable ? "" : "not ") << "applicable."; |
| 272 | return ExitWhenIdle(status); |
| 273 | } |
| 274 | |
Yifan Hong | 82cd9d3 | 2020-01-10 14:40:25 -0800 | [diff] [blame] | 275 | if (FLAGS_allocate) { |
| 276 | auto headers = ParseHeaders(FLAGS_headers); |
| 277 | int64_t ret = 0; |
| 278 | Status status = service_->allocateSpaceForPayload( |
| 279 | android::String16{FLAGS_metadata.data(), FLAGS_metadata.size()}, |
| 280 | headers, |
| 281 | &ret); |
| 282 | if (status.isOk()) { |
| 283 | if (ret == 0) { |
| 284 | LOG(INFO) << "Successfully allocated space for payload."; |
| 285 | } else { |
| 286 | LOG(INFO) << "Insufficient space; required " << ret << " bytes."; |
| 287 | } |
| 288 | } else { |
| 289 | LOG(INFO) << "Allocation failed."; |
| 290 | } |
| 291 | return ExitWhenIdle(status); |
| 292 | } |
| 293 | |
Yifan Hong | e5a8f23 | 2020-01-16 09:37:16 -0800 | [diff] [blame] | 294 | if (FLAGS_merge) { |
Yifan Hong | 40bb0d0 | 2020-02-24 17:33:14 -0800 | [diff] [blame] | 295 | // Register a callback object with the service. |
| 296 | cleanup_callback_ = new UECallback(this); |
| 297 | Status status = service_->cleanupSuccessfulUpdate(cleanup_callback_); |
| 298 | if (!status.isOk()) { |
| 299 | LOG(ERROR) << "Failed to call cleanupSuccessfulUpdate."; |
| 300 | return ExitWhenIdle(status); |
Yifan Hong | e5a8f23 | 2020-01-16 09:37:16 -0800 | [diff] [blame] | 301 | } |
Yifan Hong | 40bb0d0 | 2020-02-24 17:33:14 -0800 | [diff] [blame] | 302 | keep_running = true; |
Yifan Hong | e5a8f23 | 2020-01-16 09:37:16 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 305 | if (FLAGS_update) { |
Yifan Hong | 82cd9d3 | 2020-01-10 14:40:25 -0800 | [diff] [blame] | 306 | auto and_headers = ParseHeaders(FLAGS_headers); |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 307 | Status status = service_->applyPayload( |
| 308 | android::String16{FLAGS_payload.data(), FLAGS_payload.size()}, |
Alex Deymo | 95b8f24 | 2016-01-28 16:06:57 -0800 | [diff] [blame] | 309 | FLAGS_offset, |
| 310 | FLAGS_size, |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 311 | and_headers); |
| 312 | if (!status.isOk()) |
| 313 | return ExitWhenIdle(status); |
| 314 | } |
| 315 | |
| 316 | if (!keep_running) |
| 317 | return ExitWhenIdle(EX_OK); |
| 318 | |
Kelvin Zhang | be1c180 | 2021-06-21 10:03:36 -0400 | [diff] [blame] | 319 | RegisterDeathNotification(); |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 320 | return EX_OK; |
| 321 | } |
| 322 | |
| 323 | int UpdateEngineClientAndroid::ExitWhenIdle(const Status& status) { |
| 324 | if (status.isOk()) |
| 325 | return ExitWhenIdle(EX_OK); |
| 326 | LOG(ERROR) << status.toString8(); |
| 327 | return ExitWhenIdle(status.exceptionCode()); |
| 328 | } |
| 329 | |
| 330 | int UpdateEngineClientAndroid::ExitWhenIdle(int return_code) { |
| 331 | auto delayed_exit = base::Bind( |
| 332 | &Daemon::QuitWithExitCode, base::Unretained(this), return_code); |
| 333 | if (!brillo::MessageLoop::current()->PostTask(delayed_exit)) |
| 334 | return 1; |
| 335 | return EX_OK; |
| 336 | } |
| 337 | |
Alex Deymo | 2130ee0 | 2016-02-02 18:35:50 -0800 | [diff] [blame] | 338 | void UpdateEngineClientAndroid::UpdateEngineServiceDied() { |
| 339 | LOG(ERROR) << "UpdateEngineService died."; |
| 340 | QuitWithExitCode(1); |
| 341 | } |
| 342 | |
Yifan Hong | 82cd9d3 | 2020-01-10 14:40:25 -0800 | [diff] [blame] | 343 | std::vector<android::String16> UpdateEngineClientAndroid::ParseHeaders( |
| 344 | const std::string& arg) { |
| 345 | std::vector<std::string> headers = base::SplitString( |
| 346 | arg, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 347 | std::vector<android::String16> and_headers; |
| 348 | for (const auto& header : headers) { |
| 349 | and_headers.push_back(android::String16{header.data(), header.size()}); |
| 350 | } |
| 351 | return and_headers; |
| 352 | } |
| 353 | |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 354 | } // namespace internal |
| 355 | } // namespace chromeos_update_engine |
| 356 | |
| 357 | int main(int argc, char** argv) { |
Kelvin Zhang | 8ddadd3 | 2023-12-12 12:54:30 -0800 | [diff] [blame] | 358 | const auto start = std::chrono::system_clock::now(); |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 359 | chromeos_update_engine::internal::UpdateEngineClientAndroid client(argc, |
| 360 | argv); |
Kelvin Zhang | 8ddadd3 | 2023-12-12 12:54:30 -0800 | [diff] [blame] | 361 | const auto ret = client.Run(); |
| 362 | const auto end = std::chrono::system_clock::now(); |
| 363 | const auto duration = end - start; |
| 364 | LOG(INFO) |
| 365 | << "Command took " |
| 366 | << std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() |
| 367 | << " ms"; |
| 368 | return ret; |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 369 | } |