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

Commit e234dced authored by Henri Chataing's avatar Henri Chataing
Browse files

system: Implement formatters for bluetooth::hci::(Address|AddressWithType)

The default formatter implementation will display redacted addresses,
as if ADDRESS_TO_LOGGABLE_STR were used on the address log parameters.

Test: m com.android.btservices
Bug: 305066880
Flag: EXEMPT, log change
Change-Id: I52fdf98bfc875b499ce936148c82d4b421f98716
parent 04864c39
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <string>

#include "common/interfaces/ILoggable.h"
#include "os/logging/log_adapter.h"
#include "packet/custom_field_fixed_size_interface.h"
#include "storage/serializable.h"

@@ -127,3 +128,21 @@ struct hash<bluetooth::hci::Address> {
  }
};
}  // namespace std

#if __has_include(<bluetooth/log.h>)
#include <bluetooth/log.h>

namespace fmt {
template <>
struct formatter<bluetooth::hci::Address> : formatter<std::string> {
  template <class Context>
  typename Context::iterator format(const bluetooth::hci::Address& address, Context& ctx) const {
    std::string repr = bluetooth::os::should_log_be_redacted()
                           ? address.ToRedactedStringForLogging()
                           : address.ToStringForLogging();
    return fmt::formatter<std::string>::format(repr, ctx);
  }
};
}  // namespace fmt

#endif  // __has_include(<bluetooth/log.h>
+20 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "hci/address.h"
#include "hci/hci_packets.h"
#include "hci/octets.h"
#include "os/logging/log_adapter.h"

namespace bluetooth {
namespace hci {
@@ -156,3 +157,22 @@ struct hash<bluetooth::hci::AddressWithType> {
  }
};
}  // namespace std

#if __has_include(<bluetooth/log.h>)
#include <bluetooth/log.h>

namespace fmt {
template <>
struct formatter<bluetooth::hci::AddressWithType> : formatter<std::string> {
  template <class Context>
  typename Context::iterator format(
      const bluetooth::hci::AddressWithType& address, Context& ctx) const {
    std::string repr = bluetooth::os::should_log_be_redacted()
                           ? address.ToRedactedStringForLogging()
                           : address.ToStringForLogging();
    return fmt::formatter<std::string>::format(repr, ctx);
  }
};
}  // namespace fmt

#endif  // __has_include(<bluetooth/log.h>
+14 −0
Original line number Diff line number Diff line
@@ -117,6 +117,20 @@ struct hash<ConnectAddressWithType> {
};
}  // namespace std

namespace fmt {
template <>
struct formatter<ConnectAddressWithType> : formatter<std::string> {
  template <class Context>
  typename Context::iterator format(const ConnectAddressWithType& address,
                                    Context& ctx) const {
    std::string repr = bluetooth::os::should_log_be_redacted()
                           ? address.ToRedactedStringForLogging()
                           : address.ToStringForLogging();
    return fmt::formatter<std::string>::format(repr, ctx);
  }
};
}  // namespace fmt

namespace {

constexpr uint32_t kRunicBjarkan = 0x0016D2;
+20 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <string>

#include "common/interfaces/ILoggable.h"
#include "os/logging/log_adapter.h"
#include "packet/custom_field_fixed_size_interface.h"
#include "storage/serializable.h"

@@ -110,3 +111,22 @@ struct hash<bluetooth::hci::Address> {
  }
};
}  // namespace std

#if __has_include(<bluetooth/log.h>)
#include <bluetooth/log.h>

namespace fmt {
template <>
struct formatter<bluetooth::hci::Address> : formatter<std::string> {
  template <class Context>
  typename Context::iterator format(const bluetooth::hci::Address& address,
                                    Context& ctx) const {
    std::string repr = bluetooth::os::should_log_be_redacted()
                           ? address.ToRedactedStringForLogging()
                           : address.ToStringForLogging();
    return fmt::formatter<std::string>::format(repr, ctx);
  }
};
}  // namespace fmt

#endif  // __has_include(<bluetooth/log.h>)
+34 −0
Original line number Diff line number Diff line
@@ -187,4 +187,38 @@ struct tAclLinkSpec {
  }
};

#if __has_include(<bluetooth/log.h>)
#include <bluetooth/log.h>

namespace bluetooth::os {
bool should_log_be_redacted();
}  // namespace bluetooth::os

namespace fmt {
template <>
struct formatter<tBLE_BD_ADDR> : formatter<std::string> {
  template <class Context>
  typename Context::iterator format(const tBLE_BD_ADDR& address,
                                    Context& ctx) const {
    std::string repr = bluetooth::os::should_log_be_redacted()
                           ? address.ToRedactedStringForLogging()
                           : address.ToStringForLogging();
    return fmt::formatter<std::string>::format(repr, ctx);
  }
};
template <>
struct formatter<tAclLinkSpec> : formatter<std::string> {
  template <class Context>
  typename Context::iterator format(const tAclLinkSpec& address,
                                    Context& ctx) const {
    std::string repr = bluetooth::os::should_log_be_redacted()
                           ? address.ToRedactedStringForLogging()
                           : address.ToStringForLogging();
    return fmt::formatter<std::string>::format(repr, ctx);
  }
};
}  // namespace fmt

#endif  // __has_include(<bluetooth/log.h>

#endif
Loading