Implement a new resetStatus() method in Android interface.
When an alredy applied update is deleted from the server (normally
because is was detected to be a bad update), we need to go back to
the idle state and remove the update to prevent it from breaking
more devices.
This patch allows the application side to reset the applied update
back to idle.
Bug: 27081760
TEST=Deployed on a non-Brillo device, sent resetStatus.
Change-Id: I1bf5a141388250d225515e40f13bc3564fa5d957
diff --git a/update_attempter_android.cc b/update_attempter_android.cc
index f7bcab1..90501fb 100644
--- a/update_attempter_android.cc
+++ b/update_attempter_android.cc
@@ -35,6 +35,7 @@
#include "update_engine/payload_consumer/download_action.h"
#include "update_engine/payload_consumer/filesystem_verifier_action.h"
#include "update_engine/payload_consumer/postinstall_runner_action.h"
+#include "update_engine/update_status_utils.h"
using base::Bind;
using base::TimeDelta;
@@ -199,6 +200,44 @@
return LogAndSetError(error, FROM_HERE, "Cancel not implemented");
}
+bool UpdateAttempterAndroid::ResetStatus(brillo::ErrorPtr* error) {
+ LOG(INFO) << "Attempting to reset state from "
+ << UpdateStatusToString(status_) << " to UpdateStatus::IDLE";
+
+ switch (status_) {
+ case UpdateStatus::IDLE:
+ return true;
+
+ case UpdateStatus::UPDATED_NEED_REBOOT: {
+ // Remove the reboot marker so that if the machine is rebooted
+ // after resetting to idle state, it doesn't go back to
+ // UpdateStatus::UPDATED_NEED_REBOOT state.
+ bool ret_value = prefs_->Delete(kPrefsUpdateCompletedOnBootId);
+
+ // Update the boot flags so the current slot has higher priority.
+ if (!boot_control_->SetActiveBootSlot(boot_control_->GetCurrentSlot()))
+ ret_value = false;
+
+ if (!ret_value) {
+ return LogAndSetError(
+ error,
+ FROM_HERE,
+ "Failed to reset the status to ");
+ }
+
+ SetStatusAndNotify(UpdateStatus::IDLE);
+ LOG(INFO) << "Reset status successful";
+ return true;
+ }
+
+ default:
+ return LogAndSetError(
+ error,
+ FROM_HERE,
+ "Reset not allowed in this state. Cancel the ongoing update first");
+ }
+}
+
void UpdateAttempterAndroid::ProcessingDone(const ActionProcessor* processor,
ErrorCode code) {
LOG(INFO) << "Processing Done.";