Move BufferHub-based IGBP into libgui

Currently the BufferHub based IGBP implementation lives inside
frameworks/libs/vr and libbufferhubqueue is depending on libgui. This CL
reverses the dependency and paves the way of future integration of
BufferHub into libgui.

Mirrors changes to make this work:
1/ Fix shared lib dependency of libpdx
2/ Allow implicit template instantiation in libgui
3/ Mute clang warnings caused by libpdx

Bug: 72051005
Bug: 70046255
Test: libgui-test, buffer_hub_queue_producer-test, dvr_api-test
Change-Id: I7541498f78aaeb4b15fc6cb6439a2e2d706b9e99
diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp
index 7ee4d49..ad04d03 100644
--- a/libs/gui/Android.bp
+++ b/libs/gui/Android.bp
@@ -62,6 +62,9 @@
         // Allow documentation warnings
         "-Wno-documentation",
 
+        // Allow implicit instantiation for templated class function
+        "-Wno-undefined-func-template",
+
         "-DDEBUG_ONLY_CODE=0",
     ],
 
@@ -79,6 +82,7 @@
 
     srcs: [
         "BitTube.cpp",
+        "BufferHubProducer.cpp",
         "BufferItem.cpp",
         "BufferItemConsumer.cpp",
         "BufferQueue.cpp",
@@ -131,7 +135,15 @@
         "android.hardware.configstore-utils",
     ],
 
+    // TODO(b/70046255): Remove these once BufferHub is integrated into libgui.
+    static_libs: [
+        "libbufferhub",
+        "libbufferhubqueue",
+        "libpdx_default_transport",
+    ],
+
     header_libs: [
+        "libdvr_headers",
         "libnativebase_headers",
         "libgui_headers",
     ],
diff --git a/libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp b/libs/gui/BufferHubProducer.cpp
similarity index 71%
rename from libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp
rename to libs/gui/BufferHubProducer.cpp
index ace01a6..43206fa 100644
--- a/libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp
+++ b/libs/gui/BufferHubProducer.cpp
@@ -1,49 +1,59 @@
-#include "include/private/dvr/buffer_hub_queue_producer.h"
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Weverything"
+#endif
 
+// The following headers are included without checking every warning.
+// TODO(b/72172820): Remove the workaround once we have enforced -Weverything
+// in these headers and their dependencies.
 #include <dvr/dvr_api.h>
+#include <gui/BufferHubProducer.h>
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
 #include <inttypes.h>
 #include <log/log.h>
 #include <system/window.h>
 
 namespace android {
-namespace dvr {
 
 /* static */
-sp<BufferHubQueueProducer> BufferHubQueueProducer::Create(
-    const std::shared_ptr<ProducerQueue>& queue) {
+sp<BufferHubProducer> BufferHubProducer::Create(
+    const std::shared_ptr<dvr::ProducerQueue>& queue) {
   if (queue->metadata_size() != sizeof(DvrNativeBufferMetadata)) {
     ALOGE(
-        "BufferHubQueueProducer::Create producer's metadata size is different "
+        "BufferHubProducer::Create producer's metadata size is different "
         "than the size of DvrNativeBufferMetadata");
     return nullptr;
   }
 
-  sp<BufferHubQueueProducer> producer = new BufferHubQueueProducer;
+  sp<BufferHubProducer> producer = new BufferHubProducer;
   producer->queue_ = queue;
   return producer;
 }
 
 /* static */
-sp<BufferHubQueueProducer> BufferHubQueueProducer::Create(
-    ProducerQueueParcelable parcelable) {
+sp<BufferHubProducer> BufferHubProducer::Create(
+    dvr::ProducerQueueParcelable parcelable) {
   if (!parcelable.IsValid()) {
-    ALOGE("BufferHubQueueProducer::Create: Invalid producer parcelable.");
+    ALOGE("BufferHubProducer::Create: Invalid producer parcelable.");
     return nullptr;
   }
 
-  sp<BufferHubQueueProducer> producer = new BufferHubQueueProducer;
-  producer->queue_ = ProducerQueue::Import(parcelable.TakeChannelHandle());
+  sp<BufferHubProducer> producer = new BufferHubProducer;
+  producer->queue_ = dvr::ProducerQueue::Import(parcelable.TakeChannelHandle());
   return producer;
 }
 
-status_t BufferHubQueueProducer::requestBuffer(int slot,
-                                               sp<GraphicBuffer>* buf) {
-  ALOGD_IF(TRACE, "requestBuffer: slot=%d", slot);
+status_t BufferHubProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
+  ALOGV("requestBuffer: slot=%d", slot);
 
   std::unique_lock<std::mutex> lock(mutex_);
 
   if (connected_api_ == kNoConnectedApi) {
-    ALOGE("requestBuffer: BufferHubQueueProducer has no connected producer");
+    ALOGE("requestBuffer: BufferHubProducer has no connected producer");
     return NO_INIT;
   }
 
@@ -73,19 +83,18 @@
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::setMaxDequeuedBufferCount(
+status_t BufferHubProducer::setMaxDequeuedBufferCount(
     int max_dequeued_buffers) {
-  ALOGD_IF(TRACE, "setMaxDequeuedBufferCount: max_dequeued_buffers=%d",
-           max_dequeued_buffers);
+  ALOGV("setMaxDequeuedBufferCount: max_dequeued_buffers=%d",
+        max_dequeued_buffers);
 
   std::unique_lock<std::mutex> lock(mutex_);
 
   if (max_dequeued_buffers <= 0 ||
       max_dequeued_buffers >
-          static_cast<int>(BufferHubQueue::kMaxQueueCapacity -
-                           kDefaultUndequeuedBuffers)) {
+          int(dvr::BufferHubQueue::kMaxQueueCapacity - kDefaultUndequeuedBuffers)) {
     ALOGE("setMaxDequeuedBufferCount: %d out of range (0, %zu]",
-          max_dequeued_buffers, BufferHubQueue::kMaxQueueCapacity);
+          max_dequeued_buffers, dvr::BufferHubQueue::kMaxQueueCapacity);
     return BAD_VALUE;
   }
 
@@ -109,7 +118,7 @@
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::setAsyncMode(bool async) {
+status_t BufferHubProducer::setAsyncMode(bool async) {
   if (async) {
     // TODO(b/36724099) BufferHubQueue's consumer end always acquires the buffer
     // automatically and behaves differently from IGraphicBufferConsumer. Thus,
@@ -125,19 +134,19 @@
     // See: IGraphicBufferProducer::setAsyncMode and
     // BufferQueueProducer::setAsyncMode for more about original implementation.
     ALOGW(
-        "BufferHubQueueProducer::setAsyncMode: BufferHubQueue should always be "
+        "BufferHubProducer::setAsyncMode: BufferHubQueue should always be "
         "asynchronous. This call makes no effact.");
     return NO_ERROR;
   }
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::dequeueBuffer(
+status_t BufferHubProducer::dequeueBuffer(
     int* out_slot, sp<Fence>* out_fence, uint32_t width, uint32_t height,
     PixelFormat format, uint64_t usage, uint64_t* /*outBufferAge*/,
     FrameEventHistoryDelta* /* out_timestamps */) {
-  ALOGD_IF(TRACE, "dequeueBuffer: w=%u, h=%u, format=%d, usage=%" PRIu64, width,
-           height, format, usage);
+  ALOGV("dequeueBuffer: w=%u, h=%u, format=%d, usage=%" PRIu64, width, height,
+        format, usage);
 
   status_t ret;
   std::unique_lock<std::mutex> lock(mutex_);
@@ -148,8 +157,7 @@
   }
 
   const uint32_t kLayerCount = 1;
-  if (static_cast<int32_t>(queue_->capacity()) <
-      max_dequeued_buffer_count_ + kDefaultUndequeuedBuffers) {
+  if (int32_t(queue_->capacity()) < max_dequeued_buffer_count_ + kDefaultUndequeuedBuffers) {
     // Lazy allocation. When the capacity of |queue_| has not reached
     // |max_dequeued_buffer_count_|, allocate new buffer.
     // TODO(jwcai) To save memory, the really reasonable thing to do is to go
@@ -159,10 +167,11 @@
       return ret;
   }
 
-  size_t slot;
-  std::shared_ptr<BufferProducer> buffer_producer;
+  size_t slot = 0;
+  std::shared_ptr<dvr::BufferProducer> buffer_producer;
 
-  for (size_t retry = 0; retry < BufferHubQueue::kMaxQueueCapacity; retry++) {
+  for (size_t retry = 0; retry < dvr::BufferHubQueue::kMaxQueueCapacity;
+       retry++) {
     LocalHandle fence;
     auto buffer_status = queue_->Dequeue(dequeue_timeout_ms_, &slot, &fence);
     if (!buffer_status)
@@ -174,7 +183,7 @@
 
     if (width == buffer_producer->width() &&
         height == buffer_producer->height() &&
-        static_cast<uint32_t>(format) == buffer_producer->format()) {
+        uint32_t(format) == buffer_producer->format()) {
       // The producer queue returns a buffer producer matches the request.
       break;
     }
@@ -217,12 +226,12 @@
 
   buffers_[slot].mBufferState.freeQueued();
   buffers_[slot].mBufferState.dequeue();
-  ALOGD_IF(TRACE, "dequeueBuffer: slot=%zu", slot);
+  ALOGV("dequeueBuffer: slot=%zu", slot);
 
   // TODO(jwcai) Handle fence properly. |BufferHub| has full fence support, we
   // just need to exopose that through |BufferHubQueue| once we need fence.
   *out_fence = Fence::NO_FENCE;
-  *out_slot = slot;
+  *out_slot = int(slot);
   ret = NO_ERROR;
 
   if (buffers_[slot].mIsReallocating) {
@@ -233,30 +242,29 @@
   return ret;
 }
 
-status_t BufferHubQueueProducer::detachBuffer(int /* slot */) {
-  ALOGE("BufferHubQueueProducer::detachBuffer not implemented.");
+status_t BufferHubProducer::detachBuffer(int /* slot */) {
+  ALOGE("BufferHubProducer::detachBuffer not implemented.");
   return INVALID_OPERATION;
 }
 
-status_t BufferHubQueueProducer::detachNextBuffer(
+status_t BufferHubProducer::detachNextBuffer(
     sp<GraphicBuffer>* /* out_buffer */, sp<Fence>* /* out_fence */) {
-  ALOGE("BufferHubQueueProducer::detachNextBuffer not implemented.");
+  ALOGE("BufferHubProducer::detachNextBuffer not implemented.");
   return INVALID_OPERATION;
 }
 
-status_t BufferHubQueueProducer::attachBuffer(
+status_t BufferHubProducer::attachBuffer(
     int* /* out_slot */, const sp<GraphicBuffer>& /* buffer */) {
   // With this BufferHub backed implementation, we assume (for now) all buffers
   // are allocated and owned by the BufferHub. Thus the attempt of transfering
   // ownership of a buffer to the buffer queue is intentionally unsupported.
-  LOG_ALWAYS_FATAL("BufferHubQueueProducer::attachBuffer not supported.");
+  LOG_ALWAYS_FATAL("BufferHubProducer::attachBuffer not supported.");
   return INVALID_OPERATION;
 }
 
-status_t BufferHubQueueProducer::queueBuffer(int slot,
-                                             const QueueBufferInput& input,
-                                             QueueBufferOutput* output) {
-  ALOGD_IF(TRACE, "queueBuffer: slot %d", slot);
+status_t BufferHubProducer::queueBuffer(int slot, const QueueBufferInput& input,
+                                        QueueBufferOutput* output) {
+  ALOGV("queueBuffer: slot %d", slot);
 
   if (output == nullptr) {
     return BAD_VALUE;
@@ -291,7 +299,6 @@
     return BAD_VALUE;
   }
 
-  status_t ret;
   std::unique_lock<std::mutex> lock(mutex_);
 
   if (connected_api_ == kNoConnectedApi) {
@@ -333,14 +340,14 @@
 
   DvrNativeBufferMetadata meta_data;
   meta_data.timestamp = timestamp;
-  meta_data.is_auto_timestamp = static_cast<int32_t>(is_auto_timestamp);
-  meta_data.dataspace = static_cast<int32_t>(dataspace);
+  meta_data.is_auto_timestamp = int32_t(is_auto_timestamp);
+  meta_data.dataspace = int32_t(dataspace);
   meta_data.crop_left = crop.left;
   meta_data.crop_top = crop.top;
   meta_data.crop_right = crop.right;
   meta_data.crop_bottom = crop.bottom;
-  meta_data.scaling_mode = static_cast<int32_t>(scaling_mode);
-  meta_data.transform = static_cast<int32_t>(transform);
+  meta_data.scaling_mode = int32_t(scaling_mode);
+  meta_data.transform = int32_t(transform);
 
   buffer_producer->PostAsync(&meta_data, fence_fd);
   buffers_[slot].mBufferState.queue();
@@ -362,9 +369,8 @@
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::cancelBuffer(int slot,
-                                              const sp<Fence>& fence) {
-  ALOGD_IF(TRACE, __FUNCTION__);
+status_t BufferHubProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
+  ALOGV(__FUNCTION__);
 
   std::unique_lock<std::mutex> lock(mutex_);
 
@@ -387,16 +393,16 @@
   }
 
   auto buffer_producer = buffers_[slot].mBufferProducer;
-  queue_->Enqueue(buffer_producer, slot, 0ULL);
+  queue_->Enqueue(buffer_producer, size_t(slot), 0ULL);
   buffers_[slot].mBufferState.cancel();
   buffers_[slot].mFence = fence;
-  ALOGD_IF(TRACE, "cancelBuffer: slot %d", slot);
+  ALOGV("cancelBuffer: slot %d", slot);
 
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::query(int what, int* out_value) {
-  ALOGD_IF(TRACE, __FUNCTION__);
+status_t BufferHubProducer::query(int what, int* out_value) {
+  ALOGV(__FUNCTION__);
 
   std::unique_lock<std::mutex> lock(mutex_);
 
@@ -417,13 +423,13 @@
       value = 0;
       break;
     case NATIVE_WINDOW_WIDTH:
-      value = queue_->default_width();
+      value = int32_t(queue_->default_width());
       break;
     case NATIVE_WINDOW_HEIGHT:
-      value = queue_->default_height();
+      value = int32_t(queue_->default_height());
       break;
     case NATIVE_WINDOW_FORMAT:
-      value = queue_->default_format();
+      value = int32_t(queue_->default_format());
       break;
     case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND:
       // BufferHubQueue is always operating in async mode, thus semantically
@@ -455,18 +461,19 @@
       return BAD_VALUE;
   }
 
-  ALOGD_IF(TRACE, "query: key=%d, v=%d", what, value);
+  ALOGV("query: key=%d, v=%d", what, value);
   *out_value = value;
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::connect(
-    const sp<IProducerListener>& /* listener */, int api,
-    bool /* producer_controlled_by_app */, QueueBufferOutput* output) {
+status_t BufferHubProducer::connect(const sp<IProducerListener>& /* listener */,
+                                    int api,
+                                    bool /* producer_controlled_by_app */,
+                                    QueueBufferOutput* output) {
   // Consumer interaction are actually handled by buffer hub, and we need
   // to maintain consumer operations here. We only need to perform basic input
   // parameter checks here.
-  ALOGD_IF(TRACE, __FUNCTION__);
+  ALOGV(__FUNCTION__);
 
   if (output == nullptr) {
     return BAD_VALUE;
@@ -480,7 +487,7 @@
 
   if (!queue_->is_connected()) {
     ALOGE(
-        "BufferHubQueueProducer::connect: This BufferHubQueueProducer is not "
+        "BufferHubProducer::connect: This BufferHubProducer is not "
         "connected to bufferhud. Has it been taken out as a parcelable?");
     return BAD_VALUE;
   }
@@ -503,18 +510,18 @@
 
       break;
     default:
-      ALOGE("BufferHubQueueProducer::connect: unknow API %d", api);
+      ALOGE("BufferHubProducer::connect: unknow API %d", api);
       return BAD_VALUE;
   }
 
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::disconnect(int api, DisconnectMode /*mode*/) {
+status_t BufferHubProducer::disconnect(int api, DisconnectMode /*mode*/) {
   // Consumer interaction are actually handled by buffer hub, and we need
   // to maintain consumer operations here.  We only need to perform basic input
   // parameter checks here.
-  ALOGD_IF(TRACE, __FUNCTION__);
+  ALOGV(__FUNCTION__);
 
   std::unique_lock<std::mutex> lock(mutex_);
 
@@ -529,8 +536,7 @@
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::setSidebandStream(
-    const sp<NativeHandle>& stream) {
+status_t BufferHubProducer::setSidebandStream(const sp<NativeHandle>& stream) {
   if (stream != nullptr) {
     // TODO(jwcai) Investigate how is is used, maybe use BufferHubBuffer's
     // metadata.
@@ -540,42 +546,40 @@
   return NO_ERROR;
 }
 
-void BufferHubQueueProducer::allocateBuffers(uint32_t /* width */,
-                                             uint32_t /* height */,
-                                             PixelFormat /* format */,
-                                             uint64_t /* usage */) {
+void BufferHubProducer::allocateBuffers(uint32_t /* width */,
+                                        uint32_t /* height */,
+                                        PixelFormat /* format */,
+                                        uint64_t /* usage */) {
   // TODO(jwcai) |allocateBuffers| aims to preallocate up to the maximum number
   // of buffers permitted by the current BufferQueue configuration (aka
   // |max_buffer_count_|).
-  ALOGE("BufferHubQueueProducer::allocateBuffers not implemented.");
+  ALOGE("BufferHubProducer::allocateBuffers not implemented.");
 }
 
-status_t BufferHubQueueProducer::allowAllocation(bool /* allow */) {
-  ALOGE("BufferHubQueueProducer::allowAllocation not implemented.");
+status_t BufferHubProducer::allowAllocation(bool /* allow */) {
+  ALOGE("BufferHubProducer::allowAllocation not implemented.");
   return INVALID_OPERATION;
 }
 
-status_t BufferHubQueueProducer::setGenerationNumber(
-    uint32_t generation_number) {
-  ALOGD_IF(TRACE, __FUNCTION__);
+status_t BufferHubProducer::setGenerationNumber(uint32_t generation_number) {
+  ALOGV(__FUNCTION__);
 
   std::unique_lock<std::mutex> lock(mutex_);
   generation_number_ = generation_number;
   return NO_ERROR;
 }
 
-String8 BufferHubQueueProducer::getConsumerName() const {
+String8 BufferHubProducer::getConsumerName() const {
   // BufferHub based implementation could have one to many producer/consumer
   // relationship, thus |getConsumerName| from the producer side does not
   // make any sense.
-  ALOGE("BufferHubQueueProducer::getConsumerName not supported.");
+  ALOGE("BufferHubProducer::getConsumerName not supported.");
   return String8("BufferHubQueue::DummyConsumer");
 }
 
-status_t BufferHubQueueProducer::setSharedBufferMode(bool shared_buffer_mode) {
+status_t BufferHubProducer::setSharedBufferMode(bool shared_buffer_mode) {
   if (shared_buffer_mode) {
-    ALOGE(
-        "BufferHubQueueProducer::setSharedBufferMode(true) is not supported.");
+    ALOGE("BufferHubProducer::setSharedBufferMode(true) is not supported.");
     // TODO(b/36373181) Front buffer mode for buffer hub queue as ANativeWindow.
     return INVALID_OPERATION;
   }
@@ -583,65 +587,65 @@
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::setAutoRefresh(bool auto_refresh) {
+status_t BufferHubProducer::setAutoRefresh(bool auto_refresh) {
   if (auto_refresh) {
-    ALOGE("BufferHubQueueProducer::setAutoRefresh(true) is not supported.");
+    ALOGE("BufferHubProducer::setAutoRefresh(true) is not supported.");
     return INVALID_OPERATION;
   }
   // Setting to default should just work as a no-op.
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::setDequeueTimeout(nsecs_t timeout) {
-  ALOGD_IF(TRACE, __FUNCTION__);
+status_t BufferHubProducer::setDequeueTimeout(nsecs_t timeout) {
+  ALOGV(__FUNCTION__);
 
   std::unique_lock<std::mutex> lock(mutex_);
-  dequeue_timeout_ms_ = static_cast<int>(timeout / (1000 * 1000));
+  dequeue_timeout_ms_ = int(timeout / (1000 * 1000));
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::getLastQueuedBuffer(
+status_t BufferHubProducer::getLastQueuedBuffer(
     sp<GraphicBuffer>* /* out_buffer */, sp<Fence>* /* out_fence */,
     float /*out_transform_matrix*/[16]) {
-  ALOGE("BufferHubQueueProducer::getLastQueuedBuffer not implemented.");
+  ALOGE("BufferHubProducer::getLastQueuedBuffer not implemented.");
   return INVALID_OPERATION;
 }
 
-void BufferHubQueueProducer::getFrameTimestamps(
+void BufferHubProducer::getFrameTimestamps(
     FrameEventHistoryDelta* /*outDelta*/) {
-  ALOGE("BufferHubQueueProducer::getFrameTimestamps not implemented.");
+  ALOGE("BufferHubProducer::getFrameTimestamps not implemented.");
 }
 
-status_t BufferHubQueueProducer::getUniqueId(uint64_t* out_id) const {
-  ALOGD_IF(TRACE, __FUNCTION__);
+status_t BufferHubProducer::getUniqueId(uint64_t* out_id) const {
+  ALOGV(__FUNCTION__);
 
   *out_id = unique_id_;
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::getConsumerUsage(uint64_t* out_usage) const {
-  ALOGD_IF(TRACE, __FUNCTION__);
+status_t BufferHubProducer::getConsumerUsage(uint64_t* out_usage) const {
+  ALOGV(__FUNCTION__);
 
   // same value as returned by querying NATIVE_WINDOW_CONSUMER_USAGE_BITS
   *out_usage = 0;
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::TakeAsParcelable(
-    ProducerQueueParcelable* out_parcelable) {
+status_t BufferHubProducer::TakeAsParcelable(
+    dvr::ProducerQueueParcelable* out_parcelable) {
   if (!out_parcelable || out_parcelable->IsValid())
     return BAD_VALUE;
 
   if (connected_api_ != kNoConnectedApi) {
     ALOGE(
-        "BufferHubQueueProducer::TakeAsParcelable: BufferHubQueueProducer has "
+        "BufferHubProducer::TakeAsParcelable: BufferHubProducer has "
         "connected client. Must disconnect first.");
     return BAD_VALUE;
   }
 
   if (!queue_->is_connected()) {
     ALOGE(
-        "BufferHubQueueProducer::TakeAsParcelable: This BufferHubQueueProducer "
+        "BufferHubProducer::TakeAsParcelable: This BufferHubProducer "
         "is not connected to bufferhud. Has it been taken out as a "
         "parcelable?");
     return BAD_VALUE;
@@ -650,7 +654,7 @@
   auto status = queue_->TakeAsParcelable();
   if (!status) {
     ALOGE(
-        "BufferHubQueueProducer::TakeAsParcelable: Failed to take out "
+        "BufferHubProducer::TakeAsParcelable: Failed to take out "
         "ProducuerQueueParcelable from the producer queue, error: %s.",
         status.GetErrorMessage().c_str());
     return BAD_VALUE;
@@ -660,16 +664,14 @@
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::AllocateBuffer(uint32_t width, uint32_t height,
-                                                uint32_t layer_count,
-                                                PixelFormat format,
-                                                uint64_t usage) {
-  auto status =
-      queue_->AllocateBuffer(width, height, layer_count, format, usage);
+status_t BufferHubProducer::AllocateBuffer(uint32_t width, uint32_t height,
+                                           uint32_t layer_count,
+                                           PixelFormat format, uint64_t usage) {
+  auto status = queue_->AllocateBuffer(width, height, layer_count,
+                                       uint32_t(format), usage);
   if (!status) {
-    ALOGE(
-        "BufferHubQueueProducer::AllocateBuffer: Failed to allocate buffer: %s",
-        status.GetErrorMessage().c_str());
+    ALOGE("BufferHubProducer::AllocateBuffer: Failed to allocate buffer: %s",
+          status.GetErrorMessage().c_str());
     return NO_MEMORY;
   }
 
@@ -684,10 +686,10 @@
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::RemoveBuffer(size_t slot) {
+status_t BufferHubProducer::RemoveBuffer(size_t slot) {
   auto status = queue_->RemoveBuffer(slot);
   if (!status) {
-    ALOGE("BufferHubQueueProducer::RemoveBuffer: Failed to remove buffer: %s",
+    ALOGE("BufferHubProducer::RemoveBuffer: Failed to remove buffer: %s",
           status.GetErrorMessage().c_str());
     return INVALID_OPERATION;
   }
@@ -699,8 +701,8 @@
   return NO_ERROR;
 }
 
-status_t BufferHubQueueProducer::FreeAllBuffers() {
-  for (size_t slot = 0; slot < BufferHubQueue::kMaxQueueCapacity; slot++) {
+status_t BufferHubProducer::FreeAllBuffers() {
+  for (size_t slot = 0; slot < dvr::BufferHubQueue::kMaxQueueCapacity; slot++) {
     // Reset in memory objects related the the buffer.
     buffers_[slot].mGraphicBuffer = nullptr;
     buffers_[slot].mBufferState.reset();
@@ -712,18 +714,17 @@
   auto status = queue_->FreeAllBuffers();
   if (!status) {
     ALOGE(
-        "BufferHubQueueProducer::FreeAllBuffers: Failed to free all buffers on "
+        "BufferHubProducer::FreeAllBuffers: Failed to free all buffers on "
         "the queue: %s",
         status.GetErrorMessage().c_str());
   }
 
   if (queue_->capacity() != 0 || queue_->count() != 0) {
     LOG_ALWAYS_FATAL(
-        "BufferHubQueueProducer::FreeAllBuffers: Not all buffers are freed.");
+        "BufferHubProducer::FreeAllBuffers: Not all buffers are freed.");
   }
 
   return NO_ERROR;
 }
 
-}  // namespace dvr
 }  // namespace android
diff --git a/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_producer.h b/libs/gui/include/gui/BufferHubProducer.h
similarity index 87%
rename from libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_producer.h
rename to libs/gui/include/gui/BufferHubProducer.h
index 9c85048..6b23e06 100644
--- a/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_producer.h
+++ b/libs/gui/include/gui/BufferHubProducer.h
@@ -1,14 +1,14 @@
-#ifndef ANDROID_DVR_BUFFER_HUB_QUEUE_PRODUCER_H_
-#define ANDROID_DVR_BUFFER_HUB_QUEUE_PRODUCER_H_
+#ifndef ANDROID_GUI_BUFFERHUBPRODUCER_H_
+#define ANDROID_GUI_BUFFERHUBPRODUCER_H_
 
+#include <gui/BufferSlot.h>
 #include <gui/IGraphicBufferProducer.h>
 #include <private/dvr/buffer_hub_queue_client.h>
 #include <private/dvr/buffer_hub_queue_parcelable.h>
 
 namespace android {
-namespace dvr {
 
-class BufferHubQueueProducer : public BnGraphicBufferProducer {
+class BufferHubProducer : public BnGraphicBufferProducer {
  public:
   static constexpr int kNoConnectedApi = -1;
 
@@ -18,15 +18,15 @@
   // that.
   static constexpr int kDefaultUndequeuedBuffers = 1;
 
-  // Creates a BufferHubQueueProducer instance by importing an existing prodcuer
+  // Creates a BufferHubProducer instance by importing an existing prodcuer
   // queue.
-  static sp<BufferHubQueueProducer> Create(
-      const std::shared_ptr<ProducerQueue>& producer);
+  static sp<BufferHubProducer> Create(
+      const std::shared_ptr<dvr::ProducerQueue>& producer);
 
-  // Creates a BufferHubQueueProducer instance by importing an existing prodcuer
+  // Creates a BufferHubProducer instance by importing an existing prodcuer
   // parcelable. Note that this call takes the ownership of the parcelable
   // object and is guaranteed to succeed if parcelable object is valid.
-  static sp<BufferHubQueueProducer> Create(ProducerQueueParcelable parcelable);
+  static sp<BufferHubProducer> Create(dvr::ProducerQueueParcelable parcelable);
 
   // See |IGraphicBufferProducer::requestBuffer|
   status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) override;
@@ -124,13 +124,13 @@
   // takeout is successful and out_parcelable will hold the new parcelable
   // object. Also note that out_parcelable cannot be NULL and must points to an
   // invalid parcelable.
-  status_t TakeAsParcelable(ProducerQueueParcelable* out_parcelable);
+  status_t TakeAsParcelable(dvr::ProducerQueueParcelable* out_parcelable);
 
  private:
   using LocalHandle = pdx::LocalHandle;
 
   // Private constructor to force use of |Create|.
-  BufferHubQueueProducer() {}
+  BufferHubProducer() {}
 
   static uint64_t genUniqueId() {
     static std::atomic<uint32_t> counter{0};
@@ -151,7 +151,7 @@
   status_t FreeAllBuffers();
 
   // Concreate implementation backed by BufferHubBuffer.
-  std::shared_ptr<ProducerQueue> queue_;
+  std::shared_ptr<dvr::ProducerQueue> queue_;
 
   // Mutex for thread safety.
   std::mutex mutex_;
@@ -160,7 +160,7 @@
   int connected_api_{kNoConnectedApi};
 
   // |max_buffer_count_| sets the capacity of the underlying buffer queue.
-  int32_t max_buffer_count_{BufferHubQueue::kMaxQueueCapacity};
+  int32_t max_buffer_count_{dvr::BufferHubQueue::kMaxQueueCapacity};
 
   // |max_dequeued_buffer_count_| set the maximum number of buffers that can
   // be dequeued at the same momment.
@@ -168,7 +168,7 @@
 
   // Sets how long dequeueBuffer or attachBuffer will block if a buffer or
   // slot is not yet available. The timeout is stored in milliseconds.
-  int dequeue_timeout_ms_{BufferHubQueue::kNoTimeOut};
+  int dequeue_timeout_ms_{dvr::BufferHubQueue::kNoTimeOut};
 
   // |generation_number_| stores the current generation number of the attached
   // producer. Any attempt to attach a buffer with a different generation
@@ -187,16 +187,15 @@
     BufferHubSlot() : mBufferProducer(nullptr), mIsReallocating(false) {}
     // BufferSlot comes from android framework, using m prefix to comply with
     // the name convention with the reset of data fields from BufferSlot.
-    std::shared_ptr<BufferProducer> mBufferProducer;
+    std::shared_ptr<dvr::BufferProducer> mBufferProducer;
     bool mIsReallocating;
   };
-  BufferHubSlot buffers_[BufferHubQueue::kMaxQueueCapacity];
+  BufferHubSlot buffers_[dvr::BufferHubQueue::kMaxQueueCapacity];
 
   // A uniqueId used by IGraphicBufferProducer interface.
   const uint64_t unique_id_{genUniqueId()};
 };
 
-}  // namespace dvr
 }  // namespace android
 
-#endif  // ANDROID_DVR_BUFFER_HUB_QUEUE_PRODUCER_H_
+#endif  // ANDROID_GUI_BUFFERHUBPRODUCER_H_
diff --git a/libs/vr/libbufferhub/Android.bp b/libs/vr/libbufferhub/Android.bp
index fa8e565..7ea37a7 100644
--- a/libs/vr/libbufferhub/Android.bp
+++ b/libs/vr/libbufferhub/Android.bp
@@ -59,6 +59,10 @@
     export_header_lib_headers: [
         "libnativebase_headers",
     ],
+    vendor_available: false,
+    vndk: {
+        enabled: true,
+    },
 }
 
 cc_test {
diff --git a/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h b/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h
index f9fd42d..f105b02 100644
--- a/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h
+++ b/libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h
@@ -2,8 +2,8 @@
 #define ANDROID_DVR_BUFFERHUB_RPC_H_
 
 #include <cutils/native_handle.h>
-#include <gui/BufferQueueDefs.h>
 #include <sys/types.h>
+#include <ui/BufferQueueDefs.h>
 
 #include <dvr/dvr_api.h>
 #include <pdx/channel_handle.h>
diff --git a/libs/vr/libbufferhubqueue/Android.bp b/libs/vr/libbufferhubqueue/Android.bp
index b9568ee..84e7427 100644
--- a/libs/vr/libbufferhubqueue/Android.bp
+++ b/libs/vr/libbufferhubqueue/Android.bp
@@ -15,7 +15,6 @@
 sourceFiles = [
     "buffer_hub_queue_client.cpp",
     "buffer_hub_queue_parcelable.cpp",
-    "buffer_hub_queue_producer.cpp",
 ]
 
 includeFiles = [
@@ -35,7 +34,6 @@
     "liblog",
     "libui",
     "libutils",
-    "libgui",
 ]
 
 headerLibraries = [
@@ -61,6 +59,10 @@
     static_libs: staticLibraries,
     shared_libs: sharedLibraries,
     header_libs: headerLibraries,
+    vendor_available: false,
+    vndk: {
+        enabled: true,
+    },
 }
 
 subdirs = ["tests"]
diff --git a/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_client.h b/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_client.h
index 5bab4a5..8965530 100644
--- a/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_client.h
+++ b/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_client.h
@@ -1,7 +1,7 @@
 #ifndef ANDROID_DVR_BUFFER_HUB_QUEUE_CLIENT_H_
 #define ANDROID_DVR_BUFFER_HUB_QUEUE_CLIENT_H_
 
-#include <gui/BufferQueueDefs.h>
+#include <ui/BufferQueueDefs.h>
 
 #include <pdx/client.h>
 #include <pdx/status.h>
diff --git a/libs/vr/libbufferhubqueue/tests/buffer_hub_queue_producer-test.cpp b/libs/vr/libbufferhubqueue/tests/buffer_hub_queue_producer-test.cpp
index 96f5404..3e96989 100644
--- a/libs/vr/libbufferhubqueue/tests/buffer_hub_queue_producer-test.cpp
+++ b/libs/vr/libbufferhubqueue/tests/buffer_hub_queue_producer-test.cpp
@@ -1,6 +1,5 @@
-#include <private/dvr/buffer_hub_queue_producer.h>
-
 #include <base/logging.h>
+#include <gui/BufferHubProducer.h>
 #include <gui/IProducerListener.h>
 #include <gui/Surface.h>
 #include <pdx/default_transport/channel_parcelable.h>
@@ -101,7 +100,7 @@
     auto queue = ProducerQueue::Create(config, UsagePolicy{});
     ASSERT_TRUE(queue != nullptr);
 
-    mProducer = BufferHubQueueProducer::Create(std::move(queue));
+    mProducer = BufferHubProducer::Create(std::move(queue));
     ASSERT_TRUE(mProducer != nullptr);
     mSurface = new Surface(mProducer, true);
     ASSERT_TRUE(mSurface != nullptr);
@@ -145,7 +144,7 @@
 
   const sp<IProducerListener> kDummyListener{new DummyProducerListener};
 
-  sp<BufferHubQueueProducer> mProducer;
+  sp<BufferHubProducer> mProducer;
   sp<Surface> mSurface;
 };
 
@@ -596,8 +595,8 @@
 
   // Create a new producer from the parcelable and connect to kTestApi should
   // succeed.
-  sp<BufferHubQueueProducer> new_producer =
-      BufferHubQueueProducer::Create(std::move(producer_parcelable));
+  sp<BufferHubProducer> new_producer =
+      BufferHubProducer::Create(std::move(producer_parcelable));
   ASSERT_TRUE(new_producer != nullptr);
   EXPECT_EQ(new_producer->connect(kDummyListener, kTestApi,
                                   kTestControlledByApp, &output),
diff --git a/libs/vr/libbufferhubqueue/tests/buffer_transport_benchmark.cpp b/libs/vr/libbufferhubqueue/tests/buffer_transport_benchmark.cpp
index d4d25b0..73932c2 100644
--- a/libs/vr/libbufferhubqueue/tests/buffer_transport_benchmark.cpp
+++ b/libs/vr/libbufferhubqueue/tests/buffer_transport_benchmark.cpp
@@ -5,10 +5,10 @@
 #include <binder/IServiceManager.h>
 #include <dvr/dvr_api.h>
 #include <dvr/performance_client_api.h>
+#include <gui/BufferHubProducer.h>
 #include <gui/BufferItem.h>
 #include <gui/BufferItemConsumer.h>
 #include <gui/Surface.h>
-#include <private/dvr/buffer_hub_queue_producer.h>
 #include <utils/Trace.h>
 
 #include <chrono>
@@ -338,7 +338,7 @@
         }
       });
 
-      producer_ = BufferHubQueueProducer::Create(producer_queue_);
+      producer_ = BufferHubProducer::Create(producer_queue_);
     }
 
     int count_ = 0;
diff --git a/libs/vr/libdvr/Android.bp b/libs/vr/libdvr/Android.bp
index 04418d2..4f0e561 100644
--- a/libs/vr/libdvr/Android.bp
+++ b/libs/vr/libdvr/Android.bp
@@ -15,8 +15,11 @@
 
 cc_library_headers {
     name: "libdvr_headers",
-    owner: "google",
     export_include_dirs: ["include"],
+    vendor_available: false,
+    vndk: {
+        enabled: true,
+    },
 }
 
 cflags = [
diff --git a/libs/vr/libdvr/dvr_buffer_queue.cpp b/libs/vr/libdvr/dvr_buffer_queue.cpp
index 09a49dd..c36d190 100644
--- a/libs/vr/libdvr/dvr_buffer_queue.cpp
+++ b/libs/vr/libdvr/dvr_buffer_queue.cpp
@@ -2,7 +2,7 @@
 #include "include/dvr/dvr_buffer_queue.h"
 
 #include <android/native_window.h>
-#include <private/dvr/buffer_hub_queue_producer.h>
+#include <gui/BufferHubProducer.h>
 
 #include "dvr_internal.h"
 #include "dvr_buffer_queue_internal.h"
@@ -10,7 +10,6 @@
 using namespace android;
 using android::dvr::BufferConsumer;
 using android::dvr::BufferHubBuffer;
-using android::dvr::BufferHubQueueProducer;
 using android::dvr::BufferProducer;
 using android::dvr::ConsumerQueue;
 using android::dvr::ProducerQueue;
@@ -30,8 +29,7 @@
   if (native_window_ == nullptr) {
     // Lazy creation of |native_window|, as not everyone is using
     // DvrWriteBufferQueue as an external surface.
-    sp<IGraphicBufferProducer> gbp =
-        BufferHubQueueProducer::Create(producer_queue_);
+    sp<IGraphicBufferProducer> gbp = BufferHubProducer::Create(producer_queue_);
     native_window_ = new Surface(gbp, true);
   }
 
diff --git a/libs/vr/libpdx/Android.bp b/libs/vr/libpdx/Android.bp
index 10c0b31..9b84d65 100644
--- a/libs/vr/libpdx/Android.bp
+++ b/libs/vr/libpdx/Android.bp
@@ -16,6 +16,16 @@
         "service_dispatcher.cpp",
         "status.cpp",
     ],
+    shared_libs: [
+        "libbinder",
+        "libcutils",
+        "libutils",
+        "liblog",
+    ],
+    vendor_available: false,
+    vndk: {
+        enabled: true,
+    },
 }
 
 cc_test {
diff --git a/libs/vr/libpdx_default_transport/Android.bp b/libs/vr/libpdx_default_transport/Android.bp
index cda3c95..779e3a1 100644
--- a/libs/vr/libpdx_default_transport/Android.bp
+++ b/libs/vr/libpdx_default_transport/Android.bp
@@ -12,6 +12,10 @@
     name: "pdx_default_transport_lib_defaults",
     export_include_dirs: ["private"],
     whole_static_libs: ["libpdx"],
+    vendor_available: false,
+    vndk: {
+        enabled: true,
+    },
 }
 
 cc_defaults {
diff --git a/libs/vr/libpdx_uds/Android.bp b/libs/vr/libpdx_uds/Android.bp
index d640950..79cfdf6 100644
--- a/libs/vr/libpdx_uds/Android.bp
+++ b/libs/vr/libpdx_uds/Android.bp
@@ -30,6 +30,10 @@
     whole_static_libs: [
         "libselinux",
     ],
+    vendor_available: false,
+    vndk: {
+        enabled: true,
+    },
 }
 
 cc_test {