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