aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu2016-10-18 16:13:07 -0500
committerTianjie Xu2016-10-18 16:31:04 -0500
commit8176cf232e9f613a2e500f09461fc3f448267d07 (patch)
tree7bef9898660d13fc74dbe528bc0331950fe19604 /install.cpp
parent430b7ae4699eb3685dcc0f7c736a9aebd76829a8 (diff)
parent6fba98ce645bb00b4fa7f03dd1786566af919d78 (diff)
downloadplatform-bootable-recovery-8176cf232e9f613a2e500f09461fc3f448267d07.tar.gz
platform-bootable-recovery-8176cf232e9f613a2e500f09461fc3f448267d07.tar.xz
platform-bootable-recovery-8176cf232e9f613a2e500f09461fc3f448267d07.zip
resolve merge conflicts of 6fba98c to stage-aosp-master
Change-Id: I2fa8b85109309ec88c1f8d8def593aa65ab885d7
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp79
1 files changed, 43 insertions, 36 deletions
diff --git a/install.cpp b/install.cpp
index 83ddc4b0..fada2de6 100644
--- a/install.cpp
+++ b/install.cpp
@@ -36,14 +36,13 @@
36#include <android-base/stringprintf.h> 36#include <android-base/stringprintf.h>
37#include <android-base/strings.h> 37#include <android-base/strings.h>
38#include <cutils/properties.h> 38#include <cutils/properties.h>
39#include <android-base/logging.h> 39#include <ziparchive/zip_archive.h>
40 40
41#include "common.h" 41#include "common.h"
42#include "error_code.h" 42#include "error_code.h"
43#include "install.h" 43#include "install.h"
44#include "minui/minui.h" 44#include "minui/minui.h"
45#include "minzip/SysUtil.h" 45#include "otautil/SysUtil.h"
46#include "minzip/Zip.h"
47#include "roots.h" 46#include "roots.h"
48#include "ui.h" 47#include "ui.h"
49#include "verifier.h" 48#include "verifier.h"
@@ -78,15 +77,21 @@ static int parse_build_number(const std::string& str) {
78 return -1; 77 return -1;
79} 78}
80 79
81bool read_metadata_from_package(ZipArchive* zip, std::string* meta_data) { 80bool read_metadata_from_package(ZipArchiveHandle zip, std::string* meta_data) {
82 const ZipEntry* meta_entry = mzFindZipEntry(zip, METADATA_PATH); 81 ZipString metadata_path(METADATA_PATH);
83 if (meta_entry == nullptr) { 82 ZipEntry meta_entry;
83 if (meta_data == nullptr) {
84 LOG(ERROR) << "string* meta_data can't be nullptr";
85 return false;
86 }
87 if (FindEntry(zip, metadata_path, &meta_entry) != 0) {
84 LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package"; 88 LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package";
85 return false; 89 return false;
86 } 90 }
87 91
88 meta_data->resize(meta_entry->uncompLen, '\0'); 92 meta_data->resize(meta_entry.uncompressed_length, '\0');
89 if (!mzReadZipEntry(zip, meta_entry, &(*meta_data)[0], meta_entry->uncompLen)) { 93 if (ExtractToMemory(zip, &meta_entry, reinterpret_cast<uint8_t*>(&(*meta_data)[0]),
94 meta_entry.uncompressed_length) != 0) {
90 LOG(ERROR) << "Failed to read metadata in update package"; 95 LOG(ERROR) << "Failed to read metadata in update package";
91 return false; 96 return false;
92 } 97 }
@@ -94,7 +99,7 @@ bool read_metadata_from_package(ZipArchive* zip, std::string* meta_data) {
94} 99}
95 100
96// Read the build.version.incremental of src/tgt from the metadata and log it to last_install. 101// Read the build.version.incremental of src/tgt from the metadata and log it to last_install.
97static void read_source_target_build(ZipArchive* zip, std::vector<std::string>& log_buffer) { 102static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::string>& log_buffer) {
98 std::string meta_data; 103 std::string meta_data;
99 if (!read_metadata_from_package(zip, &meta_data)) { 104 if (!read_metadata_from_package(zip, &meta_data)) {
100 return; 105 return;
@@ -126,7 +131,7 @@ static void read_source_target_build(ZipArchive* zip, std::vector<std::string>&
126// is the file descriptor the child process should use to report back the 131// is the file descriptor the child process should use to report back the
127// progress of the update. 132// progress of the update.
128static int 133static int
129update_binary_command(const char* path, ZipArchive* zip, int retry_count, 134update_binary_command(const char* path, ZipArchiveHandle zip, int retry_count,
130 int status_fd, std::vector<std::string>* cmd); 135 int status_fd, std::vector<std::string>* cmd);
131 136
132#ifdef AB_OTA_UPDATER 137#ifdef AB_OTA_UPDATER
@@ -134,7 +139,7 @@ update_binary_command(const char* path, ZipArchive* zip, int retry_count,
134// Parses the metadata of the OTA package in |zip| and checks whether we are 139// Parses the metadata of the OTA package in |zip| and checks whether we are
135// allowed to accept this A/B package. Downgrading is not allowed unless 140// allowed to accept this A/B package. Downgrading is not allowed unless
136// explicitly enabled in the package and only for incremental packages. 141// explicitly enabled in the package and only for incremental packages.
137static int check_newer_ab_build(ZipArchive* zip) 142static int check_newer_ab_build(ZipArchiveHandle zip)
138{ 143{
139 std::string metadata_str; 144 std::string metadata_str;
140 if (!read_metadata_from_package(zip, &metadata_str)) { 145 if (!read_metadata_from_package(zip, &metadata_str)) {
@@ -212,7 +217,7 @@ static int check_newer_ab_build(ZipArchive* zip)
212} 217}
213 218
214static int 219static int
215update_binary_command(const char* path, ZipArchive* zip, int retry_count, 220update_binary_command(const char* path, ZipArchiveHandle zip, int retry_count,
216 int status_fd, std::vector<std::string>* cmd) 221 int status_fd, std::vector<std::string>* cmd)
217{ 222{
218 int ret = check_newer_ab_build(zip); 223 int ret = check_newer_ab_build(zip);
@@ -222,26 +227,27 @@ update_binary_command(const char* path, ZipArchive* zip, int retry_count,
222 227
223 // For A/B updates we extract the payload properties to a buffer and obtain 228 // For A/B updates we extract the payload properties to a buffer and obtain
224 // the RAW payload offset in the zip file. 229 // the RAW payload offset in the zip file.
225 const ZipEntry* properties_entry = 230 ZipString property_name(AB_OTA_PAYLOAD_PROPERTIES);
226 mzFindZipEntry(zip, AB_OTA_PAYLOAD_PROPERTIES); 231 ZipEntry properties_entry;
227 if (!properties_entry) { 232 if (FindEntry(zip, property_name, &properties_entry) != 0) {
228 LOG(ERROR) << "Can't find " << AB_OTA_PAYLOAD_PROPERTIES; 233 LOG(ERROR) << "Can't find " << AB_OTA_PAYLOAD_PROPERTIES;
229 return INSTALL_CORRUPT; 234 return INSTALL_CORRUPT;
230 } 235 }
231 std::vector<unsigned char> payload_properties( 236 std::vector<uint8_t> payload_properties(
232 mzGetZipEntryUncompLen(properties_entry)); 237 properties_entry.uncompressed_length);
233 if (!mzExtractZipEntryToBuffer(zip, properties_entry, 238 if (ExtractToMemory(zip, &properties_entry, payload_properties.data(),
234 payload_properties.data())) { 239 properties_entry.uncompressed_length) != 0) {
235 LOG(ERROR) << "Can't extract " << AB_OTA_PAYLOAD_PROPERTIES; 240 LOG(ERROR) << "Can't extract " << AB_OTA_PAYLOAD_PROPERTIES;
236 return INSTALL_CORRUPT; 241 return INSTALL_CORRUPT;
237 } 242 }
238 243
239 const ZipEntry* payload_entry = mzFindZipEntry(zip, AB_OTA_PAYLOAD); 244 ZipString payload_name(AB_OTA_PAYLOAD);
240 if (!payload_entry) { 245 ZipEntry payload_entry;
246 if (FindEntry(zip, payload_name, &payload_entry) != 0) {
241 LOG(ERROR) << "Can't find " << AB_OTA_PAYLOAD; 247 LOG(ERROR) << "Can't find " << AB_OTA_PAYLOAD;
242 return INSTALL_CORRUPT; 248 return INSTALL_CORRUPT;
243 } 249 }
244 long payload_offset = mzGetZipEntryOffset(payload_entry); 250 long payload_offset = payload_entry.offset;
245 *cmd = { 251 *cmd = {
246 "/sbin/update_engine_sideload", 252 "/sbin/update_engine_sideload",
247 android::base::StringPrintf("--payload=file://%s", path), 253 android::base::StringPrintf("--payload=file://%s", path),
@@ -256,13 +262,13 @@ update_binary_command(const char* path, ZipArchive* zip, int retry_count,
256#else // !AB_OTA_UPDATER 262#else // !AB_OTA_UPDATER
257 263
258static int 264static int
259update_binary_command(const char* path, ZipArchive* zip, int retry_count, 265update_binary_command(const char* path, ZipArchiveHandle zip, int retry_count,
260 int status_fd, std::vector<std::string>* cmd) 266 int status_fd, std::vector<std::string>* cmd)
261{ 267{
262 // On traditional updates we extract the update binary from the package. 268 // On traditional updates we extract the update binary from the package.
263 const ZipEntry* binary_entry = 269 ZipString binary_name(ASSUMED_UPDATE_BINARY_NAME);
264 mzFindZipEntry(zip, ASSUMED_UPDATE_BINARY_NAME); 270 ZipEntry binary_entry;
265 if (binary_entry == NULL) { 271 if (FindEntry(zip, binary_name, &binary_entry) != 0) {
266 return INSTALL_CORRUPT; 272 return INSTALL_CORRUPT;
267 } 273 }
268 274
@@ -273,11 +279,12 @@ update_binary_command(const char* path, ZipArchive* zip, int retry_count,
273 PLOG(ERROR) << "Can't make " << binary; 279 PLOG(ERROR) << "Can't make " << binary;
274 return INSTALL_ERROR; 280 return INSTALL_ERROR;
275 } 281 }
276 bool ok = mzExtractZipEntryToFile(zip, binary_entry, fd); 282 int error = ExtractEntryToFile(zip, &binary_entry, fd);
277 close(fd); 283 close(fd);
278 284
279 if (!ok) { 285 if (error != 0) {
280 LOG(ERROR) << "Can't copy " << ASSUMED_UPDATE_BINARY_NAME; 286 LOG(ERROR) << "Can't copy " << ASSUMED_UPDATE_BINARY_NAME
287 << " : " << ErrorCodeString(error);
281 return INSTALL_ERROR; 288 return INSTALL_ERROR;
282 } 289 }
283 290
@@ -295,7 +302,7 @@ update_binary_command(const char* path, ZipArchive* zip, int retry_count,
295 302
296// If the package contains an update binary, extract it and run it. 303// If the package contains an update binary, extract it and run it.
297static int 304static int
298try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, 305try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_cache,
299 std::vector<std::string>& log_buffer, int retry_count) 306 std::vector<std::string>& log_buffer, int retry_count)
300{ 307{
301 read_source_target_build(zip, log_buffer); 308 read_source_target_build(zip, log_buffer);
@@ -305,7 +312,6 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache,
305 312
306 std::vector<std::string> args; 313 std::vector<std::string> args;
307 int ret = update_binary_command(path, zip, retry_count, pipefd[1], &args); 314 int ret = update_binary_command(path, zip, retry_count, pipefd[1], &args);
308 mzCloseZipArchive(zip);
309 if (ret) { 315 if (ret) {
310 close(pipefd[0]); 316 close(pipefd[0]);
311 close(pipefd[1]); 317 close(pipefd[1]);
@@ -485,13 +491,14 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
485 } 491 }
486 492
487 // Try to open the package. 493 // Try to open the package.
488 ZipArchive zip; 494 ZipArchiveHandle zip;
489 int err = mzOpenZipArchive(map.addr, map.length, &zip); 495 int err = OpenArchiveFromMemory(map.addr, map.length, path, &zip);
490 if (err != 0) { 496 if (err != 0) {
491 LOG(ERROR) << "Can't open " << path; 497 LOG(ERROR) << "Can't open " << path << " : " << ErrorCodeString(err);
492 log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure)); 498 log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure));
493 499
494 sysReleaseMap(&map); 500 sysReleaseMap(&map);
501 CloseArchive(zip);
495 return INSTALL_CORRUPT; 502 return INSTALL_CORRUPT;
496 } 503 }
497 504
@@ -501,12 +508,12 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
501 ui->Print("Retry attempt: %d\n", retry_count); 508 ui->Print("Retry attempt: %d\n", retry_count);
502 } 509 }
503 ui->SetEnableReboot(false); 510 ui->SetEnableReboot(false);
504 int result = try_update_binary(path, &zip, wipe_cache, log_buffer, retry_count); 511 int result = try_update_binary(path, zip, wipe_cache, log_buffer, retry_count);
505 ui->SetEnableReboot(true); 512 ui->SetEnableReboot(true);
506 ui->Print("\n"); 513 ui->Print("\n");
507 514
508 sysReleaseMap(&map); 515 sysReleaseMap(&map);
509 516 CloseArchive(zip);
510 return result; 517 return result;
511} 518}
512 519