1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
//
// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#pragma once
#include <string>
#include "super_flash_helper.h"
#include "util.h"
struct FlashingPlan;
struct Image;
using ImageEntry = std::pair<const Image*, std::string>;
class FlashTask;
class RebootTask;
class UpdateSuperTask;
class OptimizedFlashSuperTask;
class WipeTask;
class ResizeTask;
class Task {
public:
Task() = default;
virtual void Run() = 0;
virtual std::string ToString() const = 0;
virtual FlashTask* AsFlashTask() { return nullptr; }
virtual RebootTask* AsRebootTask() { return nullptr; }
virtual UpdateSuperTask* AsUpdateSuperTask() { return nullptr; }
virtual OptimizedFlashSuperTask* AsOptimizedFlashSuperTask() { return nullptr; }
virtual WipeTask* AsWipeTask() { return nullptr; }
virtual ResizeTask* AsResizeTask() { return nullptr; }
virtual ~Task() = default;
};
class FlashTask : public Task {
public:
FlashTask(const std::string& slot, const std::string& pname, const std::string& fname,
const bool apply_vbmeta, const FlashingPlan* fp);
virtual FlashTask* AsFlashTask() override { return this; }
static bool IsDynamicParitition(const ImageSource* source, const FlashTask* task);
void Run() override;
std::string ToString() const override;
std::string GetPartition() const { return pname_; }
std::string GetImageName() const { return fname_; }
std::string GetSlot() const { return slot_; }
std::string GetPartitionAndSlot() const;
private:
const std::string pname_;
const std::string fname_;
const std::string slot_;
const bool apply_vbmeta_;
const FlashingPlan* fp_;
};
class RebootTask : public Task {
public:
RebootTask(const FlashingPlan* fp);
RebootTask(const FlashingPlan* fp, const std::string& reboot_target);
virtual RebootTask* AsRebootTask() override { return this; }
void Run() override;
std::string ToString() const override;
std::string GetTarget() const { return reboot_target_; };
private:
const std::string reboot_target_ = "";
const FlashingPlan* fp_;
};
class OptimizedFlashSuperTask : public Task {
public:
OptimizedFlashSuperTask(const std::string& super_name, std::unique_ptr<SuperFlashHelper> helper,
SparsePtr sparse_layout, uint64_t super_size, const FlashingPlan* fp);
virtual OptimizedFlashSuperTask* AsOptimizedFlashSuperTask() override { return this; }
static std::unique_ptr<OptimizedFlashSuperTask> Initialize(
const FlashingPlan* fp, std::vector<std::unique_ptr<Task>>& tasks);
static bool CanOptimize(const ImageSource* source,
const std::vector<std::unique_ptr<Task>>& tasks);
void Run() override;
std::string ToString() const override;
private:
const std::string super_name_;
std::unique_ptr<SuperFlashHelper> helper_;
SparsePtr sparse_layout_;
uint64_t super_size_;
const FlashingPlan* fp_;
};
class UpdateSuperTask : public Task {
public:
UpdateSuperTask(const FlashingPlan* fp);
virtual UpdateSuperTask* AsUpdateSuperTask() override { return this; }
void Run() override;
std::string ToString() const override;
private:
const FlashingPlan* fp_;
};
class ResizeTask : public Task {
public:
ResizeTask(const FlashingPlan* fp, const std::string& pname, const std::string& size,
const std::string& slot);
void Run() override;
std::string ToString() const override;
virtual ResizeTask* AsResizeTask() override { return this; }
private:
const FlashingPlan* fp_;
const std::string pname_;
const std::string size_;
const std::string slot_;
};
class DeleteTask : public Task {
public:
DeleteTask(const FlashingPlan* fp, const std::string& pname);
void Run() override;
std::string ToString() const override;
private:
const FlashingPlan* fp_;
const std::string pname_;
};
class WipeTask : public Task {
public:
WipeTask(const FlashingPlan* fp, const std::string& pname);
virtual WipeTask* AsWipeTask() override { return this; }
void Run() override;
std::string ToString() const override;
private:
const FlashingPlan* fp_;
const std::string pname_;
};
|