blob: 4220445c6aa279c05ee7da44e6df3f7d239413fc [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
Amin Hassaniec7bc112020-10-29 16:47:58 -070017#include "update_engine/aosp/dynamic_partition_control_android.h"
Yifan Hong537802d2018-08-15 13:15:42 -070018
Kelvin Zhang91d95fa2020-11-05 13:52:00 -050019#include <algorithm>
Yifan Hong420db9b2019-07-23 20:50:33 -070020#include <chrono> // NOLINT(build/c++11) - using libsnapshot / liblp API
Kelvin Zhang34618522020-09-28 09:21:02 -040021#include <cstdint>
Yifan Hong13d41cb2019-09-16 13:18:22 -070022#include <map>
Yifan Hong537802d2018-08-15 13:15:42 -070023#include <memory>
24#include <set>
25#include <string>
Tianjie99d570d2020-06-04 14:57:19 -070026#include <string_view>
27#include <utility>
Yifan Hong012508e2019-07-22 18:30:40 -070028#include <vector>
Yifan Hong537802d2018-08-15 13:15:42 -070029
30#include <android-base/properties.h>
31#include <android-base/strings.h>
32#include <base/files/file_util.h>
33#include <base/logging.h>
Yifan Hong012508e2019-07-22 18:30:40 -070034#include <base/strings/string_util.h>
Yifan Hong537802d2018-08-15 13:15:42 -070035#include <bootloader_message/bootloader_message.h>
Yifan Hong012508e2019-07-22 18:30:40 -070036#include <fs_mgr.h>
Yifan Hong537802d2018-08-15 13:15:42 -070037#include <fs_mgr_dm_linear.h>
Yifan Hong3a1a5612019-11-05 16:34:32 -080038#include <fs_mgr_overlayfs.h>
Yifan Hong29692902020-03-26 12:47:05 -070039#include <libavb/libavb.h>
Yifan Hong3a1a5612019-11-05 16:34:32 -080040#include <libdm/dm.h>
Kelvin Zhang34618522020-09-28 09:21:02 -040041#include <liblp/liblp.h>
42#include <libsnapshot/cow_writer.h>
Yifan Hong420db9b2019-07-23 20:50:33 -070043#include <libsnapshot/snapshot.h>
Yifan Hongf9cb4492020-04-15 13:00:20 -070044#include <libsnapshot/snapshot_stub.h>
Yifan Hong537802d2018-08-15 13:15:42 -070045
Amin Hassaniec7bc112020-10-29 16:47:58 -070046#include "update_engine/aosp/cleanup_previous_update_action.h"
47#include "update_engine/aosp/dynamic_partition_utils.h"
Yifan Hong537802d2018-08-15 13:15:42 -070048#include "update_engine/common/boot_control_interface.h"
Kelvin Zhangb9a5f612021-01-22 14:34:05 -050049#include "update_engine/common/dynamic_partition_control_interface.h"
50#include "update_engine/common/platform_constants.h"
Yifan Hong537802d2018-08-15 13:15:42 -070051#include "update_engine/common/utils.h"
Yifan Hong6a6d0f12020-03-11 13:20:52 -070052#include "update_engine/payload_consumer/delta_performer.h"
Yifan Hong537802d2018-08-15 13:15:42 -070053
54using android::base::GetBoolProperty;
Yifan Hong29692902020-03-26 12:47:05 -070055using android::base::GetProperty;
Yifan Hong537802d2018-08-15 13:15:42 -070056using android::base::Join;
57using android::dm::DeviceMapper;
58using android::dm::DmDeviceState;
59using android::fs_mgr::CreateLogicalPartition;
David Andersonbb90dfb2019-08-13 14:14:56 -070060using android::fs_mgr::CreateLogicalPartitionParams;
Yifan Hong537802d2018-08-15 13:15:42 -070061using android::fs_mgr::DestroyLogicalPartition;
Yifan Hong29692902020-03-26 12:47:05 -070062using android::fs_mgr::Fstab;
Yifan Hong537802d2018-08-15 13:15:42 -070063using android::fs_mgr::MetadataBuilder;
Yifan Hong012508e2019-07-22 18:30:40 -070064using android::fs_mgr::Partition;
Yifan Hong6e706b12018-11-09 16:50:51 -080065using android::fs_mgr::PartitionOpener;
Yifan Hong012508e2019-07-22 18:30:40 -070066using android::fs_mgr::SlotSuffixForSlotNumber;
Yifan Hongf5261562020-03-10 10:28:10 -070067using android::snapshot::OptimizeSourceCopyOperation;
Yifan Hong0850bca2020-01-16 15:14:07 -080068using android::snapshot::Return;
Yifan Hongf033ecb2020-01-07 18:13:56 -080069using android::snapshot::SnapshotManager;
Yifan Hongf9cb4492020-04-15 13:00:20 -070070using android::snapshot::SnapshotManagerStub;
Yifan Hong2257ee12020-01-13 18:33:00 -080071using android::snapshot::UpdateState;
Yifan Hong537802d2018-08-15 13:15:42 -070072
73namespace chromeos_update_engine {
74
Yifan Hong6e706b12018-11-09 16:50:51 -080075constexpr char kUseDynamicPartitions[] = "ro.boot.dynamic_partitions";
76constexpr char kRetrfoitDynamicPartitions[] =
77 "ro.boot.dynamic_partitions_retrofit";
Yifan Hong413d5722019-07-23 14:21:09 -070078constexpr char kVirtualAbEnabled[] = "ro.virtual_ab.enabled";
79constexpr char kVirtualAbRetrofit[] = "ro.virtual_ab.retrofit";
Kelvin Zhangda1b3142020-09-24 17:09:02 -040080constexpr char kVirtualAbCompressionEnabled[] =
81 "ro.virtual_ab.compression.enabled";
82
83// Currently, android doesn't have a retrofit prop for VAB Compression. However,
84// struct FeatureFlag forces us to determine if a feature is 'retrofit'. So this
85// is here just to simplify code. Replace it with real retrofit prop name once
86// there is one.
87constexpr char kVirtualAbCompressionRetrofit[] = "";
Yifan Hong29692902020-03-26 12:47:05 -070088constexpr char kPostinstallFstabPrefix[] = "ro.postinstall.fstab.prefix";
Yifan Hong420db9b2019-07-23 20:50:33 -070089// Map timeout for dynamic partitions.
90constexpr std::chrono::milliseconds kMapTimeout{1000};
91// Map timeout for dynamic partitions with snapshots. Since several devices
92// needs to be mapped, this timeout is longer than |kMapTimeout|.
93constexpr std::chrono::milliseconds kMapSnapshotTimeout{5000};
94
Yifan Hong537802d2018-08-15 13:15:42 -070095DynamicPartitionControlAndroid::~DynamicPartitionControlAndroid() {
Yifan Hongbae27842019-10-24 16:56:12 -070096 Cleanup();
Yifan Hong537802d2018-08-15 13:15:42 -070097}
98
Yifan Hong186bb682019-07-23 14:04:39 -070099static FeatureFlag GetFeatureFlag(const char* enable_prop,
100 const char* retrofit_prop) {
Kelvin Zhangda1b3142020-09-24 17:09:02 -0400101 // Default retrofit to false if retrofit_prop is empty.
102 bool retrofit = retrofit_prop && retrofit_prop[0] != '\0' &&
103 GetBoolProperty(retrofit_prop, false);
Yifan Hong186bb682019-07-23 14:04:39 -0700104 bool enabled = GetBoolProperty(enable_prop, false);
105 if (retrofit && !enabled) {
106 LOG(ERROR) << retrofit_prop << " is true but " << enable_prop
107 << " is not. These sysprops are inconsistent. Assume that "
108 << enable_prop << " is true from now on.";
109 }
110 if (retrofit) {
111 return FeatureFlag(FeatureFlag::Value::RETROFIT);
112 }
113 if (enabled) {
114 return FeatureFlag(FeatureFlag::Value::LAUNCH);
115 }
116 return FeatureFlag(FeatureFlag::Value::NONE);
Yifan Hong537802d2018-08-15 13:15:42 -0700117}
118
Kelvin Zhangebd115e2021-03-08 16:10:25 -0500119DynamicPartitionControlAndroid::DynamicPartitionControlAndroid(
120 uint32_t source_slot)
Yifan Hongb38e1af2019-10-17 14:59:22 -0700121 : dynamic_partitions_(
122 GetFeatureFlag(kUseDynamicPartitions, kRetrfoitDynamicPartitions)),
Kelvin Zhangda1b3142020-09-24 17:09:02 -0400123 virtual_ab_(GetFeatureFlag(kVirtualAbEnabled, kVirtualAbRetrofit)),
124 virtual_ab_compression_(GetFeatureFlag(kVirtualAbCompressionEnabled,
Kelvin Zhangebd115e2021-03-08 16:10:25 -0500125 kVirtualAbCompressionRetrofit)),
126 source_slot_(source_slot) {
Yifan Hongb38e1af2019-10-17 14:59:22 -0700127 if (GetVirtualAbFeatureFlag().IsEnabled()) {
Yifan Hongf033ecb2020-01-07 18:13:56 -0800128 snapshot_ = SnapshotManager::New();
Yifan Hongf9cb4492020-04-15 13:00:20 -0700129 } else {
130 snapshot_ = SnapshotManagerStub::New();
Yifan Hongb38e1af2019-10-17 14:59:22 -0700131 }
Yifan Hongf9cb4492020-04-15 13:00:20 -0700132 CHECK(snapshot_ != nullptr) << "Cannot initialize SnapshotManager.";
Yifan Hongb38e1af2019-10-17 14:59:22 -0700133}
134
Yifan Hong186bb682019-07-23 14:04:39 -0700135FeatureFlag DynamicPartitionControlAndroid::GetDynamicPartitionsFeatureFlag() {
Yifan Hongb38e1af2019-10-17 14:59:22 -0700136 return dynamic_partitions_;
Yifan Hong6e706b12018-11-09 16:50:51 -0800137}
138
Yifan Hong413d5722019-07-23 14:21:09 -0700139FeatureFlag DynamicPartitionControlAndroid::GetVirtualAbFeatureFlag() {
Yifan Hongb38e1af2019-10-17 14:59:22 -0700140 return virtual_ab_;
Yifan Hong413d5722019-07-23 14:21:09 -0700141}
142
Kelvin Zhangda1b3142020-09-24 17:09:02 -0400143FeatureFlag
144DynamicPartitionControlAndroid::GetVirtualAbCompressionFeatureFlag() {
Kelvin Zhangb9a5f612021-01-22 14:34:05 -0500145 if constexpr (constants::kIsRecovery) {
146 // Don't attempt VABC in recovery
147 return FeatureFlag(FeatureFlag::Value::NONE);
148 }
Kelvin Zhangda1b3142020-09-24 17:09:02 -0400149 return virtual_ab_compression_;
150}
151
Yifan Hongf5261562020-03-10 10:28:10 -0700152bool DynamicPartitionControlAndroid::OptimizeOperation(
153 const std::string& partition_name,
154 const InstallOperation& operation,
155 InstallOperation* optimized) {
Alessio Balsini2a3b4a22019-11-25 16:46:51 +0000156 switch (operation.type()) {
157 case InstallOperation::SOURCE_COPY:
158 return target_supports_snapshot_ &&
159 GetVirtualAbFeatureFlag().IsEnabled() &&
Yifan Hong6eec9952019-12-04 13:12:01 -0800160 mapped_devices_.count(partition_name +
161 SlotSuffixForSlotNumber(target_slot_)) > 0 &&
Yifan Hongf5261562020-03-10 10:28:10 -0700162 OptimizeSourceCopyOperation(operation, optimized);
Alessio Balsini2a3b4a22019-11-25 16:46:51 +0000163 break;
164 default:
165 break;
166 }
Alessio Balsini14980e22019-11-26 11:46:06 +0000167 return false;
168}
169
Yifan Hong8546a712019-03-28 14:42:53 -0700170bool DynamicPartitionControlAndroid::MapPartitionInternal(
Yifan Hong537802d2018-08-15 13:15:42 -0700171 const std::string& super_device,
172 const std::string& target_partition_name,
173 uint32_t slot,
Yifan Hongaf65ef12018-10-29 11:09:06 -0700174 bool force_writable,
Yifan Hong537802d2018-08-15 13:15:42 -0700175 std::string* path) {
David Andersonbb90dfb2019-08-13 14:14:56 -0700176 CreateLogicalPartitionParams params = {
177 .block_device = super_device,
178 .metadata_slot = slot,
179 .partition_name = target_partition_name,
180 .force_writable = force_writable,
David Andersonbb90dfb2019-08-13 14:14:56 -0700181 };
Yifan Hong420db9b2019-07-23 20:50:33 -0700182 bool success = false;
Yifan Hongf0f4a912019-09-26 17:51:33 -0700183 if (GetVirtualAbFeatureFlag().IsEnabled() && target_supports_snapshot_ &&
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700184 force_writable && ExpectMetadataMounted()) {
Yifan Hong420db9b2019-07-23 20:50:33 -0700185 // Only target partitions are mapped with force_writable. On Virtual
186 // A/B devices, target partitions may overlap with source partitions, so
187 // they must be mapped with snapshot.
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700188 // One exception is when /metadata is not mounted. Fallback to
189 // CreateLogicalPartition as snapshots are not created in the first place.
Yifan Hong420db9b2019-07-23 20:50:33 -0700190 params.timeout_ms = kMapSnapshotTimeout;
191 success = snapshot_->MapUpdateSnapshot(params, path);
192 } else {
193 params.timeout_ms = kMapTimeout;
194 success = CreateLogicalPartition(params, path);
195 }
David Andersonbb90dfb2019-08-13 14:14:56 -0700196
Yifan Hong420db9b2019-07-23 20:50:33 -0700197 if (!success) {
Yifan Hong537802d2018-08-15 13:15:42 -0700198 LOG(ERROR) << "Cannot map " << target_partition_name << " in "
199 << super_device << " on device mapper.";
200 return false;
201 }
202 LOG(INFO) << "Succesfully mapped " << target_partition_name
Yifan Hongaf65ef12018-10-29 11:09:06 -0700203 << " to device mapper (force_writable = " << force_writable
204 << "); device path at " << *path;
Yifan Hong537802d2018-08-15 13:15:42 -0700205 mapped_devices_.insert(target_partition_name);
206 return true;
207}
208
Yifan Hong8546a712019-03-28 14:42:53 -0700209bool DynamicPartitionControlAndroid::MapPartitionOnDeviceMapper(
210 const std::string& super_device,
211 const std::string& target_partition_name,
212 uint32_t slot,
213 bool force_writable,
214 std::string* path) {
215 DmDeviceState state = GetState(target_partition_name);
216 if (state == DmDeviceState::ACTIVE) {
217 if (mapped_devices_.find(target_partition_name) != mapped_devices_.end()) {
218 if (GetDmDevicePathByName(target_partition_name, path)) {
219 LOG(INFO) << target_partition_name
220 << " is mapped on device mapper: " << *path;
221 return true;
222 }
223 LOG(ERROR) << target_partition_name << " is mapped but path is unknown.";
224 return false;
225 }
226 // If target_partition_name is not in mapped_devices_ but state is ACTIVE,
227 // the device might be mapped incorrectly before. Attempt to unmap it.
228 // Note that for source partitions, if GetState() == ACTIVE, callers (e.g.
229 // BootControlAndroid) should not call MapPartitionOnDeviceMapper, but
230 // should directly call GetDmDevicePathByName.
David Anderson4c891c92019-06-21 17:45:23 -0700231 if (!UnmapPartitionOnDeviceMapper(target_partition_name)) {
Yifan Hong8546a712019-03-28 14:42:53 -0700232 LOG(ERROR) << target_partition_name
233 << " is mapped before the update, and it cannot be unmapped.";
234 return false;
235 }
236 state = GetState(target_partition_name);
237 if (state != DmDeviceState::INVALID) {
238 LOG(ERROR) << target_partition_name << " is unmapped but state is "
239 << static_cast<std::underlying_type_t<DmDeviceState>>(state);
240 return false;
241 }
242 }
243 if (state == DmDeviceState::INVALID) {
244 return MapPartitionInternal(
245 super_device, target_partition_name, slot, force_writable, path);
246 }
247
248 LOG(ERROR) << target_partition_name
249 << " is mapped on device mapper but state is unknown: "
250 << static_cast<std::underlying_type_t<DmDeviceState>>(state);
251 return false;
252}
253
Yifan Hong537802d2018-08-15 13:15:42 -0700254bool DynamicPartitionControlAndroid::UnmapPartitionOnDeviceMapper(
David Anderson4c891c92019-06-21 17:45:23 -0700255 const std::string& target_partition_name) {
Yifan Hong537802d2018-08-15 13:15:42 -0700256 if (DeviceMapper::Instance().GetState(target_partition_name) !=
257 DmDeviceState::INVALID) {
Yifan Hong420db9b2019-07-23 20:50:33 -0700258 // Partitions at target slot on non-Virtual A/B devices are mapped as
259 // dm-linear. Also, on Virtual A/B devices, system_other may be mapped for
260 // preopt apps as dm-linear.
261 // Call DestroyLogicalPartition to handle these cases.
262 bool success = DestroyLogicalPartition(target_partition_name);
263
264 // On a Virtual A/B device, |target_partition_name| may be a leftover from
265 // a paused update. Clean up any underlying devices.
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700266 if (ExpectMetadataMounted()) {
Yifan Hong420db9b2019-07-23 20:50:33 -0700267 success &= snapshot_->UnmapUpdateSnapshot(target_partition_name);
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700268 } else {
269 LOG(INFO) << "Skip UnmapUpdateSnapshot(" << target_partition_name
270 << ") because metadata is not mounted";
Yifan Hong420db9b2019-07-23 20:50:33 -0700271 }
272
273 if (!success) {
Yifan Hong537802d2018-08-15 13:15:42 -0700274 LOG(ERROR) << "Cannot unmap " << target_partition_name
275 << " from device mapper.";
276 return false;
277 }
278 LOG(INFO) << "Successfully unmapped " << target_partition_name
279 << " from device mapper.";
280 }
281 mapped_devices_.erase(target_partition_name);
282 return true;
283}
284
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -0400285bool DynamicPartitionControlAndroid::UnmapAllPartitions() {
Tao Bao8c4d0082019-08-08 08:56:16 -0700286 if (mapped_devices_.empty()) {
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -0400287 return false;
Tao Bao8c4d0082019-08-08 08:56:16 -0700288 }
Yifan Hong537802d2018-08-15 13:15:42 -0700289 // UnmapPartitionOnDeviceMapper removes objects from mapped_devices_, hence
290 // a copy is needed for the loop.
291 std::set<std::string> mapped = mapped_devices_;
292 LOG(INFO) << "Destroying [" << Join(mapped, ", ") << "] from device mapper";
293 for (const auto& partition_name : mapped) {
David Anderson4c891c92019-06-21 17:45:23 -0700294 ignore_result(UnmapPartitionOnDeviceMapper(partition_name));
Yifan Hong537802d2018-08-15 13:15:42 -0700295 }
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -0400296 return true;
Yifan Hong537802d2018-08-15 13:15:42 -0700297}
298
299void DynamicPartitionControlAndroid::Cleanup() {
Yifan Hongbae27842019-10-24 16:56:12 -0700300 UnmapAllPartitions();
301 metadata_device_.reset();
Yifan Hong537802d2018-08-15 13:15:42 -0700302}
303
304bool DynamicPartitionControlAndroid::DeviceExists(const std::string& path) {
305 return base::PathExists(base::FilePath(path));
306}
307
308android::dm::DmDeviceState DynamicPartitionControlAndroid::GetState(
309 const std::string& name) {
310 return DeviceMapper::Instance().GetState(name);
311}
312
313bool DynamicPartitionControlAndroid::GetDmDevicePathByName(
314 const std::string& name, std::string* path) {
315 return DeviceMapper::Instance().GetDmDevicePathByName(name, path);
316}
317
318std::unique_ptr<MetadataBuilder>
319DynamicPartitionControlAndroid::LoadMetadataBuilder(
Tianjie24f96092020-06-30 12:26:25 -0700320 const std::string& super_device, uint32_t slot) {
321 auto builder = MetadataBuilder::New(PartitionOpener(), super_device, slot);
322 if (builder == nullptr) {
323 LOG(WARNING) << "No metadata slot " << BootControlInterface::SlotName(slot)
324 << " in " << super_device;
325 return nullptr;
326 }
327 LOG(INFO) << "Loaded metadata from slot "
328 << BootControlInterface::SlotName(slot) << " in " << super_device;
329 return builder;
Yifan Hong012508e2019-07-22 18:30:40 -0700330}
331
332std::unique_ptr<MetadataBuilder>
333DynamicPartitionControlAndroid::LoadMetadataBuilder(
Yifan Hong6e706b12018-11-09 16:50:51 -0800334 const std::string& super_device,
335 uint32_t source_slot,
336 uint32_t target_slot) {
Tianjie24f96092020-06-30 12:26:25 -0700337 bool always_keep_source_slot = !target_supports_snapshot_;
338 auto builder = MetadataBuilder::NewForUpdate(PartitionOpener(),
339 super_device,
340 source_slot,
341 target_slot,
342 always_keep_source_slot);
Yifan Hong537802d2018-08-15 13:15:42 -0700343 if (builder == nullptr) {
344 LOG(WARNING) << "No metadata slot "
345 << BootControlInterface::SlotName(source_slot) << " in "
346 << super_device;
Yifan Hongf48a0052018-10-29 16:30:43 -0700347 return nullptr;
Yifan Hong537802d2018-08-15 13:15:42 -0700348 }
Tianjie24f96092020-06-30 12:26:25 -0700349 LOG(INFO) << "Created metadata for new update from slot "
Yifan Hong537802d2018-08-15 13:15:42 -0700350 << BootControlInterface::SlotName(source_slot) << " in "
351 << super_device;
352 return builder;
353}
354
355bool DynamicPartitionControlAndroid::StoreMetadata(
356 const std::string& super_device,
357 MetadataBuilder* builder,
358 uint32_t target_slot) {
359 auto metadata = builder->Export();
360 if (metadata == nullptr) {
361 LOG(ERROR) << "Cannot export metadata to slot "
362 << BootControlInterface::SlotName(target_slot) << " in "
363 << super_device;
364 return false;
365 }
366
Yifan Hong186bb682019-07-23 14:04:39 -0700367 if (GetDynamicPartitionsFeatureFlag().IsRetrofit()) {
Yifan Hong6e706b12018-11-09 16:50:51 -0800368 if (!FlashPartitionTable(super_device, *metadata)) {
369 LOG(ERROR) << "Cannot write metadata to " << super_device;
370 return false;
371 }
372 LOG(INFO) << "Written metadata to " << super_device;
373 } else {
374 if (!UpdatePartitionTable(super_device, *metadata, target_slot)) {
375 LOG(ERROR) << "Cannot write metadata to slot "
376 << BootControlInterface::SlotName(target_slot) << " in "
377 << super_device;
378 return false;
379 }
380 LOG(INFO) << "Copied metadata to slot "
381 << BootControlInterface::SlotName(target_slot) << " in "
382 << super_device;
Yifan Hong537802d2018-08-15 13:15:42 -0700383 }
384
Yifan Hong537802d2018-08-15 13:15:42 -0700385 return true;
386}
387
388bool DynamicPartitionControlAndroid::GetDeviceDir(std::string* out) {
389 // We can't use fs_mgr to look up |partition_name| because fstab
390 // doesn't list every slot partition (it uses the slotselect option
391 // to mask the suffix).
392 //
393 // We can however assume that there's an entry for the /misc mount
394 // point and use that to get the device file for the misc
395 // partition. This helps us locate the disk that |partition_name|
396 // resides on. From there we'll assume that a by-name scheme is used
397 // so we can just replace the trailing "misc" by the given
398 // |partition_name| and suffix corresponding to |slot|, e.g.
399 //
400 // /dev/block/platform/soc.0/7824900.sdhci/by-name/misc ->
401 // /dev/block/platform/soc.0/7824900.sdhci/by-name/boot_a
402 //
403 // If needed, it's possible to relax the by-name assumption in the
404 // future by trawling /sys/block looking for the appropriate sibling
405 // of misc and then finding an entry in /dev matching the sysfs
406 // entry.
407
408 std::string err, misc_device = get_bootloader_message_blk_device(&err);
409 if (misc_device.empty()) {
410 LOG(ERROR) << "Unable to get misc block device: " << err;
411 return false;
412 }
413
414 if (!utils::IsSymlink(misc_device.c_str())) {
415 LOG(ERROR) << "Device file " << misc_device << " for /misc "
416 << "is not a symlink.";
417 return false;
418 }
419 *out = base::FilePath(misc_device).DirName().value();
420 return true;
421}
Yifan Hong012508e2019-07-22 18:30:40 -0700422
423bool DynamicPartitionControlAndroid::PreparePartitionsForUpdate(
424 uint32_t source_slot,
425 uint32_t target_slot,
Yifan Hongf0f4a912019-09-26 17:51:33 -0700426 const DeltaArchiveManifest& manifest,
Yifan Hongf033ecb2020-01-07 18:13:56 -0800427 bool update,
428 uint64_t* required_size) {
Yifan Hong6eec9952019-12-04 13:12:01 -0800429 source_slot_ = source_slot;
430 target_slot_ = target_slot;
Yifan Hongf033ecb2020-01-07 18:13:56 -0800431 if (required_size != nullptr) {
432 *required_size = 0;
433 }
Yifan Hong6eec9952019-12-04 13:12:01 -0800434
Yifan Hong3a1a5612019-11-05 16:34:32 -0800435 if (fs_mgr_overlayfs_is_setup()) {
436 // Non DAP devices can use overlayfs as well.
437 LOG(WARNING)
438 << "overlayfs overrides are active and can interfere with our "
439 "resources.\n"
440 << "run adb enable-verity to deactivate if required and try again.";
441 }
442
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700443 // If metadata is erased but not formatted, it is possible to not mount
444 // it in recovery. It is acceptable to skip mounting and choose fallback path
445 // (PrepareDynamicPartitionsForUpdate) when sideloading full OTAs.
446 TEST_AND_RETURN_FALSE(EnsureMetadataMounted() || IsRecovery());
Yifan Hong29692902020-03-26 12:47:05 -0700447
448 if (update) {
449 TEST_AND_RETURN_FALSE(EraseSystemOtherAvbFooter(source_slot, target_slot));
450 }
451
Yifan Hong3a1a5612019-11-05 16:34:32 -0800452 if (!GetDynamicPartitionsFeatureFlag().IsEnabled()) {
453 return true;
454 }
455
456 if (target_slot == source_slot) {
457 LOG(ERROR) << "Cannot call PreparePartitionsForUpdate on current slot.";
458 return false;
459 }
460
Yifan Hongf6f75c22020-07-31 15:20:25 -0700461 if (!SetTargetBuildVars(manifest)) {
462 return false;
463 }
464
Yifan Hong3a1a5612019-11-05 16:34:32 -0800465 // Although the current build supports dynamic partitions, the given payload
466 // doesn't use it for target partitions. This could happen when applying a
467 // retrofit update. Skip updating the partition metadata for the target slot.
Yifan Hong3a1a5612019-11-05 16:34:32 -0800468 if (!is_target_dynamic_) {
469 return true;
470 }
471
Yifan Hongf0f4a912019-09-26 17:51:33 -0700472 if (!update)
473 return true;
474
Yifan Hongbae27842019-10-24 16:56:12 -0700475 bool delete_source = false;
476
Yifan Hong6d888562019-10-01 13:00:31 -0700477 if (GetVirtualAbFeatureFlag().IsEnabled()) {
478 // On Virtual A/B device, either CancelUpdate() or BeginUpdate() must be
479 // called before calling UnmapUpdateSnapshot.
480 // - If target_supports_snapshot_, PrepareSnapshotPartitionsForUpdate()
481 // calls BeginUpdate() which resets update state
Yifan Hongbae27842019-10-24 16:56:12 -0700482 // - If !target_supports_snapshot_ or PrepareSnapshotPartitionsForUpdate
483 // failed in recovery, explicitly CancelUpdate().
Yifan Hong6d888562019-10-01 13:00:31 -0700484 if (target_supports_snapshot_) {
Yifan Hongbae27842019-10-24 16:56:12 -0700485 if (PrepareSnapshotPartitionsForUpdate(
486 source_slot, target_slot, manifest, required_size)) {
487 return true;
488 }
489
490 // Virtual A/B device doing Virtual A/B update in Android mode must use
491 // snapshots.
492 if (!IsRecovery()) {
493 LOG(ERROR) << "PrepareSnapshotPartitionsForUpdate failed in Android "
494 << "mode";
495 return false;
496 }
497
498 delete_source = true;
499 LOG(INFO) << "PrepareSnapshotPartitionsForUpdate failed in recovery. "
500 << "Attempt to overwrite existing partitions if possible";
501 } else {
502 // Downgrading to an non-Virtual A/B build or is secondary OTA.
503 LOG(INFO) << "Using regular A/B on Virtual A/B because package disabled "
504 << "snapshots.";
Yifan Hong6d888562019-10-01 13:00:31 -0700505 }
Yifan Hongbae27842019-10-24 16:56:12 -0700506
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700507 // In recovery, if /metadata is not mounted, it is likely that metadata
508 // partition is erased and not formatted yet. After sideloading, when
509 // rebooting into the new version, init will erase metadata partition,
510 // hence the failure of CancelUpdate() can be ignored here.
511 // However, if metadata is mounted and CancelUpdate fails, sideloading
512 // should not proceed because during next boot, snapshots will overlay on
513 // the devices incorrectly.
514 if (ExpectMetadataMounted()) {
515 TEST_AND_RETURN_FALSE(snapshot_->CancelUpdate());
516 } else {
517 LOG(INFO) << "Skip canceling previous update because metadata is not "
518 << "mounted";
Yifan Hong6d888562019-10-01 13:00:31 -0700519 }
Yifan Hong420db9b2019-07-23 20:50:33 -0700520 }
Yifan Hongbae27842019-10-24 16:56:12 -0700521
Tianjie24f96092020-06-30 12:26:25 -0700522 // TODO(xunchang) support partial update on non VAB enabled devices.
Yifan Hong5c5743f2020-04-16 12:59:07 -0700523 TEST_AND_RETURN_FALSE(PrepareDynamicPartitionsForUpdate(
524 source_slot, target_slot, manifest, delete_source));
525
526 if (required_size != nullptr) {
527 *required_size = 0;
528 }
529 return true;
Yifan Hong420db9b2019-07-23 20:50:33 -0700530}
531
Yifan Hongf6f75c22020-07-31 15:20:25 -0700532bool DynamicPartitionControlAndroid::SetTargetBuildVars(
533 const DeltaArchiveManifest& manifest) {
534 // Precondition: current build supports dynamic partition.
535 CHECK(GetDynamicPartitionsFeatureFlag().IsEnabled());
536
537 bool is_target_dynamic =
538 !manifest.dynamic_partition_metadata().groups().empty();
539 bool target_supports_snapshot =
540 manifest.dynamic_partition_metadata().snapshot_enabled();
541
542 if (manifest.partial_update()) {
543 // Partial updates requires DAP. On partial updates that does not involve
544 // dynamic partitions, groups() can be empty, so also assume
545 // is_target_dynamic in this case. This assumption should be safe because we
546 // also check target_supports_snapshot below, which presumably also implies
547 // target build supports dynamic partition.
548 if (!is_target_dynamic) {
549 LOG(INFO) << "Assuming target build supports dynamic partitions for "
550 "partial updates.";
551 is_target_dynamic = true;
552 }
553
554 // Partial updates requires Virtual A/B. Double check that both current
555 // build and target build supports Virtual A/B.
556 if (!GetVirtualAbFeatureFlag().IsEnabled()) {
557 LOG(ERROR) << "Partial update cannot be applied on a device that does "
558 "not support snapshots.";
559 return false;
560 }
561 if (!target_supports_snapshot) {
562 LOG(ERROR) << "Cannot apply partial update to a build that does not "
563 "support snapshots.";
564 return false;
565 }
566 }
567
568 // Store the flags.
569 is_target_dynamic_ = is_target_dynamic;
570 // If !is_target_dynamic_, leave target_supports_snapshot_ unset because
571 // snapshots would not work without dynamic partition.
572 if (is_target_dynamic_) {
573 target_supports_snapshot_ = target_supports_snapshot;
574 }
575 return true;
576}
577
Yifan Hong29692902020-03-26 12:47:05 -0700578namespace {
579// Try our best to erase AVB footer.
580class AvbFooterEraser {
581 public:
582 explicit AvbFooterEraser(const std::string& path) : path_(path) {}
583 bool Erase() {
584 // Try to mark the block device read-only. Ignore any
585 // failure since this won't work when passing regular files.
586 ignore_result(utils::SetBlockDeviceReadOnly(path_, false /* readonly */));
587
588 fd_.reset(new EintrSafeFileDescriptor());
589 int flags = O_WRONLY | O_TRUNC | O_CLOEXEC | O_SYNC;
590 TEST_AND_RETURN_FALSE(fd_->Open(path_.c_str(), flags));
591
592 // Need to write end-AVB_FOOTER_SIZE to end.
593 static_assert(AVB_FOOTER_SIZE > 0);
594 off64_t offset = fd_->Seek(-AVB_FOOTER_SIZE, SEEK_END);
595 TEST_AND_RETURN_FALSE_ERRNO(offset >= 0);
596 uint64_t write_size = AVB_FOOTER_SIZE;
597 LOG(INFO) << "Zeroing " << path_ << " @ [" << offset << ", "
598 << (offset + write_size) << "] (" << write_size << " bytes)";
599 brillo::Blob zeros(write_size);
600 TEST_AND_RETURN_FALSE(utils::WriteAll(fd_, zeros.data(), zeros.size()));
601 return true;
602 }
603 ~AvbFooterEraser() {
604 TEST_AND_RETURN(fd_ != nullptr && fd_->IsOpen());
605 if (!fd_->Close()) {
606 LOG(WARNING) << "Failed to close fd for " << path_;
607 }
608 }
609
610 private:
611 std::string path_;
612 FileDescriptorPtr fd_;
613};
614
615} // namespace
616
617std::optional<bool>
618DynamicPartitionControlAndroid::IsAvbEnabledOnSystemOther() {
619 auto prefix = GetProperty(kPostinstallFstabPrefix, "");
620 if (prefix.empty()) {
621 LOG(WARNING) << "Cannot get " << kPostinstallFstabPrefix;
622 return std::nullopt;
623 }
624 auto path = base::FilePath(prefix).Append("etc/fstab.postinstall").value();
625 return IsAvbEnabledInFstab(path);
626}
627
628std::optional<bool> DynamicPartitionControlAndroid::IsAvbEnabledInFstab(
629 const std::string& path) {
630 Fstab fstab;
631 if (!ReadFstabFromFile(path, &fstab)) {
Yifan Hong93cde302020-04-27 12:59:29 -0700632 PLOG(WARNING) << "Cannot read fstab from " << path;
633 if (errno == ENOENT) {
634 return false;
635 }
Yifan Hong29692902020-03-26 12:47:05 -0700636 return std::nullopt;
637 }
638 for (const auto& entry : fstab) {
639 if (!entry.avb_keys.empty()) {
640 return true;
641 }
642 }
643 return false;
644}
645
646bool DynamicPartitionControlAndroid::GetSystemOtherPath(
647 uint32_t source_slot,
648 uint32_t target_slot,
649 const std::string& partition_name_suffix,
650 std::string* path,
651 bool* should_unmap) {
652 path->clear();
653 *should_unmap = false;
654
P.Adarsh Reddy13e4195d2020-06-08 23:17:36 +0530655 // Check that AVB is enabled on system_other before erasing.
656 auto has_avb = IsAvbEnabledOnSystemOther();
657 TEST_AND_RETURN_FALSE(has_avb.has_value());
658 if (!has_avb.value()) {
659 LOG(INFO) << "AVB is not enabled on system_other. Skip erasing.";
660 return true;
661 }
Yifan Hong29692902020-03-26 12:47:05 -0700662
P.Adarsh Reddy13e4195d2020-06-08 23:17:36 +0530663 if (!IsRecovery()) {
Yifan Hong29692902020-03-26 12:47:05 -0700664 // Found unexpected avb_keys for system_other on devices retrofitting
665 // dynamic partitions. Previous crash in update_engine may leave logical
666 // partitions mapped on physical system_other partition. It is difficult to
667 // handle these cases. Just fail.
668 if (GetDynamicPartitionsFeatureFlag().IsRetrofit()) {
669 LOG(ERROR) << "Cannot erase AVB footer on system_other on devices with "
670 << "retrofit dynamic partitions. They should not have AVB "
671 << "enabled on system_other.";
672 return false;
673 }
674 }
675
676 std::string device_dir_str;
677 TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str));
678 base::FilePath device_dir(device_dir_str);
679
680 // On devices without dynamic partition, search for static partitions.
681 if (!GetDynamicPartitionsFeatureFlag().IsEnabled()) {
682 *path = device_dir.Append(partition_name_suffix).value();
683 TEST_AND_RETURN_FALSE(DeviceExists(*path));
684 return true;
685 }
686
687 auto source_super_device =
688 device_dir.Append(GetSuperPartitionName(source_slot)).value();
689
690 auto builder = LoadMetadataBuilder(source_super_device, source_slot);
691 if (builder == nullptr) {
692 if (IsRecovery()) {
693 // It might be corrupted for some reason. It should still be able to
694 // sideload.
695 LOG(WARNING) << "Super partition metadata cannot be read from the source "
696 << "slot, skip erasing.";
697 return true;
698 } else {
699 // Device has booted into Android mode, indicating that the super
700 // partition metadata should be there.
701 LOG(ERROR) << "Super partition metadata cannot be read from the source "
702 << "slot. This is unexpected on devices with dynamic "
703 << "partitions enabled.";
704 return false;
705 }
706 }
707 auto p = builder->FindPartition(partition_name_suffix);
708 if (p == nullptr) {
709 // If the source slot is flashed without system_other, it does not exist
710 // in super partition metadata at source slot. It is safe to skip it.
711 LOG(INFO) << "Can't find " << partition_name_suffix
712 << " in metadata source slot, skip erasing.";
713 return true;
714 }
715 // System_other created by flashing tools should be erased.
716 // If partition is created by update_engine (via NewForUpdate), it is a
717 // left-over partition from the previous update and does not contain
718 // system_other, hence there is no need to erase.
719 // Note the reverse is not necessary true. If the flag is not set, we don't
720 // know if the partition is created by update_engine or by flashing tools
721 // because older versions of super partition metadata does not contain this
722 // flag. It is okay to erase the AVB footer anyways.
723 if (p->attributes() & LP_PARTITION_ATTR_UPDATED) {
724 LOG(INFO) << partition_name_suffix
725 << " does not contain system_other, skip erasing.";
726 return true;
727 }
728
Yifan Hong64331b32020-05-13 16:50:40 -0700729 if (p->size() < AVB_FOOTER_SIZE) {
730 LOG(INFO) << partition_name_suffix << " has length " << p->size()
731 << "( < AVB_FOOTER_SIZE " << AVB_FOOTER_SIZE
732 << "), skip erasing.";
733 return true;
734 }
735
Yifan Hong29692902020-03-26 12:47:05 -0700736 // Delete any pre-existing device with name |partition_name_suffix| and
737 // also remove it from |mapped_devices_|.
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700738 // In recovery, metadata might not be mounted, and
739 // UnmapPartitionOnDeviceMapper might fail. However,
740 // it is unusual that system_other has already been mapped. Hence, just skip.
Yifan Hong29692902020-03-26 12:47:05 -0700741 TEST_AND_RETURN_FALSE(UnmapPartitionOnDeviceMapper(partition_name_suffix));
742 // Use CreateLogicalPartition directly to avoid mapping with existing
743 // snapshots.
744 CreateLogicalPartitionParams params = {
745 .block_device = source_super_device,
746 .metadata_slot = source_slot,
747 .partition_name = partition_name_suffix,
748 .force_writable = true,
749 .timeout_ms = kMapTimeout,
750 };
751 TEST_AND_RETURN_FALSE(CreateLogicalPartition(params, path));
752 *should_unmap = true;
753 return true;
754}
755
756bool DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter(
757 uint32_t source_slot, uint32_t target_slot) {
758 LOG(INFO) << "Erasing AVB footer of system_other partition before update.";
759
760 const std::string target_suffix = SlotSuffixForSlotNumber(target_slot);
761 const std::string partition_name_suffix = "system" + target_suffix;
762
763 std::string path;
764 bool should_unmap = false;
765
766 TEST_AND_RETURN_FALSE(GetSystemOtherPath(
767 source_slot, target_slot, partition_name_suffix, &path, &should_unmap));
768
769 if (path.empty()) {
770 return true;
771 }
772
773 bool ret = AvbFooterEraser(path).Erase();
774
775 // Delete |partition_name_suffix| from device mapper and from
776 // |mapped_devices_| again so that it does not interfere with update process.
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700777 // In recovery, metadata might not be mounted, and
778 // UnmapPartitionOnDeviceMapper might fail. However, DestroyLogicalPartition
779 // should be called. If DestroyLogicalPartition does fail, it is still okay
780 // to skip the error here and let Prepare*() fail later.
Yifan Hong29692902020-03-26 12:47:05 -0700781 if (should_unmap) {
782 TEST_AND_RETURN_FALSE(UnmapPartitionOnDeviceMapper(partition_name_suffix));
783 }
784
785 return ret;
786}
787
Yifan Hong420db9b2019-07-23 20:50:33 -0700788bool DynamicPartitionControlAndroid::PrepareDynamicPartitionsForUpdate(
789 uint32_t source_slot,
790 uint32_t target_slot,
Yifan Hongbae27842019-10-24 16:56:12 -0700791 const DeltaArchiveManifest& manifest,
792 bool delete_source) {
Yifan Hong012508e2019-07-22 18:30:40 -0700793 const std::string target_suffix = SlotSuffixForSlotNumber(target_slot);
794
795 // Unmap all the target dynamic partitions because they would become
796 // inconsistent with the new metadata.
Yifan Hong13d41cb2019-09-16 13:18:22 -0700797 for (const auto& group : manifest.dynamic_partition_metadata().groups()) {
798 for (const auto& partition_name : group.partition_names()) {
799 if (!UnmapPartitionOnDeviceMapper(partition_name + target_suffix)) {
Yifan Hong012508e2019-07-22 18:30:40 -0700800 return false;
801 }
802 }
803 }
804
805 std::string device_dir_str;
806 if (!GetDeviceDir(&device_dir_str)) {
807 return false;
808 }
809 base::FilePath device_dir(device_dir_str);
810 auto source_device =
Yifan Hong700d7c12019-07-23 20:49:16 -0700811 device_dir.Append(GetSuperPartitionName(source_slot)).value();
Yifan Hong012508e2019-07-22 18:30:40 -0700812
813 auto builder = LoadMetadataBuilder(source_device, source_slot, target_slot);
814 if (builder == nullptr) {
815 LOG(ERROR) << "No metadata at "
816 << BootControlInterface::SlotName(source_slot);
817 return false;
818 }
819
Yifan Hongbae27842019-10-24 16:56:12 -0700820 if (delete_source) {
821 TEST_AND_RETURN_FALSE(
822 DeleteSourcePartitions(builder.get(), source_slot, manifest));
823 }
824
Yifan Hong13d41cb2019-09-16 13:18:22 -0700825 if (!UpdatePartitionMetadata(builder.get(), target_slot, manifest)) {
Yifan Hong012508e2019-07-22 18:30:40 -0700826 return false;
827 }
828
829 auto target_device =
Yifan Hong700d7c12019-07-23 20:49:16 -0700830 device_dir.Append(GetSuperPartitionName(target_slot)).value();
Yifan Hong012508e2019-07-22 18:30:40 -0700831 return StoreMetadata(target_device, builder.get(), target_slot);
832}
833
Yifan Hong420db9b2019-07-23 20:50:33 -0700834bool DynamicPartitionControlAndroid::PrepareSnapshotPartitionsForUpdate(
835 uint32_t source_slot,
836 uint32_t target_slot,
Yifan Hongf033ecb2020-01-07 18:13:56 -0800837 const DeltaArchiveManifest& manifest,
838 uint64_t* required_size) {
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700839 TEST_AND_RETURN_FALSE(ExpectMetadataMounted());
Yifan Hong420db9b2019-07-23 20:50:33 -0700840 if (!snapshot_->BeginUpdate()) {
841 LOG(ERROR) << "Cannot begin new update.";
842 return false;
843 }
Yifan Hongf033ecb2020-01-07 18:13:56 -0800844 auto ret = snapshot_->CreateUpdateSnapshots(manifest);
845 if (!ret) {
846 LOG(ERROR) << "Cannot create update snapshots: " << ret.string();
847 if (required_size != nullptr &&
Yifan Hong0850bca2020-01-16 15:14:07 -0800848 ret.error_code() == Return::ErrorCode::NO_SPACE) {
Yifan Hongf033ecb2020-01-07 18:13:56 -0800849 *required_size = ret.required_size();
850 }
Yifan Hong420db9b2019-07-23 20:50:33 -0700851 return false;
852 }
853 return true;
854}
855
Yifan Hong700d7c12019-07-23 20:49:16 -0700856std::string DynamicPartitionControlAndroid::GetSuperPartitionName(
857 uint32_t slot) {
858 return fs_mgr_get_super_partition_name(slot);
859}
860
Yifan Hong012508e2019-07-22 18:30:40 -0700861bool DynamicPartitionControlAndroid::UpdatePartitionMetadata(
862 MetadataBuilder* builder,
863 uint32_t target_slot,
Yifan Hong13d41cb2019-09-16 13:18:22 -0700864 const DeltaArchiveManifest& manifest) {
Yifan Hong8d6df9a2020-08-13 13:59:54 -0700865 // Check preconditions.
Kelvin Zhang1c21eb82021-03-10 13:39:56 -0500866 LOG_IF(WARNING, !GetVirtualAbFeatureFlag().IsEnabled() || IsRecovery())
Yifan Hong8d6df9a2020-08-13 13:59:54 -0700867 << "UpdatePartitionMetadata is called on a Virtual A/B device "
868 "but source partitions is not deleted. This is not allowed.";
869
Yifan Honga4e7da32019-09-30 18:25:03 -0700870 // If applying downgrade from Virtual A/B to non-Virtual A/B, the left-over
871 // COW group needs to be deleted to ensure there are enough space to create
872 // target partitions.
873 builder->RemoveGroupAndPartitions(android::snapshot::kCowGroupName);
874
Yifan Hong012508e2019-07-22 18:30:40 -0700875 const std::string target_suffix = SlotSuffixForSlotNumber(target_slot);
876 DeleteGroupsWithSuffix(builder, target_suffix);
877
878 uint64_t total_size = 0;
Yifan Hong13d41cb2019-09-16 13:18:22 -0700879 for (const auto& group : manifest.dynamic_partition_metadata().groups()) {
880 total_size += group.size();
Yifan Hong012508e2019-07-22 18:30:40 -0700881 }
882
883 std::string expr;
884 uint64_t allocatable_space = builder->AllocatableSpace();
Yifan Hong8d6df9a2020-08-13 13:59:54 -0700885 // On device retrofitting dynamic partitions, allocatable_space = super.
886 // On device launching dynamic partitions w/o VAB,
887 // allocatable_space = super / 2.
888 // On device launching dynamic partitions with VAB, allocatable_space = super.
889 if (!GetDynamicPartitionsFeatureFlag().IsRetrofit() &&
890 !GetVirtualAbFeatureFlag().IsEnabled()) {
Yifan Hong012508e2019-07-22 18:30:40 -0700891 allocatable_space /= 2;
892 expr = "half of ";
893 }
894 if (total_size > allocatable_space) {
895 LOG(ERROR) << "The maximum size of all groups with suffix " << target_suffix
896 << " (" << total_size << ") has exceeded " << expr
897 << "allocatable space for dynamic partitions "
898 << allocatable_space << ".";
899 return false;
900 }
901
Yifan Hong13d41cb2019-09-16 13:18:22 -0700902 // name of partition(e.g. "system") -> size in bytes
903 std::map<std::string, uint64_t> partition_sizes;
904 for (const auto& partition : manifest.partitions()) {
905 partition_sizes.emplace(partition.partition_name(),
906 partition.new_partition_info().size());
907 }
908
909 for (const auto& group : manifest.dynamic_partition_metadata().groups()) {
910 auto group_name_suffix = group.name() + target_suffix;
911 if (!builder->AddGroup(group_name_suffix, group.size())) {
Yifan Hong012508e2019-07-22 18:30:40 -0700912 LOG(ERROR) << "Cannot add group " << group_name_suffix << " with size "
Yifan Hong13d41cb2019-09-16 13:18:22 -0700913 << group.size();
Yifan Hong012508e2019-07-22 18:30:40 -0700914 return false;
915 }
916 LOG(INFO) << "Added group " << group_name_suffix << " with size "
Yifan Hong13d41cb2019-09-16 13:18:22 -0700917 << group.size();
Yifan Hong012508e2019-07-22 18:30:40 -0700918
Yifan Hong13d41cb2019-09-16 13:18:22 -0700919 for (const auto& partition_name : group.partition_names()) {
920 auto partition_sizes_it = partition_sizes.find(partition_name);
921 if (partition_sizes_it == partition_sizes.end()) {
922 // TODO(tbao): Support auto-filling partition info for framework-only
923 // OTA.
924 LOG(ERROR) << "dynamic_partition_metadata contains partition "
925 << partition_name << " but it is not part of the manifest. "
926 << "This is not supported.";
927 return false;
928 }
929 uint64_t partition_size = partition_sizes_it->second;
930
931 auto partition_name_suffix = partition_name + target_suffix;
Yifan Hong012508e2019-07-22 18:30:40 -0700932 Partition* p = builder->AddPartition(
933 partition_name_suffix, group_name_suffix, LP_PARTITION_ATTR_READONLY);
934 if (!p) {
935 LOG(ERROR) << "Cannot add partition " << partition_name_suffix
936 << " to group " << group_name_suffix;
937 return false;
938 }
Yifan Hong13d41cb2019-09-16 13:18:22 -0700939 if (!builder->ResizePartition(p, partition_size)) {
Yifan Hong012508e2019-07-22 18:30:40 -0700940 LOG(ERROR) << "Cannot resize partition " << partition_name_suffix
Yifan Hong13d41cb2019-09-16 13:18:22 -0700941 << " to size " << partition_size << ". Not enough space?";
Yifan Hong012508e2019-07-22 18:30:40 -0700942 return false;
943 }
David Anderson0e1c7fd2021-03-08 19:01:59 -0800944 if (p->size() < partition_size) {
945 LOG(ERROR) << "Partition " << partition_name_suffix
946 << " was expected to have size " << partition_size
947 << ", but instead has size " << p->size();
948 return false;
949 }
Yifan Hong012508e2019-07-22 18:30:40 -0700950 LOG(INFO) << "Added partition " << partition_name_suffix << " to group "
Yifan Hong13d41cb2019-09-16 13:18:22 -0700951 << group_name_suffix << " with size " << partition_size;
Yifan Hong012508e2019-07-22 18:30:40 -0700952 }
953 }
954
955 return true;
956}
957
Yifan Hong7b3910a2020-03-24 17:47:32 -0700958bool DynamicPartitionControlAndroid::FinishUpdate(bool powerwash_required) {
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700959 if (ExpectMetadataMounted()) {
960 if (snapshot_->GetUpdateState() == UpdateState::Initiated) {
961 LOG(INFO) << "Snapshot writes are done.";
962 return snapshot_->FinishedSnapshotWrites(powerwash_required);
963 }
964 } else {
965 LOG(INFO) << "Skip FinishedSnapshotWrites() because /metadata is not "
966 << "mounted";
Yifan Hongf0f4a912019-09-26 17:51:33 -0700967 }
968 return true;
Yifan Honga33bca42019-09-03 20:29:45 -0700969}
970
Yifan Hong3a1a5612019-11-05 16:34:32 -0800971bool DynamicPartitionControlAndroid::GetPartitionDevice(
972 const std::string& partition_name,
973 uint32_t slot,
974 uint32_t current_slot,
Tianjie51a5a392020-06-03 14:39:32 -0700975 bool not_in_payload,
976 std::string* device,
977 bool* is_dynamic) {
Kelvin Zhang66a9ebb2021-01-25 13:35:10 -0500978 auto partition_dev =
979 GetPartitionDevice(partition_name, slot, current_slot, not_in_payload);
Kelvin Zhang91d95fa2020-11-05 13:52:00 -0500980 if (!partition_dev.has_value()) {
Yifan Hong3a1a5612019-11-05 16:34:32 -0800981 return false;
982 }
Kelvin Zhang91d95fa2020-11-05 13:52:00 -0500983 if (device) {
984 *device = std::move(partition_dev->rw_device_path);
985 }
986 if (is_dynamic) {
987 *is_dynamic = partition_dev->is_dynamic;
988 }
Yifan Hong3a1a5612019-11-05 16:34:32 -0800989 return true;
990}
991
Tianjie51a5a392020-06-03 14:39:32 -0700992bool DynamicPartitionControlAndroid::GetPartitionDevice(
993 const std::string& partition_name,
994 uint32_t slot,
995 uint32_t current_slot,
996 std::string* device) {
997 return GetPartitionDevice(
998 partition_name, slot, current_slot, false, device, nullptr);
999}
1000
Kelvin Zhang91d95fa2020-11-05 13:52:00 -05001001static std::string GetStaticDevicePath(
1002 const base::FilePath& device_dir,
1003 const std::string& partition_name_suffixed) {
1004 base::FilePath path = device_dir.Append(partition_name_suffixed);
1005 return path.value();
1006}
1007
1008std::optional<PartitionDevice>
1009DynamicPartitionControlAndroid::GetPartitionDevice(
1010 const std::string& partition_name,
1011 uint32_t slot,
1012 uint32_t current_slot,
1013 bool not_in_payload) {
1014 std::string device_dir_str;
1015 if (!GetDeviceDir(&device_dir_str)) {
1016 LOG(ERROR) << "Failed to GetDeviceDir()";
1017 return {};
1018 }
1019 const base::FilePath device_dir(device_dir_str);
1020 // When VABC is enabled, we can't get device path for dynamic partitions in
1021 // target slot.
1022 const auto& partition_name_suffix =
1023 partition_name + SlotSuffixForSlotNumber(slot);
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001024 if (UpdateUsesSnapshotCompression() && slot != current_slot &&
1025 IsDynamicPartition(partition_name, slot)) {
Kelvin Zhang91ad6622021-03-01 13:46:17 -05001026 return {
1027 {.mountable_device_path = base::FilePath{std::string{VABC_DEVICE_DIR}}
1028 .Append(partition_name_suffix)
1029 .value(),
1030 .is_dynamic = true}};
Kelvin Zhang91d95fa2020-11-05 13:52:00 -05001031 }
1032
1033 // When looking up target partition devices, treat them as static if the
1034 // current payload doesn't encode them as dynamic partitions. This may happen
1035 // when applying a retrofit update on top of a dynamic-partitions-enabled
1036 // build.
1037 std::string device;
1038 if (GetDynamicPartitionsFeatureFlag().IsEnabled() &&
1039 (slot == current_slot || is_target_dynamic_)) {
1040 switch (GetDynamicPartitionDevice(device_dir,
1041 partition_name_suffix,
1042 slot,
1043 current_slot,
1044 not_in_payload,
1045 &device)) {
1046 case DynamicPartitionDeviceStatus::SUCCESS:
1047 return {{.rw_device_path = device,
1048 .mountable_device_path = device,
1049 .is_dynamic = true}};
1050
1051 case DynamicPartitionDeviceStatus::TRY_STATIC:
1052 break;
1053 case DynamicPartitionDeviceStatus::ERROR: // fallthrough
1054 default:
1055 return {};
1056 }
1057 }
1058 // Try static partitions.
1059 auto static_path = GetStaticDevicePath(device_dir, partition_name_suffix);
1060 if (!DeviceExists(static_path)) {
1061 LOG(ERROR) << "Device file " << static_path << " does not exist.";
1062 return {};
1063 }
1064
1065 return {{.rw_device_path = static_path,
1066 .mountable_device_path = static_path,
1067 .is_dynamic = false}};
1068}
1069
Yifan Hong3a1a5612019-11-05 16:34:32 -08001070bool DynamicPartitionControlAndroid::IsSuperBlockDevice(
1071 const base::FilePath& device_dir,
1072 uint32_t current_slot,
1073 const std::string& partition_name_suffix) {
1074 std::string source_device =
1075 device_dir.Append(GetSuperPartitionName(current_slot)).value();
1076 auto source_metadata = LoadMetadataBuilder(source_device, current_slot);
1077 return source_metadata->HasBlockDevice(partition_name_suffix);
1078}
1079
1080DynamicPartitionControlAndroid::DynamicPartitionDeviceStatus
1081DynamicPartitionControlAndroid::GetDynamicPartitionDevice(
1082 const base::FilePath& device_dir,
1083 const std::string& partition_name_suffix,
1084 uint32_t slot,
1085 uint32_t current_slot,
Tianjie51a5a392020-06-03 14:39:32 -07001086 bool not_in_payload,
Yifan Hong3a1a5612019-11-05 16:34:32 -08001087 std::string* device) {
1088 std::string super_device =
1089 device_dir.Append(GetSuperPartitionName(slot)).value();
1090
1091 auto builder = LoadMetadataBuilder(super_device, slot);
1092 if (builder == nullptr) {
1093 LOG(ERROR) << "No metadata in slot "
1094 << BootControlInterface::SlotName(slot);
1095 return DynamicPartitionDeviceStatus::ERROR;
1096 }
1097 if (builder->FindPartition(partition_name_suffix) == nullptr) {
1098 LOG(INFO) << partition_name_suffix
1099 << " is not in super partition metadata.";
1100
1101 if (IsSuperBlockDevice(device_dir, current_slot, partition_name_suffix)) {
1102 LOG(ERROR) << "The static partition " << partition_name_suffix
1103 << " is a block device for current metadata."
1104 << "It cannot be used as a logical partition.";
1105 return DynamicPartitionDeviceStatus::ERROR;
1106 }
1107
1108 return DynamicPartitionDeviceStatus::TRY_STATIC;
1109 }
1110
1111 if (slot == current_slot) {
1112 if (GetState(partition_name_suffix) != DmDeviceState::ACTIVE) {
1113 LOG(WARNING) << partition_name_suffix << " is at current slot but it is "
1114 << "not mapped. Now try to map it.";
1115 } else {
1116 if (GetDmDevicePathByName(partition_name_suffix, device)) {
1117 LOG(INFO) << partition_name_suffix
1118 << " is mapped on device mapper: " << *device;
1119 return DynamicPartitionDeviceStatus::SUCCESS;
1120 }
1121 LOG(ERROR) << partition_name_suffix << "is mapped but path is unknown.";
1122 return DynamicPartitionDeviceStatus::ERROR;
1123 }
1124 }
1125
Tianjie51a5a392020-06-03 14:39:32 -07001126 bool force_writable = (slot != current_slot) && !not_in_payload;
Yifan Hong3a1a5612019-11-05 16:34:32 -08001127 if (MapPartitionOnDeviceMapper(
1128 super_device, partition_name_suffix, slot, force_writable, device)) {
1129 return DynamicPartitionDeviceStatus::SUCCESS;
1130 }
1131 return DynamicPartitionDeviceStatus::ERROR;
1132}
1133
Yifan Hong6eec9952019-12-04 13:12:01 -08001134void DynamicPartitionControlAndroid::set_fake_mapped_devices(
1135 const std::set<std::string>& fake) {
1136 mapped_devices_ = fake;
1137}
1138
Yifan Hongbae27842019-10-24 16:56:12 -07001139bool DynamicPartitionControlAndroid::IsRecovery() {
Kelvin Zhanga22ef552020-10-12 19:03:52 -04001140 return constants::kIsRecovery;
Yifan Hongbae27842019-10-24 16:56:12 -07001141}
1142
1143static bool IsIncrementalUpdate(const DeltaArchiveManifest& manifest) {
1144 const auto& partitions = manifest.partitions();
1145 return std::any_of(partitions.begin(), partitions.end(), [](const auto& p) {
1146 return p.has_old_partition_info();
1147 });
1148}
1149
1150bool DynamicPartitionControlAndroid::DeleteSourcePartitions(
1151 MetadataBuilder* builder,
1152 uint32_t source_slot,
1153 const DeltaArchiveManifest& manifest) {
1154 TEST_AND_RETURN_FALSE(IsRecovery());
1155
1156 if (IsIncrementalUpdate(manifest)) {
1157 LOG(ERROR) << "Cannot sideload incremental OTA because snapshots cannot "
1158 << "be created.";
1159 if (GetVirtualAbFeatureFlag().IsLaunch()) {
1160 LOG(ERROR) << "Sideloading incremental updates on devices launches "
1161 << " Virtual A/B is not supported.";
1162 }
1163 return false;
1164 }
1165
1166 LOG(INFO) << "Will overwrite existing partitions. Slot "
1167 << BootControlInterface::SlotName(source_slot)
1168 << "may be unbootable until update finishes!";
1169 const std::string source_suffix = SlotSuffixForSlotNumber(source_slot);
1170 DeleteGroupsWithSuffix(builder, source_suffix);
1171
1172 return true;
1173}
1174
Yifan Hong90965502020-02-19 15:22:47 -08001175std::unique_ptr<AbstractAction>
1176DynamicPartitionControlAndroid::GetCleanupPreviousUpdateAction(
1177 BootControlInterface* boot_control,
1178 PrefsInterface* prefs,
1179 CleanupPreviousUpdateActionDelegateInterface* delegate) {
1180 if (!GetVirtualAbFeatureFlag().IsEnabled()) {
1181 return std::make_unique<NoOpAction>();
1182 }
1183 return std::make_unique<CleanupPreviousUpdateAction>(
1184 prefs, boot_control, snapshot_.get(), delegate);
1185}
1186
Yifan Hong6a6d0f12020-03-11 13:20:52 -07001187bool DynamicPartitionControlAndroid::ResetUpdate(PrefsInterface* prefs) {
1188 if (!GetVirtualAbFeatureFlag().IsEnabled()) {
1189 return true;
1190 }
1191
1192 LOG(INFO) << __func__ << " resetting update state and deleting snapshots.";
1193 TEST_AND_RETURN_FALSE(prefs != nullptr);
1194
1195 // If the device has already booted into the target slot,
1196 // ResetUpdateProgress may pass but CancelUpdate fails.
1197 // This is expected. A scheduled CleanupPreviousUpdateAction should free
1198 // space when it is done.
1199 TEST_AND_RETURN_FALSE(DeltaPerformer::ResetUpdateProgress(
1200 prefs, false /* quick */, false /* skip dynamic partitions metadata */));
1201
Yifan Hong4d7c5eb2020-04-03 11:31:50 -07001202 if (ExpectMetadataMounted()) {
1203 TEST_AND_RETURN_FALSE(snapshot_->CancelUpdate());
1204 } else {
1205 LOG(INFO) << "Skip cancelling update in ResetUpdate because /metadata is "
1206 << "not mounted";
1207 }
Yifan Hong6a6d0f12020-03-11 13:20:52 -07001208
1209 return true;
1210}
1211
Tianjie99d570d2020-06-04 14:57:19 -07001212bool DynamicPartitionControlAndroid::ListDynamicPartitionsForSlot(
Tianjie3a55fc22021-02-13 16:02:22 -08001213 uint32_t slot,
1214 uint32_t current_slot,
1215 std::vector<std::string>* partitions) {
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001216 CHECK(slot == source_slot_ || target_slot_ != UINT32_MAX)
1217 << " source slot: " << source_slot_ << " target slot: " << target_slot_
1218 << " slot: " << slot
1219 << " attempting to query dynamic partition metadata for target slot "
1220 "before PreparePartitionForUpdate() is called. The "
1221 "metadata in target slot isn't valid until "
1222 "PreparePartitionForUpdate() is called, contining execution would "
1223 "likely cause problems.";
Tianjie3a55fc22021-02-13 16:02:22 -08001224 bool slot_enables_dynamic_partitions =
1225 GetDynamicPartitionsFeatureFlag().IsEnabled();
1226 // Check if the target slot has dynamic partitions, this may happen when
1227 // applying a retrofit package.
1228 if (slot != current_slot) {
1229 slot_enables_dynamic_partitions =
1230 slot_enables_dynamic_partitions && is_target_dynamic_;
1231 }
1232
1233 if (!slot_enables_dynamic_partitions) {
1234 LOG(INFO) << "Dynamic partition is not enabled for slot " << slot;
1235 return true;
Tianjie99d570d2020-06-04 14:57:19 -07001236 }
1237
1238 std::string device_dir_str;
1239 TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str));
1240 base::FilePath device_dir(device_dir_str);
Tianjie3a55fc22021-02-13 16:02:22 -08001241 auto super_device = device_dir.Append(GetSuperPartitionName(slot)).value();
1242 auto builder = LoadMetadataBuilder(super_device, slot);
Tianjie99d570d2020-06-04 14:57:19 -07001243 TEST_AND_RETURN_FALSE(builder != nullptr);
1244
1245 std::vector<std::string> result;
Tianjie3a55fc22021-02-13 16:02:22 -08001246 auto suffix = SlotSuffixForSlotNumber(slot);
Tianjie99d570d2020-06-04 14:57:19 -07001247 for (const auto& group : builder->ListGroups()) {
1248 for (const auto& partition : builder->ListPartitionsInGroup(group)) {
1249 std::string_view partition_name = partition->name();
1250 if (!android::base::ConsumeSuffix(&partition_name, suffix)) {
1251 continue;
1252 }
1253 result.emplace_back(partition_name);
1254 }
1255 }
1256 *partitions = std::move(result);
1257 return true;
1258}
1259
Tianjie24f96092020-06-30 12:26:25 -07001260bool DynamicPartitionControlAndroid::VerifyExtentsForUntouchedPartitions(
1261 uint32_t source_slot,
1262 uint32_t target_slot,
1263 const std::vector<std::string>& partitions) {
1264 std::string device_dir_str;
1265 TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str));
1266 base::FilePath device_dir(device_dir_str);
1267
1268 auto source_super_device =
1269 device_dir.Append(GetSuperPartitionName(source_slot)).value();
1270 auto source_builder = LoadMetadataBuilder(source_super_device, source_slot);
1271 TEST_AND_RETURN_FALSE(source_builder != nullptr);
1272
1273 auto target_super_device =
1274 device_dir.Append(GetSuperPartitionName(target_slot)).value();
1275 auto target_builder = LoadMetadataBuilder(target_super_device, target_slot);
1276 TEST_AND_RETURN_FALSE(target_builder != nullptr);
1277
1278 return MetadataBuilder::VerifyExtentsAgainstSourceMetadata(
1279 *source_builder, source_slot, *target_builder, target_slot, partitions);
1280}
1281
Yifan Hong4d7c5eb2020-04-03 11:31:50 -07001282bool DynamicPartitionControlAndroid::ExpectMetadataMounted() {
1283 // No need to mount metadata for non-Virtual A/B devices.
1284 if (!GetVirtualAbFeatureFlag().IsEnabled()) {
1285 return false;
1286 }
1287 // Intentionally not checking |metadata_device_| in Android mode.
1288 // /metadata should always be mounted in Android mode. If it isn't, let caller
1289 // fails when calling into SnapshotManager.
1290 if (!IsRecovery()) {
1291 return true;
1292 }
1293 // In recovery mode, explicitly check |metadata_device_|.
1294 return metadata_device_ != nullptr;
1295}
1296
1297bool DynamicPartitionControlAndroid::EnsureMetadataMounted() {
1298 // No need to mount metadata for non-Virtual A/B devices.
1299 if (!GetVirtualAbFeatureFlag().IsEnabled()) {
1300 return true;
1301 }
1302
1303 if (metadata_device_ == nullptr) {
1304 metadata_device_ = snapshot_->EnsureMetadataMounted();
1305 }
1306 return metadata_device_ != nullptr;
1307}
1308
Kelvin Zhang34618522020-09-28 09:21:02 -04001309std::unique_ptr<android::snapshot::ISnapshotWriter>
1310DynamicPartitionControlAndroid::OpenCowWriter(
1311 const std::string& partition_name,
1312 const std::optional<std::string>& source_path,
1313 bool is_append) {
1314 auto suffix = SlotSuffixForSlotNumber(target_slot_);
1315
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -04001316 auto super_device = GetSuperDevice();
1317 if (!super_device.has_value()) {
Kelvin Zhang34618522020-09-28 09:21:02 -04001318 return nullptr;
1319 }
Kelvin Zhang34618522020-09-28 09:21:02 -04001320 CreateLogicalPartitionParams params = {
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -04001321 .block_device = super_device->value(),
Kelvin Zhang34618522020-09-28 09:21:02 -04001322 .metadata_slot = target_slot_,
1323 .partition_name = partition_name + suffix,
1324 .force_writable = true,
Kelvin Zhang877ddbe2020-11-09 13:37:56 -05001325 .timeout_ms = kMapSnapshotTimeout};
Kelvin Zhang34618522020-09-28 09:21:02 -04001326 // TODO(zhangkelvin) Open an APPEND mode CowWriter once there's an API to do
1327 // it.
1328 return snapshot_->OpenSnapshotWriter(params, std::move(source_path));
Kelvin Zhang877ddbe2020-11-09 13:37:56 -05001329} // namespace chromeos_update_engine
Kelvin Zhang34618522020-09-28 09:21:02 -04001330
Kelvin Zhangc82511c2020-11-06 16:01:24 -05001331FileDescriptorPtr DynamicPartitionControlAndroid::OpenCowReader(
1332 const std::string& unsuffixed_partition_name,
1333 const std::optional<std::string>& source_path,
1334 bool is_append) {
1335 auto cow_writer =
1336 OpenCowWriter(unsuffixed_partition_name, source_path, is_append);
1337 if (cow_writer == nullptr) {
1338 return nullptr;
1339 }
Kelvin Zhangec205cf2020-09-28 13:23:40 -04001340 cow_writer->InitializeAppend(kEndOfInstallLabel);
Kelvin Zhangc82511c2020-11-06 16:01:24 -05001341 return cow_writer->OpenReader();
1342}
1343
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -04001344std::optional<base::FilePath> DynamicPartitionControlAndroid::GetSuperDevice() {
1345 std::string device_dir_str;
1346 if (!GetDeviceDir(&device_dir_str)) {
1347 LOG(ERROR) << "Failed to get device dir!";
1348 return {};
1349 }
1350 base::FilePath device_dir(device_dir_str);
1351 auto super_device = device_dir.Append(GetSuperPartitionName(target_slot_));
1352 return super_device;
1353}
1354
1355bool DynamicPartitionControlAndroid::MapAllPartitions() {
Kelvin Zhang877ddbe2020-11-09 13:37:56 -05001356 return snapshot_->MapAllSnapshots(kMapSnapshotTimeout);
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -04001357}
1358
Kelvin Zhangeb9de162020-11-16 15:47:28 -05001359bool DynamicPartitionControlAndroid::IsDynamicPartition(
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001360 const std::string& partition_name, uint32_t slot) {
1361 if (slot >= dynamic_partition_list_.size()) {
1362 LOG(ERROR) << "Seeing unexpected slot # " << slot << " currently assuming "
1363 << dynamic_partition_list_.size() << " slots";
1364 return false;
1365 }
1366 auto& dynamic_partition_list = dynamic_partition_list_[slot];
1367 if (dynamic_partition_list.empty() &&
Kelvin Zhangeb9de162020-11-16 15:47:28 -05001368 GetDynamicPartitionsFeatureFlag().IsEnabled()) {
Tianjie3a55fc22021-02-13 16:02:22 -08001369 // Use the DAP config of the target slot.
1370 CHECK(ListDynamicPartitionsForSlot(
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001371 slot, source_slot_, &dynamic_partition_list));
Kelvin Zhangeb9de162020-11-16 15:47:28 -05001372 }
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001373 return std::find(dynamic_partition_list.begin(),
1374 dynamic_partition_list.end(),
1375 partition_name) != dynamic_partition_list.end();
Kelvin Zhangeb9de162020-11-16 15:47:28 -05001376}
Kelvin Zhang91d95fa2020-11-05 13:52:00 -05001377
Yifan Hongb0cbd392021-02-04 11:11:45 -08001378bool DynamicPartitionControlAndroid::UpdateUsesSnapshotCompression() {
1379 return snapshot_->UpdateUsesCompression();
1380}
1381
Yifan Hong537802d2018-08-15 13:15:42 -07001382} // namespace chromeos_update_engine