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

Commit f8a5ea18 authored by Sumit Pundir's avatar Sumit Pundir
Browse files
parent 6f1bf731
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ void sideload_wait(bool cancel) {
  pthread_join(sideload_thread, nullptr);
}

int sideload_install(bool* wipe_cache, const char* install_file, bool verify) {
int sideload_install(bool* wipe_cache, const char* install_file, bool verify, bool allow_ab_downgrade) {
  int result = INSTALL_ERROR;
  if (sideload_started) {
    modified_flash = true;
@@ -154,7 +154,7 @@ int sideload_install(bool* wipe_cache, const char* install_file, bool verify) {
    set_perf_mode(true);

    result =
        install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, install_file, false, 0, verify);
        install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, install_file, false, 0, verify, allow_ab_downgrade);

    set_perf_mode(false);
  }
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@

void sideload_start();
void sideload_wait(bool cancel);
int sideload_install(bool* wipe_cache, const char* install_file, bool verify);
int sideload_install(bool* wipe_cache, const char* install_file, bool verify, bool allow_ab_downgrade);
void sideload_stop();

#endif
+29 −27
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::stri
// Parses the metadata of the OTA package in |zip| and checks whether we are
// allowed to accept this A/B package. Downgrading is not allowed unless
// explicitly enabled in the package and only for incremental packages.
static int check_newer_ab_build(ZipArchiveHandle zip) {
static int check_newer_ab_build(ZipArchiveHandle zip, bool allow_ab_downgrade) {
  std::string metadata_str;
  if (!read_metadata_from_package(zip, &metadata_str)) {
    return INSTALL_CORRUPT;
@@ -191,6 +191,7 @@ static int check_newer_ab_build(ZipArchiveHandle zip) {
  }

  // Check for downgrade version.
  if (!allow_ab_downgrade) {
    int64_t build_timestamp =
        android::base::GetIntProperty("ro.build.date.utc", std::numeric_limits<int64_t>::max());
    int64_t pkg_post_timestamp = 0;
@@ -204,11 +205,12 @@ static int check_newer_ab_build(ZipArchiveHandle zip) {
                      "newer than timestamp "
                   << build_timestamp << " but package has timestamp " << pkg_post_timestamp
                   << " and downgrade not allowed.";
      return INSTALL_ERROR;
        return INSTALL_DOWNGRADE;
      }
      if (pkg_pre_build_fingerprint.empty()) {
        LOG(ERROR) << "Downgrade package must have a pre-build version set, not allowed.";
      return INSTALL_ERROR;
        return INSTALL_DOWNGRADE;
      }
    }
  }

@@ -217,9 +219,9 @@ static int check_newer_ab_build(ZipArchiveHandle zip) {

int update_binary_command_ab(const std::string& package, ZipArchiveHandle zip,
                             const std::string& binary_path, int /* retry_count */, int status_fd,
                             std::vector<std::string>* cmd) {
                             std::vector<std::string>* cmd, bool allow_ab_downgrade) {
  CHECK(cmd != nullptr);
  int ret = check_newer_ab_build(zip);
  int ret = check_newer_ab_build(zip, allow_ab_downgrade);
  if (ret != 0) {
    return ret;
  }
@@ -318,7 +320,7 @@ static void sig_bus(int) {
// If the package contains an update binary, extract it and run it.
static int try_update_binary(const std::string& package, ZipArchiveHandle zip, bool* wipe_cache,
                             std::vector<std::string>* log_buffer, int retry_count,
                             int* max_temperature) {
                             int* max_temperature, bool allow_ab_downgrade) {
  read_source_target_build(zip, log_buffer);

  int ret;
@@ -342,7 +344,7 @@ static int try_update_binary(const std::string& package, ZipArchiveHandle zip, b

  if (ab_ota) {
    ret = update_binary_command_ab(package, zip, "/sbin/update_engine_sideload", retry_count,
                                   pipefd[1], &args);
                                   pipefd[1], &args, allow_ab_downgrade);
  } else {
    ret = update_binary_command_legacy(package, zip, "/tmp/update-binary", retry_count, pipefd[1],
                                       &args);
@@ -582,7 +584,7 @@ bool verify_package_compatibility(ZipArchiveHandle package_zip) {

static int really_install_package(std::string path, bool* wipe_cache, bool needs_mount,
                                  std::vector<std::string>* log_buffer, int retry_count,
                                  bool verify, int* max_temperature) {
                                  bool verify, int* max_temperature, bool allow_ab_downgrade) {
  ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
  ui->Print("Finding update package...\n");
  // Give verification half the progress bar...
@@ -657,7 +659,7 @@ static int really_install_package(std::string path, bool* wipe_cache, bool needs
    ui->Print("Retry attempt: %d\n", retry_count);
  }
  ui->SetEnableReboot(false);
  int result = try_update_binary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature);
  int result = try_update_binary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature, allow_ab_downgrade);
  ui->SetEnableReboot(true);
  ui->Print("\n");

@@ -667,7 +669,7 @@ static int really_install_package(std::string path, bool* wipe_cache, bool needs
}

int install_package(const std::string& path, bool* wipe_cache, const std::string& install_file,
                    bool needs_mount, int retry_count, bool verify) {
                    bool needs_mount, int retry_count, bool verify, bool allow_ab_downgrade) {
  CHECK(!path.empty());
  CHECK(!install_file.empty());
  CHECK(wipe_cache != nullptr);
@@ -685,7 +687,7 @@ int install_package(const std::string& path, bool* wipe_cache, const std::string
    result = INSTALL_ERROR;
  } else {
    result = really_install_package(path, wipe_cache, needs_mount, &log_buffer, retry_count, verify,
                                    &max_temperature);
                                    &max_temperature, allow_ab_downgrade);
  }

  // Measure the time spent to apply OTA update in seconds.
+3 −2
Original line number Diff line number Diff line
@@ -27,13 +27,14 @@ enum {
  INSTALL_NONE,
  INSTALL_SKIPPED,
  INSTALL_RETRY,
  INSTALL_UNVERIFIED
  INSTALL_UNVERIFIED,
  INSTALL_DOWNGRADE
};

// 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, bool verify);
                    bool needs_mount, int retry_count, bool verify, bool allow_ab_downgrade);

// Verify the package by ota keys. Return true if the package is verified successfully,
// otherwise return false.
+27 −7
Original line number Diff line number Diff line
@@ -906,6 +906,16 @@ static bool ask_to_continue_unverified_install(Device* device) {
#endif
}

bool ask_to_continue_downgrade(Device* device) {
#ifdef RELEASE_BUILD
    (void) device; // silence unused parameter warning
    return false;
#else
    ui->SetProgressType(RecoveryUI::EMPTY);
    return yes_no(device, "This package will downgrade your system", "Install anyway?");
#endif
}

static bool ask_to_wipe_data(Device* device) {
    return yes_no(device, "Wipe all user data?", "  THIS CAN NOT BE UNDONE!");
}
@@ -1253,10 +1263,14 @@ static int apply_from_storage(Device* device, VolumeInfo& vi, bool* wipe_cache)

  ui->UpdateScreenOnPrint(true);
  status = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, TEMPORARY_INSTALL_FILE, false,
                           0 /*retry_count*/, true /*verify*/);
                           0 /*retry_count*/, true /*verify*/, false);
  if (status == INSTALL_UNVERIFIED && ask_to_continue_unverified_install(device)) {
    status = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, TEMPORARY_INSTALL_FILE, false,
                             0 /*retry_count*/, false /*verify*/);
                             0 /*retry_count*/, false /*verify*/, false);
  }
  if (status == INSTALL_DOWNGRADE && ask_to_continue_downgrade(device)) {
    status = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, TEMPORARY_INSTALL_FILE, false,
                             0 /*retry_count*/, false /*verify*/, true);
  }
  ui->UpdateScreenOnPrint(false);

@@ -1311,9 +1325,12 @@ refresh:
    if (item == Device::kRefresh) {
      sideload_wait(false);
      ui->UpdateScreenOnPrint(true);
      status = sideload_install(wipe_cache, TEMPORARY_INSTALL_FILE, true);
      status = sideload_install(wipe_cache, TEMPORARY_INSTALL_FILE, true, false);
      if (status == INSTALL_UNVERIFIED && ask_to_continue_unverified_install(device)) {
        status = sideload_install(wipe_cache, TEMPORARY_INSTALL_FILE, false);
        status = sideload_install(wipe_cache, TEMPORARY_INSTALL_FILE, false, false);
      }
      if (status == INSTALL_DOWNGRADE && ask_to_continue_downgrade(device)) {
	status = sideload_install(wipe_cache, TEMPORARY_INSTALL_FILE, false, true);
      }
      ui->UpdateScreenOnPrint(false);
    } else {
@@ -1889,7 +1906,7 @@ int main(int argc, char **argv) {
      }

      status = install_package(update_package, &should_wipe_cache, TEMPORARY_INSTALL_FILE, true,
                               retry_count, true);
                               retry_count, true, false);
      if (status == INSTALL_SUCCESS && should_wipe_cache) {
        wipe_cache(false, device);
      }
@@ -1953,9 +1970,12 @@ int main(int argc, char **argv) {
    sideload_start();
    sideload_wait(false);
    ui->UpdateScreenOnPrint(true);
    status = sideload_install(&should_wipe_cache, TEMPORARY_INSTALL_FILE, true);
    status = sideload_install(&should_wipe_cache, TEMPORARY_INSTALL_FILE, true, false);
    if (status == INSTALL_UNVERIFIED && ask_to_continue_unverified_install(device)) {
      status = sideload_install(&should_wipe_cache, TEMPORARY_INSTALL_FILE, false);
      status = sideload_install(&should_wipe_cache, TEMPORARY_INSTALL_FILE, false, false);
    }
    if (status == INSTALL_DOWNGRADE && ask_to_continue_downgrade(device)) {
      status = sideload_install(&should_wipe_cache, TEMPORARY_INSTALL_FILE, false, true);
    }
    ui->UpdateScreenOnPrint(false);
    sideload_stop();