HardwareInterface::IsPartitionUpdateValid: fine grained error

Let the function emit an error code instead of a boolean to indicate
details of the error that is encountered.

For every partition, if downgrade is detected, emit
kPayloadTimestampError. In this case, still check other partitions for
more severe errors before returning this error.

In some cases, e.g. DeltaArchiveManifest carries a version field that is
not a recognized format, or timestamp sysprops in Android is not an
integer, report a more severe error.

If only downgrade errors are encountered, AllowDowngrade() can still
override the result, and proceed with the update; but, AllowDowngrade
cannot override those severe errors.

Test: update_engine_unittest
Bug: 162623577
Bug: 162553432

Change-Id: Ifc2a6fcd66239c755fb4f6528c3d8c6848afcb27
diff --git a/hardware_android.cc b/hardware_android.cc
index 659e67e..361b9f1 100644
--- a/hardware_android.cc
+++ b/hardware_android.cc
@@ -27,6 +27,7 @@
 #include <base/files/file_util.h>
 #include <bootloader_message/bootloader_message.h>
 
+#include "update_engine/common/error_code_utils.h"
 #include "update_engine/common/hardware.h"
 #include "update_engine/common/platform_constants.h"
 #include "update_engine/common/utils.h"
@@ -233,18 +234,19 @@
                                     "");
 }
 
-bool HardwareAndroid::IsPartitionUpdateValid(
+ErrorCode HardwareAndroid::IsPartitionUpdateValid(
     const std::string& partition_name, const std::string& new_version) const {
   const auto old_version = GetVersionForLogging(partition_name);
   // TODO(zhangkelvin)  for some partitions, missing a current timestamp should
   // be an error, e.g. system, vendor, product etc.
-  auto applicable = utils::IsTimestampNewer(old_version, new_version);
-  if (!applicable) {
-    LOG(ERROR) << "Timestamp on partition " << partition_name
-               << " is newer than update. Partition timestamp: " << old_version
+  auto error_code = utils::IsTimestampNewer(old_version, new_version);
+  if (error_code != ErrorCode::kSuccess) {
+    LOG(ERROR) << "Timestamp check failed with "
+               << utils::ErrorCodeToString(error_code)
+               << " Partition timestamp: " << old_version
                << " Update timestamp: " << new_version;
   }
-  return applicable;
+  return error_code;
 }
 
 }  // namespace chromeos_update_engine