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

Commit 68f77ecb authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge changes Ibb49d336,Icea5097c,Ibc6530d2,I5c8edb33 into main

* changes:
  system/gd/storage: Migrate to libbluetooth_log
  system/gd/security: Migrate to libbluetooth_log
  system/gd/l2cap: Migrate to libbluetooth_log
  system/gd/hal: Migrate to libbluetooth_log
parents 507340c1 80f8370e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -893,6 +893,7 @@ cc_test {
        "LeAudioSetConfigSchemas_h",
    ],
    shared_libs: [
        "libbase",
        "libcrypto",
        "libhidlbase",
        "liblog", // __android_log_print
+4 −0
Original line number Diff line number Diff line
@@ -609,6 +609,7 @@ cc_defaults {
        "libcrypto",
        "libgrpc++",
        "libgrpc_wrap",
        "liblog",
        "server_configurable_flags",
    ],
    cflags: [
@@ -680,9 +681,12 @@ cc_benchmark {
        "benchmark.cc",
    ],
    static_libs: [
        "libbase",
        "libbluetooth_gd",
        "libbluetooth_log",
        "libbt_shim_bridge",
        "libchrome",
        "liblog",
    ],
}

+31 −20
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <android/hardware/bluetooth/1.0/types.h>
#include <android/hardware/bluetooth/1.1/IBluetoothHci.h>
#include <android/hardware/bluetooth/1.1/IBluetoothHciCallbacks.h>
#include <bluetooth/log.h>
#include <stdlib.h>

// AIDL uses syslog.h, so these defines conflict with os/log.h
@@ -55,6 +56,12 @@ using AidlStatus = ::aidl::android::hardware::bluetooth::Status;
using IBluetoothHci_1_0 = ::android::hardware::bluetooth::V1_0::IBluetoothHci;
using bluetooth::common::BindOnce;

namespace fmt {
template <>
struct formatter<android::hardware::bluetooth::V1_0::Status>
    : enum_formatter<android::hardware::bluetooth::V1_0::Status> {};
}  // namespace fmt

namespace bluetooth {
namespace hal {
namespace {
@@ -62,11 +69,11 @@ namespace {
class HciDeathRecipient : public ::android::hardware::hidl_death_recipient {
 public:
  virtual void serviceDied(uint64_t /*cookie*/, const android::wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
    LOG_ERROR("The Bluetooth HAL service died. Dumping logs and crashing in 1 second.");
    log::error("The Bluetooth HAL service died. Dumping logs and crashing in 1 second.");
    common::StopWatch::DumpStopWatchLog();
    // At shutdown, sometimes the HAL service gets killed before Bluetooth.
    std::this_thread::sleep_for(std::chrono::seconds(1));
    LOG_ALWAYS_FATAL("The Bluetooth HAL died.");
    log::fatal("The Bluetooth HAL died.");
  }
};

@@ -96,7 +103,7 @@ class InternalHciCallbacks : public IBluetoothHciCallbacks_1_1 {

  void ResetCallback() {
    std::lock_guard<std::mutex> incoming_packet_callback_lock(incoming_packet_callback_mutex_);
    LOG_INFO("callbacks have been reset!");
    log::info("callbacks have been reset!");
    callback_ = nullptr;
  }

@@ -106,7 +113,7 @@ class InternalHciCallbacks : public IBluetoothHciCallbacks_1_1 {

  Return<void> initializationComplete(HidlStatus status) {
    common::StopWatch stop_watch(__func__);
    LOG_INFO("initialization complete with status: %d", status);
    log::info("initialization complete with status: {}", status);
    CHECK_EQ(status, HidlStatus::SUCCESS);
    init_promise_->set_value();
    return Void();
@@ -225,7 +232,7 @@ class AidlHciCallbacks : public ::aidl::android::hardware::bluetooth::BnBluetoot
      }
    }
    if (!sent) {
      LOG_INFO("Dropping HCI Event, since callback_ is null");
      log::info("Dropping HCI Event, since callback_ is null");
    }
    return ::ndk::ScopedAStatus::ok();
  }
@@ -245,7 +252,7 @@ class AidlHciCallbacks : public ::aidl::android::hardware::bluetooth::BnBluetoot
      }
    }
    if (!sent) {
      LOG_INFO("Dropping ACL Data, since callback_ is null");
      log::info("Dropping ACL Data, since callback_ is null");
    }
    return ::ndk::ScopedAStatus::ok();
  }
@@ -264,7 +271,7 @@ class AidlHciCallbacks : public ::aidl::android::hardware::bluetooth::BnBluetoot
      }
    }
    if (!sent) {
      LOG_INFO("Dropping SCO Data, since callback_ is null");
      log::info("Dropping SCO Data, since callback_ is null");
    }
    return ::ndk::ScopedAStatus::ok();
  }
@@ -283,7 +290,7 @@ class AidlHciCallbacks : public ::aidl::android::hardware::bluetooth::BnBluetoot
      }
    }
    if (!sent) {
      LOG_INFO("Dropping ISO Data, since callback_ is null");
      log::info("Dropping ISO Data, since callback_ is null");
    }
    return ::ndk::ScopedAStatus::ok();
  }
@@ -350,7 +357,7 @@ class HciHalHidl : public HciHal {

  void sendIsoData(HciPacket packet) override {
    if (aidl_hci_ == nullptr && bt_hci_1_1_ == nullptr) {
      LOG_ERROR("ISO is not supported in HAL v1.0");
      log::error("ISO is not supported in HAL v1.0");
      return;
    }

@@ -393,14 +400,14 @@ class HciHalHidl : public HciHal {
    ::ndk::SpAIBinder binder(AServiceManager_waitForService(kBluetoothAidlHalServiceName));
    aidl_hci_ = IBluetoothHci::fromBinder(binder);
    if (aidl_hci_ != nullptr) {
      LOG_INFO("Using the AIDL interface");
      log::info("Using the AIDL interface");
      aidl_death_recipient_ =
          ::ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new([](void* /* cookie*/) {
            LOG_ERROR("The Bluetooth HAL service died. Dumping logs and crashing in 1 second.");
            log::error("The Bluetooth HAL service died. Dumping logs and crashing in 1 second.");
            common::StopWatch::DumpStopWatchLog();
            // At shutdown, sometimes the HAL service gets killed before Bluetooth.
            std::this_thread::sleep_for(std::chrono::seconds(1));
            LOG_ALWAYS_FATAL("The Bluetooth HAL died.");
            log::fatal("The Bluetooth HAL died.");
          }));

      auto death_link =
@@ -418,7 +425,7 @@ class HciHalHidl : public HciHal {
  void start_hidl() {
    common::StopWatch stop_watch(__func__);

    LOG_INFO("Trying to find a HIDL interface");
    log::info("Trying to find a HIDL interface");

    auto get_service_alarm = new os::Alarm(GetHandler());
    get_service_alarm->Schedule(
@@ -428,11 +435,15 @@ class HciHalHidl : public HciHal {
          auto board_name = os::GetSystemProperty(kBoardProperty);
          bool emulator = board_name.has_value() && board_name.value() == kCuttlefishBoard;
          if (emulator) {
            LOG_ERROR("board_name: %s", board_name.value().c_str());
            LOG_ERROR("Unable to get a Bluetooth service after 500ms, start the HAL before starting Bluetooth");
            log::error("board_name: {}", board_name.value());
            log::error(
                "Unable to get a Bluetooth service after 500ms, start the HAL before starting "
                "Bluetooth");
            return;
          }
          LOG_ALWAYS_FATAL("Unable to get a Bluetooth service after 500ms, start the HAL before starting Bluetooth");
          log::fatal(
              "Unable to get a Bluetooth service after 500ms, start the HAL before starting "
              "Bluetooth");
        }),
        std::chrono::milliseconds(500));

@@ -477,11 +488,11 @@ class HciHalHidl : public HciHal {
    ASSERT(bt_hci_ != nullptr);
    auto death_unlink = bt_hci_->unlinkToDeath(hci_death_recipient_);
    if (!death_unlink.isOk()) {
      LOG_ERROR("Error unlinking death recipient from the Bluetooth HAL");
      log::error("Error unlinking death recipient from the Bluetooth HAL");
    }
    auto close_status = bt_hci_->close();
    if (!close_status.isOk()) {
      LOG_ERROR("Error calling close on the Bluetooth HAL");
      log::error("Error calling close on the Bluetooth HAL");
    }
    bt_hci_ = nullptr;
    bt_hci_1_1_ = nullptr;
@@ -493,11 +504,11 @@ class HciHalHidl : public HciHal {
    auto death_unlink =
        AIBinder_unlinkToDeath(aidl_hci_->asBinder().get(), aidl_death_recipient_.get(), this);
    if (death_unlink != STATUS_OK) {
      LOG_ERROR("Error unlinking death recipient from the Bluetooth HAL");
      log::error("Error unlinking death recipient from the Bluetooth HAL");
    }
    auto close_status = aidl_hci_->close();
    if (!close_status.isOk()) {
      LOG_ERROR("Error calling close on the Bluetooth HAL");
      log::error("Error calling close on the Bluetooth HAL");
    }
    aidl_hci_ = nullptr;
    aidl_callbacks_->ResetCallback();
+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#pragma once

#include <bluetooth/log.h>

#include <future>
#include <list>
#include <optional>
@@ -34,7 +36,7 @@ class TestHciHal : public hal::HciHal {

  ~TestHciHal() {
    if (callbacks != nullptr) {
      LOG_ALWAYS_FATAL("unregisterIncomingPacketCallback() must be called");
      log::fatal("unregisterIncomingPacketCallback() must be called");
    }
  }

+30 −28
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include "hal/hci_hal_host.h"

#include <bluetooth/log.h>
#include <netdb.h>
#include <netinet/in.h>
#include <poll.h>
@@ -96,7 +97,7 @@ int waitHciDev(int hci_interface) {

  fd = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
  if (fd < 0) {
    LOG_ERROR("Bluetooth socket error: %s", strerror(errno));
    bluetooth::log::error("Bluetooth socket error: {}", strerror(errno));
    return -1;
  }
  memset(&addr, 0, sizeof(addr));
@@ -106,7 +107,7 @@ int waitHciDev(int hci_interface) {

  ret = bind(fd, (struct sockaddr*)&addr, sizeof(addr));
  if (ret < 0) {
    LOG_ERROR("HCI Channel Control: %d %s", errno, strerror(errno));
    bluetooth::log::error("HCI Channel Control: {} {}", errno, strerror(errno));
    close(fd);
    return -1;
  }
@@ -122,7 +123,7 @@ int waitHciDev(int hci_interface) {
  ssize_t wrote;
  REPEAT_ON_INTR(wrote = write(fd, &ev, 6));
  if (wrote != 6) {
    LOG_ERROR("Unable to write mgmt command: %s", strerror(errno));
    bluetooth::log::error("Unable to write mgmt command: {}", strerror(errno));
    close(fd);
    return -1;
  }
@@ -131,17 +132,17 @@ int waitHciDev(int hci_interface) {
    int n;
    REPEAT_ON_INTR(n = poll(fds, 1, -1));
    if (n == -1) {
      LOG_ERROR("Poll error: %s", strerror(errno));
      bluetooth::log::error("Poll error: {}", strerror(errno));
      break;
    } else if (n == 0) {
      LOG_ERROR("Timeout, no HCI device detected");
      bluetooth::log::error("Timeout, no HCI device detected");
      break;
    }

    if (fds[0].revents & POLLIN) {
      REPEAT_ON_INTR(n = read(fd, &ev, sizeof(struct mgmt_pkt)));
      if (n < 0) {
        LOG_ERROR("Error reading control channel: %s", strerror(errno));
        bluetooth::log::error("Error reading control channel: {}", strerror(errno));
        break;
      }

@@ -165,10 +166,11 @@ int waitHciDev(int hci_interface) {
          }

          // Chipset might be lost. Wait for index added event.
          LOG_ERROR("HCI interface(%d) not found in the MGMT lndex list", hci_interface);
          bluetooth::log::error(
              "HCI interface({}) not found in the MGMT lndex list", hci_interface);
        } else {
          // Unlikely event (probably developer error or driver shut down).
          LOG_ERROR("Failed to read index list: status(%d)", cc->status);
          bluetooth::log::error("Failed to read index list: status({})", cc->status);
        }

        // Close and return result of Index List.
@@ -188,7 +190,7 @@ int ConnectToSocket() {

  int socket_fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
  if (socket_fd < 0) {
    LOG_ERROR("can't create socket: %s", strerror(errno));
    bluetooth::log::error("can't create socket: {}", strerror(errno));
    return INVALID_FD;
  }

@@ -208,11 +210,11 @@ int ConnectToSocket() {

  ret = bind(socket_fd, (struct sockaddr*)&addr, sizeof(addr));
  if (ret < 0) {
    LOG_ERROR("HCI Channel Control: %d %s", errno, strerror(errno));
    bluetooth::log::error("HCI Channel Control: {} {}", errno, strerror(errno));
    ::close(socket_fd);
    return INVALID_FD;
  }
  LOG_INFO("HCI device ready");
  bluetooth::log::info("HCI device ready");
  return socket_fd;
}
}
@@ -224,23 +226,23 @@ class HciHalHost : public HciHal {
 public:
  void registerIncomingPacketCallback(HciHalCallbacks* callback) override {
    std::lock_guard<std::mutex> lock(api_mutex_);
    LOG_INFO("%s before", __func__);
    log::info("before");
    {
      std::lock_guard<std::mutex> incoming_packet_callback_lock(incoming_packet_callback_mutex_);
      ASSERT(incoming_packet_callback_ == nullptr && callback != nullptr);
      incoming_packet_callback_ = callback;
    }
    LOG_INFO("%s after", __func__);
    log::info("after");
  }

  void unregisterIncomingPacketCallback() override {
    std::lock_guard<std::mutex> lock(api_mutex_);
    LOG_INFO("%s before", __func__);
    log::info("before");
    {
      std::lock_guard<std::mutex> incoming_packet_callback_lock(incoming_packet_callback_mutex_);
      incoming_packet_callback_ = nullptr;
    }
    LOG_INFO("%s after", __func__);
    log::info("after");
  }

  void sendHciCommand(HciPacket command) override {
@@ -297,7 +299,7 @@ class HciHalHost : public HciHal {

    // We don't want to crash when the chipset is broken.
    if (sock_fd_ == INVALID_FD) {
      LOG_ERROR("Failed to connect to HCI socket. Aborting HAL initialization process.");
      log::error("Failed to connect to HCI socket. Aborting HAL initialization process.");
      raise(SIGINT);
      return;
    }
@@ -309,18 +311,18 @@ class HciHalHost : public HciHal {
    hci_incoming_thread_.GetReactor()->ModifyRegistration(reactable_, os::Reactor::REACT_ON_READ_ONLY);
    link_clocker_ = GetDependency<LinkClocker>();
    btsnoop_logger_ = GetDependency<SnoopLogger>();
    LOG_INFO("HAL opened successfully");
    log::info("HAL opened successfully");
  }

  void Stop() override {
    std::lock_guard<std::mutex> lock(api_mutex_);
    LOG_INFO("HAL is closing");
    log::info("HAL is closing");
    if (reactable_ != nullptr) {
      hci_incoming_thread_.GetReactor()->Unregister(reactable_);
      LOG_INFO("HAL is stopping, start waiting for last callback");
      log::info("HAL is stopping, start waiting for last callback");
      // Wait up to 1 second for the last incoming packet callback to finish
      hci_incoming_thread_.GetReactor()->WaitForUnregisteredReactable(std::chrono::milliseconds(1000));
      LOG_INFO("HAL is stopping, finished waiting for last callback");
      log::info("HAL is stopping, finished waiting for last callback");
      ASSERT(sock_fd_ != INVALID_FD);
    }
    reactable_ = nullptr;
@@ -330,7 +332,7 @@ class HciHalHost : public HciHal {
    }
    ::close(sock_fd_);
    sock_fd_ = INVALID_FD;
    LOG_INFO("HAL is closed");
    log::info("HAL is closed");
  }

  std::string ToString() const override {
@@ -376,7 +378,7 @@ class HciHalHost : public HciHal {
    {
      std::lock_guard<std::mutex> incoming_packet_callback_lock(incoming_packet_callback_mutex_);
      if (incoming_packet_callback_ == nullptr) {
        LOG_INFO("Dropping a packet");
        log::info("Dropping a packet");
        return;
      }
    }
@@ -387,14 +389,14 @@ class HciHalHost : public HciHal {

    // we don't want crash when the chipset is broken.
    if (received_size == -1) {
      LOG_ERROR("Can't receive from socket: %s", strerror(errno));
      log::error("Can't receive from socket: {}", strerror(errno));
      close(sock_fd_);
      raise(SIGINT);
      return;
    }

    if (received_size == 0) {
      LOG_WARN("Can't read H4 header. EOF received");
      log::warn("Can't read H4 header. EOF received");
      // First close sock fd before raising sigint
      close(sock_fd_);
      raise(SIGINT);
@@ -419,7 +421,7 @@ class HciHalHost : public HciHal {
      {
        std::lock_guard<std::mutex> incoming_packet_callback_lock(incoming_packet_callback_mutex_);
        if (incoming_packet_callback_ == nullptr) {
          LOG_INFO("Dropping an event after processing");
          log::info("Dropping an event after processing");
          return;
        }
        incoming_packet_callback_->hciEventReceived(receivedHciPacket);
@@ -445,7 +447,7 @@ class HciHalHost : public HciHal {
      {
        std::lock_guard<std::mutex> incoming_packet_callback_lock(incoming_packet_callback_mutex_);
        if (incoming_packet_callback_ == nullptr) {
          LOG_INFO("Dropping an ACL packet after processing");
          log::info("Dropping an ACL packet after processing");
          return;
        }
        incoming_packet_callback_->aclDataReceived(receivedHciPacket);
@@ -469,7 +471,7 @@ class HciHalHost : public HciHal {
      {
        std::lock_guard<std::mutex> incoming_packet_callback_lock(incoming_packet_callback_mutex_);
        if (incoming_packet_callback_ == nullptr) {
          LOG_INFO("Dropping a SCO packet after processing");
          log::info("Dropping a SCO packet after processing");
          return;
        }
        incoming_packet_callback_->scoDataReceived(receivedHciPacket);
@@ -493,7 +495,7 @@ class HciHalHost : public HciHal {
      {
        std::lock_guard<std::mutex> incoming_packet_callback_lock(incoming_packet_callback_mutex_);
        if (incoming_packet_callback_ == nullptr) {
          LOG_INFO("Dropping a ISO packet after processing");
          log::info("Dropping a ISO packet after processing");
          return;
        }
        incoming_packet_callback_->isoDataReceived(receivedHciPacket);
Loading