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