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/common/utils.cc b/common/utils.cc
index bbb155f..5d76f3f 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -990,19 +990,26 @@
   return true;
 }
 
-bool IsTimestampNewer(const std::string& old_version,
-                      const std::string& new_version) {
+ErrorCode IsTimestampNewer(const std::string& old_version,
+                           const std::string& new_version) {
   if (old_version.empty() || new_version.empty()) {
     LOG(WARNING)
         << "One of old/new timestamp is empty, permit update anyway. Old: "
         << old_version << " New: " << new_version;
-    return true;
+    return ErrorCode::kSuccess;
   }
   int64_t old_ver = 0;
-  TEST_AND_RETURN_FALSE(ParseTimestamp(old_version, &old_ver));
+  if (!ParseTimestamp(old_version, &old_ver)) {
+    return ErrorCode::kError;
+  }
   int64_t new_ver = 0;
-  TEST_AND_RETURN_FALSE(ParseTimestamp(new_version, &new_ver));
-  return old_ver <= new_ver;
+  if (!ParseTimestamp(new_version, &new_ver)) {
+    return ErrorCode::kDownloadManifestParseError;
+  }
+  if (old_ver > new_ver) {
+    return ErrorCode::kPayloadTimestampError;
+  }
+  return ErrorCode::kSuccess;
 }
 
 }  // namespace utils