Revert "Remove changing uids/timestamps from zip/jar files"

This reverts commit 3c2c064c8791ed2d4b9d6780d7b87f406ab78f10.

zipalign depends on libandroidfw, and some setups don't include frameworks/base.

Bug: 24201956
Change-Id: I48ee95808924f6b2221f0a49ab205c2565096b1f
diff --git a/tools/zipalign/README.txt b/tools/zipalign/README.txt
index 1cdf612..0b80b35 100644
--- a/tools/zipalign/README.txt
+++ b/tools/zipalign/README.txt
@@ -6,7 +6,6 @@
   -c : check alignment only (does not modify file)
   -f : overwrite existing outfile.zip
   -p : page align stored shared object files
-  -t : remove dynamic timestamps
   -v : verbose output
   <align> is in bytes, e.g. "4" provides 32-bit alignment
   infile.zip is an existing Zip archive
@@ -39,5 +38,3 @@
 uncompressed in the zip archive, to a 4096-byte page boundary.  This
 facilitates directly loading shared libraries from inside a zip archive.
 
-The "-t" flag removes all timestamps that could change from the archive.
-
diff --git a/tools/zipalign/ZipAlign.cpp b/tools/zipalign/ZipAlign.cpp
index 2c81a03..a2dfd02 100644
--- a/tools/zipalign/ZipAlign.cpp
+++ b/tools/zipalign/ZipAlign.cpp
@@ -39,7 +39,6 @@
     fprintf(stderr, "  -c: check alignment only (does not modify file)\n");
     fprintf(stderr, "  -f: overwrite existing outfile.zip\n");
     fprintf(stderr, "  -p: page align stored shared object files\n");
-    fprintf(stderr, "  -t: remove dynamic timestamps\n");
     fprintf(stderr, "  -v: verbose output\n");
     fprintf(stderr, "  -z: recompress using Zopfli\n");
 }
@@ -65,7 +64,7 @@
  * Copy all entries from "pZin" to "pZout", aligning as needed.
  */
 static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment, bool zopfli,
-    bool pageAlignSharedLibs, bool removeTime)
+    bool pageAlignSharedLibs)
 {
     int numEntries = pZin->getNumEntries();
     ZipEntry* pEntry;
@@ -89,10 +88,10 @@
             //    (long) pEntry->getUncompressedLen());
 
             if (zopfli) {
-                status = pZout->addRecompress(pZin, pEntry, removeTime, &pNewEntry);
+                status = pZout->addRecompress(pZin, pEntry, &pNewEntry);
                 bias += pNewEntry->getCompressedLen() - pEntry->getCompressedLen();
             } else {
-                status = pZout->add(pZin, pEntry, padding, removeTime, &pNewEntry);
+                status = pZout->add(pZin, pEntry, padding, &pNewEntry);
             }
         } else {
             const int alignTo = getAlignment(pageAlignSharedLibs, alignment, pEntry);
@@ -108,7 +107,7 @@
             //printf("--- %s: orig at %ld(+%d) len=%ld, adding pad=%d\n",
             //    pEntry->getFileName(), (long) pEntry->getFileOffset(),
             //    bias, (long) pEntry->getUncompressedLen(), padding);
-            status = pZout->add(pZin, pEntry, padding, removeTime, &pNewEntry);
+            status = pZout->add(pZin, pEntry, padding, &pNewEntry);
         }
 
         if (status != NO_ERROR)
@@ -127,8 +126,7 @@
  * output file exists and "force" wasn't specified.
  */
 static int process(const char* inFileName, const char* outFileName,
-    int alignment, bool force, bool zopfli, bool pageAlignSharedLibs,
-    bool removeTime)
+    int alignment, bool force, bool zopfli, bool pageAlignSharedLibs)
 {
     ZipFile zin, zout;
 
@@ -159,7 +157,7 @@
         return 1;
     }
 
-    int result = copyAndAlign(&zin, &zout, alignment, zopfli, pageAlignSharedLibs, removeTime);
+    int result = copyAndAlign(&zin, &zout, alignment, zopfli, pageAlignSharedLibs);
     if (result != 0) {
         printf("zipalign: failed rewriting '%s' to '%s'\n",
             inFileName, outFileName);
@@ -230,7 +228,6 @@
     bool verbose = false;
     bool zopfli = false;
     bool pageAlignSharedLibs = false;
-    bool removeTime = false;
     int result = 1;
     int alignment;
     char* endp;
@@ -263,9 +260,6 @@
             case 'p':
                 pageAlignSharedLibs = true;
                 break;
-            case 't':
-                removeTime = true;
-                break;
             default:
                 fprintf(stderr, "ERROR: unknown flag -%c\n", *cp);
                 wantUsage = true;
@@ -296,7 +290,7 @@
         result = verify(argv[1], alignment, verbose, pageAlignSharedLibs);
     } else {
         /* create the new archive */
-        result = process(argv[1], argv[2], alignment, force, zopfli, pageAlignSharedLibs, removeTime);
+        result = process(argv[1], argv[2], alignment, force, zopfli, pageAlignSharedLibs);
 
         /* trust, but verify */
         if (result == 0) {
diff --git a/tools/zipalign/ZipEntry.cpp b/tools/zipalign/ZipEntry.cpp
index 9347451..b2270cb 100644
--- a/tools/zipalign/ZipEntry.cpp
+++ b/tools/zipalign/ZipEntry.cpp
@@ -386,14 +386,6 @@
     mCDE.mLastModFileDate = mLFH.mLastModFileDate = zdate;
 }
 
-/*
- * Set static timestamps
- */
-void ZipEntry::removeTimestamps()
-{
-    mCDE.mLastModFileTime = mLFH.mLastModFileTime = 0;
-    mCDE.mLastModFileDate = mLFH.mLastModFileDate = 28 << 9 | 1 << 5 | 1;
-}
 
 /*
  * ===========================================================================
diff --git a/tools/zipalign/ZipEntry.h b/tools/zipalign/ZipEntry.h
index 0acd051..7f721b4 100644
--- a/tools/zipalign/ZipEntry.h
+++ b/tools/zipalign/ZipEntry.h
@@ -186,12 +186,6 @@
     void setModWhen(time_t when);
 
     /*
-     * Set a static modification date. This only affects the standard
-     * zip modification date, not the universal time extra field.
-     */
-    void removeTimestamps();
-
-    /*
      * Return the offset of the local file header.
      */
     off_t getLFHOffset(void) const { return mCDE.mLocalHeaderRelOffset; }
diff --git a/tools/zipalign/ZipFile.cpp b/tools/zipalign/ZipFile.cpp
index 0ca4d0d..3c5ec15 100644
--- a/tools/zipalign/ZipFile.cpp
+++ b/tools/zipalign/ZipFile.cpp
@@ -359,7 +359,7 @@
  */
 status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
     const char* storageName, int sourceType, int compressionMethod,
-    bool removeTime, ZipEntry** ppEntry)
+    ZipEntry** ppEntry)
 {
     ZipEntry* pEntry = NULL;
     status_t result = NO_ERROR;
@@ -499,12 +499,8 @@
      */
     pEntry->setDataInfo(uncompressedLen, endPosn - startPosn, crc,
         compressionMethod);
-    if (removeTime) {
-        pEntry->removeTimestamps();
-    } else {
-        modWhen = getModTime(inputFp ? fileno(inputFp) : fileno(mZipFp));
-        pEntry->setModWhen(modWhen);
-    }
+    modWhen = getModTime(inputFp ? fileno(inputFp) : fileno(mZipFp));
+    pEntry->setModWhen(modWhen);
     pEntry->setLFHOffset(lfhPosn);
     mEOCD.mNumEntries++;
     mEOCD.mTotalNumEntries++;
@@ -543,7 +539,7 @@
  * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
  */
 status_t ZipFile::add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
-    int padding, bool removeTime, ZipEntry** ppEntry)
+    int padding, ZipEntry** ppEntry)
 {
     ZipEntry* pEntry = NULL;
     status_t result;
@@ -575,8 +571,6 @@
         if (result != NO_ERROR)
             goto bail;
     }
-    if (removeTime)
-        pEntry->removeTimestamps();
 
     /*
      * From here on out, failures are more interesting.
@@ -652,7 +646,7 @@
  * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
  */
 status_t ZipFile::addRecompress(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
-    bool removeTime, ZipEntry** ppEntry)
+    ZipEntry** ppEntry)
 {
     ZipEntry* pEntry = NULL;
     status_t result;
@@ -680,9 +674,6 @@
     if (result != NO_ERROR)
         goto bail;
 
-    if (removeTime)
-        pEntry->removeTimestamps();
-
     /*
      * From here on out, failures are more interesting.
      */
diff --git a/tools/zipalign/ZipFile.h b/tools/zipalign/ZipFile.h
index 787576f..b99cda5 100644
--- a/tools/zipalign/ZipFile.h
+++ b/tools/zipalign/ZipFile.h
@@ -77,17 +77,17 @@
      *
      * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
      */
-    status_t add(const char* fileName, int compressionMethod, bool removeTime,
+    status_t add(const char* fileName, int compressionMethod,
         ZipEntry** ppEntry)
     {
-        return add(fileName, fileName, compressionMethod, removeTime, ppEntry);
+        return add(fileName, fileName, compressionMethod, ppEntry);
     }
     status_t add(const char* fileName, const char* storageName,
-        int compressionMethod, bool removeTime, ZipEntry** ppEntry)
+        int compressionMethod, ZipEntry** ppEntry)
     {
         return addCommon(fileName, NULL, 0, storageName,
                          ZipEntry::kCompressStored,
-                         compressionMethod, removeTime, ppEntry);
+                         compressionMethod, ppEntry);
     }
 
     /*
@@ -96,12 +96,11 @@
      * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
      */
     status_t addGzip(const char* fileName, const char* storageName,
-        bool removeTime, ZipEntry** ppEntry)
+        ZipEntry** ppEntry)
     {
         return addCommon(fileName, NULL, 0, storageName,
                          ZipEntry::kCompressDeflated,
-                         ZipEntry::kCompressDeflated,
-                         removeTime, ppEntry);
+                         ZipEntry::kCompressDeflated, ppEntry);
     }
 
     /*
@@ -110,11 +109,11 @@
      * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
      */
     status_t add(const void* data, size_t size, const char* storageName,
-        int compressionMethod, bool removeTime, ZipEntry** ppEntry)
+        int compressionMethod, ZipEntry** ppEntry)
     {
         return addCommon(NULL, data, size, storageName,
                          ZipEntry::kCompressStored,
-                         compressionMethod, removeTime, ppEntry);
+                         compressionMethod, ppEntry);
     }
 
     /*
@@ -125,7 +124,7 @@
      * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
      */
     status_t add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
-        int padding, bool removeTime, ZipEntry** ppEntry);
+        int padding, ZipEntry** ppEntry);
 
     /*
      * Add an entry by copying it from another zip file, recompressing with
@@ -134,7 +133,7 @@
      * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
      */
     status_t addRecompress(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
-        bool removeTime, ZipEntry** ppEntry);
+        ZipEntry** ppEntry);
 
     /*
      * Mark an entry as having been removed.  It is not actually deleted
@@ -233,7 +232,7 @@
     /* common handler for all "add" functions */
     status_t addCommon(const char* fileName, const void* data, size_t size,
         const char* storageName, int sourceType, int compressionMethod,
-        bool removeTime, ZipEntry** ppEntry);
+        ZipEntry** ppEntry);
 
     /* copy all of "srcFp" into "dstFp" */
     status_t copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32);