aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-05-01 14:23:17 -0500
committerTao Bao2017-05-01 14:31:48 -0500
commit29ee69bf27cc7ad7ef7e604684110b3f562ed42d (patch)
treef14f4f41f5e9f7016f5895a3f7e3d25d7fe1abd0 /install.cpp
parent54da1122776f38ae365f61bb0ea190b456b2fa62 (diff)
downloadplatform-bootable-recovery-29ee69bf27cc7ad7ef7e604684110b3f562ed42d.tar.gz
platform-bootable-recovery-29ee69bf27cc7ad7ef7e604684110b3f562ed42d.tar.xz
platform-bootable-recovery-29ee69bf27cc7ad7ef7e604684110b3f562ed42d.zip
recovery: Change install_package() to take std::string.
Also change the parameter type for log_buffer from reference to pointer, so the styles for parameters look consistent. Test: mmma bootable/recovery Test: sideload a package with the new recovery image Change-Id: I8f25580ccf22977624648b3e2181cca44dd67c1b
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp141
1 files changed, 72 insertions, 69 deletions
diff --git a/install.cpp b/install.cpp
index e945d13a..d86f46ca 100644
--- a/install.cpp
+++ b/install.cpp
@@ -100,7 +100,7 @@ bool read_metadata_from_package(ZipArchiveHandle zip, std::string* metadata) {
100} 100}
101 101
102// Read the build.version.incremental of src/tgt from the metadata and log it to last_install. 102// Read the build.version.incremental of src/tgt from the metadata and log it to last_install.
103static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::string>& log_buffer) { 103static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::string>* log_buffer) {
104 std::string metadata; 104 std::string metadata;
105 if (!read_metadata_from_package(zip, &metadata)) { 105 if (!read_metadata_from_package(zip, &metadata)) {
106 return; 106 return;
@@ -114,12 +114,12 @@ static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::stri
114 if (android::base::StartsWith(str, "pre-build-incremental")) { 114 if (android::base::StartsWith(str, "pre-build-incremental")) {
115 int source_build = parse_build_number(str); 115 int source_build = parse_build_number(str);
116 if (source_build != -1) { 116 if (source_build != -1) {
117 log_buffer.push_back(android::base::StringPrintf("source_build: %d", source_build)); 117 log_buffer->push_back(android::base::StringPrintf("source_build: %d", source_build));
118 } 118 }
119 } else if (android::base::StartsWith(str, "post-build-incremental")) { 119 } else if (android::base::StartsWith(str, "post-build-incremental")) {
120 int target_build = parse_build_number(str); 120 int target_build = parse_build_number(str);
121 if (target_build != -1) { 121 if (target_build != -1) {
122 log_buffer.push_back(android::base::StringPrintf("target_build: %d", target_build)); 122 log_buffer->push_back(android::base::StringPrintf("target_build: %d", target_build));
123 } 123 }
124 } 124 }
125 } 125 }
@@ -308,8 +308,8 @@ static void log_max_temperature(int* max_temperature) {
308} 308}
309 309
310// If the package contains an update binary, extract it and run it. 310// If the package contains an update binary, extract it and run it.
311static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_cache, 311static int try_update_binary(const std::string& path, ZipArchiveHandle zip, bool* wipe_cache,
312 std::vector<std::string>& log_buffer, int retry_count, 312 std::vector<std::string>* log_buffer, int retry_count,
313 int* max_temperature) { 313 int* max_temperature) {
314 read_source_target_build(zip, log_buffer); 314 read_source_target_build(zip, log_buffer);
315 315
@@ -452,7 +452,7 @@ static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_
452 } else if (command == "log") { 452 } else if (command == "log") {
453 if (!args.empty()) { 453 if (!args.empty()) {
454 // Save the logging request from updater and write to last_install later. 454 // Save the logging request from updater and write to last_install later.
455 log_buffer.push_back(args); 455 log_buffer->push_back(args);
456 } else { 456 } else {
457 LOG(ERROR) << "invalid \"log\" parameters: " << line; 457 LOG(ERROR) << "invalid \"log\" parameters: " << line;
458 } 458 }
@@ -547,78 +547,81 @@ bool verify_package_compatibility(ZipArchiveHandle package_zip) {
547 return false; 547 return false;
548} 548}
549 549
550static int 550static int really_install_package(const std::string& path, bool* wipe_cache, bool needs_mount,
551really_install_package(const char *path, bool* wipe_cache, bool needs_mount, 551 std::vector<std::string>* log_buffer, int retry_count,
552 std::vector<std::string>& log_buffer, int retry_count, int* max_temperature) 552 int* max_temperature) {
553{ 553 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
554 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); 554 ui->Print("Finding update package...\n");
555 ui->Print("Finding update package...\n"); 555 // Give verification half the progress bar...
556 // Give verification half the progress bar... 556 ui->SetProgressType(RecoveryUI::DETERMINATE);
557 ui->SetProgressType(RecoveryUI::DETERMINATE); 557 ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME);
558 ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME); 558 LOG(INFO) << "Update location: " << path;
559 LOG(INFO) << "Update location: " << path; 559
560 560 // Map the update package into memory.
561 // Map the update package into memory. 561 ui->Print("Opening update package...\n");
562 ui->Print("Opening update package...\n"); 562
563 563 if (needs_mount) {
564 if (path && needs_mount) { 564 if (path[0] == '@') {
565 if (path[0] == '@') { 565 ensure_path_mounted(path.substr(1).c_str());
566 ensure_path_mounted(path+1); 566 } else {
567 } else { 567 ensure_path_mounted(path.c_str());
568 ensure_path_mounted(path);
569 }
570 }
571
572 MemMapping map;
573 if (sysMapFile(path, &map) != 0) {
574 LOG(ERROR) << "failed to map file";
575 return INSTALL_CORRUPT;
576 }
577
578 // Verify package.
579 if (!verify_package(map.addr, map.length)) {
580 log_buffer.push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure));
581 sysReleaseMap(&map);
582 return INSTALL_CORRUPT;
583 } 568 }
569 }
584 570
585 // Try to open the package. 571 MemMapping map;
586 ZipArchiveHandle zip; 572 if (sysMapFile(path.c_str(), &map) != 0) {
587 int err = OpenArchiveFromMemory(map.addr, map.length, path, &zip); 573 LOG(ERROR) << "failed to map file";
588 if (err != 0) { 574 return INSTALL_CORRUPT;
589 LOG(ERROR) << "Can't open " << path << " : " << ErrorCodeString(err); 575 }
590 log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure));
591 576
592 sysReleaseMap(&map); 577 // Verify package.
593 CloseArchive(zip); 578 if (!verify_package(map.addr, map.length)) {
594 return INSTALL_CORRUPT; 579 log_buffer->push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure));
595 } 580 sysReleaseMap(&map);
581 return INSTALL_CORRUPT;
582 }
596 583
597 // Additionally verify the compatibility of the package. 584 // Try to open the package.
598 if (!verify_package_compatibility(zip)) { 585 ZipArchiveHandle zip;
599 log_buffer.push_back(android::base::StringPrintf("error: %d", kPackageCompatibilityFailure)); 586 int err = OpenArchiveFromMemory(map.addr, map.length, path.c_str(), &zip);
600 sysReleaseMap(&map); 587 if (err != 0) {
601 CloseArchive(zip); 588 LOG(ERROR) << "Can't open " << path << " : " << ErrorCodeString(err);
602 return INSTALL_CORRUPT; 589 log_buffer->push_back(android::base::StringPrintf("error: %d", kZipOpenFailure));
603 }
604 590
605 // Verify and install the contents of the package. 591 sysReleaseMap(&map);
606 ui->Print("Installing update...\n"); 592 CloseArchive(zip);
607 if (retry_count > 0) { 593 return INSTALL_CORRUPT;
608 ui->Print("Retry attempt: %d\n", retry_count); 594 }
609 }
610 ui->SetEnableReboot(false);
611 int result = try_update_binary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature);
612 ui->SetEnableReboot(true);
613 ui->Print("\n");
614 595
596 // Additionally verify the compatibility of the package.
597 if (!verify_package_compatibility(zip)) {
598 log_buffer->push_back(android::base::StringPrintf("error: %d", kPackageCompatibilityFailure));
615 sysReleaseMap(&map); 599 sysReleaseMap(&map);
616 CloseArchive(zip); 600 CloseArchive(zip);
617 return result; 601 return INSTALL_CORRUPT;
602 }
603
604 // Verify and install the contents of the package.
605 ui->Print("Installing update...\n");
606 if (retry_count > 0) {
607 ui->Print("Retry attempt: %d\n", retry_count);
608 }
609 ui->SetEnableReboot(false);
610 int result = try_update_binary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature);
611 ui->SetEnableReboot(true);
612 ui->Print("\n");
613
614 sysReleaseMap(&map);
615 CloseArchive(zip);
616 return result;
618} 617}
619 618
620int install_package(const char* path, bool* wipe_cache, const char* install_file, bool needs_mount, 619int install_package(const std::string& path, bool* wipe_cache, const std::string& install_file,
621 int retry_count) { 620 bool needs_mount, int retry_count) {
621 CHECK(!path.empty());
622 CHECK(!install_file.empty());
623 CHECK(wipe_cache != nullptr);
624
622 modified_flash = true; 625 modified_flash = true;
623 auto start = std::chrono::system_clock::now(); 626 auto start = std::chrono::system_clock::now();
624 627
@@ -631,7 +634,7 @@ int install_package(const char* path, bool* wipe_cache, const char* install_file
631 LOG(ERROR) << "failed to set up expected mounts for install; aborting"; 634 LOG(ERROR) << "failed to set up expected mounts for install; aborting";
632 result = INSTALL_ERROR; 635 result = INSTALL_ERROR;
633 } else { 636 } else {
634 result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count, 637 result = really_install_package(path, wipe_cache, needs_mount, &log_buffer, retry_count,
635 &max_temperature); 638 &max_temperature);
636 } 639 }
637 640