[aapt2] Ensure all zip entry times are the same

We want them to be all the same, so that APKs are identical if its
contents are the same, regardless of the time zone of the machine that
produced them. The accompanying change in libziparchive
(Iefc7945bff0610f8a025d4887cd5644cfa3cfb3b) ensures this.

Bug: 277978832
Test: atest aapt2_tests
Change-Id: Iab000b7c74dcb06efad41a6495b73216fd2528d6
diff --git a/tools/aapt2/io/FileSystem.cpp b/tools/aapt2/io/FileSystem.cpp
index a64982a..6a692e4 100644
--- a/tools/aapt2/io/FileSystem.cpp
+++ b/tools/aapt2/io/FileSystem.cpp
@@ -14,9 +14,12 @@
  * limitations under the License.
  */
 
+#define _POSIX_THREAD_SAFE_FUNCTIONS  // For mingw localtime_r().
+
 #include "io/FileSystem.h"
 
 #include <dirent.h>
+#include <sys/stat.h>
 
 #include "android-base/errors.h"
 #include "androidfw/Source.h"
@@ -54,6 +57,23 @@
   return source_;
 }
 
+bool RegularFile::GetModificationTime(struct tm* buf) const {
+  if (buf == nullptr) {
+    return false;
+  }
+  struct stat stat_buf;
+  if (stat(source_.path.c_str(), &stat_buf) != 0) {
+    return false;
+  }
+
+  struct tm* ptm;
+  struct tm tm_result;
+  ptm = localtime_r(&stat_buf.st_mtime, &tm_result);
+
+  *buf = *ptm;
+  return true;
+}
+
 FileCollectionIterator::FileCollectionIterator(FileCollection* collection)
     : current_(collection->files_.begin()), end_(collection->files_.end()) {}