Merge "Add phony source target in the generated dependency file of aidl."
diff --git a/rs/java/android/renderscript/RenderScript.java b/rs/java/android/renderscript/RenderScript.java
index 0f4dced..326f273 100644
--- a/rs/java/android/renderscript/RenderScript.java
+++ b/rs/java/android/renderscript/RenderScript.java
@@ -31,6 +31,8 @@
 import android.os.Trace;
 import java.util.ArrayList;
 
+// TODO: Clean up the whitespace that separates methods in this class.
+
 /**
  * This class provides access to a RenderScript context, which controls RenderScript
  * initialization, resource management, and teardown. An instance of the RenderScript
@@ -727,6 +729,14 @@
         rsnScriptForEach(mContext, id, slot, ains, aout, params, limits);
     }
 
+    native void rsnScriptReduce(long con, long id, int slot, long ain,
+                                long aout, int[] limits);
+    synchronized void nScriptReduce(long id, int slot, long ain, long aout,
+                                    int[] limits) {
+        validate();
+        rsnScriptReduce(mContext, id, slot, ain, aout, limits);
+    }
+
     native void rsnScriptInvokeV(long con, long id, int slot, byte[] params);
     synchronized void nScriptInvokeV(long id, int slot, byte[] params) {
         validate();
diff --git a/rs/java/android/renderscript/Script.java b/rs/java/android/renderscript/Script.java
index 1083114..dfd0ea3 100644
--- a/rs/java/android/renderscript/Script.java
+++ b/rs/java/android/renderscript/Script.java
@@ -284,6 +284,35 @@
         mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits);
     }
 
+    /**
+     * Only intended for use by generated reflected code.
+     *
+     * @hide
+     */
+    protected void reduce(int slot, Allocation ain, Allocation aout, LaunchOptions sc) {
+        mRS.validate();
+        mRS.validateObject(ain);
+        mRS.validateObject(aout);
+
+        if (ain == null || aout == null) {
+            throw new RSIllegalArgumentException(
+                "Both ain and aout are required to be non-null.");
+        }
+
+        long in_id = ain.getID(mRS);
+        long out_id = aout.getID(mRS);
+
+        int[] limits = null;
+        if (sc != null) {
+            limits = new int[2];
+
+            limits[0] = sc.xstart;
+            limits[1] = sc.xend;
+        }
+
+        mRS.nScriptReduce(getID(mRS), slot, in_id, out_id, limits);
+    }
+
     long[] mInIdsBuffer;
 
     Script(long id, RenderScript rs) {
@@ -292,7 +321,6 @@
         mInIdsBuffer = new long[1];
     }
 
-
     /**
      * Only intended for use by generated reflected code.
      *
diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp
index aac6c19..d6854a2 100644
--- a/rs/jni/android_renderscript_RenderScript.cpp
+++ b/rs/jni/android_renderscript_RenderScript.cpp
@@ -1958,6 +1958,59 @@
     }
 }
 
+static void
+nScriptReduce(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
+              jlong ain, jlong aout, jintArray limits)
+{
+    if (kLogApi) {
+        ALOGD("nScriptReduce, con(%p), s(%p), slot(%i) ain(%" PRId64 ") aout(%" PRId64 ")", (RsContext)con, (void *)script, slot, ain, aout);
+    }
+
+    RsScriptCall sc, *sca = nullptr;
+    uint32_t sc_size = 0;
+
+    jint  limit_len = 0;
+    jint *limit_ptr = nullptr;
+
+    // If the caller passed limits, reflect them in the RsScriptCall.
+    if (limits != nullptr) {
+        limit_len = _env->GetArrayLength(limits);
+        limit_ptr = _env->GetIntArrayElements(limits, nullptr);
+
+        // We expect to be passed an array [x1, x2] which specifies
+        // the sub-range for a 1-dimensional reduction.
+        assert(limit_len == 2);
+        UNUSED(limit_len);  // As the assert might not be compiled.
+
+        sc.xStart     = limit_ptr[0];
+        sc.xEnd       = limit_ptr[1];
+        sc.yStart     = 0;
+        sc.yEnd       = 0;
+        sc.zStart     = 0;
+        sc.zEnd       = 0;
+        sc.strategy   = RS_FOR_EACH_STRATEGY_DONT_CARE;
+        sc.arrayStart = 0;
+        sc.arrayEnd = 0;
+        sc.array2Start = 0;
+        sc.array2End = 0;
+        sc.array3Start = 0;
+        sc.array3End = 0;
+        sc.array4Start = 0;
+        sc.array4End = 0;
+
+        sca = ≻
+        sc_size = sizeof(sc);
+    }
+
+    rsScriptReduce((RsContext)con, (RsScript)script, slot,
+                   (RsAllocation)ain, (RsAllocation)aout,
+                   sca, sc_size);
+
+    if (limits != nullptr) {
+        _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
+    }
+}
+
 // -----------------------------------
 
 static jlong
@@ -2541,6 +2594,7 @@
 {"rsnScriptInvokeV",                 "(JJI[B)V",                              (void*)nScriptInvokeV },
 
 {"rsnScriptForEach",                 "(JJI[JJ[B[I)V",                         (void*)nScriptForEach },
+{"rsnScriptReduce",                  "(JJIJJ[I)V",                            (void*)nScriptReduce },
 
 {"rsnScriptSetVarI",                 "(JJII)V",                               (void*)nScriptSetVarI },
 {"rsnScriptGetVarI",                 "(JJI)I",                                (void*)nScriptGetVarI },
diff --git a/tools/aapt/Android.mk b/tools/aapt/Android.mk
index d551c8e..94a74c4 100644
--- a/tools/aapt/Android.mk
+++ b/tools/aapt/Android.mk
@@ -53,11 +53,6 @@
     tests/Pseudolocales_test.cpp \
     tests/ResourceFilter_test.cpp
 
-aaptCIncludes := \
-    system/core/base/include \
-    external/libpng \
-    external/zlib
-
 aaptHostLdLibs :=
 aaptHostStaticLibs := \
     libandroidfw \
@@ -69,7 +64,7 @@
     libziparchive-host \
     libbase
 
-aaptCFlags := -DAAPT_VERSION=\"$(BUILD_NUMBER)\"
+aaptCFlags := -DAAPT_VERSION=\"$(BUILD_NUMBER_FROM_FILE)\"
 aaptCFlags += -Wall -Werror
 
 ifeq ($(HOST_OS),linux)
@@ -96,8 +91,8 @@
 ifeq (darwin,$(HOST_OS))
 LOCAL_CFLAGS += -D_DARWIN_UNLIMITED_STREAMS
 endif
-LOCAL_C_INCLUDES += $(aaptCIncludes)
 LOCAL_SRC_FILES := $(aaptSources)
+LOCAL_STATIC_LIBRARIES += $(aaptHostStaticLibs)
 
 include $(BUILD_HOST_STATIC_LIBRARY)
 
diff --git a/tools/aapt/StringPool.h b/tools/aapt/StringPool.h
index dbe8c85..4b0d920 100644
--- a/tools/aapt/StringPool.h
+++ b/tools/aapt/StringPool.h
@@ -20,8 +20,6 @@
 #include <ctype.h>
 #include <errno.h>
 
-#include <libexpat/expat.h>
-
 using namespace android;
 
 #define PRINT_STRING_METRICS 0
diff --git a/tools/aapt/XMLNode.h b/tools/aapt/XMLNode.h
index 3161f65..b9e5cd5 100644
--- a/tools/aapt/XMLNode.h
+++ b/tools/aapt/XMLNode.h
@@ -10,6 +10,8 @@
 #include "StringPool.h"
 #include "ResourceTable.h"
 
+#include <expat.h>
+
 class XMLNode;
 
 extern const char* const RESOURCES_ROOT_NAMESPACE;