Merge "Remove unused OFF/MIN/MAX constants from HAL."
diff --git a/automotive/Android.bp b/automotive/Android.bp
index 0302cd5..1f39e88 100644
--- a/automotive/Android.bp
+++ b/automotive/Android.bp
@@ -1,6 +1,5 @@
 // This is an autogenerated file, do not edit.
 subdirs = [
-    "vehicle",
     "vehicle/2.0",
     "vehicle/2.1",
 ]
diff --git a/automotive/vehicle/2.1/Android.bp b/automotive/vehicle/2.1/Android.bp
index 12bb4ed..dcf395c 100644
--- a/automotive/vehicle/2.1/Android.bp
+++ b/automotive/vehicle/2.1/Android.bp
@@ -13,8 +13,7 @@
     tools: ["hidl-gen"],
     cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.automotive.vehicle@2.1",
     srcs: [
-        "types.hal",
-        "IVehicle.hal",
+        ":android.hardware.automotive.vehicle@2.1_hal",
     ],
     out: [
         "android/hardware/automotive/vehicle/2.1/types.cpp",
@@ -27,8 +26,7 @@
     tools: ["hidl-gen"],
     cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.automotive.vehicle@2.1",
     srcs: [
-        "types.hal",
-        "IVehicle.hal",
+        ":android.hardware.automotive.vehicle@2.1_hal",
     ],
     out: [
         "android/hardware/automotive/vehicle/2.1/types.h",
diff --git a/automotive/vehicle/2.1/Android.mk b/automotive/vehicle/2.1/Android.mk
index f618268..2a8d1dd 100644
--- a/automotive/vehicle/2.1/Android.mk
+++ b/automotive/vehicle/2.1/Android.mk
@@ -8,7 +8,7 @@
 LOCAL_MODULE := android.hardware.automotive.vehicle@2.1-java
 LOCAL_MODULE_CLASS := JAVA_LIBRARIES
 
-intermediates := $(local-generated-sources-dir)
+intermediates := $(call local-generated-sources-dir, COMMON)
 
 HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
 
@@ -63,7 +63,7 @@
 LOCAL_MODULE := android.hardware.automotive.vehicle@2.1-java-static
 LOCAL_MODULE_CLASS := JAVA_LIBRARIES
 
-intermediates := $(local-generated-sources-dir)
+intermediates := $(call local-generated-sources-dir, COMMON)
 
 HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
 
diff --git a/automotive/vehicle/Android.bp b/automotive/vehicle/Android.bp
deleted file mode 100644
index c12cd4f..0000000
--- a/automotive/vehicle/Android.bp
+++ /dev/null
@@ -1,4 +0,0 @@
-// This is an autogenerated file, do not edit.
-subdirs = [
-    "2.0",
-]
diff --git a/bluetooth/1.0/vts/functional/Android.bp b/bluetooth/1.0/vts/functional/Android.bp
index 086ac99..2012c20 100644
--- a/bluetooth/1.0/vts/functional/Android.bp
+++ b/bluetooth/1.0/vts/functional/Android.bp
@@ -15,9 +15,9 @@
 //
 
 cc_test {
-    name: "bluetooth_hidl_hal_test",
+    name: "VtsHalBluetoothV1_0TargetTest",
     gtest: true,
-    srcs: ["bluetooth_hidl_hal_test.cpp"],
+    srcs: ["VtsHalBluetoothV1_0TargetTest.cpp"],
     shared_libs: [
         "libbase",
         "liblog",
diff --git a/bluetooth/1.0/vts/functional/bluetooth_hidl_hal_test.cpp b/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp
similarity index 100%
rename from bluetooth/1.0/vts/functional/bluetooth_hidl_hal_test.cpp
rename to bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp
diff --git a/drm/1.0/ICryptoPlugin.hal b/drm/1.0/ICryptoPlugin.hal
index d66151e..ca8fa50 100644
--- a/drm/1.0/ICryptoPlugin.hal
+++ b/drm/1.0/ICryptoPlugin.hal
@@ -62,8 +62,16 @@
      * After the shared buffer base is established, the decrypt() method
      * receives SharedBuffer instances which specify the buffer address range
      * for decrypt source and destination addresses.
+     *
+     * There can be multiple shared buffers per crypto plugin. The buffers
+     * are distinguished by the bufferId.
+     *
+     * @param base the base IMemory of the memory buffer identified by
+     * bufferId
+     * @param bufferId identifies the specific shared buffer for which
+     * the base is being set.
      */
-    setSharedBufferBase(memory base);
+    setSharedBufferBase(memory base, uint32_t bufferId);
 
     /**
      * Decrypt an array of subsamples from the source memory buffer to the
diff --git a/drm/1.0/default/CryptoPlugin.cpp b/drm/1.0/default/CryptoPlugin.cpp
index fb61ede..4a4171b 100644
--- a/drm/1.0/default/CryptoPlugin.cpp
+++ b/drm/1.0/default/CryptoPlugin.cpp
@@ -49,8 +49,9 @@
         return toStatus(mLegacyPlugin->setMediaDrmSession(toVector(sessionId)));
     }
 
-    Return<void> CryptoPlugin::setSharedBufferBase(const hidl_memory& base) {
-        mSharedBufferBase = mapMemory(base);
+    Return<void> CryptoPlugin::setSharedBufferBase(const hidl_memory& base,
+            uint32_t bufferId) {
+        mSharedBufferMap[bufferId] = mapMemory(base);
         return Void();
     }
 
@@ -62,11 +63,19 @@
             const DestinationBuffer& destination,
             decrypt_cb _hidl_cb) {
 
-        if (mSharedBufferBase == NULL) {
-            _hidl_cb(Status::BAD_VALUE, 0, "decrypt buffer base not set");
+        if (mSharedBufferMap.find(source.bufferId) == mSharedBufferMap.end()) {
+            _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "source decrypt buffer base not set");
             return Void();
         }
 
+        if (destination.type == BufferType::SHARED_MEMORY) {
+            const SharedBuffer& dest = destination.nonsecureMemory;
+            if (mSharedBufferMap.find(dest.bufferId) == mSharedBufferMap.end()) {
+                _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "destination decrypt buffer base not set");
+                return Void();
+            }
+        }
+
         android::CryptoPlugin::Mode legacyMode;
         switch(mode) {
         case Mode::UNENCRYPTED:
@@ -97,20 +106,22 @@
         }
 
         AString detailMessage;
+        sp<IMemory> sourceBase = mSharedBufferMap[source.bufferId];
 
-        if (source.offset + offset + source.size > mSharedBufferBase->getSize()) {
+        if (source.offset + offset + source.size > sourceBase->getSize()) {
             _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "invalid buffer size");
             return Void();
         }
 
         uint8_t *base = static_cast<uint8_t *>
-                (static_cast<void *>(mSharedBufferBase->getPointer()));
+                (static_cast<void *>(sourceBase->getPointer()));
         void *srcPtr = static_cast<void *>(base + source.offset + offset);
 
         void *destPtr = NULL;
         if (destination.type == BufferType::SHARED_MEMORY) {
             const SharedBuffer& destBuffer = destination.nonsecureMemory;
-            if (destBuffer.offset + destBuffer.size > mSharedBufferBase->getSize()) {
+            sp<IMemory> destBase = mSharedBufferMap[destBuffer.bufferId];
+            if (destBuffer.offset + destBuffer.size > destBase->getSize()) {
                 _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "invalid buffer size");
                 return Void();
             }
diff --git a/drm/1.0/default/CryptoPlugin.h b/drm/1.0/default/CryptoPlugin.h
index f805f09..11cc2aa 100644
--- a/drm/1.0/default/CryptoPlugin.h
+++ b/drm/1.0/default/CryptoPlugin.h
@@ -57,8 +57,8 @@
     Return<Status> setMediaDrmSession(const hidl_vec<uint8_t>& sessionId)
             override;
 
-    Return<void> setSharedBufferBase(const ::android::hardware::hidl_memory& base)
-            override;
+    Return<void> setSharedBufferBase(const ::android::hardware::hidl_memory& base,
+        uint32_t bufferId) override;
 
     Return<void> decrypt(bool secure, const hidl_array<uint8_t, 16>& keyId,
             const hidl_array<uint8_t, 16>& iv, Mode mode, const Pattern& pattern,
@@ -68,7 +68,7 @@
 
 private:
     android::CryptoPlugin *mLegacyPlugin;
-    sp<IMemory> mSharedBufferBase;
+    std::map<uint32_t, sp<IMemory> > mSharedBufferMap;
 
     CryptoPlugin() = delete;
     CryptoPlugin(const CryptoPlugin &) = delete;
diff --git a/drm/1.0/types.hal b/drm/1.0/types.hal
index 33bbf9a..5273044 100644
--- a/drm/1.0/types.hal
+++ b/drm/1.0/types.hal
@@ -293,12 +293,18 @@
 };
 
 /**
- * A SharedBuffer describes a decrypt buffer which is defined by an offset and
- * a size.  The offset is relative to the shared memory base which is established
- * using setSharedMemoryBase().
+ * SharedBuffer describes a decrypt buffer which is defined by a bufferId, an
+ * offset and a size.  The offset is relative to the shared memory base for the
+ * memory region identified by bufferId, which is established by
+ * setSharedMemoryBase().
  */
 struct SharedBuffer {
     /**
+     * The unique buffer identifier
+     */
+    uint32_t bufferId;
+
+    /**
      * The offset from the shared memory base
      */
     uint64_t offset;
diff --git a/ir/1.0/vts/functional/Android.bp b/ir/1.0/vts/functional/Android.bp
index 1acd2a0..5689474 100644
--- a/ir/1.0/vts/functional/Android.bp
+++ b/ir/1.0/vts/functional/Android.bp
@@ -15,9 +15,9 @@
 //
 
 cc_test {
-    name: "ir_hidl_hal_test",
+    name: "VtsHalIrV1_0TargetTest",
     gtest: true,
-    srcs: ["ir_hidl_hal_test.cpp"],
+    srcs: ["VtsHalIrV1_0TargetTest.cpp"],
     shared_libs: [
         "libbase",
         "liblog",
diff --git a/ir/1.0/vts/functional/ir_hidl_hal_test.cpp b/ir/1.0/vts/functional/VtsHalIrV1_0TargetTest.cpp
similarity index 100%
rename from ir/1.0/vts/functional/ir_hidl_hal_test.cpp
rename to ir/1.0/vts/functional/VtsHalIrV1_0TargetTest.cpp
diff --git a/nfc/1.0/vts/functional/Android.bp b/nfc/1.0/vts/functional/Android.bp
index 0f9eb3d..080887f 100644
--- a/nfc/1.0/vts/functional/Android.bp
+++ b/nfc/1.0/vts/functional/Android.bp
@@ -15,9 +15,9 @@
 //
 
 cc_test {
-    name: "nfc_hidl_hal_test",
+    name: "VtsHalNfcV1_0TargetTest",
     gtest: true,
-    srcs: ["nfc_hidl_hal_test.cpp"],
+    srcs: ["VtsHalNfcV1_0TargetTest.cpp"],
     shared_libs: [
         "libbase",
         "liblog",
diff --git a/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp b/nfc/1.0/vts/functional/VtsHalNfcV1_0TargetTest.cpp
similarity index 100%
rename from nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp
rename to nfc/1.0/vts/functional/VtsHalNfcV1_0TargetTest.cpp
diff --git a/radio/1.0/vts/functional/Android.bp b/radio/1.0/vts/functional/Android.bp
index a01e270..6615f03 100644
--- a/radio/1.0/vts/functional/Android.bp
+++ b/radio/1.0/vts/functional/Android.bp
@@ -15,12 +15,12 @@
 //
 
 cc_test {
-    name: "radio_hidl_hal_test",
+    name: "VtsHalRadioV1_0TargetTest",
     gtest: true,
     srcs: ["radio_hidl_hal_test.cpp",
            "radio_response.cpp",
            "radio_hidl_hal_icc.cpp",
-           "radio_hidl_hal_main.cpp"],
+           "VtsHalRadioV1_0TargetTest.cpp"],
     shared_libs: [
         "libbase",
         "liblog",
diff --git a/radio/1.0/vts/functional/radio_hidl_hal_main.cpp b/radio/1.0/vts/functional/VtsHalRadioV1_0TargetTest.cpp
similarity index 100%
rename from radio/1.0/vts/functional/radio_hidl_hal_main.cpp
rename to radio/1.0/vts/functional/VtsHalRadioV1_0TargetTest.cpp
diff --git a/wifi/1.0/vts/functional/Android.bp b/wifi/1.0/vts/functional/Android.bp
index 8a5d7e0..01eeef5 100644
--- a/wifi/1.0/vts/functional/Android.bp
+++ b/wifi/1.0/vts/functional/Android.bp
@@ -15,10 +15,10 @@
 //
 
 cc_test {
-    name: "wifi_hidl_test",
+    name: "VtsHalWifiV1_0TargetTest",
     gtest: true,
     srcs: [
-        "main.cpp",
+        "VtsHalWifiV1_0TargetTest.cpp",
         "wifi_ap_iface_hidl_test.cpp",
         "wifi_chip_hidl_test.cpp",
         "wifi_hidl_call_util_selftest.cpp",
diff --git a/wifi/1.0/vts/functional/main.cpp b/wifi/1.0/vts/functional/VtsHalWifiV1_0TargetTest.cpp
similarity index 100%
rename from wifi/1.0/vts/functional/main.cpp
rename to wifi/1.0/vts/functional/VtsHalWifiV1_0TargetTest.cpp
diff --git a/wifi/supplicant/1.0/vts/functional/Android.mk b/wifi/supplicant/1.0/vts/functional/Android.mk
index 8fa649f..52fecc2 100644
--- a/wifi/supplicant/1.0/vts/functional/Android.mk
+++ b/wifi/supplicant/1.0/vts/functional/Android.mk
@@ -16,10 +16,10 @@
 LOCAL_PATH := $(call my-dir)
 
 include $(CLEAR_VARS)
-LOCAL_MODULE := supplicant_hidl_test
+LOCAL_MODULE := VtsHalWifiSupplicantV1_0TargetTest
 LOCAL_CPPFLAGS := -Wall -Werror -Wextra
 LOCAL_SRC_FILES := \
-    main.cpp \
+    VtsHalWifiSupplicantV1_0TargetTest.cpp \
     supplicant_hidl_test.cpp \
     supplicant_hidl_test_utils.cpp \
     supplicant_p2p_iface_hidl_test.cpp \
diff --git a/wifi/supplicant/1.0/vts/functional/main.cpp b/wifi/supplicant/1.0/vts/functional/VtsHalWifiSupplicantV1_0TargetTest.cpp
similarity index 100%
rename from wifi/supplicant/1.0/vts/functional/main.cpp
rename to wifi/supplicant/1.0/vts/functional/VtsHalWifiSupplicantV1_0TargetTest.cpp