Arrays in .hal files are now exposed to C++ as hidl_array<T, SIZE ...>

instead of as native arrays. This allows them to be copied which in turn lets
them exist in vectors. In the Java backend, vectors are limited to
one-dimensional arrays and scalar arrays are properly wrapped,
i.e. vec<uint8_t[]> => Vector<Byte[]>

Change-Id: I47524ec8423dfb41a436df36af8fa05eb8b3c0cc
Bug: 31682327
Test: hidl_test and hidl_test_java
diff --git a/VectorType.cpp b/VectorType.cpp
index 544315c..04a6ac3 100644
--- a/VectorType.cpp
+++ b/VectorType.cpp
@@ -16,6 +16,8 @@
 
 #include "VectorType.h"
 
+#include "ArrayType.h"
+
 #include <hidl-util/Formatter.h>
 #include <android-base/logging.h>
 
@@ -241,14 +243,19 @@
 
 void VectorType::emitJavaFieldInitializer(
         Formatter &out, const std::string &fieldName) const {
+    std::string extra;
+    mElementType->getJavaType(&extra);
+
     const std::string wrapperType = mElementType->getJavaWrapperType();
 
     out << "final Vector<"
         << wrapperType
+        << extra
         << "> "
         << fieldName
         << " = new Vector<"
         << wrapperType
+        << extra
         << ">();\n";
 }
 
@@ -334,8 +341,16 @@
                 iteratorName + " * " + std::to_string(elementSize),
                 true /* isReader */);
 
-        out << fieldName
-            << ".add(_hidl_vec_element);\n";
+        out << fieldName;
+
+        if (elementType->isArray()
+                && static_cast<const ArrayType *>(
+                    elementType)->getElementType()->resolveToScalarType()
+                        != nullptr) {
+            out << ".add(HwBlob.wrapArray(_hidl_vec_element));\n";
+        } else {
+            out << ".add(_hidl_vec_element);\n";
+        }
 
         out.unindent();
 
@@ -440,7 +455,15 @@
 }
 
 bool VectorType::isJavaCompatible() const {
-    return mElementType->isJavaCompatible();
+    if (!mElementType->isJavaCompatible()) {
+        return false;
+    }
+
+    if (mElementType->isArray()) {
+        return static_cast<ArrayType *>(mElementType)->countDimensions() == 1;
+    }
+
+    return true;
 }
 
 void VectorType::getAlignmentAndSize(size_t *align, size_t *size) const {