blob: 801a0f6bf313ca7306415bbd22972488efe074b3 [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 Zheng1a01a1c2023-01-30 23:29:50 +000021#include "fastboot_driver.h"
Daniel Zheng47d70a52023-02-14 17:44:40 +000022#include "super_flash_helper.h"
23#include "util.h"
Daniel Zheng1a01a1c2023-01-30 23:29:50 +000024
Daniel Zheng08975262023-04-17 11:34:00 -070025struct FlashingPlan;
26struct Image;
27using ImageEntry = std::pair<const Image*, std::string>;
28
Daniel Zheng1a01a1c2023-01-30 23:29:50 +000029class Task {
30 public:
31 Task() = default;
32 virtual void Run() = 0;
Daniel Zheng1a01a1c2023-01-30 23:29:50 +000033 virtual ~Task() = default;
34};
Daniel Zheng0d307182023-01-31 21:07:53 +000035
36class FlashTask : public Task {
37 public:
Daniel Zheng403657d2023-03-10 07:37:25 +000038 FlashTask(const std::string& slot, const std::string& pname, const std::string& fname,
39 const bool apply_vbmeta);
Daniel Zheng0d307182023-01-31 21:07:53 +000040
41 void Run() override;
Daniel Zheng0d307182023-01-31 21:07:53 +000042
43 private:
44 const std::string pname_;
45 const std::string fname_;
46 const std::string slot_;
Daniel Zheng403657d2023-03-10 07:37:25 +000047 const bool apply_vbmeta_;
Daniel Zheng0d307182023-01-31 21:07:53 +000048};
Daniel Zheng71b3b432023-01-30 17:43:00 +000049
50class RebootTask : public Task {
51 public:
Daniel Zhenge6dbd4f2023-04-10 09:53:08 -070052 RebootTask(const FlashingPlan* fp);
53 RebootTask(const FlashingPlan* fp, const std::string& reboot_target);
Daniel Zheng71b3b432023-01-30 17:43:00 +000054 void Run() override;
Daniel Zheng71b3b432023-01-30 17:43:00 +000055
56 private:
57 const std::string reboot_target_ = "";
Daniel Zheng43987c92023-03-07 18:20:53 +000058 const FlashingPlan* fp_;
Daniel Zheng47d70a52023-02-14 17:44:40 +000059};
60
61class FlashSuperLayoutTask : public Task {
62 public:
63 FlashSuperLayoutTask(const std::string& super_name, std::unique_ptr<SuperFlashHelper> helper,
David Anderson74c78072023-03-16 21:21:28 -070064 SparsePtr sparse_layout, uint64_t super_size);
Daniel Zheng47d70a52023-02-14 17:44:40 +000065 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 Anderson74c78072023-03-16 21:21:28 -070074 uint64_t super_size_;
Daniel Zheng47d70a52023-02-14 17:44:40 +000075};
Daniel Zheng6bb8baa2023-03-03 07:14:23 +000076
77class UpdateSuperTask : public Task {
78 public:
Daniel Zhenge6dbd4f2023-04-10 09:53:08 -070079 UpdateSuperTask(const FlashingPlan* fp);
Daniel Zheng6bb8baa2023-03-03 07:14:23 +000080 void Run() override;
81
82 private:
Daniel Zheng43987c92023-03-07 18:20:53 +000083 const FlashingPlan* fp_;
Daniel Zheng6bb8baa2023-03-03 07:14:23 +000084};
Daniel Zheng9f7bf7e2023-03-03 07:16:46 +000085
86class ResizeTask : public Task {
87 public:
Daniel Zhenge6dbd4f2023-04-10 09:53:08 -070088 ResizeTask(const FlashingPlan* fp, const std::string& pname, const std::string& size,
Daniel Zheng9f7bf7e2023-03-03 07:16:46 +000089 const std::string& slot);
90 void Run() override;
91
92 private:
Daniel Zheng43987c92023-03-07 18:20:53 +000093 const FlashingPlan* fp_;
Daniel Zheng9f7bf7e2023-03-03 07:16:46 +000094 const std::string pname_;
95 const std::string size_;
96 const std::string slot_;
97};
Daniel Zhengaa70f4c2023-03-07 18:59:51 +000098
99class DeleteTask : public Task {
100 public:
Daniel Zhenge6dbd4f2023-04-10 09:53:08 -0700101 DeleteTask(const FlashingPlan* _fp, const std::string& _pname);
Daniel Zhengaa70f4c2023-03-07 18:59:51 +0000102 void Run() override;
103
104 private:
Daniel Zheng43987c92023-03-07 18:20:53 +0000105 const FlashingPlan* fp_;
Daniel Zhengaa70f4c2023-03-07 18:59:51 +0000106 const std::string pname_;
107};
Daniel Zheng15e77832023-03-13 17:09:43 +0000108
109class WipeTask : public Task {
110 public:
Daniel Zhenge6dbd4f2023-04-10 09:53:08 -0700111 WipeTask(const FlashingPlan* fp, const std::string& pname);
Daniel Zheng15e77832023-03-13 17:09:43 +0000112 void Run() override;
113
114 private:
115 const FlashingPlan* fp_;
116 const std::string pname_;
117};