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

Commit 5c97aa1a authored by Fan Xu's avatar Fan Xu
Browse files

Implement dumpsys for BufferHubBinderService

Now you can run "adb shell dumpsys bufferhubd" to get information from
the bufferhubd binder service. Information from BufferHubService, which
is the PDX service, will also be dumped. If the PDX service is not
present, a message will indicate that.

Note that currently the binder service has no valuable info to share, so
this command actually only return the PDX service info.

Renaming the variable name in bufferhubd.cpp is for preventing
confusion. As during migrating we will have the binder service and pdx
service at the same time, distinguishing them is necessary while both of
them are called "bufferhubd service".

Adjust some newlines to meet 80-char column limit.

Test: "adb shell dumpsys bufferhubd"
Should out put the same as command
"adb shell pdx_tool --dump /dev/socket/pdx/system/buffer_hub/client"

Change-Id: Ie1386cde39ed973051734e63768216f1345a1945
Fixes: 115435506
parent c212f793
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