Merge changes I7e8fcd2e,Ie12d743c

* changes:
  Add soong_javac_filter to all javac commands
  Re-enable dx support
diff --git a/core/version_defaults.mk b/core/version_defaults.mk
index 2449ea9..86d77bb 100644
--- a/core/version_defaults.mk
+++ b/core/version_defaults.mk
@@ -38,6 +38,44 @@
   include $(INTERNAL_BUILD_ID_MAKEFILE)
 endif
 
+# Returns all words in $1 up to and including $2
+define find_and_earlier
+  $(strip $(if $(1),
+    $(firstword $(1))
+    $(if $(filter $(firstword $(1)),$(2)),,
+      $(call find_and_earlier,$(wordlist 2,$(words $(1)),$(1)),$(2)))))
+endef
+
+#$(warning $(call find_and_earlier,A B C,A))
+#$(warning $(call find_and_earlier,A B C,B))
+#$(warning $(call find_and_earlier,A B C,C))
+#$(warning $(call find_and_earlier,A B C,D))
+
+define version-list
+$(1) $(1)DR1 $(1)DR2 $(1)MR1 $(1)MR2
+endef
+
+ALL_VERSIONS := O P
+ALL_VERSIONS := $(foreach v,$(ALL_VERSIONS),$(call version-list,$(v)))
+
+ifeq (,$(TARGET_PLATFORM_VERSION))
+  # Default targeted platform version
+  # TODO: PLATFORM_VERSION, PLATFORM_SDK_VERSION, etc. should be conditional
+  # on this
+  TARGET_PLATFORM_VERSION := O
+endif
+
+ifeq (,$(filter $(ALL_VERSIONS), $(TARGET_PLATFORM_VERSION)))
+$(warning Invalid TARGET_PLATFORM_VERSION '$(TARGET_PLATFORM_VERSION)', must be one of)
+$(warning $(ALL_VERSIONS))
+$(error Stopping...)
+endif
+
+ENABLED_VERSIONS := $(call find_and_earlier,$(ALL_VERSIONS),$(TARGET_PLATFORM_VERSION))
+
+$(foreach v,$(ENABLED_VERSIONS), \
+  $(eval IS_AT_LEAST_$(v) := true))
+
 ifeq "" "$(PLATFORM_VERSION)"
   # This is the canonical definition of the platform version,
   # which is the version that we reveal to the end user.
diff --git a/tools/zipalign/ZipFile.cpp b/tools/zipalign/ZipFile.cpp
index 98d02e0..1b39902 100644
--- a/tools/zipalign/ZipFile.cpp
+++ b/tools/zipalign/ZipFile.cpp
@@ -359,8 +359,7 @@
  * safely written.  Not really a concern for us.
  */
 status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
-    const char* storageName, int sourceType, int compressionMethod,
-    ZipEntry** ppEntry)
+    const char* storageName, int compressionMethod, ZipEntry** ppEntry)
 {
     ZipEntry* pEntry = NULL;
     status_t result = NO_ERROR;
@@ -414,81 +413,51 @@
     /*
      * Copy the data in, possibly compressing it as we go.
      */
-    if (sourceType == ZipEntry::kCompressStored) {
-        if (compressionMethod == ZipEntry::kCompressDeflated) {
-            bool failed = false;
-            result = compressFpToFp(mZipFp, inputFp, data, size, &crc);
-            if (result != NO_ERROR) {
-                ALOGD("compression failed, storing\n");
-                failed = true;
-            } else {
-                /*
-                 * Make sure it has compressed "enough".  This probably ought
-                 * to be set through an API call, but I don't expect our
-                 * criteria to change over time.
-                 */
-                long src = inputFp ? ftell(inputFp) : size;
-                long dst = ftell(mZipFp) - startPosn;
-                if (dst + (dst / 10) > src) {
-                    ALOGD("insufficient compression (src=%ld dst=%ld), storing\n",
-                        src, dst);
-                    failed = true;
-                }
-            }
-
-            if (failed) {
-                compressionMethod = ZipEntry::kCompressStored;
-                if (inputFp) rewind(inputFp);
-                fseek(mZipFp, startPosn, SEEK_SET);
-                /* fall through to kCompressStored case */
-            }
-        }
-        /* handle "no compression" request, or failed compression from above */
-        if (compressionMethod == ZipEntry::kCompressStored) {
-            if (inputFp) {
-                result = copyFpToFp(mZipFp, inputFp, &crc);
-            } else {
-                result = copyDataToFp(mZipFp, data, size, &crc);
-            }
-            if (result != NO_ERROR) {
-                // don't need to truncate; happens in CDE rewrite
-                ALOGD("failed copying data in\n");
-                goto bail;
-            }
-        }
-
-        // currently seeked to end of file
-        uncompressedLen = inputFp ? ftell(inputFp) : size;
-    } else if (sourceType == ZipEntry::kCompressDeflated) {
-        /* we should support uncompressed-from-compressed, but it's not
-         * important right now */
-        assert(compressionMethod == ZipEntry::kCompressDeflated);
-
-        bool scanResult;
-        int method;
-        long compressedLen;
-        unsigned long longcrc;
-
-        scanResult = ZipUtils::examineGzip(inputFp, &method, &uncompressedLen,
-                        &compressedLen, &longcrc);
-        if (!scanResult || method != ZipEntry::kCompressDeflated) {
-            ALOGD("this isn't a deflated gzip file?");
-            result = UNKNOWN_ERROR;
-            goto bail;
-        }
-        crc = longcrc;
-
-        result = copyPartialFpToFp(mZipFp, inputFp, compressedLen, NULL);
+    if (compressionMethod == ZipEntry::kCompressDeflated) {
+        bool failed = false;
+        result = compressFpToFp(mZipFp, inputFp, data, size, &crc);
         if (result != NO_ERROR) {
-            ALOGD("failed copying gzip data in\n");
+            ALOGD("compression failed, storing\n");
+            failed = true;
+        } else {
+            /*
+             * Make sure it has compressed "enough".  This probably ought
+             * to be set through an API call, but I don't expect our
+             * criteria to change over time.
+             */
+            long src = inputFp ? ftell(inputFp) : size;
+            long dst = ftell(mZipFp) - startPosn;
+            if (dst + (dst / 10) > src) {
+                ALOGD("insufficient compression (src=%ld dst=%ld), storing\n",
+                    src, dst);
+                failed = true;
+            }
+        }
+
+        if (failed) {
+            compressionMethod = ZipEntry::kCompressStored;
+            if (inputFp) rewind(inputFp);
+            fseek(mZipFp, startPosn, SEEK_SET);
+            /* fall through to kCompressStored case */
+        }
+    }
+    /* handle "no compression" request, or failed compression from above */
+    if (compressionMethod == ZipEntry::kCompressStored) {
+        if (inputFp) {
+            result = copyFpToFp(mZipFp, inputFp, &crc);
+        } else {
+            result = copyDataToFp(mZipFp, data, size, &crc);
+        }
+        if (result != NO_ERROR) {
+            // don't need to truncate; happens in CDE rewrite
+            ALOGD("failed copying data in\n");
             goto bail;
         }
-    } else {
-        assert(false);
-        result = UNKNOWN_ERROR;
-        goto bail;
     }
 
+    // currently seeked to end of file
+    uncompressedLen = inputFp ? ftell(inputFp) : size;
+
     /*
      * We could write the "Data Descriptor", but there doesn't seem to
      * be any point since we're going to go back and write the LFH.
diff --git a/tools/zipalign/ZipFile.h b/tools/zipalign/ZipFile.h
index b0bafe9..d5ace7c 100644
--- a/tools/zipalign/ZipFile.h
+++ b/tools/zipalign/ZipFile.h
@@ -86,24 +86,10 @@
         int compressionMethod, ZipEntry** ppEntry)
     {
         return addCommon(fileName, NULL, 0, storageName,
-                         ZipEntry::kCompressStored,
                          compressionMethod, ppEntry);
     }
 
     /*
-     * Add a file that is already compressed with gzip.
-     *
-     * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
-     */
-    status_t addGzip(const char* fileName, const char* storageName,
-        ZipEntry** ppEntry)
-    {
-        return addCommon(fileName, NULL, 0, storageName,
-                         ZipEntry::kCompressDeflated,
-                         ZipEntry::kCompressDeflated, ppEntry);
-    }
-
-    /*
      * Add a file from an in-memory data buffer.
      *
      * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
@@ -112,7 +98,6 @@
         int compressionMethod, ZipEntry** ppEntry)
     {
         return addCommon(NULL, data, size, storageName,
-                         ZipEntry::kCompressStored,
                          compressionMethod, ppEntry);
     }
 
@@ -231,8 +216,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,
-        ZipEntry** ppEntry);
+        const char* storageName, int compressionMethod, ZipEntry** ppEntry);
 
     /* copy all of "srcFp" into "dstFp" */
     status_t copyFpToFp(FILE* dstFp, FILE* srcFp, uint32_t* pCRC32);