David Zeuthen | 6eddf26 | 2015-10-16 15:23:53 -0400 | [diff] [blame] | 1 | // |
| 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 Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_COMMON_BOOT_CONTROL_STUB_H_ |
| 18 | #define UPDATE_ENGINE_COMMON_BOOT_CONTROL_STUB_H_ |
David Zeuthen | 6eddf26 | 2015-10-16 15:23:53 -0400 | [diff] [blame] | 19 | |
Yifan Hong | daac732 | 2019-11-07 10:48:26 -0800 | [diff] [blame] | 20 | #include <memory> |
David Zeuthen | 6eddf26 | 2015-10-16 15:23:53 -0400 | [diff] [blame] | 21 | #include <string> |
| 22 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 23 | #include "update_engine/common/boot_control_interface.h" |
Yifan Hong | daac732 | 2019-11-07 10:48:26 -0800 | [diff] [blame] | 24 | #include "update_engine/common/dynamic_partition_control_interface.h" |
David Zeuthen | 6eddf26 | 2015-10-16 15:23:53 -0400 | [diff] [blame] | 25 | |
| 26 | namespace 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 Jiang | 771f648 | 2018-04-04 17:59:10 -0700 | [diff] [blame] | 32 | // You are guaranteed that the implementation of GetNumSlots() method |
David Zeuthen | 6eddf26 | 2015-10-16 15:23:53 -0400 | [diff] [blame] | 33 | // always returns 0. This can be used to identify that this |
| 34 | // implementation is in use. |
| 35 | class BootControlStub : public BootControlInterface { |
| 36 | public: |
Yifan Hong | daac732 | 2019-11-07 10:48:26 -0800 | [diff] [blame] | 37 | BootControlStub(); |
David Zeuthen | 6eddf26 | 2015-10-16 15:23:53 -0400 | [diff] [blame] | 38 | ~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, |
Tianjie | 51a5a39 | 2020-06-03 14:39:32 -0700 | [diff] [blame] | 44 | 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 Zeuthen | 6eddf26 | 2015-10-16 15:23:53 -0400 | [diff] [blame] | 49 | BootControlInterface::Slot slot, |
| 50 | std::string* device) const override; |
Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 51 | 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 Zeuthen | 6eddf26 | 2015-10-16 15:23:53 -0400 | [diff] [blame] | 56 | bool IsSlotBootable(BootControlInterface::Slot slot) const override; |
| 57 | bool MarkSlotUnbootable(BootControlInterface::Slot slot) override; |
| 58 | bool SetActiveBootSlot(BootControlInterface::Slot slot) override; |
Kelvin Zhang | cb419e6 | 2021-06-16 13:56:47 -0400 | [diff] [blame^] | 59 | Slot GetActiveBootSlot() override { return kInvalidSlot; } |
David Zeuthen | 6eddf26 | 2015-10-16 15:23:53 -0400 | [diff] [blame] | 60 | bool MarkBootSuccessfulAsync(base::Callback<void(bool)> callback) override; |
Yifan Hong | f141594 | 2020-02-24 18:34:49 -0800 | [diff] [blame] | 61 | bool IsSlotMarkedSuccessful(BootControlInterface::Slot slot) const override; |
Yifan Hong | daac732 | 2019-11-07 10:48:26 -0800 | [diff] [blame] | 62 | DynamicPartitionControlInterface* GetDynamicPartitionControl() override; |
David Zeuthen | 6eddf26 | 2015-10-16 15:23:53 -0400 | [diff] [blame] | 63 | |
| 64 | private: |
Yifan Hong | daac732 | 2019-11-07 10:48:26 -0800 | [diff] [blame] | 65 | std::unique_ptr<DynamicPartitionControlInterface> dynamic_partition_control_; |
| 66 | |
David Zeuthen | 6eddf26 | 2015-10-16 15:23:53 -0400 | [diff] [blame] | 67 | DISALLOW_COPY_AND_ASSIGN(BootControlStub); |
| 68 | }; |
| 69 | |
| 70 | } // namespace chromeos_update_engine |
| 71 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 72 | #endif // UPDATE_ENGINE_COMMON_BOOT_CONTROL_STUB_H_ |