blob: e80f88de2e91d3df4a315951e4eb3c9d75cbc6af [file] [log] [blame]
Daniel Zheng1a01a1c2023-01-30 23:29:50 +00001//
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 Zhengbc01da52023-02-23 03:25:52 +000021#include "fastboot.h"
Daniel Zheng1a01a1c2023-01-30 23:29:50 +000022#include "fastboot_driver.h"
Daniel Zheng47d70a52023-02-14 17:44:40 +000023#include "super_flash_helper.h"
24#include "util.h"
Daniel Zheng1a01a1c2023-01-30 23:29:50 +000025
26class Task {
27 public:
28 Task() = default;
29 virtual void Run() = 0;
Daniel Zheng1a01a1c2023-01-30 23:29:50 +000030 virtual ~Task() = default;
31};
Daniel Zheng0d307182023-01-31 21:07:53 +000032
33class FlashTask : public Task {
34 public:
Daniel Zheng403657d2023-03-10 07:37:25 +000035 FlashTask(const std::string& slot, const std::string& pname, const std::string& fname,
36 const bool apply_vbmeta);
Daniel Zheng0d307182023-01-31 21:07:53 +000037
38 void Run() override;
Daniel Zheng0d307182023-01-31 21:07:53 +000039
40 private:
41 const std::string pname_;
42 const std::string fname_;
43 const std::string slot_;
Daniel Zheng403657d2023-03-10 07:37:25 +000044 const bool apply_vbmeta_;
Daniel Zheng0d307182023-01-31 21:07:53 +000045};
Daniel Zheng71b3b432023-01-30 17:43:00 +000046
47class RebootTask : public Task {
48 public:
Daniel Zhenge6dbd4f2023-04-10 09:53:08 -070049 RebootTask(const FlashingPlan* fp);
50 RebootTask(const FlashingPlan* fp, const std::string& reboot_target);
Daniel Zheng71b3b432023-01-30 17:43:00 +000051 void Run() override;
Daniel Zheng71b3b432023-01-30 17:43:00 +000052
53 private:
54 const std::string reboot_target_ = "";
Daniel Zheng43987c92023-03-07 18:20:53 +000055 const FlashingPlan* fp_;
Daniel Zheng47d70a52023-02-14 17:44:40 +000056};
57
58class FlashSuperLayoutTask : public Task {
59 public:
60 FlashSuperLayoutTask(const std::string& super_name, std::unique_ptr<SuperFlashHelper> helper,
David Anderson74c78072023-03-16 21:21:28 -070061 SparsePtr sparse_layout, uint64_t super_size);
Daniel Zheng47d70a52023-02-14 17:44:40 +000062 static std::unique_ptr<FlashSuperLayoutTask> Initialize(FlashingPlan* fp,
63 std::vector<ImageEntry>& os_images);
64 using ImageEntry = std::pair<const Image*, std::string>;
65 void Run() override;
66
67 private:
68 const std::string super_name_;
69 std::unique_ptr<SuperFlashHelper> helper_;
70 SparsePtr sparse_layout_;
David Anderson74c78072023-03-16 21:21:28 -070071 uint64_t super_size_;
Daniel Zheng47d70a52023-02-14 17:44:40 +000072};
Daniel Zheng6bb8baa2023-03-03 07:14:23 +000073
74class UpdateSuperTask : public Task {
75 public:
Daniel Zhenge6dbd4f2023-04-10 09:53:08 -070076 UpdateSuperTask(const FlashingPlan* fp);
Daniel Zheng6bb8baa2023-03-03 07:14:23 +000077 void Run() override;
78
79 private:
Daniel Zheng43987c92023-03-07 18:20:53 +000080 const FlashingPlan* fp_;
Daniel Zheng6bb8baa2023-03-03 07:14:23 +000081};
Daniel Zheng9f7bf7e2023-03-03 07:16:46 +000082
83class ResizeTask : public Task {
84 public:
Daniel Zhenge6dbd4f2023-04-10 09:53:08 -070085 ResizeTask(const FlashingPlan* fp, const std::string& pname, const std::string& size,
Daniel Zheng9f7bf7e2023-03-03 07:16:46 +000086 const std::string& slot);
87 void Run() override;
88
89 private:
Daniel Zheng43987c92023-03-07 18:20:53 +000090 const FlashingPlan* fp_;
Daniel Zheng9f7bf7e2023-03-03 07:16:46 +000091 const std::string pname_;
92 const std::string size_;
93 const std::string slot_;
94};
Daniel Zhengaa70f4c2023-03-07 18:59:51 +000095
96class DeleteTask : public Task {
97 public:
Daniel Zhenge6dbd4f2023-04-10 09:53:08 -070098 DeleteTask(const FlashingPlan* _fp, const std::string& _pname);
Daniel Zhengaa70f4c2023-03-07 18:59:51 +000099 void Run() override;
100
101 private:
Daniel Zheng43987c92023-03-07 18:20:53 +0000102 const FlashingPlan* fp_;
Daniel Zhengaa70f4c2023-03-07 18:59:51 +0000103 const std::string pname_;
104};
Daniel Zheng15e77832023-03-13 17:09:43 +0000105
106class WipeTask : public Task {
107 public:
Daniel Zhenge6dbd4f2023-04-10 09:53:08 -0700108 WipeTask(const FlashingPlan* fp, const std::string& pname);
Daniel Zheng15e77832023-03-13 17:09:43 +0000109 void Run() override;
110
111 private:
112 const FlashingPlan* fp_;
113 const std::string pname_;
114};