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

Commit 20efe360 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

groups: Add debug dump

Adds the following info to the dumpsys logs:

Device Groups Manager:
  Num. registered clients: 2
  Groups:
    == Group id: 1 ==
      Uuid: 0000ffff-0000-1000-8000-00805f9b34fb
      Devices:
        XX:XX:XX:XX:XX:XX
        YY:YY:YY:YY:YY:YY
    == Group id: 2 ==
      Uuid: ...
      ...

Bug: 150670922
Tag: #feature
Test: atest --host bluetooth_groups_test
Sponsor: jpawlowski@
Change-Id: Ie3306462ec15f39123647324a3fb0b90e7686ec7
parent 6f15687d
Loading
Loading
Loading
Loading
+34 −0
Original line number Original line Diff line number Diff line
@@ -57,6 +57,8 @@ class DeviceGroup {
  const Uuid& GetUuid(void) const { return group_uuid_; }
  const Uuid& GetUuid(void) const { return group_uuid_; }


 private:
 private:
  friend std::ostream& operator<<(std::ostream& out,
                                  const bluetooth::groups::DeviceGroup& value);
  int group_id_;
  int group_id_;
  Uuid group_uuid_;
  Uuid group_uuid_;
  std::unordered_set<RawAddress> devices_;
  std::unordered_set<RawAddress> devices_;
@@ -261,6 +263,18 @@ class DeviceGroupsImpl : public DeviceGroups {
    return true;
    return true;
  }
  }


  void Dump(int fd) {
    std::stringstream stream;

    stream << "  Num. registered clients: " << callbacks_.size() << std::endl;
    stream << "  Groups:\n";
    for (const auto& kv_pair : groups_) {
      stream << kv_pair.second << std::endl;
    }

    dprintf(fd, "%s", stream.str().c_str());
  }

 private:
 private:
  DeviceGroup* find_device_group(int group_id) {
  DeviceGroup* find_device_group(int group_id) {
    return groups_.count(group_id) ? &groups_.at(group_id) : nullptr;
    return groups_.count(group_id) ? &groups_.at(group_id) : nullptr;
@@ -350,6 +364,26 @@ void DeviceGroups::CleanUp(DeviceGroupsCallbacks* callbacks) {
    instance = nullptr;
    instance = nullptr;
  }
  }
}
}

std::ostream& operator<<(std::ostream& out,
                         bluetooth::groups::DeviceGroup const& group) {
  out << "    == Group id: " << group.group_id_ << " == \n"
      << "      Uuid: " << group.group_uuid_ << std::endl;
  out << "      Devices:\n";
  for (auto const& addr : group.devices_) {
    out << "        " << addr << std::endl;
  }
  return out;
}

void DeviceGroups::DebugDump(int fd) {
  dprintf(fd, "Device Groups Manager:\n");
  if (instance)
    instance->Dump(fd);
  else
    dprintf(fd, "  Not initialized \n");
}

DeviceGroups* DeviceGroups::Get() { return instance; }
DeviceGroups* DeviceGroups::Get() { return instance; }


}  // namespace groups
}  // namespace groups
+1 −0
Original line number Original line Diff line number Diff line
@@ -65,6 +65,7 @@ class DeviceGroups {
  static bool GetForStorage(const RawAddress& addr, std::vector<uint8_t>& out);
  static bool GetForStorage(const RawAddress& addr, std::vector<uint8_t>& out);
  static void CleanUp(DeviceGroupsCallbacks* callbacks);
  static void CleanUp(DeviceGroupsCallbacks* callbacks);
  static DeviceGroups* Get();
  static DeviceGroups* Get();
  static void DebugDump(int fd);
  /** To add to the existing group, group_id needs to be provided.
  /** To add to the existing group, group_id needs to be provided.
   *  Otherwise a new group for the given context uuid will be created.
   *  Otherwise a new group for the given context uuid will be created.
   */
   */
+2 −0
Original line number Original line Diff line number Diff line
@@ -2927,6 +2927,8 @@ void LeAudioClient::Initialize(
}
}


void LeAudioClient::DebugDump(int fd) {
void LeAudioClient::DebugDump(int fd) {
  DeviceGroups::DebugDump(fd);

  dprintf(fd, "LeAudio Manager: \n");
  dprintf(fd, "LeAudio Manager: \n");
  if (instance)
  if (instance)
    instance->Dump(fd);
    instance->Dump(fd);
+2 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,8 @@ void bluetooth::groups::DeviceGroups::Initialize(
  mock_groups->Initialize(callbacks);
  mock_groups->Initialize(callbacks);
};
};


void bluetooth::groups::DeviceGroups::DebugDump(int) {}

void bluetooth::groups::DeviceGroups::CleanUp(
void bluetooth::groups::DeviceGroups::CleanUp(
    bluetooth::groups::DeviceGroupsCallbacks* callbacks) {
    bluetooth::groups::DeviceGroupsCallbacks* callbacks) {
  LOG_ASSERT(mock_groups) << "Mock Device Groups not set!";
  LOG_ASSERT(mock_groups) << "Mock Device Groups not set!";