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

Commit c4e9d9eb authored by Myles Watson's avatar Myles Watson Committed by Gerrit Code Review
Browse files

Merge changes I3bd2629e,I01bb6e37 into main

* changes:
  stack_btm_inq_test: Include what you use
  Add an InquiryInterface
parents 1fbb80ca ffcfaa15
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include "hci/class_of_device.h"
#include "hci/distance_measurement_interface.h"
#include "hci/hci_packets.h"
#include "hci/inquiry_interface.h"
#include "hci/le_acl_connection_interface.h"
#include "hci/le_advertising_interface.h"
#include "hci/le_iso_interface.h"
@@ -112,12 +113,19 @@ public:
  virtual DistanceMeasurementInterface* GetDistanceMeasurementInterface(
          common::ContextualCallback<void(LeMetaEventView)> event_handler) = 0;

  virtual std::unique_ptr<InquiryInterface> GetInquiryInterface(
          common::ContextualCallback<void(EventView)> event_handler) = 0;

protected:
  template <typename T>
  class CommandInterfaceImpl : public CommandInterface<T> {
  public:
    explicit CommandInterfaceImpl(HciInterface* hci) : hci_(hci) {}
    virtual ~CommandInterfaceImpl() = default;
    explicit CommandInterfaceImpl(HciInterface* hci, common::OnceCallback<void()> cleanup)
        : hci_(hci), cleanup_(std::move(cleanup)) {}
    explicit CommandInterfaceImpl(HciInterface* hci) : hci_(hci) {
      cleanup_ = common::BindOnce([]() {});
    }
    ~CommandInterfaceImpl() { std::move(cleanup_).Run(); }

    void EnqueueCommand(
            std::unique_ptr<T> command,
@@ -131,6 +139,7 @@ protected:
      hci_->EnqueueCommand(std::move(command), std::move(on_status));
    }
    HciInterface* hci_;
    common::OnceCallback<void()> cleanup_;
  };
};

+16 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include "hal/hci_hal.h"
#include "hci/class_of_device.h"
#include "hci/hci_metrics_logging.h"
#include "hci/inquiry_interface.h"
#include "os/alarm.h"
#include "os/metrics.h"
#include "os/queue.h"
@@ -793,6 +794,21 @@ DistanceMeasurementInterface* HciLayer::GetDistanceMeasurementInterface(
  return &distance_measurement_interface;
}

std::unique_ptr<InquiryInterface> HciLayer::GetInquiryInterface(
        ContextualCallback<void(EventView)> event_handler) {
  for (const auto event : InquiryEvents) {
    RegisterEventHandler(event, event_handler);
  }
  auto cleanup = common::BindOnce(
          [](HciLayer* hci) {
            for (const auto event : InquiryEvents) {
              hci->UnregisterEventHandler(event);
            }
          },
          common::Unretained(this));
  return std::make_unique<CommandInterfaceImpl<DiscoveryCommandBuilder>>(this, std::move(cleanup));
}

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

void HciLayer::ListDependencies(ModuleList* list) const {
+4 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include "hci/distance_measurement_interface.h"
#include "hci/hci_interface.h"
#include "hci/hci_packets.h"
#include "hci/inquiry_interface.h"
#include "hci/le_acl_connection_interface.h"
#include "hci/le_advertising_interface.h"
#include "hci/le_iso_interface.h"
@@ -119,6 +120,9 @@ public:
  virtual DistanceMeasurementInterface* GetDistanceMeasurementInterface(
          common::ContextualCallback<void(LeMetaEventView)> event_handler);

  std::unique_ptr<InquiryInterface> GetInquiryInterface(
          common::ContextualCallback<void(EventView)> event_handler) override;

  std::string ToString() const override { return "Hci Layer"; }

  static constexpr std::chrono::milliseconds kHciTimeoutMs = std::chrono::milliseconds(2000);
+4 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "hci/address.h"
#include "hci/hci_interface.h"
#include "hci/hci_packets.h"
#include "hci/inquiry_interface.h"

// Unit test interfaces
namespace bluetooth {
@@ -92,6 +93,9 @@ public:
  MOCK_METHOD((DistanceMeasurementInterface*), GetDistanceMeasurementInterface,
              (common::ContextualCallback<void(LeMetaEventView)> event_handler), (override));

  MOCK_METHOD((std::unique_ptr<InquiryInterface>), GetInquiryInterface,
              (common::ContextualCallback<void(EventView)> event_handler), (override));

  MOCK_METHOD(void, RegisterForScoConnectionRequests,
              (common::ContextualCallback<void(Address, ClassOfDevice, ConnectionRequestLinkType)>
                       on_sco_connection_request));
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 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 "hci/command_interface.h"
#include "hci/hci_packets.h"

namespace bluetooth {
namespace hci {

constexpr hci::EventCode InquiryEvents[] = {
        hci::EventCode::INQUIRY_COMPLETE,
        hci::EventCode::INQUIRY_RESULT,
        hci::EventCode::INQUIRY_RESULT_WITH_RSSI,
        hci::EventCode::EXTENDED_INQUIRY_RESULT,
};

typedef CommandInterface<DiscoveryCommandBuilder> InquiryInterface;

}  // namespace hci
}  // namespace bluetooth
Loading