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

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

Merge "Implement dumpsys for BufferHubBinderService"

parents ed7eb36c 5c97aa1a
Loading
Loading
Loading
Loading
+38 −8
Original line number Diff line number Diff line
#include <stdio.h>

#include <binder/IServiceManager.h>
#include <binder/IPCThreadState.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();
  process_self->giveThreadPoolName();
  IPCThreadState::self()->joinThreadPool();

  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;
+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");
+6 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#define ANDROID_DVR_BUFFER_HUB_BINDER_H

#include <binder/BinderService.h>
#include <private/dvr/buffer_hub.h>

#include "android/dvr/BnBufferHub.h"

@@ -10,11 +11,14 @@ namespace dvr {

class BufferHubBinderService : public BinderService<BufferHubBinderService>, public BnBufferHub {
 public:
  static status_t start();
  static status_t start(const std::shared_ptr<BufferHubService> &pdx_service);
  static const char* getServiceName() { return "bufferhubd"; }
  // Dump bufferhub related information to given fd (usually stdout)
  // usage: adb shell dumpsys bufferhubd
  virtual status_t dump(int fd, const Vector<String16> &args) override;

 private:
  std::shared_ptr<BufferHubService> pdx_service_;
};

}  // namespace dvr
+8 −1
Original line number Diff line number Diff line
@@ -6,11 +6,18 @@ cc_test {
        "-DTRACE=0",
        "-DATRACE_TAG=ATRACE_TAG_GRAPHICS",
    ],
    static_libs: ["libbufferhubd"],
    header_libs: ["libdvr_headers"],
    static_libs: [
        "libbufferhub",
        "libbufferhubd",
        "libgmock",
    ],
    shared_libs: [
        "libbase",
        "libbinder",
        "liblog",
        "libpdx_default_transport",
        "libui",
        "libutils",
    ],
}
 No newline at end of file
+9 −4
Original line number Diff line number Diff line
#include <private/dvr/buffer_hub_binder.h>

#include <binder/IServiceManager.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <private/dvr/buffer_hub_binder.h>

namespace android {
namespace dvr {
@@ -12,8 +13,12 @@ class BufferHubBinderServiceTest : public ::testing::Test {
};

TEST_F(BufferHubBinderServiceTest, TestInitialize) {
  // Test if start binder server returns OK
  EXPECT_EQ(BufferHubBinderService::start(), OK);
  // Create a new service will kill the current one.
  // So just check if Binder service is running
  sp<IServiceManager> sm = defaultServiceManager();
  sp<IBinder> service = sm->checkService(
      String16(BufferHubBinderService::getServiceName()));
  EXPECT_THAT(service, ::testing::Ne(nullptr));
}

}  // namespace