Adding error for when overlayfs is enabled in OTA

when running adb remount, overlayfs is enabled on the device interfering
with OTA being able to run. Currently we don't have a good debug message
and users aren't able to realize why the OTA fails. Adding this log will
make it clear this behavior is intended, and we need verity-enabled for
OTA to work

Test: adb remount, update_device.py
Bug: 286889613
Change-Id: Ibcd27911afe6f02ddf0c38ad40904a7e17735b31
diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc
index 298bde1..267805e 100644
--- a/payload_consumer/delta_performer.cc
+++ b/payload_consumer/delta_performer.cc
@@ -440,6 +440,9 @@
 // were written, or false on any error, regardless of progress
 // and stores an action exit code in |error|.
 bool DeltaPerformer::Write(const void* bytes, size_t count, ErrorCode* error) {
+  if (!error) {
+    return false;
+  }
   *error = ErrorCode::kSuccess;
   const char* c_bytes = reinterpret_cast<const char*>(bytes);
 
@@ -730,8 +733,10 @@
   // slot suffix of the partitions in the metadata.
   if (install_plan_->target_slot != BootControlInterface::kInvalidSlot) {
     uint64_t required_size = 0;
-    if (!PreparePartitionsForUpdate(&required_size)) {
-      if (required_size > 0) {
+    if (!PreparePartitionsForUpdate(&required_size, error)) {
+      if (*error == ErrorCode::kOverlayfsenabledError) {
+        return false;
+      } else if (required_size > 0) {
         *error = ErrorCode::kNotEnoughSpace;
       } else {
         *error = ErrorCode::kInstallDeviceOpenError;
@@ -802,7 +807,8 @@
   return true;
 }
 
-bool DeltaPerformer::PreparePartitionsForUpdate(uint64_t* required_size) {
+bool DeltaPerformer::PreparePartitionsForUpdate(uint64_t* required_size,
+                                                ErrorCode* error) {
   // Call static PreparePartitionsForUpdate with hash from
   // kPrefsUpdateCheckResponseHash to ensure hash of payload that space is
   // preallocated for is the same as the hash of payload being applied.
@@ -814,7 +820,8 @@
                                     install_plan_->target_slot,
                                     manifest_,
                                     update_check_response_hash,
-                                    required_size);
+                                    required_size,
+                                    error);
 }
 
 bool DeltaPerformer::PreparePartitionsForUpdate(
@@ -823,7 +830,8 @@
     BootControlInterface::Slot target_slot,
     const DeltaArchiveManifest& manifest,
     const std::string& update_check_response_hash,
-    uint64_t* required_size) {
+    uint64_t* required_size,
+    ErrorCode* error) {
   string last_hash;
   ignore_result(
       prefs->GetString(kPrefsDynamicPartitionMetadataUpdated, &last_hash));
@@ -845,9 +853,11 @@
           target_slot,
           manifest,
           !is_resume /* should update */,
-          required_size)) {
+          required_size,
+          error)) {
     LOG(ERROR) << "Unable to initialize partition metadata for slot "
-               << BootControlInterface::SlotName(target_slot);
+               << BootControlInterface::SlotName(target_slot) << " "
+               << utils::ErrorCodeToString(*error);
     return false;
   }
 
diff --git a/payload_consumer/delta_performer.h b/payload_consumer/delta_performer.h
index 2616b6e..e83e000 100644
--- a/payload_consumer/delta_performer.h
+++ b/payload_consumer/delta_performer.h
@@ -158,7 +158,7 @@
   // complete metadata. Returns kMetadataParseError if the metadata can't be
   // parsed given the payload.
   MetadataParseResult ParsePayloadMetadata(const brillo::Blob& payload,
-                                           ErrorCode* error);
+                                           ErrorCode* error = nullptr);
 
   void set_public_key_path(const std::string& public_key_path) {
     public_key_path_ = public_key_path;
@@ -189,7 +189,8 @@
       BootControlInterface::Slot target_slot,
       const DeltaArchiveManifest& manifest,
       const std::string& update_check_response_hash,
-      uint64_t* required_size);
+      uint64_t* required_size,
+      ErrorCode* error = nullptr);
 
  protected:
   // Exposed as virtual for testing purposes.
@@ -221,7 +222,7 @@
   // Parse and move the update instructions of all partitions into our local
   // |partitions_| variable based on the version of the payload. Requires the
   // manifest to be parsed and valid.
-  bool ParseManifestPartitions(ErrorCode* error);
+  bool ParseManifestPartitions(ErrorCode* error = nullptr);
 
   // Appends up to |*count_p| bytes from |*bytes_p| to |buffer_|, but only to
   // the extent that the size of |buffer_| does not exceed |max|. Advances
@@ -233,7 +234,7 @@
   // sets |*error| accordingly. Otherwise does nothing. Returns |op_result|.
   bool HandleOpResult(bool op_result,
                       const char* op_type_name,
-                      ErrorCode* error);
+                      ErrorCode* error = nullptr);
 
   // Logs the progress of downloading/applying an update.
   void LogProgress(const char* message_prefix);
@@ -263,9 +264,9 @@
   bool PerformReplaceOperation(const InstallOperation& operation);
   bool PerformZeroOrDiscardOperation(const InstallOperation& operation);
   bool PerformSourceCopyOperation(const InstallOperation& operation,
-                                  ErrorCode* error);
+                                  ErrorCode* error = nullptr);
   bool PerformDiffOperation(const InstallOperation& operation,
-                            ErrorCode* error);
+                            ErrorCode* error = nullptr);
 
   // Extracts the payload signature message from the current |buffer_| if the
   // offset matches the one specified by the manifest. Returns whether the
@@ -300,7 +301,8 @@
   // After install_plan_ is filled with partition names and sizes, initialize
   // metadata of partitions and map necessary devices before opening devices.
   // Also see comment for the static PreparePartitionsForUpdate().
-  bool PreparePartitionsForUpdate(uint64_t* required_size);
+  bool PreparePartitionsForUpdate(uint64_t* required_size,
+                                  ErrorCode* error = nullptr);
 
   // Check if current manifest contains timestamp errors.
   // Return: