Use ActionProcessor::IsRunning() to check for ongoing update.

If we started the update but the action processor haven't started yet,
and at this moment we get a call to CancelUpdate(), |ongoing_update_|
will be true but processor_->IsRunning() is false, which will crash by
CHECK(IsRunning()) in ActionProcessor::StopProcessing().

We can simply always use ActionProcessor::IsRunning() to track the state
and remove |ongoing_update_| variable.

Bug: 111354431
Test: start an update and cancel it
Change-Id: I1bcb4ecf62d931e649389062bd6a08834d94a4cc
diff --git a/update_attempter_android.cc b/update_attempter_android.cc
index 2f842ac..76fa92e 100644
--- a/update_attempter_android.cc
+++ b/update_attempter_android.cc
@@ -137,7 +137,7 @@
     return LogAndSetError(
         error, FROM_HERE, "An update already applied, waiting for reboot");
   }
-  if (ongoing_update_) {
+  if (processor_->IsRunning()) {
     return LogAndSetError(
         error, FROM_HERE, "Already processing an update, cancel it first.");
   }
@@ -254,7 +254,6 @@
     fetcher->SetHeader("User-Agent", headers[kPayloadPropertyUserAgent]);
 
   SetStatusAndNotify(UpdateStatus::UPDATE_AVAILABLE);
-  ongoing_update_ = true;
 
   // Just in case we didn't update boot flags yet, make sure they're updated
   // before any update processing starts. This will start the update process.
@@ -267,21 +266,21 @@
 }
 
 bool UpdateAttempterAndroid::SuspendUpdate(brillo::ErrorPtr* error) {
-  if (!ongoing_update_)
+  if (!processor_->IsRunning())
     return LogAndSetError(error, FROM_HERE, "No ongoing update to suspend.");
   processor_->SuspendProcessing();
   return true;
 }
 
 bool UpdateAttempterAndroid::ResumeUpdate(brillo::ErrorPtr* error) {
-  if (!ongoing_update_)
+  if (!processor_->IsRunning())
     return LogAndSetError(error, FROM_HERE, "No ongoing update to resume.");
   processor_->ResumeProcessing();
   return true;
 }
 
 bool UpdateAttempterAndroid::CancelUpdate(brillo::ErrorPtr* error) {
-  if (!ongoing_update_)
+  if (!processor_->IsRunning())
     return LogAndSetError(error, FROM_HERE, "No ongoing update to cancel.");
   processor_->StopProcessing();
   return true;
@@ -568,7 +567,6 @@
       (error_code == ErrorCode::kSuccess ? UpdateStatus::UPDATED_NEED_REBOOT
                                          : UpdateStatus::IDLE);
   SetStatusAndNotify(new_status);
-  ongoing_update_ = false;
 
   // The network id is only applicable to one download attempt and once it's
   // done the network id should not be re-used anymore.
diff --git a/update_attempter_android.h b/update_attempter_android.h
index f00692e..a8f388c 100644
--- a/update_attempter_android.h
+++ b/update_attempter_android.h
@@ -179,11 +179,6 @@
   // Pointer to the DownloadAction in the actions_ vector.
   std::shared_ptr<DownloadAction> download_action_;
 
-  // Whether there is an ongoing update. This implies that an update was started
-  // but not finished yet. This value will be true even if the update was
-  // suspended.
-  bool ongoing_update_{false};
-
   // The InstallPlan used during the ongoing update.
   InstallPlan install_plan_;