Fix merge in sideload
For UpdateAttempterAndroid:
- In sideload, ApplyPayload is immediately called after
UpdateAttempterAndroid::Init(), and errors out because
ScheduleCleanupPreviousUpdate starts the ActionProcessor. Do not
call it in sideload since ApplyPayload schedules a
CleanupPreviousUpdateAction too.
- Also fixes TerminateUpdateAndNotify in sideload if it errors at
CleanupPreviousUpdateAction.
For CleanupPreviousUpdateAction:
- Don't wait for boot_completed and slot verification in sideload.
- Ensure metadata is mounted.
Fixes: 151640692
Test: sideload
Change-Id: Ib91b208d3f8d79285b9a87a44410a575bd2da42e
Merged-In: Ib91b208d3f8d79285b9a87a44410a575bd2da42e
diff --git a/cleanup_previous_update_action.cc b/cleanup_previous_update_action.cc
index 6c5cd1c..91373d4 100644
--- a/cleanup_previous_update_action.cc
+++ b/cleanup_previous_update_action.cc
@@ -43,6 +43,12 @@
// Interval to call SnapshotManager::ProcessUpdateState
constexpr auto kWaitForMergeInterval = base::TimeDelta::FromSeconds(2);
+#ifdef __ANDROID_RECOVERY__
+static constexpr bool kIsRecovery = true;
+#else
+static constexpr bool kIsRecovery = false;
+#endif
+
namespace chromeos_update_engine {
CleanupPreviousUpdateAction::CleanupPreviousUpdateAction(
@@ -84,6 +90,7 @@
void CleanupPreviousUpdateAction::ActionCompleted(ErrorCode error_code) {
running_ = false;
ReportMergeStats();
+ metadata_device_ = nullptr;
}
std::string CleanupPreviousUpdateAction::Type() const {
@@ -118,7 +125,8 @@
void CleanupPreviousUpdateAction::WaitBootCompletedOrSchedule() {
TEST_AND_RETURN(running_);
- if (!android::base::GetBoolProperty(kBootCompletedProp, false)) {
+ if (!kIsRecovery &&
+ !android::base::GetBoolProperty(kBootCompletedProp, false)) {
// repeat
ScheduleWaitBootCompleted();
return;
@@ -140,9 +148,21 @@
void CleanupPreviousUpdateAction::CheckSlotMarkedSuccessfulOrSchedule() {
TEST_AND_RETURN(running_);
- if (!boot_control_->IsSlotMarkedSuccessful(boot_control_->GetCurrentSlot())) {
+ if (!kIsRecovery &&
+ !boot_control_->IsSlotMarkedSuccessful(boot_control_->GetCurrentSlot())) {
ScheduleWaitMarkBootSuccessful();
}
+
+ if (metadata_device_ == nullptr) {
+ metadata_device_ = snapshot_->EnsureMetadataMounted();
+ }
+
+ if (metadata_device_ == nullptr) {
+ LOG(ERROR) << "Failed to mount /metadata.";
+ processor_->ActionComplete(this, ErrorCode::kError);
+ return;
+ }
+
if (!merge_stats_->Start()) {
// Not an error because CleanupPreviousUpdateAction may be paused and
// resumed while kernel continues merging snapshots in the background.
diff --git a/cleanup_previous_update_action.h b/cleanup_previous_update_action.h
index 7b1586c..91e08b0 100644
--- a/cleanup_previous_update_action.h
+++ b/cleanup_previous_update_action.h
@@ -69,6 +69,7 @@
BootControlInterface* boot_control_;
android::snapshot::SnapshotManager* snapshot_;
CleanupPreviousUpdateActionDelegateInterface* delegate_;
+ std::unique_ptr<android::snapshot::AutoDevice> metadata_device_;
bool running_{false};
bool cancel_failed_{false};
unsigned int last_percentage_{0};
diff --git a/update_attempter_android.cc b/update_attempter_android.cc
index eecd2da..4b198e2 100644
--- a/update_attempter_android.cc
+++ b/update_attempter_android.cc
@@ -158,7 +158,12 @@
} else {
SetStatusAndNotify(UpdateStatus::IDLE);
UpdatePrefsAndReportUpdateMetricsOnReboot();
+#ifdef _UE_SIDELOAD
+ LOG(INFO) << "Skip ScheduleCleanupPreviousUpdate in sideload because "
+ << "ApplyPayload will call it later.";
+#else
ScheduleCleanupPreviousUpdate();
+#endif
}
}
@@ -644,6 +649,8 @@
if (status_ == UpdateStatus::CLEANUP_PREVIOUS_UPDATE) {
LOG(INFO) << "Terminating cleanup previous update.";
SetStatusAndNotify(UpdateStatus::IDLE);
+ for (auto observer : daemon_state_->service_observers())
+ observer->SendPayloadApplicationComplete(error_code);
return;
}