Call SnapshotManager::CancelUpdate on downgrade path
When applying a downgrade package on Virtual A/B
device, /metadata/ota/state may not be present,
and the attempt to unmap any previous devices,UnmapUpdateSnapshot
may fail.
Call CancelUpdate() no matter what OTA package (update, downgrade)
is applied.
Test: apply downgrade when /metadata/ota/state is not present
Bug: 138258570
Change-Id: If9a438762db757089376d531b752ac384caa059c
diff --git a/dynamic_partition_control_android.cc b/dynamic_partition_control_android.cc
index 2bd7d51..90e489a 100644
--- a/dynamic_partition_control_android.cc
+++ b/dynamic_partition_control_android.cc
@@ -352,9 +352,20 @@
if (!update)
return true;
- if (GetVirtualAbFeatureFlag().IsEnabled() && target_supports_snapshot_) {
- return PrepareSnapshotPartitionsForUpdate(
- source_slot, target_slot, manifest);
+ if (GetVirtualAbFeatureFlag().IsEnabled()) {
+ // On Virtual A/B device, either CancelUpdate() or BeginUpdate() must be
+ // called before calling UnmapUpdateSnapshot.
+ // - If target_supports_snapshot_, PrepareSnapshotPartitionsForUpdate()
+ // calls BeginUpdate() which resets update state
+ // - If !target_supports_snapshot_, explicitly CancelUpdate().
+ if (target_supports_snapshot_) {
+ return PrepareSnapshotPartitionsForUpdate(
+ source_slot, target_slot, manifest);
+ }
+ if (!snapshot_->CancelUpdate()) {
+ LOG(ERROR) << "Cannot cancel previous update.";
+ return false;
+ }
}
return PrepareDynamicPartitionsForUpdate(source_slot, target_slot, manifest);
}