aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-05-02 17:48:54 -0500
committerTao Bao2017-05-08 14:16:45 -0500
commit00d5757186c279ba5e8a52a6f5209be3e7152025 (patch)
treeef219b66bb8ac8f7a20a182a91292213131505aa /install.cpp
parentf347c1abcac3bb1684d1ae329e3c229e7bf0b5b7 (diff)
downloadplatform-bootable-recovery-00d5757186c279ba5e8a52a6f5209be3e7152025.tar.gz
platform-bootable-recovery-00d5757186c279ba5e8a52a6f5209be3e7152025.tar.xz
platform-bootable-recovery-00d5757186c279ba5e8a52a6f5209be3e7152025.zip
Add a binary path param to update_binary_command().
This allows writing native tests for non-A/B update_binary_command(). Prior to this CL, it was extracting the updater to a hard-coded location (/tmp/update_binary) that's not available under the test environment. Test: recovery_component_test on angler and marlin respectively. Test: Sideload OTA packages on angler and marlin respectively. Change-Id: I78b9cc211d90c0a16a84e94e339b65759300e2a8
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/install.cpp b/install.cpp
index 689f4a0c..a1f2e4fb 100644
--- a/install.cpp
+++ b/install.cpp
@@ -51,6 +51,7 @@
51#include "error_code.h" 51#include "error_code.h"
52#include "otautil/SysUtil.h" 52#include "otautil/SysUtil.h"
53#include "otautil/ThermalUtil.h" 53#include "otautil/ThermalUtil.h"
54#include "private/install.h"
54#include "roots.h" 55#include "roots.h"
55#include "ui.h" 56#include "ui.h"
56#include "verifier.h" 57#include "verifier.h"
@@ -125,12 +126,6 @@ static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::stri
125 } 126 }
126} 127}
127 128
128// Extract the update binary from the open zip archive |zip| located at |path| and store into |cmd|
129// the command line that should be called. The |status_fd| is the file descriptor the child process
130// should use to report back the progress of the update.
131int update_binary_command(const std::string& path, ZipArchiveHandle zip, int retry_count,
132 int status_fd, std::vector<std::string>* cmd);
133
134#ifdef AB_OTA_UPDATER 129#ifdef AB_OTA_UPDATER
135 130
136// Parses the metadata of the OTA package in |zip| and checks whether we are 131// Parses the metadata of the OTA package in |zip| and checks whether we are
@@ -211,8 +206,9 @@ static int check_newer_ab_build(ZipArchiveHandle zip) {
211 return 0; 206 return 0;
212} 207}
213 208
214int update_binary_command(const std::string& path, ZipArchiveHandle zip, int /* retry_count */, 209int update_binary_command(const std::string& package, ZipArchiveHandle zip,
215 int status_fd, std::vector<std::string>* cmd) { 210 const std::string& binary_path, int /* retry_count */, int status_fd,
211 std::vector<std::string>* cmd) {
216 CHECK(cmd != nullptr); 212 CHECK(cmd != nullptr);
217 int ret = check_newer_ab_build(zip); 213 int ret = check_newer_ab_build(zip);
218 if (ret != 0) { 214 if (ret != 0) {
@@ -246,8 +242,8 @@ int update_binary_command(const std::string& path, ZipArchiveHandle zip, int /*
246 } 242 }
247 long payload_offset = payload_entry.offset; 243 long payload_offset = payload_entry.offset;
248 *cmd = { 244 *cmd = {
249 "/sbin/update_engine_sideload", 245 binary_path,
250 "--payload=file://" + path, 246 "--payload=file://" + package,
251 android::base::StringPrintf("--offset=%ld", payload_offset), 247 android::base::StringPrintf("--offset=%ld", payload_offset),
252 "--headers=" + std::string(payload_properties.begin(), payload_properties.end()), 248 "--headers=" + std::string(payload_properties.begin(), payload_properties.end()),
253 android::base::StringPrintf("--status_fd=%d", status_fd), 249 android::base::StringPrintf("--status_fd=%d", status_fd),
@@ -257,8 +253,9 @@ int update_binary_command(const std::string& path, ZipArchiveHandle zip, int /*
257 253
258#else // !AB_OTA_UPDATER 254#else // !AB_OTA_UPDATER
259 255
260int update_binary_command(const std::string& path, ZipArchiveHandle zip, int retry_count, 256int update_binary_command(const std::string& package, ZipArchiveHandle zip,
261 int status_fd, std::vector<std::string>* cmd) { 257 const std::string& binary_path, int retry_count, int status_fd,
258 std::vector<std::string>* cmd) {
262 CHECK(cmd != nullptr); 259 CHECK(cmd != nullptr);
263 260
264 // On traditional updates we extract the update binary from the package. 261 // On traditional updates we extract the update binary from the package.
@@ -270,11 +267,10 @@ int update_binary_command(const std::string& path, ZipArchiveHandle zip, int ret
270 return INSTALL_CORRUPT; 267 return INSTALL_CORRUPT;
271 } 268 }
272 269
273 const char* binary = "/tmp/update_binary"; 270 unlink(binary_path.c_str());
274 unlink(binary); 271 int fd = creat(binary_path.c_str(), 0755);
275 int fd = creat(binary, 0755);
276 if (fd == -1) { 272 if (fd == -1) {
277 PLOG(ERROR) << "Failed to create " << binary; 273 PLOG(ERROR) << "Failed to create " << binary_path;
278 return INSTALL_ERROR; 274 return INSTALL_ERROR;
279 } 275 }
280 276
@@ -286,10 +282,10 @@ int update_binary_command(const std::string& path, ZipArchiveHandle zip, int ret
286 } 282 }
287 283
288 *cmd = { 284 *cmd = {
289 binary, 285 binary_path,
290 EXPAND(RECOVERY_API_VERSION), // defined in Android.mk 286 EXPAND(RECOVERY_API_VERSION), // defined in Android.mk
291 std::to_string(status_fd), 287 std::to_string(status_fd),
292 path, 288 package,
293 }; 289 };
294 if (retry_count > 0) { 290 if (retry_count > 0) {
295 cmd->push_back("retry"); 291 cmd->push_back("retry");
@@ -308,7 +304,7 @@ static void log_max_temperature(int* max_temperature) {
308} 304}
309 305
310// If the package contains an update binary, extract it and run it. 306// If the package contains an update binary, extract it and run it.
311static int try_update_binary(const std::string& path, ZipArchiveHandle zip, bool* wipe_cache, 307static int try_update_binary(const std::string& package, ZipArchiveHandle zip, bool* wipe_cache,
312 std::vector<std::string>* log_buffer, int retry_count, 308 std::vector<std::string>* log_buffer, int retry_count,
313 int* max_temperature) { 309 int* max_temperature) {
314 read_source_target_build(zip, log_buffer); 310 read_source_target_build(zip, log_buffer);
@@ -317,7 +313,13 @@ static int try_update_binary(const std::string& path, ZipArchiveHandle zip, bool
317 pipe(pipefd); 313 pipe(pipefd);
318 314
319 std::vector<std::string> args; 315 std::vector<std::string> args;
320 int ret = update_binary_command(path, zip, retry_count, pipefd[1], &args); 316#ifdef AB_OTA_UPDATER
317 int ret = update_binary_command(package, zip, "/sbin/update_engine_sideload", retry_count,
318 pipefd[1], &args);
319#else
320 int ret = update_binary_command(package, zip, "/tmp/update-binary", retry_count, pipefd[1],
321 &args);
322#endif
321 if (ret) { 323 if (ret) {
322 close(pipefd[0]); 324 close(pipefd[0]);
323 close(pipefd[1]); 325 close(pipefd[1]);
@@ -472,7 +474,7 @@ static int try_update_binary(const std::string& path, ZipArchiveHandle zip, bool
472 return INSTALL_RETRY; 474 return INSTALL_RETRY;
473 } 475 }
474 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { 476 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
475 LOG(ERROR) << "Error in " << path << " (Status " << WEXITSTATUS(status) << ")"; 477 LOG(ERROR) << "Error in " << package << " (Status " << WEXITSTATUS(status) << ")";
476 return INSTALL_ERROR; 478 return INSTALL_ERROR;
477 } 479 }
478 480