blob: 31671154b6c07f509a362f0b9ee1820c0cb65f7b [file] [log] [blame]
David Zeuthen6eddf262015-10-16 15:23:53 -04001//
2// Copyright (C) 2015 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
Alex Deymo39910dc2015-11-09 17:04:30 -080017#ifndef UPDATE_ENGINE_COMMON_BOOT_CONTROL_STUB_H_
18#define UPDATE_ENGINE_COMMON_BOOT_CONTROL_STUB_H_
David Zeuthen6eddf262015-10-16 15:23:53 -040019
Yifan Hongdaac7322019-11-07 10:48:26 -080020#include <memory>
David Zeuthen6eddf262015-10-16 15:23:53 -040021#include <string>
22
Alex Deymo39910dc2015-11-09 17:04:30 -080023#include "update_engine/common/boot_control_interface.h"
Yifan Hongdaac7322019-11-07 10:48:26 -080024#include "update_engine/common/dynamic_partition_control_interface.h"
David Zeuthen6eddf262015-10-16 15:23:53 -040025
26namespace chromeos_update_engine {
27
28// An implementation of the BootControlInterface that does nothing,
29// typically used when e.g. an underlying HAL implementation cannot be
30// loaded or doesn't exist.
31//
Sen Jiang771f6482018-04-04 17:59:10 -070032// You are guaranteed that the implementation of GetNumSlots() method
David Zeuthen6eddf262015-10-16 15:23:53 -040033// always returns 0. This can be used to identify that this
34// implementation is in use.
35class BootControlStub : public BootControlInterface {
36 public:
Yifan Hongdaac7322019-11-07 10:48:26 -080037 BootControlStub();
David Zeuthen6eddf262015-10-16 15:23:53 -040038 ~BootControlStub() = default;
39
40 // BootControlInterface overrides.
41 unsigned int GetNumSlots() const override;
42 BootControlInterface::Slot GetCurrentSlot() const override;
43 bool GetPartitionDevice(const std::string& partition_name,
Tianjie51a5a392020-06-03 14:39:32 -070044 Slot slot,
45 bool not_in_payload,
46 std::string* device,
47 bool* is_dynamic) const override;
48 bool GetPartitionDevice(const std::string& partition_name,
David Zeuthen6eddf262015-10-16 15:23:53 -040049 BootControlInterface::Slot slot,
50 std::string* device) const override;
Kelvin Zhang91d95fa2020-11-05 13:52:00 -050051 std::optional<PartitionDevice> GetPartitionDevice(
52 const std::string& partition_name,
53 uint32_t slot,
54 uint32_t current_slot,
55 bool not_in_payload = false) const override;
David Zeuthen6eddf262015-10-16 15:23:53 -040056 bool IsSlotBootable(BootControlInterface::Slot slot) const override;
57 bool MarkSlotUnbootable(BootControlInterface::Slot slot) override;
58 bool SetActiveBootSlot(BootControlInterface::Slot slot) override;
Kelvin Zhangcb419e62021-06-16 13:56:47 -040059 Slot GetActiveBootSlot() override { return kInvalidSlot; }
David Zeuthen6eddf262015-10-16 15:23:53 -040060 bool MarkBootSuccessfulAsync(base::Callback<void(bool)> callback) override;
Yifan Hongf1415942020-02-24 18:34:49 -080061 bool IsSlotMarkedSuccessful(BootControlInterface::Slot slot) const override;
Yifan Hongdaac7322019-11-07 10:48:26 -080062 DynamicPartitionControlInterface* GetDynamicPartitionControl() override;
David Zeuthen6eddf262015-10-16 15:23:53 -040063
64 private:
Yifan Hongdaac7322019-11-07 10:48:26 -080065 std::unique_ptr<DynamicPartitionControlInterface> dynamic_partition_control_;
66
David Zeuthen6eddf262015-10-16 15:23:53 -040067 DISALLOW_COPY_AND_ASSIGN(BootControlStub);
68};
69
70} // namespace chromeos_update_engine
71
Alex Deymo39910dc2015-11-09 17:04:30 -080072#endif // UPDATE_ENGINE_COMMON_BOOT_CONTROL_STUB_H_