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 | bc01da5 | 2023-02-23 03:25:52 +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; |
| 39 | ~FlashTask() {} |
| 40 | |
| 41 | private: |
| 42 | const std::string pname_; |
| 43 | const std::string fname_; |
| 44 | const std::string slot_; |
Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 45 | }; |
Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 46 | |
| 47 | class RebootTask : public Task { |
| 48 | public: |
Daniel Zheng | bc01da5 | 2023-02-23 03:25:52 +0000 | [diff] [blame] | 49 | RebootTask(FlashingPlan* _fp); |
| 50 | RebootTask(FlashingPlan* _fp, const std::string& _reboot_target); |
Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 51 | void Run() override; |
| 52 | ~RebootTask() {} |
| 53 | |
| 54 | private: |
| 55 | const std::string reboot_target_ = ""; |
Daniel Zheng | bc01da5 | 2023-02-23 03:25:52 +0000 | [diff] [blame] | 56 | FlashingPlan* fp_; |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame^] | 57 | }; |
| 58 | |
| 59 | class FlashSuperLayoutTask : public Task { |
| 60 | public: |
| 61 | FlashSuperLayoutTask(const std::string& super_name, std::unique_ptr<SuperFlashHelper> helper, |
| 62 | SparsePtr sparse_layout); |
| 63 | static std::unique_ptr<FlashSuperLayoutTask> Initialize(FlashingPlan* fp, |
| 64 | std::vector<ImageEntry>& os_images); |
| 65 | using ImageEntry = std::pair<const Image*, std::string>; |
| 66 | void Run() override; |
| 67 | |
| 68 | private: |
| 69 | const std::string super_name_; |
| 70 | std::unique_ptr<SuperFlashHelper> helper_; |
| 71 | SparsePtr sparse_layout_; |
| 72 | }; |