Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 642519a9 authored by Fan Xu's avatar Fan Xu Committed by Android (Google) Code Review
Browse files

Merge changes from topic "bufferhub_binder"

* changes:
  Temporarily disable detach and promote
  Implement dumpsys for BufferHubBinderService
parents a3ccde8b ddb90db0
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -729,6 +729,9 @@ TEST_F(LibBufferHubTest, TestOrphanedAcquire) {
}

TEST_F(LibBufferHubTest, TestDetachBufferFromProducer) {
  // TODO(b/112338294) rewrite test after migration
  return;

  std::unique_ptr<BufferProducer> p = BufferProducer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  std::unique_ptr<BufferConsumer> c =
@@ -834,6 +837,9 @@ TEST_F(LibBufferHubTest, TestCreateDetachedBuffer) {
}

TEST_F(LibBufferHubTest, TestPromoteDetachedBuffer) {
  // TODO(b/112338294) rewrite test after migration
  return;

  auto b1 = DetachedBuffer::Create(kWidth, kHeight, kLayerCount, kFormat,
                                   kUsage, kUserMetadataSize);
  int b1_id = b1->id();
@@ -867,6 +873,9 @@ TEST_F(LibBufferHubTest, TestPromoteDetachedBuffer) {
}

TEST_F(LibBufferHubTest, TestDetachThenPromote) {
  // TODO(b/112338294) rewrite test after migration
  return;

  std::unique_ptr<BufferProducer> p1 = BufferProducer::Create(
      kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
  ASSERT_TRUE(p1.get() != nullptr);
@@ -942,6 +951,9 @@ TEST_F(LibBufferHubTest, TestDuplicateDetachedBuffer) {
  EXPECT_TRUE(IsBufferGained(b1->buffer_state()));
  EXPECT_TRUE(IsBufferGained(b2->buffer_state()));

  // TODO(b/112338294) rewrite test after migration
  return;

  // Promote the detached buffer should fail as b1 is no longer the exclusive
  // owner of the buffer..
  status_or_handle = b1->Promote();
+4 −0
Original line number Diff line number Diff line
@@ -155,6 +155,10 @@ int DetachedBuffer::Poll(int timeout_ms) {
}

Status<LocalChannelHandle> DetachedBuffer::Promote() {
  // TODO(b/112338294) remove after migrate producer buffer to binder
  ALOGW("DetachedBuffer::Promote: not supported operation during migration");
  return {};

  ATRACE_NAME("DetachedBuffer::Promote");
  ALOGD_IF(TRACE, "DetachedBuffer::Promote: id=%d.", id_);

+4 −0
Original line number Diff line number Diff line
@@ -222,6 +222,10 @@ std::unique_ptr<ProducerBuffer> ProducerBuffer::Import(
}

Status<LocalChannelHandle> ProducerBuffer::Detach() {
  // TODO(b/112338294) remove after migrate producer buffer to binder
  ALOGW("ProducerBuffer::Detach: not supported operation during migration");
  return {};

  uint64_t buffer_state = buffer_state_->load();
  if (!BufferHubDefs::IsBufferGained(buffer_state)) {
    // Can only detach a ProducerBuffer when it's in gained state.
+39 −10
Original line number Diff line number Diff line
#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>

namespace android {
namespace dvr {

status_t BufferHubBinderService::start() {
  ProcessState::self()->startThreadPool();
status_t BufferHubBinderService::start(
    const std::shared_ptr<BufferHubService>& pdx_service) {
  IPCThreadState::self()->disableBackgroundScheduling(true);
  status_t result = BinderService<BufferHubBinderService>::publish();
  if (result != OK) {

  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 != NO_ERROR) {
    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 */) {
  // TODO(b/115435506): not implemented yet
status_t BufferHubBinderService::dump(int fd, const Vector<String16>& args) {
  FILE* out = fdopen(dup(fd), "w");

  fprintf(out, "BufferHubBinderService::dump(): Not Implemented.\n");
  // 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");
  }

  // TODO(b/116526156): output real data in this class once we have it
  if (pdx_service_) {
    // 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 NO_ERROR;
}


}  // namespace dvr
}  // namespace android
+8 −7
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@

int main(int, char**) {
  int ret = -1;
  std::shared_ptr<android::pdx::Service> service;
  std::shared_ptr<android::dvr::BufferHubService> pdx_service;
  std::unique_ptr<android::pdx::ServiceDispatcher> dispatcher;

  // We need to be able to create endpoints with full perms.
@@ -33,15 +33,16 @@ int main(int, char**) {
  else
    ALOGI("New nofile limit is %llu/%llu.", rlim.rlim_cur, rlim.rlim_max);

  CHECK_ERROR(android::dvr::BufferHubBinderService::start() != android::OK,
              error, "Failed to create bufferhub binder service\n");

  dispatcher = android::pdx::ServiceDispatcher::Create();
  CHECK_ERROR(!dispatcher, error, "Failed to create service dispatcher\n");

  service = android::dvr::BufferHubService::Create();
  CHECK_ERROR(!service, error, "Failed to create bufferhubd service\n");
  dispatcher->AddService(service);
  pdx_service = android::dvr::BufferHubService::Create();
  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::NO_ERROR, error,
              "Failed to create bufferhub binder service\n");

  ret = dvrSetSchedulerClass(0, "graphics");
  CHECK_ERROR(ret < 0, error, "Failed to set thread priority");
Loading