Add DynamicPartitionControlInterface::CleanupSuccessfulUpdate
This is a wrapper over SnapshotManager::WaitForMerge. It waits until the
previous update is merged, then return.
Bug: 138808328
Test: manual with update_engine_client
Change-Id: If44854810f37dd959ffdf3f62f26528867a71fc8
diff --git a/common/dynamic_partition_control_interface.h b/common/dynamic_partition_control_interface.h
index 19bb523..48cd9be 100644
--- a/common/dynamic_partition_control_interface.h
+++ b/common/dynamic_partition_control_interface.h
@@ -22,6 +22,7 @@
#include <memory>
#include <string>
+#include "update_engine/common/error_code.h"
#include "update_engine/update_metadata.pb.h"
namespace chromeos_update_engine {
@@ -77,6 +78,14 @@
// After writing to new partitions, before rebooting into the new slot, call
// this function to indicate writes to new partitions are done.
virtual bool FinishUpdate() = 0;
+
+ // Before applying the next update, call this function to clean up previous
+ // update files. This function blocks until delta files are merged into
+ // current OS partitions and finished cleaning up.
+ // - If successful, return kSuccess.
+ // - If any error, but caller should retry after reboot, return kError.
+ // - If any irrecoverable failures, return kDeviceCorrupted.
+ virtual ErrorCode CleanupSuccessfulUpdate() = 0;
};
} // namespace chromeos_update_engine
diff --git a/common/dynamic_partition_control_stub.cc b/common/dynamic_partition_control_stub.cc
index 974cd1b..cc36c5c 100644
--- a/common/dynamic_partition_control_stub.cc
+++ b/common/dynamic_partition_control_stub.cc
@@ -52,4 +52,8 @@
return true;
}
+ErrorCode DynamicPartitionControlStub::CleanupSuccessfulUpdate() {
+ return ErrorCode::kError;
+}
+
} // namespace chromeos_update_engine
diff --git a/common/dynamic_partition_control_stub.h b/common/dynamic_partition_control_stub.h
index 09990a7..02575a1 100644
--- a/common/dynamic_partition_control_stub.h
+++ b/common/dynamic_partition_control_stub.h
@@ -39,6 +39,7 @@
uint64_t* required_size) override;
bool FinishUpdate() override;
+ ErrorCode CleanupSuccessfulUpdate() override;
};
} // namespace chromeos_update_engine
diff --git a/dynamic_partition_control_android.cc b/dynamic_partition_control_android.cc
index bd07165..881ff11 100644
--- a/dynamic_partition_control_android.cc
+++ b/dynamic_partition_control_android.cc
@@ -53,6 +53,7 @@
using android::snapshot::Return;
using android::snapshot::SnapshotManager;
using android::snapshot::SourceCopyOperationIsClone;
+using android::snapshot::UpdateState;
namespace chromeos_update_engine {
@@ -697,4 +698,19 @@
mapped_devices_ = fake;
}
+ErrorCode DynamicPartitionControlAndroid::CleanupSuccessfulUpdate() {
+ // Already reboot into new boot. Clean up.
+ if (!GetVirtualAbFeatureFlag().IsEnabled()) {
+ return ErrorCode::kSuccess;
+ }
+ auto ret = snapshot_->WaitForMerge();
+ if (ret.is_ok()) {
+ return ErrorCode::kSuccess;
+ }
+ if (ret.error_code() == Return::ErrorCode::NEEDS_REBOOT) {
+ return ErrorCode::kError;
+ }
+ return ErrorCode::kDeviceCorrupted;
+}
+
} // namespace chromeos_update_engine
diff --git a/dynamic_partition_control_android.h b/dynamic_partition_control_android.h
index a79f41a..ba23e7c 100644
--- a/dynamic_partition_control_android.h
+++ b/dynamic_partition_control_android.h
@@ -45,6 +45,7 @@
bool update,
uint64_t* required_size) override;
bool FinishUpdate() override;
+ ErrorCode CleanupSuccessfulUpdate() override;
// Return the device for partition |partition_name| at slot |slot|.
// |current_slot| should be set to the current active slot.
diff --git a/mock_dynamic_partition_control.h b/mock_dynamic_partition_control.h
index ffabac7..1237d76 100644
--- a/mock_dynamic_partition_control.h
+++ b/mock_dynamic_partition_control.h
@@ -43,6 +43,7 @@
bool(uint32_t, uint32_t, const DeltaArchiveManifest&, bool, uint64_t*));
MOCK_METHOD0(GetVirtualAbFeatureFlag, FeatureFlag());
MOCK_METHOD0(FinishUpdate, bool());
+ MOCK_METHOD0(CleanupSuccessfulUpdate, ErrorCode());
};
class MockDynamicPartitionControlAndroid