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 "update_engine/common/boot_control_interface.h"
26 #include "update_engine/common/dynamic_partition_control_interface.h"
27 #include "update_engine/dynamic_partition_control_android.h"
28 
29 namespace chromeos_update_engine {
30 
31 class MockDynamicPartitionControlAndroid
32     : public DynamicPartitionControlAndroid {
33  public:
34   MOCK_METHOD(
35       bool,
36       MapPartitionOnDeviceMapper,
37       (const std::string&, const std::string&, uint32_t, bool, std::string*),
38       (override));
39   MOCK_METHOD(bool,
40               UnmapPartitionOnDeviceMapper,
41               (const std::string&),
42               (override));
43   MOCK_METHOD(void, Cleanup, (), (override));
44   MOCK_METHOD(bool, DeviceExists, (const std::string&), (override));
45   MOCK_METHOD(::android::dm::DmDeviceState,
46               GetState,
47               (const std::string&),
48               (override));
49   MOCK_METHOD(bool,
50               GetDmDevicePathByName,
51               (const std::string&, std::string*),
52               (override));
53   MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>,
54               LoadMetadataBuilder,
55               (const std::string&, uint32_t),
56               (override));
57   MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>,
58               LoadMetadataBuilder,
59               (const std::string&, uint32_t, uint32_t),
60               (override));
61   MOCK_METHOD(bool,
62               StoreMetadata,
63               (const std::string&, android::fs_mgr::MetadataBuilder*, uint32_t),
64               (override));
65   MOCK_METHOD(bool, GetDeviceDir, (std::string*), (override));
66   MOCK_METHOD(FeatureFlag, GetDynamicPartitionsFeatureFlag, (), (override));
67   MOCK_METHOD(std::string, GetSuperPartitionName, (uint32_t), (override));
68   MOCK_METHOD(FeatureFlag, GetVirtualAbFeatureFlag, (), (override));
69   MOCK_METHOD(bool, FinishUpdate, (bool), (override));
70   MOCK_METHOD(bool,
71               GetSystemOtherPath,
72               (uint32_t, uint32_t, const std::string&, std::string*, bool*),
73               (override));
74   MOCK_METHOD(bool,
75               EraseSystemOtherAvbFooter,
76               (uint32_t, uint32_t),
77               (override));
78   MOCK_METHOD(std::optional<bool>, IsAvbEnabledOnSystemOther, (), (override));
79   MOCK_METHOD(bool, IsRecovery, (), (override));
80   MOCK_METHOD(bool,
81               PrepareDynamicPartitionsForUpdate,
82               (uint32_t, uint32_t, const DeltaArchiveManifest&, bool),
83               (override));
84 
set_fake_mapped_devices(const std::set<std::string> & fake)85   void set_fake_mapped_devices(const std::set<std::string>& fake) override {
86     DynamicPartitionControlAndroid::set_fake_mapped_devices(fake);
87   }
88 
RealGetSystemOtherPath(uint32_t source_slot,uint32_t target_slot,const std::string & partition_name_suffix,std::string * path,bool * should_unmap)89   bool RealGetSystemOtherPath(uint32_t source_slot,
90                               uint32_t target_slot,
91                               const std::string& partition_name_suffix,
92                               std::string* path,
93                               bool* should_unmap) {
94     return DynamicPartitionControlAndroid::GetSystemOtherPath(
95         source_slot, target_slot, partition_name_suffix, path, should_unmap);
96   }
97 
RealEraseSystemOtherAvbFooter(uint32_t source_slot,uint32_t target_slot)98   bool RealEraseSystemOtherAvbFooter(uint32_t source_slot,
99                                      uint32_t target_slot) {
100     return DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter(
101         source_slot, target_slot);
102   }
103 
RealIsAvbEnabledInFstab(const std::string & path)104   std::optional<bool> RealIsAvbEnabledInFstab(const std::string& path) {
105     return DynamicPartitionControlAndroid::IsAvbEnabledInFstab(path);
106   }
107 
RealPrepareDynamicPartitionsForUpdate(uint32_t source_slot,uint32_t target_slot,const DeltaArchiveManifest & manifest,bool delete_source)108   bool RealPrepareDynamicPartitionsForUpdate(
109       uint32_t source_slot,
110       uint32_t target_slot,
111       const DeltaArchiveManifest& manifest,
112       bool delete_source) {
113     return DynamicPartitionControlAndroid::PrepareDynamicPartitionsForUpdate(
114         source_slot, target_slot, manifest, delete_source);
115   }
116 };
117 
118 }  // namespace chromeos_update_engine
119