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

Commit 44c1d2d7 authored by Zach Johnson's avatar Zach Johnson Committed by Hansong Zhang
Browse files

Remove redundant Bluetooth from internal class names

Test: atest --host bluetooth_test_gd and ./cert/run_cert.sh
Change-Id: I55b2c1ecc1ec254a197d6fde70968a9aa8c06c00
parent 704cc88c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
filegroup {
    name: "BluetoothHalSources",
    srcs: [
        "bluetooth_snoop_logger.cc",
        "snoop_logger.cc",
    ],
}

+5 −5
Original line number Diff line number Diff line
@@ -37,9 +37,9 @@ namespace facade {

class HciTransportationService
    : public HciTransportation::Service,
      public ::bluetooth::hal::BluetoothHciHalCallbacks {
      public ::bluetooth::hal::HciHalCallbacks {
 public:
  HciTransportationService(BluetoothHciHal* hal) : hal_(hal) {
  HciTransportationService(HciHal* hal) : hal_(hal) {
  }

  ::grpc::Status SetLoopbackMode(::grpc::ServerContext* context,
@@ -88,17 +88,17 @@ class HciTransportationService
    // TODO
  }
 private:
  BluetoothHciHal* hal_;
  HciHal* hal_;
};

void HalFacadeModule::ListDependencies(ModuleList* list) {
  ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list);
  list->add<BluetoothHciHal>();
  list->add<HciHal>();
}

void HalFacadeModule::Start(const ModuleRegistry* registry) {
  ::bluetooth::grpc::GrpcFacadeModule::Start(registry);
  auto hal = registry->GetInstance<BluetoothHciHal>();
  auto hal = registry->GetInstance<HciHal>();

  service_ = new HciTransportationService(hal);
  hal->registerIncomingPacketCallback(service_);
+5 −5
Original line number Diff line number Diff line
@@ -31,9 +31,9 @@ enum class Status : int32_t { SUCCESS, TRANSPORT_ERROR, INITIALIZATION_ERROR, UN
// callback to BluetoothInitializationCompleteCallback

// The interface from the Bluetooth Controller to the stack
class BluetoothHciHalCallbacks {
class HciHalCallbacks {
 public:
  virtual ~BluetoothHciHalCallbacks() = default;
  virtual ~HciHalCallbacks() = default;

  // This function is invoked when an HCI event is received from the
  // Bluetooth controller to be forwarded to the Bluetooth stack
@@ -56,11 +56,11 @@ class BluetoothHciHalCallbacks {
// Abstraction Layer (HAL). Dealing only in HCI packets and events simplifies
// the stack and abstracts away power management, initialization, and other
// implementation-specific details related to the hardware.
class BluetoothHciHal : public ::bluetooth::Module {
class HciHal : public ::bluetooth::Module {
 public:
  static const ModuleFactory Factory;

  virtual ~BluetoothHciHal() = default;
  virtual ~HciHal() = default;

  // Register the callback for incoming packets. All incoming packets are dropped before
  // this callback is registered. Callback can only be registered once, but will be reset
@@ -71,7 +71,7 @@ class BluetoothHciHal : public ::bluetooth::Module {
  // @param callback implements BluetoothHciHalCallbacks which will
  //    receive callbacks when incoming HCI packets are received
  //    from the controller to be sent to the host.
  virtual void registerIncomingPacketCallback(BluetoothHciHalCallbacks* callback) = 0;
  virtual void registerIncomingPacketCallback(HciHalCallbacks* callback) = 0;

  // Send an HCI command (as specified in the Bluetooth Specification
  // V4.2, Vol 2, Part 5, Section 5.4.1) to the Bluetooth controller.
+27 −27
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
#include <android/hardware/bluetooth/1.0/IBluetoothHciCallbacks.h>
#include <android/hardware/bluetooth/1.0/types.h>

#include "hal/bluetooth_snoop_logger.h"
#include "hal/snoop_logger.h"
#include "os/log.h"

using ::android::hardware::hidl_vec;
@@ -39,7 +39,7 @@ namespace hal {
namespace {
constexpr char kDefaultBtsnoopPath[] = "/data/misc/bluetooth/logs/btsnoop_hci.log";

class BluetoothHciDeathRecipient : public ::android::hardware::hidl_death_recipient {
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("Bluetooth HAL service died!");
@@ -47,16 +47,16 @@ class BluetoothHciDeathRecipient : public ::android::hardware::hidl_death_recipi
  }
};

android::sp<BluetoothHciDeathRecipient> bluetooth_hci_death_recipient_ = new BluetoothHciDeathRecipient();
android::sp<HciDeathRecipient> hci_death_recipient_ = new HciDeathRecipient();

class HciHalBluetoothHciCallbacks : public IBluetoothHciCallbacks {
class InternalHciCallbacks : public IBluetoothHciCallbacks {
 public:
  HciHalBluetoothHciCallbacks(BluetoothSnoopLogger* btsnoop_logger)
  InternalHciCallbacks(SnoopLogger* btsnoop_logger)
      : btsnoop_logger_(btsnoop_logger) {
    init_promise_ = new std::promise<void>();
  }

  void SetCallback(BluetoothHciHalCallbacks* callback) {
  void SetCallback(HciHalCallbacks* callback) {
    ASSERT(callback_ == nullptr && callback != nullptr);
    callback_ = callback;
  }
@@ -77,8 +77,8 @@ class HciHalBluetoothHciCallbacks : public IBluetoothHciCallbacks {

  Return<void> hciEventReceived(const hidl_vec<uint8_t>& event) {
    std::vector<uint8_t> received_hci_packet(event.begin(), event.end());
    btsnoop_logger_->capture(received_hci_packet, BluetoothSnoopLogger::Direction::INCOMING,
                             BluetoothSnoopLogger::PacketType::EVT);
    btsnoop_logger_->capture(received_hci_packet, SnoopLogger::Direction::INCOMING,
                             SnoopLogger::PacketType::EVT);
    if (callback_ != nullptr) {
      callback_->hciEventReceived(std::move(received_hci_packet));
    }
@@ -87,8 +87,8 @@ class HciHalBluetoothHciCallbacks : public IBluetoothHciCallbacks {

  Return<void> aclDataReceived(const hidl_vec<uint8_t>& data) {
    std::vector<uint8_t> received_hci_packet(data.begin(), data.end());
    btsnoop_logger_->capture(received_hci_packet, BluetoothSnoopLogger::Direction::INCOMING,
                             BluetoothSnoopLogger::PacketType::ACL);
    btsnoop_logger_->capture(received_hci_packet, SnoopLogger::Direction::INCOMING,
                             SnoopLogger::PacketType::ACL);
    if (callback_ != nullptr) {
      callback_->aclDataReceived(std::move(received_hci_packet));
    }
@@ -97,8 +97,8 @@ class HciHalBluetoothHciCallbacks : public IBluetoothHciCallbacks {

  Return<void> scoDataReceived(const hidl_vec<uint8_t>& data) {
    std::vector<uint8_t> received_hci_packet(data.begin(), data.end());
    btsnoop_logger_->capture(received_hci_packet, BluetoothSnoopLogger::Direction::INCOMING,
                             BluetoothSnoopLogger::PacketType::SCO);
    btsnoop_logger_->capture(received_hci_packet, SnoopLogger::Direction::INCOMING,
                             SnoopLogger::PacketType::SCO);
    if (callback_ != nullptr) {
      callback_->scoDataReceived(std::move(received_hci_packet));
    }
@@ -107,30 +107,30 @@ class HciHalBluetoothHciCallbacks : public IBluetoothHciCallbacks {

 private:
  std::promise<void>* init_promise_ = nullptr;
  BluetoothHciHalCallbacks* callback_ = nullptr;
  BluetoothSnoopLogger* btsnoop_logger_ = nullptr;
  HciHalCallbacks* callback_ = nullptr;
  SnoopLogger* btsnoop_logger_ = nullptr;
};

}  // namespace

class BluetoothHciHalHidl : public BluetoothHciHal {
class HciHalHidl : public HciHal {
 public:
  void registerIncomingPacketCallback(BluetoothHciHalCallbacks* callback) override {
  void registerIncomingPacketCallback(HciHalCallbacks* callback) override {
    callbacks_->SetCallback(callback);
  }

  void sendHciCommand(HciPacket command) override {
    btsnoop_logger_->capture(command, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::CMD);
    btsnoop_logger_->capture(command, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    bt_hci_->sendHciCommand(command);
  }

  void sendAclData(HciPacket packet) override {
    btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::ACL);
    btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
    bt_hci_->sendAclData(packet);
  }

  void sendScoData(HciPacket packet) override {
    btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::SCO);
    btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::SCO);
    bt_hci_->sendScoData(packet);
  }

@@ -140,14 +140,14 @@ class BluetoothHciHalHidl : public BluetoothHciHal {
  }

  void Start(const ModuleRegistry* registry) override {
    btsnoop_logger_ = new BluetoothSnoopLogger(kDefaultBtsnoopPath);
    btsnoop_logger_ = new SnoopLogger(kDefaultBtsnoopPath);
    bt_hci_ = IBluetoothHci::getService();
    ASSERT(bt_hci_ != nullptr);
    auto death_link = bt_hci_->linkToDeath(bluetooth_hci_death_recipient_, 0);
    auto death_link = bt_hci_->linkToDeath(hci_death_recipient_, 0);
    ASSERT_LOG(death_link.isOk(), "Unable to set the death recipient for the Bluetooth HAL");
    // Block allows allocation of a variable that might be bypassed by goto.
    {
      callbacks_ = new HciHalBluetoothHciCallbacks(btsnoop_logger_);
      callbacks_ = new InternalHciCallbacks(btsnoop_logger_);
      bt_hci_->initialize(callbacks_);
      // Don't timeout here, time out at a higher layer
      callbacks_->GetInitPromise()->get_future().wait();
@@ -156,7 +156,7 @@ class BluetoothHciHalHidl : public BluetoothHciHal {

  void Stop(const ModuleRegistry* registry) override {
    ASSERT(bt_hci_ != nullptr);
    auto death_unlink = bt_hci_->unlinkToDeath(bluetooth_hci_death_recipient_);
    auto death_unlink = bt_hci_->unlinkToDeath(hci_death_recipient_);
    if (!death_unlink.isOk()) {
      LOG_ERROR("Error unlinking death recipient from the Bluetooth HAL");
    }
@@ -168,13 +168,13 @@ class BluetoothHciHalHidl : public BluetoothHciHal {
  }

 private:
  android::sp<HciHalBluetoothHciCallbacks> callbacks_;
  android::sp<InternalHciCallbacks> callbacks_;
  android::sp<IBluetoothHci> bt_hci_;
  BluetoothSnoopLogger* btsnoop_logger_;
  SnoopLogger* btsnoop_logger_;
};

const ModuleFactory BluetoothHciHal::Factory = ModuleFactory([]() {
  return new BluetoothHciHalHidl();
const ModuleFactory HciHal::Factory = ModuleFactory([]() {
  return new HciHalHidl();
});

}  // namespace hal
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ class HciHalHidlTest : public ::testing::Test {
};

TEST_F(HciHalHidlTest, init_and_close) {
  fake_registry_.Start<BluetoothHciHal>();
  fake_registry_.Start<HciHal>();
  fake_registry_.StopAll();
}
}  // namespace
Loading