| 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 |  | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_AOSP_DYNAMIC_PARTITION_CONTROL_ANDROID_H_ | 
|  | 18 | #define UPDATE_ENGINE_AOSP_DYNAMIC_PARTITION_CONTROL_ANDROID_H_ | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 19 |  | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 20 | #include <memory> | 
|  | 21 | #include <set> | 
|  | 22 | #include <string> | 
| Tianjie | 99d570d | 2020-06-04 14:57:19 -0700 | [diff] [blame] | 23 | #include <vector> | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 24 |  | 
| Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 25 | #include <base/files/file_util.h> | 
| Yifan Hong | 2c62c13 | 2019-10-24 14:53:40 -0700 | [diff] [blame] | 26 | #include <libsnapshot/auto_device.h> | 
| Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 27 | #include <libsnapshot/snapshot.h> | 
| Kelvin Zhang | 3461852 | 2020-09-28 09:21:02 -0400 | [diff] [blame] | 28 | #include <libsnapshot/snapshot_writer.h> | 
| Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 29 |  | 
| Yifan Hong | 15726b9 | 2019-11-05 19:06:48 -0800 | [diff] [blame] | 30 | #include "update_engine/common/dynamic_partition_control_interface.h" | 
|  | 31 |  | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 32 | namespace chromeos_update_engine { | 
|  | 33 |  | 
|  | 34 | class DynamicPartitionControlAndroid : public DynamicPartitionControlInterface { | 
|  | 35 | public: | 
| Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 36 | DynamicPartitionControlAndroid(); | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 37 | ~DynamicPartitionControlAndroid(); | 
| Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 38 |  | 
| Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 39 | FeatureFlag GetDynamicPartitionsFeatureFlag() override; | 
| Yifan Hong | 413d572 | 2019-07-23 14:21:09 -0700 | [diff] [blame] | 40 | FeatureFlag GetVirtualAbFeatureFlag() override; | 
| Kelvin Zhang | da1b314 | 2020-09-24 17:09:02 -0400 | [diff] [blame] | 41 | FeatureFlag GetVirtualAbCompressionFeatureFlag() override; | 
| Yifan Hong | f526156 | 2020-03-10 10:28:10 -0700 | [diff] [blame] | 42 | bool OptimizeOperation(const std::string& partition_name, | 
|  | 43 | const InstallOperation& operation, | 
|  | 44 | InstallOperation* optimized) override; | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 45 | void Cleanup() override; | 
| Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 46 |  | 
| Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 47 | bool PreparePartitionsForUpdate(uint32_t source_slot, | 
|  | 48 | uint32_t target_slot, | 
|  | 49 | const DeltaArchiveManifest& manifest, | 
| Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 50 | bool update, | 
|  | 51 | uint64_t* required_size) override; | 
| Yifan Hong | 7b3910a | 2020-03-24 17:47:32 -0700 | [diff] [blame] | 52 | bool FinishUpdate(bool powerwash_required) override; | 
| Yifan Hong | 9096550 | 2020-02-19 15:22:47 -0800 | [diff] [blame] | 53 | std::unique_ptr<AbstractAction> GetCleanupPreviousUpdateAction( | 
|  | 54 | BootControlInterface* boot_control, | 
|  | 55 | PrefsInterface* prefs, | 
|  | 56 | CleanupPreviousUpdateActionDelegateInterface* delegate) override; | 
| Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 57 |  | 
| Yifan Hong | 6a6d0f1 | 2020-03-11 13:20:52 -0700 | [diff] [blame] | 58 | bool ResetUpdate(PrefsInterface* prefs) override; | 
|  | 59 |  | 
| Tianjie | 99d570d | 2020-06-04 14:57:19 -0700 | [diff] [blame] | 60 | bool ListDynamicPartitionsForSlot( | 
| Tianjie | 3a55fc2 | 2021-02-13 16:02:22 -0800 | [diff] [blame] | 61 | uint32_t slot, | 
|  | 62 | uint32_t current_slot, | 
|  | 63 | std::vector<std::string>* partitions) override; | 
| Tianjie | 99d570d | 2020-06-04 14:57:19 -0700 | [diff] [blame] | 64 |  | 
| Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 65 | bool VerifyExtentsForUntouchedPartitions( | 
|  | 66 | uint32_t source_slot, | 
|  | 67 | uint32_t target_slot, | 
|  | 68 | const std::vector<std::string>& partitions) override; | 
|  | 69 |  | 
| Tianjie | 99d570d | 2020-06-04 14:57:19 -0700 | [diff] [blame] | 70 | bool GetDeviceDir(std::string* path) override; | 
|  | 71 |  | 
| Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 72 | // Return the device for partition |partition_name| at slot |slot|. | 
|  | 73 | // |current_slot| should be set to the current active slot. | 
|  | 74 | // Note: this function is only used by BootControl*::GetPartitionDevice. | 
|  | 75 | // Other callers should prefer BootControl*::GetPartitionDevice over | 
|  | 76 | // BootControl*::GetDynamicPartitionControl()->GetPartitionDevice(). | 
| Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 77 | std::optional<PartitionDevice> GetPartitionDevice( | 
|  | 78 | const std::string& partition_name, | 
|  | 79 | uint32_t slot, | 
|  | 80 | uint32_t current_slot, | 
| Kelvin Zhang | 66a9ebb | 2021-01-25 13:35:10 -0500 | [diff] [blame] | 81 | bool not_in_payload); | 
| Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 82 | // Deprecated, please use GetPartitionDevice(string, uint32_t, uint32_t); | 
|  | 83 | // TODO(zhangkelvin) Remove below deprecated APIs. | 
| Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 84 | bool GetPartitionDevice(const std::string& partition_name, | 
|  | 85 | uint32_t slot, | 
|  | 86 | uint32_t current_slot, | 
| Tianjie | 51a5a39 | 2020-06-03 14:39:32 -0700 | [diff] [blame] | 87 | bool not_in_payload, | 
|  | 88 | std::string* device, | 
|  | 89 | bool* is_dynamic); | 
|  | 90 |  | 
|  | 91 | bool GetPartitionDevice(const std::string& partition_name, | 
|  | 92 | uint32_t slot, | 
|  | 93 | uint32_t current_slot, | 
| Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 94 | std::string* device); | 
|  | 95 |  | 
| Kelvin Zhang | 3461852 | 2020-09-28 09:21:02 -0400 | [diff] [blame] | 96 | // Partition name is expected to be unsuffixed. e.g. system, vendor | 
|  | 97 | // Return an interface to write to a snapshoted partition. | 
|  | 98 | std::unique_ptr<android::snapshot::ISnapshotWriter> OpenCowWriter( | 
|  | 99 | const std::string& unsuffixed_partition_name, | 
|  | 100 | const std::optional<std::string>& source_path, | 
|  | 101 | bool is_append) override; | 
| Kelvin Zhang | c82511c | 2020-11-06 16:01:24 -0500 | [diff] [blame] | 102 | FileDescriptorPtr OpenCowReader(const std::string& unsuffixed_partition_name, | 
|  | 103 | const std::optional<std::string>&, | 
|  | 104 | bool is_append = false) override; | 
| Kelvin Zhang | 3461852 | 2020-09-28 09:21:02 -0400 | [diff] [blame] | 105 |  | 
| Kelvin Zhang | 9d87d6d | 2020-10-23 17:03:59 -0400 | [diff] [blame] | 106 | bool UnmapAllPartitions() override; | 
|  | 107 |  | 
| Kelvin Zhang | eb9de16 | 2020-11-16 15:47:28 -0500 | [diff] [blame] | 108 | bool IsDynamicPartition(const std::string& part_name) override; | 
|  | 109 |  | 
| Yifan Hong | b0cbd39 | 2021-02-04 11:11:45 -0800 | [diff] [blame] | 110 | bool UpdateUsesSnapshotCompression() override; | 
|  | 111 |  | 
| Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 112 | protected: | 
|  | 113 | // These functions are exposed for testing. | 
|  | 114 |  | 
|  | 115 | // Unmap logical partition on device mapper. This is the reverse operation | 
|  | 116 | // of MapPartitionOnDeviceMapper. | 
|  | 117 | // Returns true if unmapped successfully. | 
|  | 118 | virtual bool UnmapPartitionOnDeviceMapper( | 
|  | 119 | const std::string& target_partition_name); | 
|  | 120 |  | 
| Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 121 | // Retrieves metadata from |super_device| at slot |slot|. | 
|  | 122 | virtual std::unique_ptr<android::fs_mgr::MetadataBuilder> LoadMetadataBuilder( | 
|  | 123 | const std::string& super_device, uint32_t slot); | 
|  | 124 |  | 
| Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 125 | // Retrieves metadata from |super_device| at slot |source_slot|. And | 
|  | 126 | // modifies the metadata so that during updates, the metadata can be written | 
|  | 127 | // to |target_slot|. In particular, on retrofit devices, the returned | 
|  | 128 | // metadata automatically includes block devices at |target_slot|. | 
| Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 129 | virtual std::unique_ptr<android::fs_mgr::MetadataBuilder> LoadMetadataBuilder( | 
| Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 130 | const std::string& super_device, | 
|  | 131 | uint32_t source_slot, | 
| Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 132 | uint32_t target_slot); | 
|  | 133 |  | 
|  | 134 | // Write metadata |builder| to |super_device| at slot |target_slot|. | 
|  | 135 | virtual bool StoreMetadata(const std::string& super_device, | 
|  | 136 | android::fs_mgr::MetadataBuilder* builder, | 
|  | 137 | uint32_t target_slot); | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 138 |  | 
| Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 139 | // Map logical partition on device-mapper. | 
|  | 140 | // |super_device| is the device path of the physical partition ("super"). | 
|  | 141 | // |target_partition_name| is the identifier used in metadata; for example, | 
|  | 142 | // "vendor_a" | 
|  | 143 | // |slot| is the selected slot to mount; for example, 0 for "_a". | 
|  | 144 | // Returns true if mapped successfully; if so, |path| is set to the device | 
|  | 145 | // path of the mapped logical partition. | 
|  | 146 | virtual bool MapPartitionOnDeviceMapper( | 
|  | 147 | const std::string& super_device, | 
|  | 148 | const std::string& target_partition_name, | 
|  | 149 | uint32_t slot, | 
|  | 150 | bool force_writable, | 
|  | 151 | std::string* path); | 
|  | 152 |  | 
|  | 153 | // Return true if a static partition exists at device path |path|. | 
|  | 154 | virtual bool DeviceExists(const std::string& path); | 
|  | 155 |  | 
|  | 156 | // Returns the current state of the underlying device mapper device | 
|  | 157 | // with given name. | 
|  | 158 | // One of INVALID, SUSPENDED or ACTIVE. | 
|  | 159 | virtual android::dm::DmDeviceState GetState(const std::string& name); | 
|  | 160 |  | 
|  | 161 | // Returns the path to the device mapper device node in '/dev' corresponding | 
|  | 162 | // to 'name'. If the device does not exist, false is returned, and the path | 
|  | 163 | // parameter is not set. | 
|  | 164 | virtual bool GetDmDevicePathByName(const std::string& name, | 
|  | 165 | std::string* path); | 
|  | 166 |  | 
| Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 167 | // Return the name of the super partition (which stores super partition | 
|  | 168 | // metadata) for a given slot. | 
|  | 169 | virtual std::string GetSuperPartitionName(uint32_t slot); | 
|  | 170 |  | 
| Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 171 | virtual void set_fake_mapped_devices(const std::set<std::string>& fake); | 
|  | 172 |  | 
| Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 173 | // Allow mock objects to override this to test recovery mode. | 
|  | 174 | virtual bool IsRecovery(); | 
|  | 175 |  | 
| Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 176 | // Determine path for system_other partition. | 
|  | 177 | // |source_slot| should be current slot. | 
|  | 178 | // |target_slot| should be "other" slot. | 
|  | 179 | // |partition_name_suffix| should be "system" + suffix(|target_slot|). | 
|  | 180 | // Return true and set |path| if successful. | 
|  | 181 | // Set |path| to empty if no need to erase system_other. | 
|  | 182 | // Set |should_unmap| to true if path needs to be unmapped later. | 
|  | 183 | // | 
|  | 184 | // Note: system_other cannot use GetPartitionDevice or | 
|  | 185 | // GetDynamicPartitionDevice because: | 
|  | 186 | // - super partition metadata may be loaded from the source slot | 
|  | 187 | // - UPDATED flag needs to be check to skip erasing if partition is not | 
|  | 188 | //   created by flashing tools | 
|  | 189 | // - Snapshots from previous update attempts should not be used. | 
|  | 190 | virtual bool GetSystemOtherPath(uint32_t source_slot, | 
|  | 191 | uint32_t target_slot, | 
|  | 192 | const std::string& partition_name_suffix, | 
|  | 193 | std::string* path, | 
|  | 194 | bool* should_unmap); | 
|  | 195 |  | 
|  | 196 | // Returns true if any entry in the fstab file in |path| has AVB enabled, | 
|  | 197 | // false if not enabled, and nullopt for any error. | 
|  | 198 | virtual std::optional<bool> IsAvbEnabledInFstab(const std::string& path); | 
|  | 199 |  | 
|  | 200 | // Returns true if system_other has AVB enabled, false if not enabled, and | 
|  | 201 | // nullopt for any error. | 
|  | 202 | virtual std::optional<bool> IsAvbEnabledOnSystemOther(); | 
|  | 203 |  | 
|  | 204 | // Erase system_other partition that may contain system_other.img. | 
|  | 205 | // After the update, the content of system_other may be corrupted but with | 
|  | 206 | // valid AVB footer. If the update is rolled back and factory data reset is | 
|  | 207 | // triggered, system_b fails to be mapped with verity errors (see | 
|  | 208 | // b/152444348). Erase the system_other so that mapping system_other is | 
|  | 209 | // skipped. | 
|  | 210 | virtual bool EraseSystemOtherAvbFooter(uint32_t source_slot, | 
|  | 211 | uint32_t target_slot); | 
|  | 212 |  | 
| Yifan Hong | 302fa70 | 2020-04-16 09:48:29 -0700 | [diff] [blame] | 213 | // Helper for PreparePartitionsForUpdate. Used for devices with dynamic | 
|  | 214 | // partitions updating without snapshots. | 
|  | 215 | // If |delete_source| is set, source partitions are deleted before resizing | 
|  | 216 | // target partitions (using DeleteSourcePartitions). | 
|  | 217 | virtual bool PrepareDynamicPartitionsForUpdate( | 
|  | 218 | uint32_t source_slot, | 
|  | 219 | uint32_t target_slot, | 
|  | 220 | const DeltaArchiveManifest& manifest, | 
|  | 221 | bool delete_source); | 
|  | 222 |  | 
| Kelvin Zhang | 9d87d6d | 2020-10-23 17:03:59 -0400 | [diff] [blame] | 223 | bool MapAllPartitions() override; | 
|  | 224 |  | 
| Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 225 | void SetSourceSlot(uint32_t slot) { source_slot_ = slot; } | 
|  | 226 | void SetTargetSlot(uint32_t slot) { target_slot_ = slot; } | 
|  | 227 |  | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 228 | private: | 
| Yifan Hong | c049f93 | 2019-07-23 15:06:05 -0700 | [diff] [blame] | 229 | friend class DynamicPartitionControlAndroidTest; | 
| Yifan Hong | 302fa70 | 2020-04-16 09:48:29 -0700 | [diff] [blame] | 230 | friend class SnapshotPartitionTestP; | 
| Yifan Hong | c049f93 | 2019-07-23 15:06:05 -0700 | [diff] [blame] | 231 |  | 
| Kelvin Zhang | 9d87d6d | 2020-10-23 17:03:59 -0400 | [diff] [blame] | 232 | std::optional<base::FilePath> GetSuperDevice(); | 
|  | 233 |  | 
| Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 234 | bool MapPartitionInternal(const std::string& super_device, | 
|  | 235 | const std::string& target_partition_name, | 
|  | 236 | uint32_t slot, | 
|  | 237 | bool force_writable, | 
|  | 238 | std::string* path); | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 239 |  | 
| Yifan Hong | 8d6df9a | 2020-08-13 13:59:54 -0700 | [diff] [blame] | 240 | // Update |builder| according to |partition_metadata|. | 
|  | 241 | // - In Android mode, this is only called when the device | 
|  | 242 | //   does not have Virtual A/B. | 
|  | 243 | // - When sideloading, this maybe called as a fallback path if CoW cannot | 
|  | 244 | //   be created. | 
| Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 245 | bool UpdatePartitionMetadata(android::fs_mgr::MetadataBuilder* builder, | 
|  | 246 | uint32_t target_slot, | 
|  | 247 | const DeltaArchiveManifest& manifest); | 
| Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 248 |  | 
| Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 249 | // Helper for PreparePartitionsForUpdate. Used for snapshotted partitions | 
|  | 250 | // for Virtual A/B update. | 
| Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 251 | bool PrepareSnapshotPartitionsForUpdate(uint32_t source_slot, | 
|  | 252 | uint32_t target_slot, | 
| Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 253 | const DeltaArchiveManifest& manifest, | 
|  | 254 | uint64_t* required_size); | 
| Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 255 |  | 
| Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 256 | enum class DynamicPartitionDeviceStatus { | 
|  | 257 | SUCCESS, | 
|  | 258 | ERROR, | 
|  | 259 | TRY_STATIC, | 
|  | 260 | }; | 
|  | 261 |  | 
|  | 262 | // Return SUCCESS and path in |device| if partition is dynamic. | 
|  | 263 | // Return ERROR if any error. | 
|  | 264 | // Return TRY_STATIC if caller should resolve the partition as a static | 
|  | 265 | // partition instead. | 
|  | 266 | DynamicPartitionDeviceStatus GetDynamicPartitionDevice( | 
|  | 267 | const base::FilePath& device_dir, | 
|  | 268 | const std::string& partition_name_suffix, | 
|  | 269 | uint32_t slot, | 
|  | 270 | uint32_t current_slot, | 
| Tianjie | 51a5a39 | 2020-06-03 14:39:32 -0700 | [diff] [blame] | 271 | bool not_in_payload, | 
| Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 272 | std::string* device); | 
|  | 273 |  | 
|  | 274 | // Return true if |partition_name_suffix| is a block device of | 
|  | 275 | // super partition metadata slot |slot|. | 
|  | 276 | bool IsSuperBlockDevice(const base::FilePath& device_dir, | 
|  | 277 | uint32_t current_slot, | 
|  | 278 | const std::string& partition_name_suffix); | 
|  | 279 |  | 
| Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 280 | // If sideloading a full OTA, delete source partitions from |builder|. | 
|  | 281 | bool DeleteSourcePartitions(android::fs_mgr::MetadataBuilder* builder, | 
|  | 282 | uint32_t source_slot, | 
|  | 283 | const DeltaArchiveManifest& manifest); | 
|  | 284 |  | 
| Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 285 | // Returns true if metadata is expected to be mounted, false otherwise. | 
|  | 286 | // Note that it returns false on non-Virtual A/B devices. | 
|  | 287 | // | 
| Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 288 | // Almost all functions of SnapshotManager depends on metadata being | 
|  | 289 | // mounted. | 
| Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 290 | // - In Android mode for Virtual A/B devices, assume it is mounted. If not, | 
|  | 291 | //   let caller fails when calling into SnapshotManager. | 
| Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 292 | // - In recovery for Virtual A/B devices, it is possible that metadata is | 
|  | 293 | // not | 
| Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 294 | //   formatted, hence it cannot be mounted. Caller should not call into | 
|  | 295 | //   SnapshotManager. | 
| Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 296 | // - On non-Virtual A/B devices, updates do not depend on metadata | 
|  | 297 | // partition. | 
| Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 298 | //   Caller should not call into SnapshotManager. | 
|  | 299 | // | 
| Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 300 | // This function does NOT mount metadata partition. Use | 
|  | 301 | // EnsureMetadataMounted to mount metadata partition. | 
| Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 302 | bool ExpectMetadataMounted(); | 
|  | 303 |  | 
|  | 304 | // Ensure /metadata is mounted. Returns true if successful, false otherwise. | 
|  | 305 | // | 
|  | 306 | // Note that this function returns true on non-Virtual A/B devices without | 
|  | 307 | // doing anything. | 
|  | 308 | bool EnsureMetadataMounted(); | 
|  | 309 |  | 
| Yifan Hong | f6f75c2 | 2020-07-31 15:20:25 -0700 | [diff] [blame] | 310 | // Set boolean flags related to target build. This includes flags like | 
|  | 311 | // target_supports_snapshot_ and is_target_dynamic_. | 
|  | 312 | bool SetTargetBuildVars(const DeltaArchiveManifest& manifest); | 
|  | 313 |  | 
| Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 314 | std::set<std::string> mapped_devices_; | 
| Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 315 | const FeatureFlag dynamic_partitions_; | 
|  | 316 | const FeatureFlag virtual_ab_; | 
| Kelvin Zhang | da1b314 | 2020-09-24 17:09:02 -0400 | [diff] [blame] | 317 | const FeatureFlag virtual_ab_compression_; | 
| Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 318 | std::unique_ptr<android::snapshot::ISnapshotManager> snapshot_; | 
| Yifan Hong | 2c62c13 | 2019-10-24 14:53:40 -0700 | [diff] [blame] | 319 | std::unique_ptr<android::snapshot::AutoDevice> metadata_device_; | 
| Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 320 | bool target_supports_snapshot_ = false; | 
| Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 321 | // Whether the target partitions should be loaded as dynamic partitions. Set | 
|  | 322 | // by PreparePartitionsForUpdate() per each update. | 
|  | 323 | bool is_target_dynamic_ = false; | 
| Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 324 |  | 
| Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 325 | uint32_t source_slot_ = UINT32_MAX; | 
|  | 326 | uint32_t target_slot_ = UINT32_MAX; | 
| Kelvin Zhang | eb9de16 | 2020-11-16 15:47:28 -0500 | [diff] [blame] | 327 | std::vector<std::string> dynamic_partition_list_; | 
| Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 328 |  | 
| Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 329 | DISALLOW_COPY_AND_ASSIGN(DynamicPartitionControlAndroid); | 
|  | 330 | }; | 
|  | 331 |  | 
|  | 332 | }  // namespace chromeos_update_engine | 
|  | 333 |  | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 334 | #endif  // UPDATE_ENGINE_AOSP_DYNAMIC_PARTITION_CONTROL_ANDROID_H_ |