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

Commit f21f908e authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "gd: Use ExtendedAdvertising as main advertising function"

parents 6e9964ef 0bce64cf
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -127,16 +127,19 @@ class LeAdvertisingManagerFacadeService : public LeAdvertisingManagerFacade::Ser

  ::grpc::Status CreateAdvertiser(::grpc::ServerContext* context, const CreateAdvertiserRequest* request,
                                  CreateAdvertiserResponse* response) override {
    hci::AdvertisingConfig config = {};
    hci::ExtendedAdvertisingConfig config = {};
    if (!AdvertisingConfigFromProto(request->config(), &config)) {
      LOG_WARN("Error parsing advertising config %s", request->SerializeAsString().c_str());
      response->set_advertiser_id(LeAdvertisingManager::kInvalidId);
      return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "Error while parsing advertising config");
    }
    LeAdvertiser le_advertiser(config);
    auto advertiser_id = le_advertising_manager_->CreateAdvertiser(
        config, common::Bind(&LeAdvertiser::ScanCallback, common::Unretained(&le_advertiser)),
        common::Bind(&LeAdvertiser::TerminatedCallback, common::Unretained(&le_advertiser)), facade_handler_);
    auto advertiser_id = le_advertising_manager_->ExtendedCreateAdvertiser(
        -1,
        config,
        common::Bind(&LeAdvertiser::ScanCallback, common::Unretained(&le_advertiser)),
        common::Bind(&LeAdvertiser::TerminatedCallback, common::Unretained(&le_advertiser)),
        facade_handler_);
    if (advertiser_id != LeAdvertisingManager::kInvalidId) {
      le_advertiser.SetAdvertiserId(advertiser_id);
      le_advertisers_.push_back(le_advertiser);
+23 −18
Original line number Diff line number Diff line
@@ -108,6 +108,10 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
    return num_instances_;
  }

  AdvertisingApiType get_advertising_api_type() const {
    return advertising_api_type_;
  }

  void register_advertising_callback(AdvertisingCallback* advertising_callback) {
    advertising_callbacks_ = advertising_callback;
  }
@@ -184,7 +188,9 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
    }
  }

  void create_advertiser(AdvertiserId id, const AdvertisingConfig& config,
  void create_advertiser(
      AdvertiserId id,
      const AdvertisingConfig config,
      const common::Callback<void(Address, AddressType)>& scan_callback,
      const common::Callback<void(ErrorCode, uint8_t, uint8_t)>& set_terminated_callback,
      os::Handler* handler) {
@@ -270,15 +276,7 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
        enabled_sets_[id] = curr_set;
      } break;
      case (AdvertisingApiType::EXTENDED): {
        ExtendedAdvertisingConfig new_config = config;
        new_config.legacy_pdus = true;

        // sid must be in range 0x00 to 0x0F. Since no controller supports more than
        // 16 advertisers, it's safe to make sid equal to id.

        new_config.sid = id % kAdvertisingSetIdMask;
        // TODO remove, always call create_advertiser via create_extended_advertiser
        create_extended_advertiser(0x00, id, new_config, scan_callback, set_terminated_callback, handler);
        LOG_WARN("Unexpected AdvertisingApiType EXTENDED");
      } break;
    }
  }
@@ -286,7 +284,7 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
  void create_extended_advertiser(
      int reg_id,
      AdvertiserId id,
      const ExtendedAdvertisingConfig& config,
      const ExtendedAdvertisingConfig config,
      const common::Callback<void(Address, AddressType)>& scan_callback,
      const common::Callback<void(ErrorCode, uint8_t, uint8_t)>& set_terminated_callback,
      os::Handler* handler) {
@@ -921,9 +919,11 @@ size_t LeAdvertisingManager::GetNumberOfAdvertisingInstances() const {
  return pimpl_->GetNumberOfAdvertisingInstances();
}

AdvertiserId LeAdvertisingManager::CreateAdvertiser(
    const AdvertisingConfig& config, const common::Callback<void(Address, AddressType)>& scan_callback,
    const common::Callback<void(ErrorCode, uint8_t, uint8_t)>& set_terminated_callback, os::Handler* handler) {
AdvertiserId LeAdvertisingManager::create_advertiser(
    const AdvertisingConfig config,
    const common::Callback<void(Address, AddressType)>& scan_callback,
    const common::Callback<void(ErrorCode, uint8_t, uint8_t)>& set_terminated_callback,
    os::Handler* handler) {
  if (config.peer_address == Address::kEmpty) {
    if (config.own_address_type == hci::OwnAddressType::RESOLVABLE_OR_PUBLIC_ADDRESS ||
        config.own_address_type == hci::OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS) {
@@ -947,10 +947,15 @@ AdvertiserId LeAdvertisingManager::CreateAdvertiser(

AdvertiserId LeAdvertisingManager::ExtendedCreateAdvertiser(
    int reg_id,
    const ExtendedAdvertisingConfig& config,
    const ExtendedAdvertisingConfig config,
    const common::Callback<void(Address, AddressType)>& scan_callback,
    const common::Callback<void(ErrorCode, uint8_t, uint8_t)>& set_terminated_callback,
    os::Handler* handler) {
  AdvertisingApiType advertising_api_type = pimpl_->get_advertising_api_type();
  if (advertising_api_type != AdvertisingApiType::EXTENDED) {
    return create_advertiser(config, scan_callback, set_terminated_callback, handler);
  };

  if (config.directed) {
    if (config.peer_address == Address::kEmpty) {
      LOG_INFO("Peer address can not be empty for directed advertising");
+7 −6
Original line number Diff line number Diff line
@@ -102,14 +102,9 @@ class LeAdvertisingManager : public bluetooth::Module {

  size_t GetNumberOfAdvertisingInstances() const;

  // Return -1 if the advertiser was not created, otherwise the advertiser ID.
  AdvertiserId CreateAdvertiser(const AdvertisingConfig& config,
                                const common::Callback<void(Address, AddressType)>& scan_callback,
                                const common::Callback<void(ErrorCode, uint8_t, uint8_t)>& set_terminated_callback,
                                os::Handler* handler);
  AdvertiserId ExtendedCreateAdvertiser(
      int reg_id,
      const ExtendedAdvertisingConfig& config,
      const ExtendedAdvertisingConfig config,
      const common::Callback<void(Address, AddressType)>& scan_callback,
      const common::Callback<void(ErrorCode, uint8_t, uint8_t)>& set_terminated_callback,
      os::Handler* handler);
@@ -145,6 +140,12 @@ class LeAdvertisingManager : public bluetooth::Module {
  std::string ToString() const override;

 private:
  // Return -1 if the advertiser was not created, otherwise the advertiser ID.
  AdvertiserId create_advertiser(
      const AdvertisingConfig config,
      const common::Callback<void(Address, AddressType)>& scan_callback,
      const common::Callback<void(ErrorCode, uint8_t, uint8_t)>& set_terminated_callback,
      os::Handler* handler);
  struct impl;
  std::unique_ptr<impl> pimpl_;
  DISALLOW_COPY_AND_ASSIGN(LeAdvertisingManager);
+1 −8
Original line number Diff line number Diff line
@@ -33,18 +33,11 @@ using hci::LeAdvertisingManager;
class MockLeAdvertisingManager : public LeAdvertisingManager {
 public:
  MOCK_METHOD(size_t, GetNumberOfAdvertisingInstances, (), (const));
  MOCK_METHOD(
      AdvertiserId,
      CreateAdvertiser,
      (const AdvertisingConfig&,
       const common::Callback<void(Address, AddressType)>&,
       const common::Callback<void(ErrorCode, uint8_t, uint8_t)>&,
       os::Handler*));
  MOCK_METHOD(
      AdvertiserId,
      ExtendedCreateAdvertiser,
      (int regId,
       const ExtendedAdvertisingConfig&,
       const ExtendedAdvertisingConfig,
       const common::Callback<void(Address, AddressType)>&,
       const common::Callback<void(ErrorCode, uint8_t, uint8_t)>&,
       os::Handler*));
+6 −6
Original line number Diff line number Diff line
@@ -431,7 +431,7 @@ TEST_F(LeAndroidHciAdvertisingManagerTest, startup_teardown) {}
TEST_F(LeExtendedAdvertisingManagerTest, startup_teardown) {}

TEST_F(LeAdvertisingManagerTest, create_advertiser_test) {
  AdvertisingConfig advertising_config{};
  ExtendedAdvertisingConfig advertising_config{};
  advertising_config.advertising_type = AdvertisingType::ADV_IND;
  advertising_config.own_address_type = OwnAddressType::PUBLIC_DEVICE_ADDRESS;
  std::vector<GapData> gap_data{};
@@ -446,8 +446,8 @@ TEST_F(LeAdvertisingManagerTest, create_advertiser_test) {
  advertising_config.scan_response = gap_data;

  auto last_command_future = test_hci_layer_->GetCommandFuture(OpCode::LE_SET_ADVERTISING_ENABLE);
  auto id = le_advertising_manager_->CreateAdvertiser(advertising_config, scan_callback, set_terminated_callback,
                                                      client_handler_);
  auto id = le_advertising_manager_->ExtendedCreateAdvertiser(
      0x00, advertising_config, scan_callback, set_terminated_callback, client_handler_);
  ASSERT_NE(LeAdvertisingManager::kInvalidId, id);
  std::vector<OpCode> adv_opcodes = {
      OpCode::LE_SET_ADVERTISING_PARAMETERS,
@@ -479,7 +479,7 @@ TEST_F(LeAdvertisingManagerTest, create_advertiser_test) {
}

TEST_F(LeAndroidHciAdvertisingManagerTest, create_advertiser_test) {
  AdvertisingConfig advertising_config{};
  ExtendedAdvertisingConfig advertising_config{};
  advertising_config.advertising_type = AdvertisingType::ADV_IND;
  advertising_config.own_address_type = OwnAddressType::PUBLIC_DEVICE_ADDRESS;
  std::vector<GapData> gap_data{};
@@ -494,8 +494,8 @@ TEST_F(LeAndroidHciAdvertisingManagerTest, create_advertiser_test) {
  advertising_config.scan_response = gap_data;

  auto next_command_future = test_hci_layer_->GetSubCommandFuture(SubOcf::SET_ENABLE);
  auto id = le_advertising_manager_->CreateAdvertiser(advertising_config, scan_callback, set_terminated_callback,
                                                      client_handler_);
  auto id = le_advertising_manager_->ExtendedCreateAdvertiser(
      0x00, advertising_config, scan_callback, set_terminated_callback, client_handler_);
  ASSERT_NE(LeAdvertisingManager::kInvalidId, id);
  std::vector<SubOcf> sub_ocf = {
      SubOcf::SET_PARAM, SubOcf::SET_DATA, SubOcf::SET_SCAN_RESP, SubOcf::SET_RANDOM_ADDR, SubOcf::SET_ENABLE,
Loading