1 // 2 // Copyright (C) 2018 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 #include <stdint.h> 18 19 #include <memory> 20 #include <set> 21 #include <string> 22 23 #include <gmock/gmock.h> 24 25 #include <libsnapshot/cow_writer.h> 26 #include <libsnapshot/snapshot_writer.h> 27 28 #include "payload_consumer/file_descriptor.h" 29 #include "update_engine/aosp/dynamic_partition_control_android.h" 30 #include "update_engine/common/boot_control_interface.h" 31 #include "update_engine/common/dynamic_partition_control_interface.h" 32 33 namespace chromeos_update_engine { 34 35 class MockDynamicPartitionControlAndroid 36 : public DynamicPartitionControlAndroid { 37 public: MockDynamicPartitionControlAndroid()38 MockDynamicPartitionControlAndroid() 39 : DynamicPartitionControlAndroid(0 /*source slot*/) {} 40 MOCK_METHOD( 41 bool, 42 MapPartitionOnDeviceMapper, 43 (const std::string&, const std::string&, uint32_t, bool, std::string*), 44 (override)); 45 MOCK_METHOD(bool, 46 UnmapPartitionOnDeviceMapper, 47 (const std::string&), 48 (override)); 49 MOCK_METHOD(void, Cleanup, (), (override)); 50 MOCK_METHOD(bool, DeviceExists, (const std::string&), (override)); 51 MOCK_METHOD(::android::dm::DmDeviceState, 52 GetState, 53 (const std::string&), 54 (override)); 55 MOCK_METHOD(bool, 56 GetDmDevicePathByName, 57 (const std::string&, std::string*), 58 (override)); 59 MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>, 60 LoadMetadataBuilder, 61 (const std::string&, uint32_t), 62 (override)); 63 MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>, 64 LoadMetadataBuilder, 65 (const std::string&, uint32_t, uint32_t), 66 (override)); 67 MOCK_METHOD(bool, 68 StoreMetadata, 69 (const std::string&, android::fs_mgr::MetadataBuilder*, uint32_t), 70 (override)); 71 MOCK_METHOD(bool, GetDeviceDir, (std::string*), (override)); 72 MOCK_METHOD(FeatureFlag, GetDynamicPartitionsFeatureFlag, (), (override)); 73 MOCK_METHOD(std::string, GetSuperPartitionName, (uint32_t), (override)); 74 MOCK_METHOD(FeatureFlag, GetVirtualAbFeatureFlag, (), (override)); 75 MOCK_METHOD(FeatureFlag, GetVirtualAbCompressionFeatureFlag, (), (override)); 76 MOCK_METHOD(FeatureFlag, 77 GetVirtualAbCompressionXorFeatureFlag, 78 (), 79 (override)); 80 MOCK_METHOD(bool, FinishUpdate, (bool), (override)); 81 MOCK_METHOD(bool, 82 GetSystemOtherPath, 83 (uint32_t, uint32_t, const std::string&, std::string*, bool*), 84 (override)); 85 MOCK_METHOD(bool, 86 EraseSystemOtherAvbFooter, 87 (uint32_t, uint32_t), 88 (override)); 89 MOCK_METHOD(std::optional<bool>, IsAvbEnabledOnSystemOther, (), (override)); 90 MOCK_METHOD(bool, IsRecovery, (), (override)); 91 MOCK_METHOD(bool, 92 PrepareDynamicPartitionsForUpdate, 93 (uint32_t, uint32_t, const DeltaArchiveManifest&, bool), 94 (override)); 95 MOCK_METHOD(std::unique_ptr<android::snapshot::ISnapshotWriter>, 96 OpenCowWriter, 97 (const std::string& unsuffixed_partition_name, 98 const std::optional<std::string>& source_path, 99 bool is_append), 100 (override)); 101 MOCK_METHOD(std::unique_ptr<FileDescriptor>, 102 OpenCowFd, 103 (const std::string& unsuffixed_partition_name, 104 const std::optional<std::string>& source_path, 105 bool is_append), 106 (override)); 107 MOCK_METHOD(bool, MapAllPartitions, (), (override)); 108 MOCK_METHOD(bool, UnmapAllPartitions, (), (override)); 109 MOCK_METHOD(bool, 110 IsDynamicPartition, 111 (const std::string&, uint32_t slot), 112 (override)); 113 MOCK_METHOD(bool, UpdateUsesSnapshotCompression, (), (override)); 114 set_fake_mapped_devices(const std::set<std::string> & fake)115 void set_fake_mapped_devices(const std::set<std::string>& fake) override { 116 DynamicPartitionControlAndroid::set_fake_mapped_devices(fake); 117 } 118 RealGetSystemOtherPath(uint32_t source_slot,uint32_t target_slot,const std::string & partition_name_suffix,std::string * path,bool * should_unmap)119 bool RealGetSystemOtherPath(uint32_t source_slot, 120 uint32_t target_slot, 121 const std::string& partition_name_suffix, 122 std::string* path, 123 bool* should_unmap) { 124 return DynamicPartitionControlAndroid::GetSystemOtherPath( 125 source_slot, target_slot, partition_name_suffix, path, should_unmap); 126 } 127 RealEraseSystemOtherAvbFooter(uint32_t source_slot,uint32_t target_slot)128 bool RealEraseSystemOtherAvbFooter(uint32_t source_slot, 129 uint32_t target_slot) { 130 return DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter( 131 source_slot, target_slot); 132 } 133 RealIsAvbEnabledInFstab(const std::string & path)134 std::optional<bool> RealIsAvbEnabledInFstab(const std::string& path) { 135 return DynamicPartitionControlAndroid::IsAvbEnabledInFstab(path); 136 } 137 RealPrepareDynamicPartitionsForUpdate(uint32_t source_slot,uint32_t target_slot,const DeltaArchiveManifest & manifest,bool delete_source)138 bool RealPrepareDynamicPartitionsForUpdate( 139 uint32_t source_slot, 140 uint32_t target_slot, 141 const DeltaArchiveManifest& manifest, 142 bool delete_source) { 143 return DynamicPartitionControlAndroid::PrepareDynamicPartitionsForUpdate( 144 source_slot, target_slot, manifest, delete_source); 145 } 146 using DynamicPartitionControlAndroid::SetSourceSlot; 147 using DynamicPartitionControlAndroid::SetTargetSlot; 148 }; 149 150 } // namespace chromeos_update_engine 151