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

Commit adc99efd authored by Tao Bao's avatar Tao Bao
Browse files

install: Install functions return InstallResult.

Test: `atest recovery_unit_test recovery_component_test`
Test: Sideload a package on taimen.
Change-Id: I2d42f55a89931ee495ea5c5d9e6b5ee1058e8e52
parent 36c7276c
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ static bool WriteStatusToFd(MinadbdCommandStatus status, int fd) {

// Installs the package from FUSE. Returns the installation result and whether it should continue
// waiting for new commands.
static auto AdbInstallPackageHandler(RecoveryUI* ui, int* result) {
static auto AdbInstallPackageHandler(RecoveryUI* ui, InstallResult* result) {
  // How long (in seconds) we wait for the package path to be ready. It doesn't need to be too long
  // because the minadbd service has already issued an install command. FUSE_SIDELOAD_HOST_PATHNAME
  // will start to exist once the host connects and starts serving a package. Poll for its
@@ -110,7 +110,7 @@ static auto AdbInstallPackageHandler(RecoveryUI* ui, int* result) {
        break;
      }
    }
    *result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, false, false, 0, ui);
    *result = InstallPackage(FUSE_SIDELOAD_HOST_PATHNAME, false, false, 0, ui);
    break;
  }

@@ -120,7 +120,7 @@ static auto AdbInstallPackageHandler(RecoveryUI* ui, int* result) {
  return std::make_pair(*result == INSTALL_SUCCESS, should_continue);
}

static auto AdbRebootHandler(MinadbdCommand command, int* result,
static auto AdbRebootHandler(MinadbdCommand command, InstallResult* result,
                             Device::BuiltinAction* reboot_action) {
  // Use Device::REBOOT_{FASTBOOT,RECOVERY,RESCUE}, instead of the ones with ENTER_. This allows
  // rebooting back into fastboot/recovery/rescue mode through bootloader, which may use a newly
@@ -331,7 +331,7 @@ static void CreateMinadbdServiceAndExecuteCommands(
  signal(SIGPIPE, SIG_DFL);
}

int ApplyFromAdb(Device* device, bool rescue_mode, Device::BuiltinAction* reboot_action) {
InstallResult ApplyFromAdb(Device* device, bool rescue_mode, Device::BuiltinAction* reboot_action) {
  // Save the usb state to restore after the sideload operation.
  std::string usb_state = android::base::GetProperty("sys.usb.state", "none");
  // Clean up state and stop adbd.
@@ -342,7 +342,7 @@ int ApplyFromAdb(Device* device, bool rescue_mode, Device::BuiltinAction* reboot

  RecoveryUI* ui = device->GetUI();

  int install_result = INSTALL_ERROR;
  InstallResult install_result = INSTALL_ERROR;
  std::map<MinadbdCommand, CommandFunction> command_map{
    { MinadbdCommand::kInstall, std::bind(&AdbInstallPackageHandler, ui, &install_result) },
    { MinadbdCommand::kRebootAndroid, std::bind(&AdbRebootHandler, MinadbdCommand::kRebootAndroid,
+4 −5
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ static bool StartSdcardFuse(const std::string& path) {
  return run_fuse_sideload(std::move(file_data_reader)) == 0;
}

int ApplyFromSdcard(Device* device, RecoveryUI* ui) {
InstallResult ApplyFromSdcard(Device* device, RecoveryUI* ui) {
  if (ensure_path_mounted(SDCARD_ROOT) != 0) {
    LOG(ERROR) << "\n-- Couldn't mount " << SDCARD_ROOT << ".\n";
    return INSTALL_ERROR;
@@ -159,9 +159,8 @@ int ApplyFromSdcard(Device* device, RecoveryUI* ui) {
    _exit(status ? EXIT_SUCCESS : EXIT_FAILURE);
  }

  // FUSE_SIDELOAD_HOST_PATHNAME will start to exist once the fuse in child
  // process is ready.
  int result = INSTALL_ERROR;
  // FUSE_SIDELOAD_HOST_PATHNAME will start to exist once the fuse in child process is ready.
  InstallResult result = INSTALL_ERROR;
  int status;
  bool waited = false;
  for (int i = 0; i < SDCARD_INSTALL_TIMEOUT; ++i) {
@@ -184,7 +183,7 @@ int ApplyFromSdcard(Device* device, RecoveryUI* ui) {
      }
    }

    result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, false, false, 0 /*retry_count*/, ui);
    result = InstallPackage(FUSE_SIDELOAD_HOST_PATHNAME, false, false, 0 /* retry_count */, ui);
    break;
  }

+6 −5
Original line number Diff line number Diff line
@@ -16,9 +16,10 @@

#pragma once

#include <recovery_ui/device.h>
#include "install/install.h"
#include "recovery_ui/device.h"

// Applies a package via `adb sideload` or `adb rescue`. Returns the install result (in `enum
// InstallResult`). When a reboot has been requested, INSTALL_REBOOT will be the return value, with
// the reboot target set in reboot_action.
int ApplyFromAdb(Device* device, bool rescue_mode, Device::BuiltinAction* reboot_action);
// Applies a package via `adb sideload` or `adb rescue`. Returns the install result. When a reboot
// has been requested, INSTALL_REBOOT will be the return value, with the reboot target set in
// reboot_action.
InstallResult ApplyFromAdb(Device* device, bool rescue_mode, Device::BuiltinAction* reboot_action);
+2 −1
Original line number Diff line number Diff line
@@ -16,7 +16,8 @@

#pragma once

#include "install/install.h"
#include "recovery_ui/device.h"
#include "recovery_ui/ui.h"

int ApplyFromSdcard(Device* device, RecoveryUI* ui);
InstallResult ApplyFromSdcard(Device* device, RecoveryUI* ui);
+2 −2
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ enum class OtaType {
// Installs the given update package. This function should also wipe the cache partition after a
// successful installation if |should_wipe_cache| is true or an updater command asks to wipe the
// cache.
int install_package(const std::string& package, bool should_wipe_cache, bool needs_mount,
InstallResult InstallPackage(const std::string& package, bool should_wipe_cache, bool needs_mount,
                             int retry_count, RecoveryUI* ui);

// Verifies the package by ota keys. Returns true if the package is verified successfully,
Loading