1 // 2 // Copyright (C) 2020 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 #pragma once 17 18 #include <sstream> 19 #include <string> 20 21 #include "fastboot_driver.h" 22 #include "super_flash_helper.h" 23 #include "util.h" 24 25 struct FlashingPlan; 26 struct Image; 27 using ImageEntry = std::pair<const Image*, std::string>; 28 29 class FlashTask; 30 class RebootTask; 31 class UpdateSuperTask; 32 class WipeTask; 33 34 class Task { 35 public: 36 Task() = default; 37 virtual void Run() = 0; AsFlashTask()38 virtual FlashTask* AsFlashTask() { return nullptr; } AsRebootTask()39 virtual RebootTask* AsRebootTask() { return nullptr; } AsUpdateSuperTask()40 virtual UpdateSuperTask* AsUpdateSuperTask() { return nullptr; } AsWipeTask()41 virtual WipeTask* AsWipeTask() { return nullptr; } 42 43 virtual ~Task() = default; 44 }; 45 46 class FlashTask : public Task { 47 public: 48 FlashTask(const std::string& slot, const std::string& pname, const std::string& fname, 49 const bool apply_vbmeta); AsFlashTask()50 virtual FlashTask* AsFlashTask() override { return this; } 51 GetPartition()52 std::string GetPartition() { return pname_; } GetImageName()53 std::string GetImageName() { return fname_; } 54 std::string GetPartitionAndSlot(); GetSlot()55 std::string GetSlot() { return slot_; } 56 void Run() override; 57 58 private: 59 const std::string pname_; 60 const std::string fname_; 61 const std::string slot_; 62 const bool apply_vbmeta_; 63 }; 64 65 class RebootTask : public Task { 66 public: 67 RebootTask(const FlashingPlan* fp); 68 RebootTask(const FlashingPlan* fp, const std::string& reboot_target); AsRebootTask()69 virtual RebootTask* AsRebootTask() override { return this; } 70 void Run() override; 71 72 private: 73 const std::string reboot_target_ = ""; 74 const FlashingPlan* fp_; 75 }; 76 77 class FlashSuperLayoutTask : public Task { 78 public: 79 FlashSuperLayoutTask(const std::string& super_name, std::unique_ptr<SuperFlashHelper> helper, 80 SparsePtr sparse_layout, uint64_t super_size); 81 static std::unique_ptr<FlashSuperLayoutTask> Initialize(const FlashingPlan* fp, 82 std::vector<ImageEntry>& os_images); 83 static std::unique_ptr<FlashSuperLayoutTask> InitializeFromTasks( 84 const FlashingPlan* fp, std::vector<std::unique_ptr<Task>>& tasks); 85 using ImageEntry = std::pair<const Image*, std::string>; 86 void Run() override; 87 88 private: 89 const std::string super_name_; 90 std::unique_ptr<SuperFlashHelper> helper_; 91 SparsePtr sparse_layout_; 92 uint64_t super_size_; 93 }; 94 95 class UpdateSuperTask : public Task { 96 public: 97 UpdateSuperTask(const FlashingPlan* fp); AsUpdateSuperTask()98 virtual UpdateSuperTask* AsUpdateSuperTask() override { return this; } 99 100 void Run() override; 101 102 private: 103 const FlashingPlan* fp_; 104 }; 105 106 class ResizeTask : public Task { 107 public: 108 ResizeTask(const FlashingPlan* fp, const std::string& pname, const std::string& size, 109 const std::string& slot); 110 void Run() override; 111 112 private: 113 const FlashingPlan* fp_; 114 const std::string pname_; 115 const std::string size_; 116 const std::string slot_; 117 }; 118 119 class DeleteTask : public Task { 120 public: 121 DeleteTask(const FlashingPlan* _fp, const std::string& _pname); 122 void Run() override; 123 124 private: 125 const FlashingPlan* fp_; 126 const std::string pname_; 127 }; 128 129 class WipeTask : public Task { 130 public: 131 WipeTask(const FlashingPlan* fp, const std::string& pname); AsWipeTask()132 virtual WipeTask* AsWipeTask() override { return this; } 133 134 void Run() override; 135 136 private: 137 const FlashingPlan* fp_; 138 const std::string pname_; 139 }; 140