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

Commit ed916606 authored by Chris Manton's avatar Chris Manton
Browse files

Initial entry for gd shim dumpsys support

Bug: 147672133
Test: Boot into gd and manually verify dumpsys

Change-Id: Ie588dc0e3a1fd4dfd31abec9f5a21cae87eb0c67
parent 7f40aab9
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@
#include "common/address_obfuscator.h"
#include "common/metrics.h"
#include "device/include/interop.h"
#include "main/shim/dumpsys.h"
#include "main/shim/shim.h"
#include "osi/include/alarm.h"
#include "osi/include/allocation_tracker.h"
@@ -328,10 +329,14 @@ static void dump(int fd, const char** arguments) {
  HearingAid::DebugDump(fd);
  connection_manager::dump(fd);
  bluetooth::bqr::DebugDump(fd);
  if (bluetooth::shim::is_gd_shim_enabled()) {
    bluetooth::shim::Dump(fd);
  } else {
#if (BTSNOOP_MEM == TRUE)
    btif_debug_btsnoop_dump(fd);
#endif
  }
}

static void dumpMetrics(std::string* output) {
  bluetooth::common::BluetoothMetricsLogger::GetInstance()->WriteString(output);
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ filegroup {
            "controller.cc",
            "connectability.cc",
            "discoverability.cc",
            "dumpsys.cc",
            "hci_layer.cc",
            "inquiry.cc",
            "l2cap.cc",
+97 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define LOG_TAG "bt_gd_shim"

#include <algorithm>
#include <functional>
#include <future>
#include <memory>
#include <unordered_map>
#include <utility>

#include "module.h"
#include "os/handler.h"
#include "os/log.h"
#include "shim/dumpsys.h"

namespace bluetooth {
namespace shim {

struct Dumpsys::impl {
 public:
  void Dump(int fd, std::promise<void> promise);
  void Register(const void* token, DumpFunction func);
  void Unregister(const void* token);

  ~impl();

 private:
  std::unordered_map<const void*, DumpFunction> dump_functions_;
};

const ModuleFactory Dumpsys::Factory = ModuleFactory([]() { return new Dumpsys(); });

Dumpsys::impl::~impl() {
  ASSERT(dump_functions_.empty());
}

void Dumpsys::impl::Dump(int fd, std::promise<void> promise) {
  dprintf(fd, "%s Registered submodules:%zd\n", "gd::shim::dumpsys", dump_functions_.size());
  std::for_each(dump_functions_.begin(), dump_functions_.end(),
                [fd](std::pair<const void*, DumpFunction> element) { element.second(fd); });
  promise.set_value();
}

void Dumpsys::impl::Register(const void* token, DumpFunction func) {
  ASSERT(dump_functions_.find(token) == dump_functions_.end());
  dump_functions_[token] = func;
}

void Dumpsys::impl::Unregister(const void* token) {
  ASSERT(dump_functions_.find(token) != dump_functions_.end());
  dump_functions_.erase(token);
}

void Dumpsys::Dump(int fd) {
  std::promise<void> promise;
  auto future = promise.get_future();
  GetHandler()->Post(common::BindOnce(&Dumpsys::impl::Dump, common::Unretained(pimpl_.get()), fd, std::move(promise)));
  future.get();
}

void Dumpsys::Register(const void* token, DumpFunction func) {
  GetHandler()->Post(common::BindOnce(&Dumpsys::impl::Register, common::Unretained(pimpl_.get()), token, func));
}

void Dumpsys::Unregister(const void* token) {
  GetHandler()->Post(common::BindOnce(&Dumpsys::impl::Unregister, common::Unretained(pimpl_.get()), token));
}

/**
 * Module methods
 */
void Dumpsys::ListDependencies(ModuleList* list) {}

void Dumpsys::Start() {
  pimpl_ = std::make_unique<impl>();
}

void Dumpsys::Stop() {
  pimpl_.reset();
}

}  // namespace shim
}  // namespace bluetooth
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include <memory>

#include "module.h"
#include "shim/idumpsys.h"

namespace bluetooth {
namespace shim {

class Dumpsys : public bluetooth::Module, public bluetooth::shim::IDumpsys {
 public:
  void Dump(int fd) override;
  void Register(const void* token, DumpFunction func);
  void Unregister(const void* token);

  Dumpsys() = default;
  ~Dumpsys() = default;

  static const ModuleFactory Factory;

 protected:
  void ListDependencies(ModuleList* list) override;  // Module
  void Start() override;                             // Module
  void Stop() override;                              // Module

 private:
  struct impl;
  std::unique_ptr<impl> pimpl_;
  DISALLOW_COPY_AND_ASSIGN(Dumpsys);
};

}  // namespace shim
}  // namespace bluetooth
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include <cstdint>
#include <functional>
#include <string>

/**
 * The gd API exported to the legacy api
 */
namespace bluetooth {
namespace shim {

using DumpFunction = std::function<void(int fd)>;

struct IDumpsys {
  virtual void Dump(int fd) = 0;

  virtual ~IDumpsys() {}
};

}  // namespace shim
}  // namespace bluetooth
Loading