| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 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> | 
| Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 20 | #include <set> | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 21 | #include <string> | 
|  | 22 |  | 
|  | 23 | #include <gmock/gmock.h> | 
|  | 24 |  | 
| Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 25 | #include "update_engine/common/boot_control_interface.h" | 
| Yifan Hong | 15726b9 | 2019-11-05 19:06:48 -0800 | [diff] [blame] | 26 | #include "update_engine/common/dynamic_partition_control_interface.h" | 
| Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 27 | #include "update_engine/dynamic_partition_control_android.h" | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 28 |  | 
|  | 29 | namespace chromeos_update_engine { | 
|  | 30 |  | 
| Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 31 | class MockDynamicPartitionControlAndroid | 
|  | 32 | : public DynamicPartitionControlAndroid { | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 33 | public: | 
| Yifan Hong | 5f32ee2 | 2020-04-15 18:22:39 -0700 | [diff] [blame] | 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, | 
| Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 55 | (const std::string&, uint32_t), | 
|  | 56 | (override)); | 
|  | 57 | MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>, | 
|  | 58 | LoadMetadataBuilder, | 
| Yifan Hong | 5f32ee2 | 2020-04-15 18:22:39 -0700 | [diff] [blame] | 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)); | 
| Yifan Hong | 302fa70 | 2020-04-16 09:48:29 -0700 | [diff] [blame] | 79 | MOCK_METHOD(bool, IsRecovery, (), (override)); | 
|  | 80 | MOCK_METHOD(bool, | 
|  | 81 | PrepareDynamicPartitionsForUpdate, | 
|  | 82 | (uint32_t, uint32_t, const DeltaArchiveManifest&, bool), | 
|  | 83 | (override)); | 
| Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 84 |  | 
|  | 85 | void set_fake_mapped_devices(const std::set<std::string>& fake) override { | 
|  | 86 | DynamicPartitionControlAndroid::set_fake_mapped_devices(fake); | 
|  | 87 | } | 
| Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 88 |  | 
|  | 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 Hong | 302fa70 | 2020-04-16 09:48:29 -0700 | [diff] [blame] | 107 |  | 
|  | 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 Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 116 | }; | 
|  | 117 |  | 
|  | 118 | }  // namespace chromeos_update_engine |