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

Commit 4f3d6e2b authored by Daniel Zheng's avatar Daniel Zheng Committed by Gerrit Code Review
Browse files

Merge "Adding parsing for fastboot-info"

parents 3c381ee0 c97eeed5
Loading
Loading
Loading
Loading
+27 −3
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ static std::vector<Image> images = {
        // clang-format on
};

static char* get_android_product_out() {
char* get_android_product_out() {
    char* dir = getenv("ANDROID_PRODUCT_OUT");
    if (dir == nullptr || dir[0] == '\0') {
        return nullptr;
@@ -1787,13 +1787,25 @@ void FlashAllTool::Flash() {

    CancelSnapshotIfNeeded();

    tasks_ = CollectTasksFromImageList();
    tasks_ = CollectTasks();
    for (auto& task : tasks_) {
        task->Run();
    }
    return;
}

std::vector<std::unique_ptr<Task>> FlashAllTool::CollectTasks() {
    std::vector<std::unique_ptr<Task>> tasks;
    if (fp_->should_use_fastboot_info) {
        tasks = CollectTasksFromFastbootInfo();

    } else {
        tasks = CollectTasksFromImageList();
    }

    return tasks;
}

void FlashAllTool::CheckRequirements() {
    std::vector<char> contents;
    if (!fp_->source->ReadFile("android-info.txt", &contents)) {
@@ -1848,7 +1860,6 @@ std::vector<std::unique_ptr<Task>> FlashAllTool::CollectTasksFromImageList() {
    // or in bootloader fastboot.
    std::vector<std::unique_ptr<Task>> tasks;
    AddFlashTasks(boot_images_, tasks);

    if (auto flash_super_task = OptimizedFlashSuperTask::Initialize(fp_, os_images_)) {
        tasks.emplace_back(std::move(flash_super_task));
    } else {
@@ -1871,10 +1882,23 @@ std::vector<std::unique_ptr<Task>> FlashAllTool::CollectTasksFromImageList() {
            tasks.emplace_back(std::make_unique<ResizeTask>(fp_, image->part_name, "0", slot));
        }
    }

    AddFlashTasks(os_images_, tasks);
    return tasks;
}

std::vector<std::unique_ptr<Task>> FlashAllTool::CollectTasksFromFastbootInfo() {
    std::vector<std::unique_ptr<Task>> tasks;
    std::vector<char> contents;
    if (!fp_->source->ReadFile("fastboot-info.txt", &contents)) {
        LOG(VERBOSE) << "Flashing from hardcoded images. fastboot-info.txt is empty or does not "
                        "exist";
        return CollectTasksFromImageList();
    }
    tasks = ParseFastbootInfo(fp_, Split({contents.data(), contents.size()}, "\n"));
    return tasks;
}

void FlashAllTool::AddFlashTasks(const std::vector<std::pair<const Image*, std::string>>& images,
                                 std::vector<std::unique_ptr<Task>>& tasks) {
    for (const auto& [image, slot] : images) {
+5 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ struct FlashingPlan {
    bool skip_secondary = false;
    bool force_flash = false;
    bool should_optimize_flash_super = true;
    bool should_use_fastboot_info = false;
    uint64_t sparse_limit = 0;

    std::string slot_override;
@@ -111,6 +112,7 @@ class FlashAllTool {
    FlashAllTool(FlashingPlan* fp);

    void Flash();
    std::vector<std::unique_ptr<Task>> CollectTasks();

  private:
    void CheckRequirements();
@@ -118,6 +120,8 @@ class FlashAllTool {
    void CollectImages();
    void AddFlashTasks(const std::vector<std::pair<const Image*, std::string>>& images,
                       std::vector<std::unique_ptr<Task>>& tasks);

    std::vector<std::unique_ptr<Task>> CollectTasksFromFastbootInfo();
    std::vector<std::unique_ptr<Task>> CollectTasksFromImageList();

    std::vector<ImageEntry> boot_images_;
@@ -143,6 +147,7 @@ class LocalImageSource final : public ImageSource {
    unique_fd OpenFile(const std::string& name) const override;
};

char* get_android_product_out();
bool should_flash_in_userspace(const std::string& partition_name);
bool is_userspace_fastboot();
void do_flash(const char* pname, const char* fname, const bool apply_vbmeta,