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

Commit 666b847b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Convert fastboot/libsnapshot to new BootControl client" am: c29f0745

parents 906ebf77 c29f0745
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -164,6 +164,8 @@ cc_binary {
    shared_libs: [
        "android.hardware.boot@1.0",
        "android.hardware.boot@1.1",
        "android.hardware.boot-V1-ndk",
        "libboot_control_client",
        "android.hardware.fastboot@1.1",
        "android.hardware.health@2.0",
        "android.hardware.health-V1-ndk",
+14 −13
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include <storage_literals/storage_literals.h>
#include <uuid/uuid.h>

#include "BootControlClient.h"
#include "constants.h"
#include "fastboot_device.h"
#include "flashing.h"
@@ -52,15 +53,12 @@ static constexpr bool kEnableFetch = false;
#endif

using android::fs_mgr::MetadataBuilder;
using android::hal::CommandResult;
using ::android::hardware::hidl_string;
using ::android::hardware::boot::V1_0::BoolResult;
using ::android::hardware::boot::V1_0::CommandResult;
using ::android::hardware::boot::V1_0::Slot;
using ::android::hardware::boot::V1_1::MergeStatus;
using ::android::hardware::fastboot::V1_0::Result;
using ::android::hardware::fastboot::V1_0::Status;
using android::snapshot::SnapshotManager;
using IBootControl1_1 = ::android::hardware::boot::V1_1::IBootControl;
using MergeStatus = android::hal::BootControlClient::MergeStatus;

using namespace android::storage_literals;

@@ -317,7 +315,7 @@ bool SetActiveHandler(FastbootDevice* device, const std::vector<std::string>& ar
                                   "set_active command is not allowed on locked devices");
    }

    Slot slot;
    int32_t slot = 0;
    if (!GetSlotNumber(args[1], &slot)) {
        // Slot suffix needs to be between 'a' and 'z'.
        return device->WriteStatus(FastbootResult::FAIL, "Bad slot suffix");
@@ -329,7 +327,7 @@ bool SetActiveHandler(FastbootDevice* device, const std::vector<std::string>& ar
        return device->WriteStatus(FastbootResult::FAIL,
                                   "Cannot set slot: boot control HAL absent");
    }
    if (slot >= boot_control_hal->getNumberSlots()) {
    if (slot >= boot_control_hal->GetNumSlots()) {
        return device->WriteStatus(FastbootResult::FAIL, "Slot out of range");
    }

@@ -358,10 +356,8 @@ bool SetActiveHandler(FastbootDevice* device, const std::vector<std::string>& ar
        }
    }

    CommandResult ret;
    auto cb = [&ret](CommandResult result) { ret = result; };
    auto result = boot_control_hal->setActiveBootSlot(slot, cb);
    if (result.isOk() && ret.success) {
    CommandResult ret = boot_control_hal->SetActiveBootSlot(slot);
    if (ret.success) {
        // Save as slot suffix to match the suffix format as returned from
        // the boot control HAL.
        auto current_slot = "_" + args[1];
@@ -682,9 +678,14 @@ bool SnapshotUpdateHandler(FastbootDevice* device, const std::vector<std::string
    if (args[1] == "cancel") {
        switch (status) {
            case MergeStatus::SNAPSHOTTED:
            case MergeStatus::MERGING:
                hal->setSnapshotMergeStatus(MergeStatus::CANCELLED);
            case MergeStatus::MERGING: {
                const auto ret = hal->SetSnapshotMergeStatus(MergeStatus::CANCELLED);
                if (!ret.success) {
                    device->WriteFail("Failed to SetSnapshotMergeStatus(MergeStatus::CANCELLED) " +
                                      ret.errMsg);
                }
                break;
            }
            default:
                break;
        }
+11 −10
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <algorithm>

#include <BootControlClient.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/strings.h>
@@ -38,9 +39,8 @@ using std::string_literals::operator""s;
using android::fs_mgr::EnsurePathUnmounted;
using android::fs_mgr::Fstab;
using ::android::hardware::hidl_string;
using ::android::hardware::boot::V1_0::IBootControl;
using ::android::hardware::boot::V1_0::Slot;
using ::android::hardware::fastboot::V1_1::IFastboot;
using BootControlClient = FastbootDevice::BootControlClient;

namespace sph = std::placeholders;

@@ -85,7 +85,7 @@ FastbootDevice::FastbootDevice()
              {FB_CMD_SNAPSHOT_UPDATE, SnapshotUpdateHandler},
              {FB_CMD_FETCH, FetchHandler},
      }),
      boot_control_hal_(IBootControl::getService()),
      boot_control_hal_(BootControlClient::WaitForService()),
      health_hal_(get_health_service()),
      fastboot_hal_(IFastboot::getService()),
      active_slot_("") {
@@ -95,10 +95,6 @@ FastbootDevice::FastbootDevice()
        transport_ = std::make_unique<ClientUsbTransport>();
    }

    if (boot_control_hal_) {
        boot1_1_ = android::hardware::boot::V1_1::IBootControl::castFrom(boot_control_hal_);
    }

    // Make sure cache is unmounted, since recovery will have mounted it for
    // logging.
    Fstab fstab;
@@ -125,12 +121,17 @@ std::string FastbootDevice::GetCurrentSlot() {
    if (!boot_control_hal_) {
        return "";
    }
    std::string suffix;
    auto cb = [&suffix](hidl_string s) { suffix = s; };
    boot_control_hal_->getSuffix(boot_control_hal_->getCurrentSlot(), cb);
    std::string suffix = boot_control_hal_->GetSuffix(boot_control_hal_->GetCurrentSlot());
    return suffix;
}

BootControlClient* FastbootDevice::boot1_1() const {
    if (boot_control_hal_->GetVersion() >= android::hal::BootControlVersion::BOOTCTL_V1_1) {
        return boot_control_hal_.get();
    }
    return nullptr;
}

bool FastbootDevice::WriteStatus(FastbootResult result, const std::string& message) {
    constexpr size_t kResponseReasonSize = 4;
    constexpr size_t kNumResponseTypes = 4;  // "FAIL", "OKAY", "INFO", "DATA"
+5 −8
Original line number Diff line number Diff line
@@ -22,9 +22,8 @@
#include <utility>
#include <vector>

#include <BootControlClient.h>
#include <aidl/android/hardware/health/IHealth.h>
#include <android/hardware/boot/1.0/IBootControl.h>
#include <android/hardware/boot/1.1/IBootControl.h>
#include <android/hardware/fastboot/1.1/IFastboot.h>

#include "commands.h"
@@ -33,6 +32,7 @@

class FastbootDevice {
  public:
    using BootControlClient = android::hal::BootControlClient;
    FastbootDevice();
    ~FastbootDevice();

@@ -50,10 +50,8 @@ class FastbootDevice {

    std::vector<char>& download_data() { return download_data_; }
    Transport* get_transport() { return transport_.get(); }
    android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal() {
        return boot_control_hal_;
    }
    android::sp<android::hardware::boot::V1_1::IBootControl> boot1_1() { return boot1_1_; }
    BootControlClient* boot_control_hal() const { return boot_control_hal_.get(); }
    BootControlClient* boot1_1() const;
    android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal() {
        return fastboot_hal_;
    }
@@ -65,8 +63,7 @@ class FastbootDevice {
    const std::unordered_map<std::string, CommandHandler> kCommandMap;

    std::unique_ptr<Transport> transport_;
    android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal_;
    android::sp<android::hardware::boot::V1_1::IBootControl> boot1_1_;
    std::unique_ptr<BootControlClient> boot_control_hal_;
    std::shared_ptr<aidl::android::hardware::health::IHealth> health_hal_;
    android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal_;
    std::vector<char> download_data_;
+2 −3
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@
using namespace android::fs_mgr;
using namespace std::chrono_literals;
using android::base::unique_fd;
using android::hardware::boot::V1_0::Slot;

namespace {

@@ -137,7 +136,7 @@ bool LogicalPartitionExists(FastbootDevice* device, const std::string& name, boo
    return true;
}

bool GetSlotNumber(const std::string& slot, Slot* number) {
bool GetSlotNumber(const std::string& slot, int32_t* number) {
    if (slot.size() != 1) {
        return false;
    }
@@ -204,7 +203,7 @@ bool UpdateAllPartitionMetadata(FastbootDevice* device, const std::string& super
    size_t num_slots = 1;
    auto boot_control_hal = device->boot_control_hal();
    if (boot_control_hal) {
        num_slots = boot_control_hal->getNumberSlots();
        num_slots = boot_control_hal->GetNumSlots();
    }

    bool ok = true;
Loading