Reset the update progress when partition verification fails.

When the update completes and there is an error verifying the new
partitions we need to reset the update progress proactivelly to
prevent the update failing repeatedly until we hit the 10 retries
limit. This patch will reset the update progress when the payload
application fails to verify the contents of the newly written
partition.

Bug: 30162558
TEST=Push an update, cancel it at 90%, erase some blocks in system,
continue the update (restarts at 90% and then fails), launch the update
again (restarts from 0%).

Change-Id: I35915d04efe5c90d1a7add2e4c2807e2fe19857b
diff --git a/update_attempter_android.cc b/update_attempter_android.cc
index 7314a1d..01eb320 100644
--- a/update_attempter_android.cc
+++ b/update_attempter_android.cc
@@ -260,14 +260,31 @@
                                             ErrorCode code) {
   LOG(INFO) << "Processing Done.";
 
-  if (code == ErrorCode::kSuccess) {
-    // Update succeeded.
-    WriteUpdateCompletedMarker();
-    prefs_->SetInt64(kPrefsDeltaUpdateFailures, 0);
-    DeltaPerformer::ResetUpdateProgress(prefs_, false);
+  switch (code) {
+    case ErrorCode::kSuccess:
+      // Update succeeded.
+      WriteUpdateCompletedMarker();
+      prefs_->SetInt64(kPrefsDeltaUpdateFailures, 0);
+      DeltaPerformer::ResetUpdateProgress(prefs_, false);
 
-    LOG(INFO) << "Update successfully applied, waiting to reboot.";
-  }
+      LOG(INFO) << "Update successfully applied, waiting to reboot.";
+      break;
+
+    case ErrorCode::kFilesystemCopierError:
+    case ErrorCode::kNewRootfsVerificationError:
+    case ErrorCode::kNewKernelVerificationError:
+    case ErrorCode::kFilesystemVerifierError:
+    case ErrorCode::kDownloadStateInitializationError:
+      // Reset the ongoing update for these errors so it starts from the
+      // beginning next time.
+      DeltaPerformer::ResetUpdateProgress(prefs_, false);
+      LOG(INFO) << "Resetting update progress.";
+      break;
+
+    default:
+      // Ignore all other error codes.
+      break;
+ }
 
   TerminateUpdateAndNotify(code);
 }