Remove buffer_hub_binder and related codes
As we decided the new bufferhub service should be hwbinder instead of
binder, these binder codes no longer make sense.
Test: build passed
Bug: 118891412
Change-Id: I5eae2516d279ea85c156d49a2ab31e8e319baae2
diff --git a/libs/vr/libbufferhub/Android.bp b/libs/vr/libbufferhub/Android.bp
index 43ac79e..fa92830 100644
--- a/libs/vr/libbufferhub/Android.bp
+++ b/libs/vr/libbufferhub/Android.bp
@@ -22,14 +22,12 @@
"buffer_hub_base.cpp",
"buffer_hub_rpc.cpp",
"consumer_buffer.cpp",
- "buffer_client_impl.cpp",
"ion_buffer.cpp",
"producer_buffer.cpp",
]
sharedLibraries = [
"libbase",
- "libbinder",
"libcutils",
"libhardware",
"liblog",
diff --git a/libs/vr/libbufferhub/buffer_client_impl.cpp b/libs/vr/libbufferhub/buffer_client_impl.cpp
deleted file mode 100644
index efa9c28..0000000
--- a/libs/vr/libbufferhub/buffer_client_impl.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-#include <log/log.h>
-#include <private/dvr/IBufferClient.h>
-
-namespace android {
-namespace dvr {
-
-class BpBufferClient : public BpInterface<IBufferClient> {
- public:
- explicit BpBufferClient(const sp<IBinder>& impl)
- : BpInterface<IBufferClient>(impl) {}
-
- bool isValid() override;
-
- status_t duplicate(uint64_t* outToken) override;
-};
-
-IMPLEMENT_META_INTERFACE(BufferClient, "android.dvr.IBufferClient");
-
-// Transaction code
-enum {
- IS_VALID = IBinder::FIRST_CALL_TRANSACTION,
- DUPLICATE,
-};
-
-bool BpBufferClient::isValid() {
- Parcel data, reply;
- status_t ret =
- data.writeInterfaceToken(IBufferClient::getInterfaceDescriptor());
- if (ret != OK) {
- ALOGE("BpBufferClient::isValid: failed to write into parcel; errno=%d",
- ret);
- return false;
- }
-
- ret = remote()->transact(IS_VALID, data, &reply);
- if (ret == OK) {
- return reply.readBool();
- } else {
- ALOGE("BpBufferClient::isValid: failed to transact; errno=%d", ret);
- return false;
- }
-}
-
-status_t BpBufferClient::duplicate(uint64_t* outToken) {
- Parcel data, reply;
- status_t ret =
- data.writeInterfaceToken(IBufferClient::getInterfaceDescriptor());
- if (ret != OK) {
- ALOGE("BpBufferClient::duplicate: failed to write into parcel; errno=%d",
- ret);
- return ret;
- }
-
- ret = remote()->transact(DUPLICATE, data, &reply);
- if (ret == OK) {
- *outToken = reply.readUint64();
- return OK;
- } else {
- ALOGE("BpBufferClient::duplicate: failed to transact; errno=%d", ret);
- return ret;
- }
-}
-
-status_t BnBufferClient::onTransact(uint32_t code, const Parcel& data,
- Parcel* reply, uint32_t flags) {
- switch (code) {
- case IS_VALID: {
- CHECK_INTERFACE(IBufferClient, data, reply);
- return reply->writeBool(isValid());
- }
- case DUPLICATE: {
- CHECK_INTERFACE(IBufferClient, data, reply);
- uint64_t token = 0;
- status_t ret = duplicate(&token);
- if (ret != OK) {
- return ret;
- }
- return reply->writeUint64(token);
- }
- default:
- // Should not reach except binder defined transactions such as dumpsys
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
-
-} // namespace dvr
-} // namespace android
\ No newline at end of file
diff --git a/libs/vr/libbufferhub/include/private/dvr/IBufferClient.h b/libs/vr/libbufferhub/include/private/dvr/IBufferClient.h
deleted file mode 100644
index 31bf79d..0000000
--- a/libs/vr/libbufferhub/include/private/dvr/IBufferClient.h
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef ANDROID_DVR_IBUFFERCLIENT_H
-#define ANDROID_DVR_IBUFFERCLIENT_H
-
-#include <binder/IInterface.h>
-#include <binder/Parcel.h>
-
-namespace android {
-namespace dvr {
-
-// Interface for acessing BufferHubBuffer remotely.
-class IBufferClient : public IInterface {
- public:
- DECLARE_META_INTERFACE(BufferClient);
-
- // Checks if the buffer node is valid.
- virtual bool isValid() = 0;
-
- // Duplicates the client. Token_out will be set to a new token when succeed,
- // and not changed when failed.
- virtual status_t duplicate(uint64_t* outToken) = 0;
-};
-
-// BnInterface for IBufferClient. Should only be created in bufferhub service.
-class BnBufferClient : public BnInterface<IBufferClient> {
- public:
- virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
- uint32_t flags = 0);
-};
-
-} // namespace dvr
-} // namespace android
-
-#endif // ANDROID_DVR_IBUFFERCLIENT_H
\ No newline at end of file
diff --git a/services/vr/bufferhubd/Android.bp b/services/vr/bufferhubd/Android.bp
index 0a59f29..7a7e437 100644
--- a/services/vr/bufferhubd/Android.bp
+++ b/services/vr/bufferhubd/Android.bp
@@ -14,7 +14,6 @@
sharedLibraries = [
"libbase",
- "libbinder",
"libbufferhubservice",
"libcutils",
"libgtest_prod",
@@ -30,12 +29,9 @@
name: "libbufferhubd",
srcs: [
"buffer_channel.cpp",
- "buffer_client.cpp",
"buffer_hub.cpp",
- "buffer_hub_binder.cpp",
"consumer_channel.cpp",
"consumer_queue_channel.cpp",
- "IBufferHub.cpp",
"producer_channel.cpp",
"producer_queue_channel.cpp",
],
@@ -45,10 +41,7 @@
"-DATRACE_TAG=ATRACE_TAG_GRAPHICS",
],
export_include_dirs: ["include"],
- header_libs: [
- "libdvr_headers",
- "libnativewindow_headers",
- ],
+ header_libs: ["libdvr_headers"],
shared_libs: sharedLibraries,
static_libs: [
"libbufferhub",
diff --git a/services/vr/bufferhubd/IBufferHub.cpp b/services/vr/bufferhubd/IBufferHub.cpp
deleted file mode 100644
index 5980873..0000000
--- a/services/vr/bufferhubd/IBufferHub.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-#include <log/log.h>
-#include <private/dvr/IBufferHub.h>
-
-namespace android {
-namespace dvr {
-
-class BpBufferHub : public BpInterface<IBufferHub> {
- public:
- explicit BpBufferHub(const sp<IBinder>& impl)
- : BpInterface<IBufferHub>(impl) {}
-
- sp<IBufferClient> createBuffer(uint32_t width, uint32_t height,
- uint32_t layer_count, uint32_t format,
- uint64_t usage,
- uint64_t user_metadata_size) override;
-
- status_t importBuffer(uint64_t token, sp<IBufferClient>* outClient) override;
-};
-
-IMPLEMENT_META_INTERFACE(BufferHub, "android.dvr.IBufferHub");
-
-// Transaction code
-enum {
- CREATE_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
- IMPORT_BUFFER,
-};
-
-sp<IBufferClient> BpBufferHub::createBuffer(uint32_t width, uint32_t height,
- uint32_t layer_count,
- uint32_t format, uint64_t usage,
- uint64_t user_metadata_size) {
- Parcel data, reply;
- status_t ret = OK;
- ret |= data.writeInterfaceToken(IBufferHub::getInterfaceDescriptor());
- ret |= data.writeUint32(width);
- ret |= data.writeUint32(height);
- ret |= data.writeUint32(layer_count);
- ret |= data.writeUint32(format);
- ret |= data.writeUint64(usage);
- ret |= data.writeUint64(user_metadata_size);
-
- if (ret != OK) {
- ALOGE("BpBufferHub::createBuffer: failed to write into parcel");
- return nullptr;
- }
-
- ret = remote()->transact(CREATE_BUFFER, data, &reply);
- if (ret == OK) {
- return interface_cast<IBufferClient>(reply.readStrongBinder());
- } else {
- ALOGE("BpBufferHub::createBuffer: failed to transact; errno=%d", ret);
- return nullptr;
- }
-}
-
-status_t BpBufferHub::importBuffer(uint64_t token,
- sp<IBufferClient>* outClient) {
- Parcel data, reply;
- status_t ret = OK;
- ret |= data.writeInterfaceToken(IBufferHub::getInterfaceDescriptor());
- ret |= data.writeUint64(token);
- if (ret != OK) {
- ALOGE("BpBufferHub::importBuffer: failed to write into parcel");
- return ret;
- }
-
- ret = remote()->transact(IMPORT_BUFFER, data, &reply);
- if (ret == OK) {
- *outClient = interface_cast<IBufferClient>(reply.readStrongBinder());
- return OK;
- } else {
- ALOGE("BpBufferHub::importBuffer: failed to transact; errno=%d", ret);
- return ret;
- }
-}
-
-status_t BnBufferHub::onTransact(uint32_t code, const Parcel& data,
- Parcel* reply, uint32_t flags) {
- switch (code) {
- case CREATE_BUFFER: {
- CHECK_INTERFACE(IBufferHub, data, reply);
- uint32_t width = data.readUint32();
- uint32_t height = data.readUint32();
- uint32_t layer_count = data.readUint32();
- uint32_t format = data.readUint32();
- uint64_t usage = data.readUint64();
- uint64_t user_metadata_size = data.readUint64();
- sp<IBufferClient> ret = createBuffer(width, height, layer_count, format,
- usage, user_metadata_size);
- return reply->writeStrongBinder(IInterface::asBinder(ret));
- }
- case IMPORT_BUFFER: {
- CHECK_INTERFACE(IBufferHub, data, reply);
- uint64_t token = data.readUint64();
- sp<IBufferClient> client;
- status_t ret = importBuffer(token, &client);
- if (ret == OK) {
- return reply->writeStrongBinder(IInterface::asBinder(client));
- } else {
- return ret;
- }
- }
- default:
- // Should not reach except binder defined transactions such as dumpsys
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
-
-} // namespace dvr
-} // namespace android
\ No newline at end of file
diff --git a/services/vr/bufferhubd/buffer_client.cpp b/services/vr/bufferhubd/buffer_client.cpp
deleted file mode 100644
index f14faf7..0000000
--- a/services/vr/bufferhubd/buffer_client.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <private/dvr/buffer_client.h>
-#include <private/dvr/buffer_hub_binder.h>
-
-namespace android {
-namespace dvr {
-
-status_t BufferClient::duplicate(uint64_t* outToken) {
- if (!buffer_node_) {
- // Should never happen
- ALOGE("BufferClient::duplicate: node is missing.");
- return UNEXPECTED_NULL;
- }
- return service_->registerToken(std::weak_ptr<BufferNode>(buffer_node_),
- outToken);
-}
-
-} // namespace dvr
-} // namespace android
\ No newline at end of file
diff --git a/services/vr/bufferhubd/buffer_hub_binder.cpp b/services/vr/bufferhubd/buffer_hub_binder.cpp
deleted file mode 100644
index 580433e..0000000
--- a/services/vr/bufferhubd/buffer_hub_binder.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-#include <stdio.h>
-
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-#include <binder/ProcessState.h>
-#include <log/log.h>
-#include <private/dvr/buffer_hub_binder.h>
-#include <private/dvr/buffer_node.h>
-
-namespace android {
-namespace dvr {
-
-status_t BufferHubBinderService::start(
- const std::shared_ptr<BufferHubService>& pdx_service) {
- IPCThreadState::self()->disableBackgroundScheduling(true);
-
- sp<BufferHubBinderService> service = new BufferHubBinderService();
- service->pdx_service_ = pdx_service;
-
- // Not using BinderService::publish because need to get an instance of this
- // class (above). Following code is the same as
- // BinderService::publishAndJoinThreadPool
- sp<IServiceManager> sm = defaultServiceManager();
- status_t result = sm->addService(
- String16(getServiceName()), service,
- /*allowIsolated =*/false,
- /*dump flags =*/IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT);
- if (result != OK) {
- ALOGE("Publishing bufferhubd failed with error %d", result);
- return result;
- }
-
- sp<ProcessState> process_self(ProcessState::self());
- process_self->startThreadPool();
-
- return result;
-}
-
-status_t BufferHubBinderService::dump(int fd, const Vector<String16>& args) {
- FILE* out = fdopen(dup(fd), "w");
-
- // Currently not supporting args, so notify the user.
- if (!args.isEmpty()) {
- fprintf(out,
- "Note: dumpsys bufferhubd currently does not support args."
- "Input arguments are ignored.\n");
- }
-
- fprintf(out, "Binder service:\n");
- // Active buffers
- fprintf(out, "Active BufferClients: %zu\n", client_list_.size());
- // TODO(b/117790952): print buffer information after BufferNode has it
- // TODO(b/116526156): print more information once we have them
-
- if (pdx_service_) {
- fprintf(out, "\nPDX service:\n");
- // BufferHubService::Dumpstate(size_t) is not actually using the param
- // So just using 0 as the length
- fprintf(out, "%s", pdx_service_->DumpState(0).c_str());
- } else {
- fprintf(out, "PDX service not registered or died.\n");
- }
-
- fclose(out);
- return OK;
-}
-
-status_t BufferHubBinderService::registerToken(
- const std::weak_ptr<BufferNode> node, uint64_t* outToken) {
- do {
- *outToken = token_engine_();
- } while (token_map_.find(*outToken) != token_map_.end());
-
- token_map_.emplace(*outToken, node);
- return OK;
-}
-
-sp<IBufferClient> BufferHubBinderService::createBuffer(
- uint32_t width, uint32_t height, uint32_t layer_count, uint32_t format,
- uint64_t usage, uint64_t user_metadata_size) {
- std::shared_ptr<BufferNode> node = std::make_shared<BufferNode>(
- width, height, layer_count, format, usage, user_metadata_size);
-
- sp<BufferClient> client = new BufferClient(node, this);
- // Add it to list for bookkeeping and dumpsys.
- client_list_.push_back(client);
-
- return client;
-}
-
-status_t BufferHubBinderService::importBuffer(uint64_t token,
- sp<IBufferClient>* outClient) {
- auto iter = token_map_.find(token);
-
- if (iter == token_map_.end()) { // Not found
- ALOGE("BufferHubBinderService::importBuffer: token %" PRIu64
- "does not exist.",
- token);
- return PERMISSION_DENIED;
- }
-
- if (iter->second.expired()) { // Gone
- ALOGW(
- "BufferHubBinderService::importBuffer: the original node of token "
- "%" PRIu64 "has gone.",
- token);
- token_map_.erase(iter);
- return DEAD_OBJECT;
- }
-
- // Promote the weak_ptr
- std::shared_ptr<BufferNode> node(iter->second);
- if (!node) {
- ALOGE("BufferHubBinderService::importBuffer: promote weak_ptr failed.");
- token_map_.erase(iter);
- return DEAD_OBJECT;
- }
-
- sp<BufferClient> client = new BufferClient(node, this);
- *outClient = client;
-
- token_map_.erase(iter);
- client_list_.push_back(client);
-
- return OK;
-}
-
-} // namespace dvr
-} // namespace android
diff --git a/services/vr/bufferhubd/bufferhubd.cpp b/services/vr/bufferhubd/bufferhubd.cpp
index e44cc2a..50cb3b7 100644
--- a/services/vr/bufferhubd/bufferhubd.cpp
+++ b/services/vr/bufferhubd/bufferhubd.cpp
@@ -6,7 +6,6 @@
#include <log/log.h>
#include <pdx/service_dispatcher.h>
#include <private/dvr/buffer_hub.h>
-#include <private/dvr/buffer_hub_binder.h>
int main(int, char**) {
int ret = -1;
@@ -40,10 +39,6 @@
CHECK_ERROR(!pdx_service, error, "Failed to create bufferhub pdx service\n");
dispatcher->AddService(pdx_service);
- ret = android::dvr::BufferHubBinderService::start(pdx_service);
- CHECK_ERROR(ret != android::OK, error,
- "Failed to create bufferhub binder service\n");
-
ret = dvrSetSchedulerClass(0, "graphics");
CHECK_ERROR(ret < 0, error, "Failed to set thread priority");
diff --git a/services/vr/bufferhubd/include/private/dvr/IBufferHub.h b/services/vr/bufferhubd/include/private/dvr/IBufferHub.h
deleted file mode 100644
index 502c6d6..0000000
--- a/services/vr/bufferhubd/include/private/dvr/IBufferHub.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef ANDROID_DVR_IBUFFERHUB_H
-#define ANDROID_DVR_IBUFFERHUB_H
-
-#include <binder/IInterface.h>
-#include <binder/Parcel.h>
-#include <private/dvr/IBufferClient.h>
-
-namespace android {
-namespace dvr {
-
-class IBufferHub : public IInterface {
- public:
- DECLARE_META_INTERFACE(BufferHub);
-
- static const char* getServiceName() { return "bufferhubd"; }
- virtual sp<IBufferClient> createBuffer(uint32_t width, uint32_t height,
- uint32_t layer_count, uint32_t format,
- uint64_t usage,
- uint64_t user_metadata_size) = 0;
-
- virtual status_t importBuffer(uint64_t token,
- sp<IBufferClient>* outClient) = 0;
-};
-
-class BnBufferHub : public BnInterface<IBufferHub> {
- public:
- virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
- uint32_t flags = 0);
-};
-
-} // namespace dvr
-} // namespace android
-
-#endif // ANDROID_DVR_IBUFFERHUB_H
\ No newline at end of file
diff --git a/services/vr/bufferhubd/include/private/dvr/buffer_client.h b/services/vr/bufferhubd/include/private/dvr/buffer_client.h
deleted file mode 100644
index d79ec0a..0000000
--- a/services/vr/bufferhubd/include/private/dvr/buffer_client.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef ANDROID_DVR_BUFFERCLIENT_H
-#define ANDROID_DVR_BUFFERCLIENT_H
-
-#include <private/dvr/IBufferClient.h>
-#include <private/dvr/buffer_node.h>
-
-namespace android {
-namespace dvr {
-
-// Forward declaration to avoid circular dependency
-class BufferHubBinderService;
-
-class BufferClient : public BnBufferClient {
- public:
- // Creates a server-side buffer client from an existing BufferNode. Note that
- // this funciton takes ownership of the shared_ptr.
- explicit BufferClient(std::shared_ptr<BufferNode> node,
- BufferHubBinderService* service)
- : service_(service), buffer_node_(std::move(node)){};
-
- // Binder IPC functions
- bool isValid() override {
- return buffer_node_ ? buffer_node_->IsValid() : false;
- };
-
- status_t duplicate(uint64_t* outToken) override;
-
- private:
- // Hold a pointer to the service to bypass binder interface, as BufferClient
- // and the service will be in the same process. Also, since service owns
- // Client, if service dead the clients will be destroyed, so this pointer is
- // guaranteed to be valid.
- BufferHubBinderService* service_;
-
- std::shared_ptr<BufferNode> buffer_node_;
-};
-
-} // namespace dvr
-} // namespace android
-
-#endif // ANDROID_DVR_IBUFFERCLIENT_H
\ No newline at end of file
diff --git a/services/vr/bufferhubd/include/private/dvr/buffer_hub_binder.h b/services/vr/bufferhubd/include/private/dvr/buffer_hub_binder.h
deleted file mode 100644
index cf6124b..0000000
--- a/services/vr/bufferhubd/include/private/dvr/buffer_hub_binder.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef ANDROID_DVR_BUFFER_HUB_BINDER_H
-#define ANDROID_DVR_BUFFER_HUB_BINDER_H
-
-#include <random>
-#include <unordered_map>
-#include <vector>
-
-#include <binder/BinderService.h>
-#include <private/dvr/IBufferHub.h>
-#include <private/dvr/buffer_client.h>
-#include <private/dvr/buffer_hub.h>
-#include <private/dvr/buffer_node.h>
-
-namespace android {
-namespace dvr {
-
-class BufferHubBinderService : public BinderService<BufferHubBinderService>,
- public BnBufferHub {
- public:
- static status_t start(const std::shared_ptr<BufferHubService>& pdx_service);
- // Dumps bufferhub related information to given fd (usually stdout)
- // usage: adb shell dumpsys bufferhubd
- virtual status_t dump(int fd, const Vector<String16>& args) override;
-
- // Marks a BufferNode to be duplicated.
- // TODO(b/116681016): add importToken(int64_t)
- status_t registerToken(const std::weak_ptr<BufferNode> node,
- uint64_t* outToken);
-
- // Binder IPC functions
- sp<IBufferClient> createBuffer(uint32_t width, uint32_t height,
- uint32_t layer_count, uint32_t format,
- uint64_t usage,
- uint64_t user_metadata_size) override;
-
- status_t importBuffer(uint64_t token, sp<IBufferClient>* outClient) override;
-
- private:
- std::shared_ptr<BufferHubService> pdx_service_;
-
- std::vector<sp<BufferClient>> client_list_;
-
- // TODO(b/118180214): use a more secure implementation
- std::mt19937_64 token_engine_;
- // The mapping from token to a specific node. This is a many-to-one mapping.
- // One node could be refered by 0 to multiple tokens.
- std::unordered_map<uint64_t, std::weak_ptr<BufferNode>> token_map_;
-};
-
-} // namespace dvr
-} // namespace android
-
-#endif // ANDROID_DVR_BUFFER_HUB_BINDER_H
diff --git a/services/vr/bufferhubd/tests/Android.bp b/services/vr/bufferhubd/tests/Android.bp
deleted file mode 100644
index a611268..0000000
--- a/services/vr/bufferhubd/tests/Android.bp
+++ /dev/null
@@ -1,26 +0,0 @@
-cc_test {
- name: "buffer_hub_binder_service-test",
- srcs: ["buffer_hub_binder_service-test.cpp"],
- cflags: [
- "-DLOG_TAG=\"buffer_hub_binder_service-test\"",
- "-DTRACE=0",
- "-DATRACE_TAG=ATRACE_TAG_GRAPHICS",
- ],
- header_libs: ["libdvr_headers"],
- static_libs: [
- "libbufferhub",
- "libbufferhubd",
- "libgmock",
- ],
- shared_libs: [
- "libbase",
- "libbinder",
- "liblog",
- "libpdx_default_transport",
- "libui",
- "libutils",
- ],
-
- // TODO(b/117568153): Temporarily opt out using libcrt.
- no_libcrt: true,
-}
diff --git a/services/vr/bufferhubd/tests/buffer_hub_binder_service-test.cpp b/services/vr/bufferhubd/tests/buffer_hub_binder_service-test.cpp
deleted file mode 100644
index 94b422a..0000000
--- a/services/vr/bufferhubd/tests/buffer_hub_binder_service-test.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-#include <binder/IServiceManager.h>
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-#include <private/dvr/IBufferClient.h>
-#include <private/dvr/IBufferHub.h>
-#include <ui/PixelFormat.h>
-
-namespace android {
-namespace dvr {
-
-namespace {
-
-using testing::IsNull;
-using testing::NotNull;
-
-const int kWidth = 640;
-const int kHeight = 480;
-const int kLayerCount = 1;
-const int kFormat = HAL_PIXEL_FORMAT_RGBA_8888;
-const int kUsage = 0;
-const size_t kUserMetadataSize = 0;
-
-class BufferHubBinderServiceTest : public ::testing::Test {
- protected:
- void SetUp() override {
- status_t ret = getService<IBufferHub>(
- String16(IBufferHub::getServiceName()), &service);
- ASSERT_EQ(ret, OK);
- ASSERT_THAT(service, NotNull());
- }
-
- sp<IBufferHub> service;
-};
-
-TEST_F(BufferHubBinderServiceTest, TestCreateBuffer) {
- sp<IBufferClient> bufferClient = service->createBuffer(
- kWidth, kHeight, kLayerCount, kFormat, kUsage, kUserMetadataSize);
- ASSERT_THAT(bufferClient, NotNull());
- EXPECT_TRUE(bufferClient->isValid());
-}
-
-TEST_F(BufferHubBinderServiceTest, TestDuplicateAndImportBuffer) {
- sp<IBufferClient> bufferClient = service->createBuffer(
- kWidth, kHeight, kLayerCount, kFormat, kUsage, kUserMetadataSize);
- ASSERT_THAT(bufferClient, NotNull());
- EXPECT_TRUE(bufferClient->isValid());
-
- uint64_t token1 = 0ULL;
- status_t ret = bufferClient->duplicate(&token1);
- EXPECT_EQ(ret, OK);
-
- // Tokens should be unique even corresponding to the same buffer
- uint64_t token2 = 0ULL;
- ret = bufferClient->duplicate(&token2);
- EXPECT_EQ(ret, OK);
- EXPECT_NE(token2, token1);
-
- sp<IBufferClient> bufferClient1;
- ret = service->importBuffer(token1, &bufferClient1);
- EXPECT_EQ(ret, OK);
- ASSERT_THAT(bufferClient1, NotNull());
- EXPECT_TRUE(bufferClient1->isValid());
-
- // Consumes the token to keep the service clean
- sp<IBufferClient> bufferClient2;
- ret = service->importBuffer(token2, &bufferClient2);
- EXPECT_EQ(ret, OK);
- ASSERT_THAT(bufferClient2, NotNull());
- EXPECT_TRUE(bufferClient2->isValid());
-}
-
-TEST_F(BufferHubBinderServiceTest, TestImportUnexistingToken) {
- // There is very little chance that this test fails if there is a token = 0
- // in the service.
- uint64_t unexistingToken = 0ULL;
- sp<IBufferClient> bufferClient;
- status_t ret = service->importBuffer(unexistingToken, &bufferClient);
- EXPECT_EQ(ret, PERMISSION_DENIED);
- EXPECT_THAT(bufferClient, IsNull());
-}
-
-} // namespace
-
-} // namespace dvr
-} // namespace android
\ No newline at end of file