1*5a923131SAndroid Build Coastguard Worker // 2*5a923131SAndroid Build Coastguard Worker // Copyright (C) 2015 The Android Open Source Project 3*5a923131SAndroid Build Coastguard Worker // 4*5a923131SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 5*5a923131SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 6*5a923131SAndroid Build Coastguard Worker // You may obtain a copy of the License at 7*5a923131SAndroid Build Coastguard Worker // 8*5a923131SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 9*5a923131SAndroid Build Coastguard Worker // 10*5a923131SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 11*5a923131SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 12*5a923131SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*5a923131SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 14*5a923131SAndroid Build Coastguard Worker // limitations under the License. 15*5a923131SAndroid Build Coastguard Worker // 16*5a923131SAndroid Build Coastguard Worker 17*5a923131SAndroid Build Coastguard Worker #ifndef UPDATE_ENGINE_AOSP_BOOT_CONTROL_ANDROID_H_ 18*5a923131SAndroid Build Coastguard Worker #define UPDATE_ENGINE_AOSP_BOOT_CONTROL_ANDROID_H_ 19*5a923131SAndroid Build Coastguard Worker 20*5a923131SAndroid Build Coastguard Worker #include <map> 21*5a923131SAndroid Build Coastguard Worker #include <memory> 22*5a923131SAndroid Build Coastguard Worker #include <string> 23*5a923131SAndroid Build Coastguard Worker 24*5a923131SAndroid Build Coastguard Worker #include <liblp/builder.h> 25*5a923131SAndroid Build Coastguard Worker #include <gtest/gtest_prod.h> 26*5a923131SAndroid Build Coastguard Worker #include <BootControlClient.h> 27*5a923131SAndroid Build Coastguard Worker 28*5a923131SAndroid Build Coastguard Worker #include "update_engine/aosp/dynamic_partition_control_android.h" 29*5a923131SAndroid Build Coastguard Worker #include "update_engine/common/boot_control_interface.h" 30*5a923131SAndroid Build Coastguard Worker #include "update_engine/common/dynamic_partition_control_interface.h" 31*5a923131SAndroid Build Coastguard Worker 32*5a923131SAndroid Build Coastguard Worker namespace chromeos_update_engine { 33*5a923131SAndroid Build Coastguard Worker 34*5a923131SAndroid Build Coastguard Worker // The Android implementation of the BootControlInterface. This implementation 35*5a923131SAndroid Build Coastguard Worker // uses the libhardware's boot_control HAL to access the bootloader. 36*5a923131SAndroid Build Coastguard Worker class BootControlAndroid final : public BootControlInterface { 37*5a923131SAndroid Build Coastguard Worker public: 38*5a923131SAndroid Build Coastguard Worker BootControlAndroid() = default; 39*5a923131SAndroid Build Coastguard Worker ~BootControlAndroid() = default; 40*5a923131SAndroid Build Coastguard Worker 41*5a923131SAndroid Build Coastguard Worker // Load boot_control HAL implementation using libhardware and 42*5a923131SAndroid Build Coastguard Worker // initializes it. Returns false if an error occurred. 43*5a923131SAndroid Build Coastguard Worker bool Init(); 44*5a923131SAndroid Build Coastguard Worker 45*5a923131SAndroid Build Coastguard Worker // BootControlInterface overrides. 46*5a923131SAndroid Build Coastguard Worker unsigned int GetNumSlots() const override; 47*5a923131SAndroid Build Coastguard Worker BootControlInterface::Slot GetCurrentSlot() const override; 48*5a923131SAndroid Build Coastguard Worker std::optional<PartitionDevice> GetPartitionDevice( 49*5a923131SAndroid Build Coastguard Worker const std::string& partition_name, 50*5a923131SAndroid Build Coastguard Worker uint32_t slot, 51*5a923131SAndroid Build Coastguard Worker uint32_t current_slot, 52*5a923131SAndroid Build Coastguard Worker bool not_in_payload = false) const override; 53*5a923131SAndroid Build Coastguard Worker bool GetPartitionDevice(const std::string& partition_name, 54*5a923131SAndroid Build Coastguard Worker BootControlInterface::Slot slot, 55*5a923131SAndroid Build Coastguard Worker bool not_in_payload, 56*5a923131SAndroid Build Coastguard Worker std::string* device, 57*5a923131SAndroid Build Coastguard Worker bool* is_dynamic) const override; 58*5a923131SAndroid Build Coastguard Worker bool GetPartitionDevice(const std::string& partition_name, 59*5a923131SAndroid Build Coastguard Worker BootControlInterface::Slot slot, 60*5a923131SAndroid Build Coastguard Worker std::string* device) const override; 61*5a923131SAndroid Build Coastguard Worker bool IsSlotBootable(BootControlInterface::Slot slot) const override; 62*5a923131SAndroid Build Coastguard Worker bool MarkSlotUnbootable(BootControlInterface::Slot slot) override; 63*5a923131SAndroid Build Coastguard Worker bool SetActiveBootSlot(BootControlInterface::Slot slot) override; 64*5a923131SAndroid Build Coastguard Worker bool MarkBootSuccessfulAsync(base::Callback<void(bool)> callback) override; 65*5a923131SAndroid Build Coastguard Worker bool IsSlotMarkedSuccessful(BootControlInterface::Slot slot) const override; 66*5a923131SAndroid Build Coastguard Worker Slot GetActiveBootSlot() override; 67*5a923131SAndroid Build Coastguard Worker DynamicPartitionControlInterface* GetDynamicPartitionControl() override; 68*5a923131SAndroid Build Coastguard Worker 69*5a923131SAndroid Build Coastguard Worker private: 70*5a923131SAndroid Build Coastguard Worker std::unique_ptr<android::hal::BootControlClient> module_; 71*5a923131SAndroid Build Coastguard Worker std::unique_ptr<DynamicPartitionControlAndroid> dynamic_control_; 72*5a923131SAndroid Build Coastguard Worker 73*5a923131SAndroid Build Coastguard Worker friend class BootControlAndroidTest; 74*5a923131SAndroid Build Coastguard Worker friend class UpdateAttempterAndroidIntegrationTest; 75*5a923131SAndroid Build Coastguard Worker 76*5a923131SAndroid Build Coastguard Worker DISALLOW_COPY_AND_ASSIGN(BootControlAndroid); 77*5a923131SAndroid Build Coastguard Worker }; 78*5a923131SAndroid Build Coastguard Worker 79*5a923131SAndroid Build Coastguard Worker } // namespace chromeos_update_engine 80*5a923131SAndroid Build Coastguard Worker 81*5a923131SAndroid Build Coastguard Worker #endif // UPDATE_ENGINE_AOSP_BOOT_CONTROL_ANDROID_H_ 82