blob: e85df327504240fde9bda5e9372e590138c1b500 [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
Yifan Hong012508e2019-07-22 18:30:40 -070025#include "update_engine/common/boot_control_interface.h"
Yifan Hong15726b92019-11-05 19:06:48 -080026#include "update_engine/common/dynamic_partition_control_interface.h"
Yifan Hong012508e2019-07-22 18:30:40 -070027#include "update_engine/dynamic_partition_control_android.h"
Yifan Hong537802d2018-08-15 13:15:42 -070028
29namespace chromeos_update_engine {
30
Yifan Hong012508e2019-07-22 18:30:40 -070031class MockDynamicPartitionControlAndroid
32 : public DynamicPartitionControlAndroid {
Yifan Hong537802d2018-08-15 13:15:42 -070033 public:
Yifan Hong5f32ee22020-04-15 18:22:39 -070034 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,
Tianjie24f96092020-06-30 12:26:25 -070055 (const std::string&, uint32_t),
56 (override));
57 MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>,
58 LoadMetadataBuilder,
Yifan Hong5f32ee22020-04-15 18:22:39 -070059 (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));
Yifan Hong302fa702020-04-16 09:48:29 -070079 MOCK_METHOD(bool, IsRecovery, (), (override));
80 MOCK_METHOD(bool,
81 PrepareDynamicPartitionsForUpdate,
82 (uint32_t, uint32_t, const DeltaArchiveManifest&, bool),
83 (override));
Yifan Hong6eec9952019-12-04 13:12:01 -080084
85 void set_fake_mapped_devices(const std::set<std::string>& fake) override {
86 DynamicPartitionControlAndroid::set_fake_mapped_devices(fake);
87 }
Yifan Hong29692902020-03-26 12:47:05 -070088
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
98 bool RealEraseSystemOtherAvbFooter(uint32_t source_slot,
99 uint32_t target_slot) {
100 return DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter(
101 source_slot, target_slot);
102 }
103
104 std::optional<bool> RealIsAvbEnabledInFstab(const std::string& path) {
105 return DynamicPartitionControlAndroid::IsAvbEnabledInFstab(path);
106 }
Yifan Hong302fa702020-04-16 09:48:29 -0700107
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 }
Yifan Hong537802d2018-08-15 13:15:42 -0700116};
117
118} // namespace chromeos_update_engine