Merge "Remove dependency to libbinder in VHAL" into oc-dev
diff --git a/camera/device/3.2/ICameraDeviceSession.hal b/camera/device/3.2/ICameraDeviceSession.hal
index e186c8d..731fc76 100644
--- a/camera/device/3.2/ICameraDeviceSession.hal
+++ b/camera/device/3.2/ICameraDeviceSession.hal
@@ -183,6 +183,11 @@
      * client, the HAL must process the requests in order of lowest index to
      * highest index.
      *
+     * The cachesToRemove argument contains a list of buffer caches (see
+     * StreamBuffer document for more information on buffer cache) to be removed
+     * by camera HAL. Camera HAL must remove these cache entries whether or not
+     * this method returns OK.
+     *
      * The actual request processing is asynchronous, with the results of
      * capture being returned by the HAL through the processCaptureResult()
      * call. This call requires the result metadata to be available, but output
@@ -238,7 +243,8 @@
      *     that HAL processed successfully before HAL runs into an error.
      *
      */
-    processCaptureRequest(vec<CaptureRequest> requests)
+    processCaptureRequest(vec<CaptureRequest> requests,
+            vec<BufferCache> cachesToRemove)
             generates (Status status, uint32_t numRequestProcessed);
 
     /**
diff --git a/camera/device/3.2/default/CameraDeviceSession.cpp b/camera/device/3.2/default/CameraDeviceSession.cpp
index 2887a75..f2f9e5e 100644
--- a/camera/device/3.2/default/CameraDeviceSession.cpp
+++ b/camera/device/3.2/default/CameraDeviceSession.cpp
@@ -678,8 +678,32 @@
     mCirculatingBuffers.erase(id);
 }
 
+void CameraDeviceSession::updateBufferCaches(const hidl_vec<BufferCache>& cachesToRemove) {
+    Mutex::Autolock _l(mInflightLock);
+    for (auto& cache : cachesToRemove) {
+        auto cbsIt = mCirculatingBuffers.find(cache.streamId);
+        if (cbsIt == mCirculatingBuffers.end()) {
+            // The stream could have been removed
+            continue;
+        }
+        CirculatingBuffers& cbs = cbsIt->second;
+        auto it = cbs.find(cache.bufferId);
+        if (it != cbs.end()) {
+            sHandleImporter.freeBuffer(it->second);
+            cbs.erase(it);
+        } else {
+            ALOGE("%s: stream %d buffer %" PRIu64 " is not cached",
+                    __FUNCTION__, cache.streamId, cache.bufferId);
+        }
+    }
+}
+
 Return<void> CameraDeviceSession::processCaptureRequest(
-        const hidl_vec<CaptureRequest>& requests, processCaptureRequest_cb _hidl_cb)  {
+        const hidl_vec<CaptureRequest>& requests,
+        const hidl_vec<BufferCache>& cachesToRemove,
+        processCaptureRequest_cb _hidl_cb)  {
+    updateBufferCaches(cachesToRemove);
+
     uint32_t numRequestProcessed = 0;
     Status s = Status::OK;
     for (size_t i = 0; i < requests.size(); i++, numRequestProcessed++) {
diff --git a/camera/device/3.2/default/CameraDeviceSession.h b/camera/device/3.2/default/CameraDeviceSession.h
index 8923c05..781056e 100644
--- a/camera/device/3.2/default/CameraDeviceSession.h
+++ b/camera/device/3.2/default/CameraDeviceSession.h
@@ -85,7 +85,9 @@
     Return<void> configureStreams(
             const StreamConfiguration& requestedConfiguration, configureStreams_cb _hidl_cb) override;
     Return<void> processCaptureRequest(
-            const hidl_vec<CaptureRequest>& requests, processCaptureRequest_cb _hidl_cb) override;
+            const hidl_vec<CaptureRequest>& requests,
+            const hidl_vec<BufferCache>& cachesToRemove,
+            processCaptureRequest_cb _hidl_cb) override;
     Return<Status> flush() override;
     Return<void> close() override;
 
@@ -234,6 +236,8 @@
 
     void cleanupBuffersLocked(int id);
 
+    void updateBufferCaches(const hidl_vec<BufferCache>& cachesToRemove);
+
     Status processOneCaptureRequest(const CaptureRequest& request);
     /**
      * Static callback forwarding methods from HAL to instance
diff --git a/camera/device/3.2/types.hal b/camera/device/3.2/types.hal
index fd75528..5ae7a18 100644
--- a/camera/device/3.2/types.hal
+++ b/camera/device/3.2/types.hal
@@ -958,3 +958,25 @@
     uint32_t partialResult;
 
 };
+
+/**
+ * BufferCache:
+ *
+ * A list of cached bufferIds associated with a certain stream.
+ * Buffers are passed between camera service and camera HAL via bufferId except
+ * the first time a new buffer is being passed to HAL in CaptureRequest. Camera
+ * service and camera HAL therefore need to maintain a cached map of bufferId
+ * and corresponing native handle.
+ *
+ */
+struct BufferCache {
+    /**
+     * The ID of the stream this list is associated with.
+     */
+    int32_t streamId;
+
+    /**
+     * A cached buffer ID associated with streamId.
+     */
+    uint64_t bufferId;
+};
diff --git a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
index af7e3bf..4d3c6eb 100644
--- a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
+++ b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
@@ -65,6 +65,7 @@
 using ::android::hardware::camera::device::V3_2::ProducerUsageFlags;
 using ::android::hardware::camera::device::V3_2::ConsumerUsageFlags;
 using ::android::hardware::camera::device::V3_2::ICameraDevice;
+using ::android::hardware::camera::device::V3_2::BufferCache;
 using ::android::hardware::camera::device::V3_2::CaptureRequest;
 using ::android::hardware::camera::device::V3_2::CaptureResult;
 using ::android::hardware::camera::device::V3_2::ICameraDeviceCallback;
@@ -2509,8 +2510,10 @@
 
             Status status = Status::INTERNAL_ERROR;
             uint32_t numRequestProcessed = 0;
+            hidl_vec<BufferCache> cachesToRemove;
             Return<void> returnStatus = session->processCaptureRequest(
                     {request},
+                    cachesToRemove,
                     [&status, &numRequestProcessed] (auto s, uint32_t n) {
                         status = s;
                         numRequestProcessed = n;
@@ -2541,6 +2544,7 @@
 
             returnStatus = session->processCaptureRequest(
                     {request},
+                    cachesToRemove,
                     [&status, &numRequestProcessed] (auto s, uint32_t n) {
                         status = s;
                         numRequestProcessed = n;
@@ -2607,8 +2611,10 @@
             //Settings were not correctly initialized, we should fail here
             Status status = Status::OK;
             uint32_t numRequestProcessed = 0;
+            hidl_vec<BufferCache> cachesToRemove;
             Return<void> ret = session->processCaptureRequest(
                     {request},
+                    cachesToRemove,
                     [&status, &numRequestProcessed] (auto s, uint32_t n) {
                         status = s;
                         numRequestProcessed = n;
@@ -2660,8 +2666,10 @@
             //Output buffers are missing, we should fail here
             Status status = Status::OK;
             uint32_t numRequestProcessed = 0;
+            hidl_vec<BufferCache> cachesToRemove;
             ret = session->processCaptureRequest(
                     {request},
+                    cachesToRemove,
                     [&status, &numRequestProcessed] (auto s, uint32_t n) {
                         status = s;
                         numRequestProcessed = n;
@@ -2729,8 +2737,10 @@
 
             Status status = Status::INTERNAL_ERROR;
             uint32_t numRequestProcessed = 0;
+            hidl_vec<BufferCache> cachesToRemove;
             ret = session->processCaptureRequest(
                     {request},
+                    cachesToRemove,
                     [&status, &numRequestProcessed] (auto s, uint32_t n) {
                         status = s;
                         numRequestProcessed = n;
diff --git a/configstore/1.0/default/android.hardware.configstore@1.0-service.rc b/configstore/1.0/default/android.hardware.configstore@1.0-service.rc
index 8741bdd..563d854 100644
--- a/configstore/1.0/default/android.hardware.configstore@1.0-service.rc
+++ b/configstore/1.0/default/android.hardware.configstore@1.0-service.rc
@@ -1,4 +1,4 @@
 service configstore-hal-1-0 /vendor/bin/hw/android.hardware.configstore@1.0-service
-    class hal
+    class hal animation
     user system
     group system
diff --git a/graphics/allocator/2.0/default/android.hardware.graphics.allocator@2.0-service.rc b/graphics/allocator/2.0/default/android.hardware.graphics.allocator@2.0-service.rc
index 3e2edda..9a08f66 100644
--- a/graphics/allocator/2.0/default/android.hardware.graphics.allocator@2.0-service.rc
+++ b/graphics/allocator/2.0/default/android.hardware.graphics.allocator@2.0-service.rc
@@ -1,5 +1,5 @@
 service gralloc-2-0 /vendor/bin/hw/android.hardware.graphics.allocator@2.0-service
-    class hal
+    class hal animation
     user system
     group graphics drmrpc
     onrestart restart surfaceflinger
diff --git a/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc b/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc
index b6060db..51b0e3b 100644
--- a/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc
+++ b/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc
@@ -1,5 +1,5 @@
 service hwcomposer-2-1 /vendor/bin/hw/android.hardware.graphics.composer@2.1-service
-    class hal
+    class hal animation
     user system
     group graphics drmrpc
     capabilities SYS_NICE
diff --git a/tests/Android.bp b/tests/Android.bp
index 31dc75e..6f99a36 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -9,6 +9,8 @@
     "foo/1.0",
     "foo/1.0/default",
     "foo/1.0/default/lib",
+    "hash/1.0",
+    "hash/1.0/default",
     "inheritance/1.0",
     "inheritance/1.0/default",
     "libhwbinder/1.0",
diff --git a/tests/hash/1.0/Android.bp b/tests/hash/1.0/Android.bp
new file mode 100644
index 0000000..c217e5c
--- /dev/null
+++ b/tests/hash/1.0/Android.bp
@@ -0,0 +1,59 @@
+// This file is autogenerated by hidl-gen. Do not edit manually.
+
+filegroup {
+    name: "android.hardware.tests.hash@1.0_hal",
+    srcs: [
+        "IHash.hal",
+    ],
+}
+
+genrule {
+    name: "android.hardware.tests.hash@1.0_genc++",
+    tools: ["hidl-gen"],
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.tests.hash@1.0",
+    srcs: [
+        ":android.hardware.tests.hash@1.0_hal",
+    ],
+    out: [
+        "android/hardware/tests/hash/1.0/HashAll.cpp",
+    ],
+}
+
+genrule {
+    name: "android.hardware.tests.hash@1.0_genc++_headers",
+    tools: ["hidl-gen"],
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.tests.hash@1.0",
+    srcs: [
+        ":android.hardware.tests.hash@1.0_hal",
+    ],
+    out: [
+        "android/hardware/tests/hash/1.0/IHash.h",
+        "android/hardware/tests/hash/1.0/IHwHash.h",
+        "android/hardware/tests/hash/1.0/BnHwHash.h",
+        "android/hardware/tests/hash/1.0/BpHwHash.h",
+        "android/hardware/tests/hash/1.0/BsHash.h",
+    ],
+}
+
+cc_library_shared {
+    name: "android.hardware.tests.hash@1.0",
+    generated_sources: ["android.hardware.tests.hash@1.0_genc++"],
+    generated_headers: ["android.hardware.tests.hash@1.0_genc++_headers"],
+    export_generated_headers: ["android.hardware.tests.hash@1.0_genc++_headers"],
+    shared_libs: [
+        "libhidlbase",
+        "libhidltransport",
+        "libhwbinder",
+        "liblog",
+        "libutils",
+        "libcutils",
+        "android.hidl.base@1.0",
+    ],
+    export_shared_lib_headers: [
+        "libhidlbase",
+        "libhidltransport",
+        "libhwbinder",
+        "libutils",
+        "android.hidl.base@1.0",
+    ],
+}
diff --git a/tests/hash/1.0/Android.mk b/tests/hash/1.0/Android.mk
new file mode 100644
index 0000000..15428b4
--- /dev/null
+++ b/tests/hash/1.0/Android.mk
@@ -0,0 +1,76 @@
+# This file is autogenerated by hidl-gen. Do not edit manually.
+
+LOCAL_PATH := $(call my-dir)
+
+################################################################################
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.tests.hash@1.0-java
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+
+intermediates := $(call local-generated-sources-dir, COMMON)
+
+HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
+
+LOCAL_JAVA_LIBRARIES := \
+    android.hidl.base@1.0-java \
+
+
+#
+# Build IHash.hal
+#
+GEN := $(intermediates)/android/hardware/tests/hash/V1_0/IHash.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IHash.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava \
+        -randroid.hardware:hardware/interfaces \
+        -randroid.hidl:system/libhidl/transport \
+        android.hardware.tests.hash@1.0::IHash
+
+$(GEN): $(LOCAL_PATH)/IHash.hal
+	$(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+include $(BUILD_JAVA_LIBRARY)
+
+
+################################################################################
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.tests.hash@1.0-java-static
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+
+intermediates := $(call local-generated-sources-dir, COMMON)
+
+HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    android.hidl.base@1.0-java-static \
+
+
+#
+# Build IHash.hal
+#
+GEN := $(intermediates)/android/hardware/tests/hash/V1_0/IHash.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IHash.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava \
+        -randroid.hardware:hardware/interfaces \
+        -randroid.hidl:system/libhidl/transport \
+        android.hardware.tests.hash@1.0::IHash
+
+$(GEN): $(LOCAL_PATH)/IHash.hal
+	$(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/hash/1.0/IHash.hal b/tests/hash/1.0/IHash.hal
new file mode 100644
index 0000000..ba48384
--- /dev/null
+++ b/tests/hash/1.0/IHash.hal
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.tests.hash@1.0;
+
+/**
+ * Test interface for hashing HAL files.
+ * This file is FREEZED to ensure its hash doesn't change.
+ */
+interface IHash {
+    /**
+     * Dummy.
+     */
+    dummy();
+    /**
+     * Dummy.
+     */
+    functions();
+};
diff --git a/tests/hash/1.0/default/Android.bp b/tests/hash/1.0/default/Android.bp
new file mode 100644
index 0000000..e798a66
--- /dev/null
+++ b/tests/hash/1.0/default/Android.bp
@@ -0,0 +1,15 @@
+cc_library_shared {
+    name: "android.hardware.tests.hash@1.0-impl",
+    relative_install_path: "hw",
+    proprietary: true,
+    srcs: [
+        "Hash.cpp",
+    ],
+    shared_libs: [
+        "libhidlbase",
+        "libhidltransport",
+        "libutils",
+        "android.hardware.tests.hash@1.0",
+        "android.hidl.base@1.0",
+    ],
+}
diff --git a/tests/hash/1.0/default/Hash.cpp b/tests/hash/1.0/default/Hash.cpp
new file mode 100644
index 0000000..caed721
--- /dev/null
+++ b/tests/hash/1.0/default/Hash.cpp
@@ -0,0 +1,30 @@
+#include "Hash.h"
+
+namespace android {
+namespace hardware {
+namespace tests {
+namespace hash {
+namespace V1_0 {
+namespace implementation {
+
+// Methods from ::android::hardware::tests::hash::V1_0::IHash follow.
+Return<void> Hash::dummy() {
+    return Void();
+}
+
+Return<void> Hash::functions() {
+    return Void();
+}
+
+// Methods from ::android::hidl::base::V1_0::IBase follow.
+
+IHash* HIDL_FETCH_IHash(const char* /* name */) {
+    return new Hash();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace hash
+}  // namespace tests
+}  // namespace hardware
+}  // namespace android
diff --git a/tests/hash/1.0/default/Hash.h b/tests/hash/1.0/default/Hash.h
new file mode 100644
index 0000000..dd1678f
--- /dev/null
+++ b/tests/hash/1.0/default/Hash.h
@@ -0,0 +1,43 @@
+#ifndef ANDROID_HARDWARE_TESTS_HASH_V1_0_HASH_H
+#define ANDROID_HARDWARE_TESTS_HASH_V1_0_HASH_H
+
+#include <android/hardware/tests/hash/1.0/IHash.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace tests {
+namespace hash {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::tests::hash::V1_0::IHash;
+using ::android::hidl::base::V1_0::DebugInfo;
+using ::android::hidl::base::V1_0::IBase;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+struct Hash : public IHash {
+    // Methods from ::android::hardware::tests::hash::V1_0::IHash follow.
+    Return<void> dummy() override;
+    Return<void> functions() override;
+
+    // Methods from ::android::hidl::base::V1_0::IBase follow.
+};
+
+extern "C" IHash* HIDL_FETCH_IHash(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace hash
+}  // namespace tests
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_TESTS_HASH_V1_0_HASH_H