Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2fdfcf17 authored by Tao Bao's avatar Tao Bao Committed by android-build-merger
Browse files

Merge "recovery: Change install_package() to take std::string." am: ba365180 am: c0c4ae15

am: a0fb95a3

Change-Id: Ieb03e2d9ecb228305274849c1f2a92b5b9842e98
parents fb26613a a0fb95a3
Loading
Loading
Loading
Loading
+72 −69
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ bool read_metadata_from_package(ZipArchiveHandle zip, std::string* metadata) {
}

// Read the build.version.incremental of src/tgt from the metadata and log it to last_install.
static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::string>& log_buffer) {
static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::string>* log_buffer) {
  std::string metadata;
  if (!read_metadata_from_package(zip, &metadata)) {
    return;
@@ -114,12 +114,12 @@ static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::stri
    if (android::base::StartsWith(str, "pre-build-incremental")) {
      int source_build = parse_build_number(str);
      if (source_build != -1) {
        log_buffer.push_back(android::base::StringPrintf("source_build: %d", source_build));
        log_buffer->push_back(android::base::StringPrintf("source_build: %d", source_build));
      }
    } else if (android::base::StartsWith(str, "post-build-incremental")) {
      int target_build = parse_build_number(str);
      if (target_build != -1) {
        log_buffer.push_back(android::base::StringPrintf("target_build: %d", target_build));
        log_buffer->push_back(android::base::StringPrintf("target_build: %d", target_build));
      }
    }
  }
@@ -308,8 +308,8 @@ static void log_max_temperature(int* max_temperature) {
}

// If the package contains an update binary, extract it and run it.
static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_cache,
                             std::vector<std::string>& log_buffer, int retry_count,
static int try_update_binary(const std::string& path, ZipArchiveHandle zip, bool* wipe_cache,
                             std::vector<std::string>* log_buffer, int retry_count,
                             int* max_temperature) {
  read_source_target_build(zip, log_buffer);

@@ -452,7 +452,7 @@ static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_
    } else if (command == "log") {
      if (!args.empty()) {
        // Save the logging request from updater and write to last_install later.
        log_buffer.push_back(args);
        log_buffer->push_back(args);
      } else {
        LOG(ERROR) << "invalid \"log\" parameters: " << line;
      }
@@ -547,10 +547,9 @@ bool verify_package_compatibility(ZipArchiveHandle package_zip) {
  return false;
}

static int
really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
                       std::vector<std::string>& log_buffer, int retry_count, int* max_temperature)
{
static int really_install_package(const std::string& path, bool* wipe_cache, bool needs_mount,
                                  std::vector<std::string>* log_buffer, int retry_count,
                                  int* max_temperature) {
  ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
  ui->Print("Finding update package...\n");
  // Give verification half the progress bar...
@@ -561,33 +560,33 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
  // Map the update package into memory.
  ui->Print("Opening update package...\n");

    if (path && needs_mount) {
  if (needs_mount) {
    if (path[0] == '@') {
            ensure_path_mounted(path+1);
      ensure_path_mounted(path.substr(1).c_str());
    } else {
            ensure_path_mounted(path);
      ensure_path_mounted(path.c_str());
    }
  }

  MemMapping map;
    if (sysMapFile(path, &map) != 0) {
  if (sysMapFile(path.c_str(), &map) != 0) {
    LOG(ERROR) << "failed to map file";
    return INSTALL_CORRUPT;
  }

  // Verify package.
  if (!verify_package(map.addr, map.length)) {
        log_buffer.push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure));
    log_buffer->push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure));
    sysReleaseMap(&map);
    return INSTALL_CORRUPT;
  }

  // Try to open the package.
  ZipArchiveHandle zip;
    int err = OpenArchiveFromMemory(map.addr, map.length, path, &zip);
  int err = OpenArchiveFromMemory(map.addr, map.length, path.c_str(), &zip);
  if (err != 0) {
    LOG(ERROR) << "Can't open " << path << " : " << ErrorCodeString(err);
        log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure));
    log_buffer->push_back(android::base::StringPrintf("error: %d", kZipOpenFailure));

    sysReleaseMap(&map);
    CloseArchive(zip);
@@ -596,7 +595,7 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,

  // Additionally verify the compatibility of the package.
  if (!verify_package_compatibility(zip)) {
      log_buffer.push_back(android::base::StringPrintf("error: %d", kPackageCompatibilityFailure));
    log_buffer->push_back(android::base::StringPrintf("error: %d", kPackageCompatibilityFailure));
    sysReleaseMap(&map);
    CloseArchive(zip);
    return INSTALL_CORRUPT;
@@ -617,8 +616,12 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
  return result;
}

int install_package(const char* path, bool* wipe_cache, const char* install_file, bool needs_mount,
                    int retry_count) {
int install_package(const std::string& path, bool* wipe_cache, const std::string& install_file,
                    bool needs_mount, int retry_count) {
  CHECK(!path.empty());
  CHECK(!install_file.empty());
  CHECK(wipe_cache != nullptr);

  modified_flash = true;
  auto start = std::chrono::system_clock::now();

@@ -631,7 +634,7 @@ int install_package(const char* path, bool* wipe_cache, const char* install_file
    LOG(ERROR) << "failed to set up expected mounts for install; aborting";
    result = INSTALL_ERROR;
  } else {
    result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count,
    result = really_install_package(path, wipe_cache, needs_mount, &log_buffer, retry_count,
                                    &max_temperature);
  }

+5 −6
Original line number Diff line number Diff line
@@ -23,10 +23,9 @@
enum { INSTALL_SUCCESS, INSTALL_ERROR, INSTALL_CORRUPT, INSTALL_NONE, INSTALL_SKIPPED,
        INSTALL_RETRY };

// Install the package specified by root_path.  If INSTALL_SUCCESS is
// returned and *wipe_cache is true on exit, caller should wipe the
// cache partition.
int install_package(const char* root_path, bool* wipe_cache, const char* install_file,
// Installs the given update package. If INSTALL_SUCCESS is returned and *wipe_cache is true on
// exit, caller should wipe the cache partition.
int install_package(const std::string& package, bool* wipe_cache, const std::string& install_file,
                    bool needs_mount, int retry_count);

// Verify the package by ota keys. Return true if the package is verified successfully,
@@ -35,9 +34,9 @@ bool verify_package(const unsigned char* package_data, size_t package_size);

// Read meta data file of the package, write its content in the string pointed by meta_data.
// Return true if succeed, otherwise return false.
bool read_metadata_from_package(ZipArchiveHandle zip, std::string* meta_data);
bool read_metadata_from_package(ZipArchiveHandle zip, std::string* metadata);

// Verifes the compatibility info in a Treble-compatible package. Returns true directly if the
// Verifies the compatibility info in a Treble-compatible package. Returns true directly if the
// entry doesn't exist.
bool verify_package_compatibility(ZipArchiveHandle package_zip);