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

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

Merge "gd: Implement GetOwnAddress"

parents 38f16b63 7393d6fc
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -245,6 +245,13 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
          set_data(id, true, config.scan_response);
        }
        set_data(id, false, config.advertisement);
        auto address_policy = le_address_manager_->GetAddressPolicy();
        if (address_policy == LeAddressManager::AddressPolicy::USE_NON_RESOLVABLE_ADDRESS ||
            address_policy == LeAddressManager::AddressPolicy::USE_RESOLVABLE_ADDRESS) {
          advertising_sets_[id].current_address = le_address_manager_->GetAnotherAddress();
        } else {
          advertising_sets_[id].current_address = le_address_manager_->GetCurrentAddress();
        }
        if (!paused) {
          enable_advertiser(id, true, 0, 0);
        } else {
@@ -440,6 +447,16 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
        le_address_manager_->GetNextPrivateAddressIntervalMs());
  }

  void get_own_address(AdvertiserId advertiser_id) {
    if (advertising_sets_.find(advertiser_id) == advertising_sets_.end()) {
      LOG_INFO("Unknown advertising id %u", advertiser_id);
      return;
    }
    auto current_address = advertising_sets_[advertiser_id].current_address;
    advertising_callbacks_->OnOwnAddressRead(
        advertiser_id, static_cast<uint8_t>(current_address.GetAddressType()), current_address.GetAddress());
  }

  void set_parameters(AdvertiserId advertiser_id, ExtendedAdvertisingConfig config) {
    advertising_sets_[advertiser_id].connectable = config.connectable;
    advertising_sets_[advertiser_id].tx_power = config.tx_power;
@@ -1251,6 +1268,10 @@ AdvertiserId LeAdvertisingManager::ExtendedCreateAdvertiser(
  return id;
}

void LeAdvertisingManager::GetOwnAddress(uint8_t advertiser_id) {
  CallOn(pimpl_.get(), &impl::get_own_address, advertiser_id);
}

void LeAdvertisingManager::SetParameters(AdvertiserId advertiser_id, ExtendedAdvertisingConfig config) {
  CallOn(pimpl_.get(), &impl::set_parameters, advertiser_id, config);
}
+3 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ class AdvertisingCallback {
  virtual void OnPeriodicAdvertisingParametersUpdated(uint8_t advertiser_id, uint8_t status) = 0;
  virtual void OnPeriodicAdvertisingDataSet(uint8_t advertiser_id, uint8_t status) = 0;
  virtual void OnPeriodicAdvertisingEnabled(uint8_t advertiser_id, bool enable, uint8_t status) = 0;
  virtual void OnOwnAddressRead(uint8_t advertiser_id, uint8_t address_type, Address address) = 0;
};

class LeAdvertisingManager : public bluetooth::Module {
@@ -113,6 +114,8 @@ class LeAdvertisingManager : public bluetooth::Module {
      uint8_t max_extended_advertising_events,
      os::Handler* handler);

  void GetOwnAddress(uint8_t advertiser_id);

  void SetParameters(AdvertiserId advertiser_id, ExtendedAdvertisingConfig config);

  void SetData(AdvertiserId advertiser_id, bool set_scan_rsp, std::vector<GapData> data);
+1 −0
Original line number Diff line number Diff line
@@ -371,6 +371,7 @@ class LeAdvertisingManagerTest : public ::testing::Test {
    MOCK_METHOD2(OnPeriodicAdvertisingParametersUpdated, void(uint8_t advertiser_id, uint8_t status));
    MOCK_METHOD2(OnPeriodicAdvertisingDataSet, void(uint8_t advertiser_id, uint8_t status));
    MOCK_METHOD3(OnPeriodicAdvertisingEnabled, void(uint8_t advertiser_id, bool enable, uint8_t status));
    MOCK_METHOD3(OnOwnAddressRead, void(uint8_t advertiser_id, uint8_t address_type, Address address));
  } mock_advertising_callback_;
};

+5 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include "gd/packet/packet_view.h"
#include "gd/storage/storage_module.h"
#include "main/shim/entry.h"
#include "main/shim/helpers.h"

#include "btif/include/btif_common.h"
#include "stack/include/ble_advertiser.h"
@@ -62,9 +63,9 @@ class BleAdvertiserInterfaceImpl : public BleAdvertiserInterface,
    bluetooth::shim::GetAdvertising()->RemoveAdvertiser(advertiser_id);
  }

  // only for PTS test
  void GetOwnAddress(uint8_t advertiser_id, GetAddressCallback cb) override {
    LOG(INFO) << __func__ << " in shim layer";
    bluetooth::shim::GetAdvertising()->GetOwnAddress(advertiser_id);
  }

  void SetParameters(uint8_t advertiser_id, AdvertiseParameters params,
@@ -317,11 +318,12 @@ class BleAdvertiserInterfaceImpl : public BleAdvertiserInterface,
  }

  void OnOwnAddressRead(uint8_t advertiser_id, uint8_t address_type,
                        RawAddress address) {
                        bluetooth::hci::Address address) {
    RawAddress raw_address = bluetooth::ToRawAddress(address);
    do_in_jni_thread(FROM_HERE,
                     base::Bind(&AdvertisingCallbacks::OnOwnAddressRead,
                                base::Unretained(advertising_callbacks_),
                                advertiser_id, address_type, address));
                                advertiser_id, address_type, raw_address));
  }

  AdvertisingCallbacks* advertising_callbacks_;