| Daniel Zheng | 1a01a1c | 2023-01-30 23:29:50 +0000 | [diff] [blame] | 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 |  | 
| Daniel Zheng | bc01da5 | 2023-02-23 03:25:52 +0000 | [diff] [blame] | 21 | #include "fastboot.h" | 
| Daniel Zheng | 1a01a1c | 2023-01-30 23:29:50 +0000 | [diff] [blame] | 22 | #include "fastboot_driver.h" | 
| Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 23 | #include "super_flash_helper.h" | 
|  | 24 | #include "util.h" | 
| Daniel Zheng | 1a01a1c | 2023-01-30 23:29:50 +0000 | [diff] [blame] | 25 |  | 
|  | 26 | class Task { | 
|  | 27 | public: | 
|  | 28 | Task() = default; | 
|  | 29 | virtual void Run() = 0; | 
| Daniel Zheng | 1a01a1c | 2023-01-30 23:29:50 +0000 | [diff] [blame] | 30 | virtual ~Task() = default; | 
|  | 31 | }; | 
| Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 32 |  | 
|  | 33 | class FlashTask : public Task { | 
|  | 34 | public: | 
| Daniel Zheng | 43987c9 | 2023-03-07 18:20:53 +0000 | [diff] [blame] | 35 | FlashTask(const std::string& slot, const std::string& pname); | 
|  | 36 | FlashTask(const std::string& slot, const std::string& pname, const std::string& fname); | 
| Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 37 |  | 
|  | 38 | void Run() override; | 
| Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 39 |  | 
|  | 40 | private: | 
|  | 41 | const std::string pname_; | 
|  | 42 | const std::string fname_; | 
|  | 43 | const std::string slot_; | 
| Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 44 | }; | 
| Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 45 |  | 
|  | 46 | class RebootTask : public Task { | 
|  | 47 | public: | 
| Daniel Zheng | 43987c9 | 2023-03-07 18:20:53 +0000 | [diff] [blame] | 48 | RebootTask(FlashingPlan* fp); | 
|  | 49 | RebootTask(FlashingPlan* fp, const std::string& reboot_target); | 
| Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 50 | void Run() override; | 
| Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 51 |  | 
|  | 52 | private: | 
|  | 53 | const std::string reboot_target_ = ""; | 
| Daniel Zheng | 43987c9 | 2023-03-07 18:20:53 +0000 | [diff] [blame] | 54 | const FlashingPlan* fp_; | 
| Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 55 | }; | 
|  | 56 |  | 
|  | 57 | class FlashSuperLayoutTask : public Task { | 
|  | 58 | public: | 
|  | 59 | FlashSuperLayoutTask(const std::string& super_name, std::unique_ptr<SuperFlashHelper> helper, | 
|  | 60 | SparsePtr sparse_layout); | 
|  | 61 | static std::unique_ptr<FlashSuperLayoutTask> Initialize(FlashingPlan* fp, | 
|  | 62 | std::vector<ImageEntry>& os_images); | 
|  | 63 | using ImageEntry = std::pair<const Image*, std::string>; | 
|  | 64 | void Run() override; | 
|  | 65 |  | 
|  | 66 | private: | 
|  | 67 | const std::string super_name_; | 
|  | 68 | std::unique_ptr<SuperFlashHelper> helper_; | 
|  | 69 | SparsePtr sparse_layout_; | 
|  | 70 | }; | 
| Daniel Zheng | 6bb8baa | 2023-03-03 07:14:23 +0000 | [diff] [blame] | 71 |  | 
|  | 72 | class UpdateSuperTask : public Task { | 
|  | 73 | public: | 
|  | 74 | UpdateSuperTask(FlashingPlan* fp); | 
|  | 75 | void Run() override; | 
|  | 76 |  | 
|  | 77 | private: | 
| Daniel Zheng | 43987c9 | 2023-03-07 18:20:53 +0000 | [diff] [blame] | 78 | const FlashingPlan* fp_; | 
| Daniel Zheng | 6bb8baa | 2023-03-03 07:14:23 +0000 | [diff] [blame] | 79 | }; | 
| Daniel Zheng | 9f7bf7e | 2023-03-03 07:16:46 +0000 | [diff] [blame] | 80 |  | 
|  | 81 | class ResizeTask : public Task { | 
|  | 82 | public: | 
|  | 83 | ResizeTask(FlashingPlan* fp, const std::string& pname, const std::string& size, | 
|  | 84 | const std::string& slot); | 
|  | 85 | void Run() override; | 
|  | 86 |  | 
|  | 87 | private: | 
| Daniel Zheng | 43987c9 | 2023-03-07 18:20:53 +0000 | [diff] [blame] | 88 | const FlashingPlan* fp_; | 
| Daniel Zheng | 9f7bf7e | 2023-03-03 07:16:46 +0000 | [diff] [blame] | 89 | const std::string pname_; | 
|  | 90 | const std::string size_; | 
|  | 91 | const std::string slot_; | 
|  | 92 | }; | 
| Daniel Zheng | aa70f4c | 2023-03-07 18:59:51 +0000 | [diff] [blame] | 93 |  | 
|  | 94 | class DeleteTask : public Task { | 
|  | 95 | public: | 
|  | 96 | DeleteTask(FlashingPlan* _fp, const std::string& _pname); | 
|  | 97 | void Run() override; | 
|  | 98 |  | 
|  | 99 | private: | 
| Daniel Zheng | 43987c9 | 2023-03-07 18:20:53 +0000 | [diff] [blame] | 100 | const FlashingPlan* fp_; | 
| Daniel Zheng | aa70f4c | 2023-03-07 18:59:51 +0000 | [diff] [blame] | 101 | const std::string pname_; | 
|  | 102 | }; | 
| Daniel Zheng | 15e7783 | 2023-03-13 17:09:43 +0000 | [diff] [blame] | 103 |  | 
|  | 104 | class WipeTask : public Task { | 
|  | 105 | public: | 
|  | 106 | WipeTask(FlashingPlan* fp, const std::string& pname); | 
|  | 107 | void Run() override; | 
|  | 108 |  | 
|  | 109 | private: | 
|  | 110 | const FlashingPlan* fp_; | 
|  | 111 | const std::string pname_; | 
|  | 112 | }; |