1 // 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 17 #ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_PARTITION_UPDATE_GENERATOR_ANDROID_H_ 18 #define UPDATE_ENGINE_PAYLOAD_CONSUMER_PARTITION_UPDATE_GENERATOR_ANDROID_H_ 19 20 #include <optional> 21 #include <set> 22 #include <string> 23 #include <vector> 24 25 #include <brillo/secure_blob.h> 26 #include <gtest/gtest_prod.h> // for FRIEND_TEST 27 28 #include "update_engine/common/boot_control_interface.h" 29 #include "update_engine/payload_consumer/partition_update_generator_interface.h" 30 31 namespace chromeos_update_engine { 32 33 class PartitionUpdateGeneratorAndroid 34 : public PartitionUpdateGeneratorInterface { 35 public: 36 PartitionUpdateGeneratorAndroid(BootControlInterface* boot_control, 37 size_t block_size); 38 39 bool GenerateOperationsForPartitionsNotInPayload( 40 BootControlInterface::Slot source_slot, 41 BootControlInterface::Slot target_slot, 42 const std::set<std::string>& partitions_in_payload, 43 std::vector<PartitionUpdate>* update_list) override; 44 virtual std::vector<std::string> GetAbPartitionsOnDevice() const; 45 46 private: 47 friend class PartitionUpdateGeneratorAndroidTest; 48 FRIEND_TEST(PartitionUpdateGeneratorAndroidTest, GetStaticPartitions); 49 FRIEND_TEST(PartitionUpdateGeneratorAndroidTest, CreatePartitionUpdate); 50 51 // Creates a PartitionUpdate object for a given partition to update from 52 // source to target. Returns std::nullopt on failure. 53 std::optional<PartitionUpdate> CreatePartitionUpdate( 54 const std::string& partition_name, 55 const std::string& source_device, 56 const std::string& target_device, 57 int64_t partition_size); 58 59 std::optional<brillo::Blob> CalculateHashForPartition( 60 const std::string& block_device, int64_t partition_size); 61 62 BootControlInterface* boot_control_; 63 size_t block_size_; 64 }; 65 66 } // namespace chromeos_update_engine 67 68 #endif 69