• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(FeatureFlag,
81               GetVirtualAbUserspaceSnapshotsFeatureFlag,
82               (),
83               (override));
84   MOCK_METHOD(bool, FinishUpdate, (bool), (override));
85   MOCK_METHOD(bool,
86               GetSystemOtherPath,
87               (uint32_t, uint32_t, const std::string&, std::string*, bool*),
88               (override));
89   MOCK_METHOD(bool,
90               EraseSystemOtherAvbFooter,
91               (uint32_t, uint32_t),
92               (override));
93   MOCK_METHOD(std::optional<bool>, IsAvbEnabledOnSystemOther, (), (override));
94   MOCK_METHOD(bool, IsRecovery, (), (override));
95   MOCK_METHOD(bool,
96               PrepareDynamicPartitionsForUpdate,
97               (uint32_t, uint32_t, const DeltaArchiveManifest&, bool),
98               (override));
99   MOCK_METHOD(std::unique_ptr<android::snapshot::ISnapshotWriter>,
100               OpenCowWriter,
101               (const std::string& unsuffixed_partition_name,
102                const std::optional<std::string>& source_path,
103                bool is_append),
104               (override));
105   MOCK_METHOD(std::unique_ptr<FileDescriptor>,
106               OpenCowFd,
107               (const std::string& unsuffixed_partition_name,
108                const std::optional<std::string>& source_path,
109                bool is_append),
110               (override));
111   MOCK_METHOD(bool, MapAllPartitions, (), (override));
112   MOCK_METHOD(bool, UnmapAllPartitions, (), (override));
113   MOCK_METHOD(bool,
114               IsDynamicPartition,
115               (const std::string&, uint32_t slot),
116               (override));
117   MOCK_METHOD(bool, UpdateUsesSnapshotCompression, (), (override));
118 
set_fake_mapped_devices(const std::set<std::string> & fake)119   void set_fake_mapped_devices(const std::set<std::string>& fake) override {
120     DynamicPartitionControlAndroid::set_fake_mapped_devices(fake);
121   }
122 
RealGetSystemOtherPath(uint32_t source_slot,uint32_t target_slot,const std::string & partition_name_suffix,std::string * path,bool * should_unmap)123   bool RealGetSystemOtherPath(uint32_t source_slot,
124                               uint32_t target_slot,
125                               const std::string& partition_name_suffix,
126                               std::string* path,
127                               bool* should_unmap) {
128     return DynamicPartitionControlAndroid::GetSystemOtherPath(
129         source_slot, target_slot, partition_name_suffix, path, should_unmap);
130   }
131 
RealEraseSystemOtherAvbFooter(uint32_t source_slot,uint32_t target_slot)132   bool RealEraseSystemOtherAvbFooter(uint32_t source_slot,
133                                      uint32_t target_slot) {
134     return DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter(
135         source_slot, target_slot);
136   }
137 
RealIsAvbEnabledInFstab(const std::string & path)138   std::optional<bool> RealIsAvbEnabledInFstab(const std::string& path) {
139     return DynamicPartitionControlAndroid::IsAvbEnabledInFstab(path);
140   }
141 
RealPrepareDynamicPartitionsForUpdate(uint32_t source_slot,uint32_t target_slot,const DeltaArchiveManifest & manifest,bool delete_source)142   bool RealPrepareDynamicPartitionsForUpdate(
143       uint32_t source_slot,
144       uint32_t target_slot,
145       const DeltaArchiveManifest& manifest,
146       bool delete_source) {
147     return DynamicPartitionControlAndroid::PrepareDynamicPartitionsForUpdate(
148         source_slot, target_slot, manifest, delete_source);
149   }
150   using DynamicPartitionControlAndroid::SetSourceSlot;
151   using DynamicPartitionControlAndroid::SetTargetSlot;
152 };
153 
154 }  // namespace chromeos_update_engine
155