blob: 5144cbbc59c5b7ae0e7ce496bb85d8897700a681 [file] [log] [blame]
Yifan Hong537802d2018-08-15 13:15:42 -07001//
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>
Yifan Hong6eec9952019-12-04 13:12:01 -080020#include <set>
Yifan Hong537802d2018-08-15 13:15:42 -070021#include <string>
22
23#include <gmock/gmock.h>
24
Kelvin Zhang34618522020-09-28 09:21:02 -040025#include <libsnapshot/cow_writer.h>
26
27#include "libsnapshot/snapshot_writer.h"
Yifan Hong012508e2019-07-22 18:30:40 -070028#include "update_engine/common/boot_control_interface.h"
Yifan Hong15726b92019-11-05 19:06:48 -080029#include "update_engine/common/dynamic_partition_control_interface.h"
Yifan Hong012508e2019-07-22 18:30:40 -070030#include "update_engine/dynamic_partition_control_android.h"
Yifan Hong537802d2018-08-15 13:15:42 -070031
32namespace chromeos_update_engine {
33
Yifan Hong012508e2019-07-22 18:30:40 -070034class MockDynamicPartitionControlAndroid
35 : public DynamicPartitionControlAndroid {
Yifan Hong537802d2018-08-15 13:15:42 -070036 public:
Yifan Hong5f32ee22020-04-15 18:22:39 -070037 MOCK_METHOD(
38 bool,
39 MapPartitionOnDeviceMapper,
40 (const std::string&, const std::string&, uint32_t, bool, std::string*),
41 (override));
42 MOCK_METHOD(bool,
43 UnmapPartitionOnDeviceMapper,
44 (const std::string&),
45 (override));
46 MOCK_METHOD(void, Cleanup, (), (override));
47 MOCK_METHOD(bool, DeviceExists, (const std::string&), (override));
48 MOCK_METHOD(::android::dm::DmDeviceState,
49 GetState,
50 (const std::string&),
51 (override));
52 MOCK_METHOD(bool,
53 GetDmDevicePathByName,
54 (const std::string&, std::string*),
55 (override));
56 MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>,
57 LoadMetadataBuilder,
Tianjie24f96092020-06-30 12:26:25 -070058 (const std::string&, uint32_t),
59 (override));
60 MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>,
61 LoadMetadataBuilder,
Yifan Hong5f32ee22020-04-15 18:22:39 -070062 (const std::string&, uint32_t, uint32_t),
63 (override));
64 MOCK_METHOD(bool,
65 StoreMetadata,
66 (const std::string&, android::fs_mgr::MetadataBuilder*, uint32_t),
67 (override));
68 MOCK_METHOD(bool, GetDeviceDir, (std::string*), (override));
69 MOCK_METHOD(FeatureFlag, GetDynamicPartitionsFeatureFlag, (), (override));
70 MOCK_METHOD(std::string, GetSuperPartitionName, (uint32_t), (override));
71 MOCK_METHOD(FeatureFlag, GetVirtualAbFeatureFlag, (), (override));
72 MOCK_METHOD(bool, FinishUpdate, (bool), (override));
73 MOCK_METHOD(bool,
74 GetSystemOtherPath,
75 (uint32_t, uint32_t, const std::string&, std::string*, bool*),
76 (override));
77 MOCK_METHOD(bool,
78 EraseSystemOtherAvbFooter,
79 (uint32_t, uint32_t),
80 (override));
81 MOCK_METHOD(std::optional<bool>, IsAvbEnabledOnSystemOther, (), (override));
Yifan Hong302fa702020-04-16 09:48:29 -070082 MOCK_METHOD(bool, IsRecovery, (), (override));
83 MOCK_METHOD(bool,
84 PrepareDynamicPartitionsForUpdate,
85 (uint32_t, uint32_t, const DeltaArchiveManifest&, bool),
86 (override));
Kelvin Zhang34618522020-09-28 09:21:02 -040087 MOCK_METHOD(std::unique_ptr<android::snapshot::ISnapshotWriter>,
88 OpenCowWriter,
89 (const std::string& unsuffixed_partition_name,
90 const std::optional<std::string>& source_path,
91 bool is_append),
92 (override));
Yifan Hong6eec9952019-12-04 13:12:01 -080093
94 void set_fake_mapped_devices(const std::set<std::string>& fake) override {
95 DynamicPartitionControlAndroid::set_fake_mapped_devices(fake);
96 }
Yifan Hong29692902020-03-26 12:47:05 -070097
98 bool RealGetSystemOtherPath(uint32_t source_slot,
99 uint32_t target_slot,
100 const std::string& partition_name_suffix,
101 std::string* path,
102 bool* should_unmap) {
103 return DynamicPartitionControlAndroid::GetSystemOtherPath(
104 source_slot, target_slot, partition_name_suffix, path, should_unmap);
105 }
106
107 bool RealEraseSystemOtherAvbFooter(uint32_t source_slot,
108 uint32_t target_slot) {
109 return DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter(
110 source_slot, target_slot);
111 }
112
113 std::optional<bool> RealIsAvbEnabledInFstab(const std::string& path) {
114 return DynamicPartitionControlAndroid::IsAvbEnabledInFstab(path);
115 }
Yifan Hong302fa702020-04-16 09:48:29 -0700116
117 bool RealPrepareDynamicPartitionsForUpdate(
118 uint32_t source_slot,
119 uint32_t target_slot,
120 const DeltaArchiveManifest& manifest,
121 bool delete_source) {
122 return DynamicPartitionControlAndroid::PrepareDynamicPartitionsForUpdate(
123 source_slot, target_slot, manifest, delete_source);
124 }
Yifan Hong537802d2018-08-15 13:15:42 -0700125};
126
127} // namespace chromeos_update_engine