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

Commit 72f12ba1 authored by Rongxuan Liu's avatar Rongxuan Liu
Browse files

Remove unused multi_adv le adversiting module and its unit test

le_audio is the only client for multi_adv, this module and the unit
tests can be removed once all clients are switched th gd le_advertising_manager

Bug: 290393336
Tag: #refactor
Test: atest --host bluetooth_test_broadcaster bluetooth_test_broadcaster_state_machine  --no-bazel-mode
Change-Id: I1b4a96cd0a00cd401c2a6b906bc6738b6d69437d
parent 92521df2
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -69,9 +69,6 @@
    {
      "name": "net_test_stack_ad_parser"
    },
    {
      "name": "net_test_stack_multi_adv"
    },
    // go/a-unit-tests tests (unit_test: true)
    // Thoses test run on the host in the CI automatically.
    // Run the one that are available on the device on the
@@ -279,9 +276,6 @@
    {
      "name": "net_test_stack_ad_parser"
    },
    {
      "name": "net_test_stack_multi_adv"
    },
    // go/a-unit-tests tests (unit_test: true)
    // Thoses test run on the host in the CI automatically.
    // Run the one that are available on the device on the
+0 −246
Original line number Diff line number Diff line
@@ -18,255 +18,9 @@

#define LOG_TAG "bt_btif_ble_advertiser"

#include <hardware/bluetooth.h>
#include <hardware/bt_gatt.h>

#include <base/functional/bind.h>
#include <base/logging.h>
#include <vector>

#include "ble_advertiser.h"
#include "btif_common.h"
#include "main/shim/le_advertising_manager.h"
#include "main/shim/shim.h"
#include "osi/include/properties.h"
#include "stack/include/btu.h"

using base::Bind;
using base::Owned;
using std::vector;

namespace {

template <typename T>
class OwnedArrayWrapper {
 public:
  explicit OwnedArrayWrapper(T* o) : ptr_(o) {}
  ~OwnedArrayWrapper() { delete[] ptr_; }
  T* get() const { return ptr_; }
  OwnedArrayWrapper(OwnedArrayWrapper&& other) noexcept {
    ptr_ = other.ptr_;
    other.ptr_ = NULL;
  }

 private:
  mutable T* ptr_;
};

template <typename T>
T* Unwrap(const OwnedArrayWrapper<T>& o) {
  return o.get();
}

template <typename T>
static inline OwnedArrayWrapper<T> OwnedArray(T* o) {
  return OwnedArrayWrapper<T>(o);
}

void parseParams(tBTM_BLE_ADV_PARAMS* p_params,
                 const AdvertiseParameters& params) {
  // By default use all channels, but have property for tweaking.
  int channel_map = osi_property_get_int32(
      "persist.bluetooth.advertising_channel_map", params.channel_map);

  p_params->advertising_event_properties = params.advertising_event_properties;
  p_params->adv_int_min = params.min_interval;
  p_params->adv_int_max = params.max_interval;
  p_params->channel_map = channel_map;
  p_params->adv_filter_policy = 0;
  p_params->tx_power = params.tx_power;
  p_params->primary_advertising_phy = params.primary_advertising_phy;
  p_params->secondary_advertising_phy = params.secondary_advertising_phy;
  p_params->scan_request_notification_enable =
      params.scan_request_notification_enable;
  p_params->own_address_type = params.own_address_type;
}

void parsePeriodicParams(tBLE_PERIODIC_ADV_PARAMS* p_periodic_params,
                         PeriodicAdvertisingParameters periodic_params) {
  p_periodic_params->enable = periodic_params.enable;
  p_periodic_params->include_adi = periodic_params.include_adi;
  p_periodic_params->min_interval = periodic_params.min_interval;
  p_periodic_params->max_interval = periodic_params.max_interval;
  p_periodic_params->periodic_advertising_properties =
      periodic_params.periodic_advertising_properties;
}

class BleAdvertiserInterfaceImpl : public BleAdvertiserInterface {
  ~BleAdvertiserInterfaceImpl() override{};

  void RegisterAdvertiserCb(IdStatusCallback cb, uint8_t advertiser_id,
                            uint8_t status) {
    LOG(INFO) << __func__ << " status: " << +status
              << " , adveriser_id: " << +advertiser_id;
    do_in_jni_thread(Bind(cb, advertiser_id, status));
  }

  void RegisterAdvertiser(IdStatusCallback cb) override {
    do_in_main_thread(
        FROM_HERE, Bind(&BleAdvertisingManager::RegisterAdvertiser,
                        BleAdvertisingManager::Get(),
                        Bind(&BleAdvertiserInterfaceImpl::RegisterAdvertiserCb,
                             base::Unretained(this), cb)));
  }

  void Unregister(uint8_t advertiser_id) override {
    do_in_main_thread(
        FROM_HERE,
        Bind(
            [](uint8_t advertiser_id) {
              if (!BleAdvertisingManager::IsInitialized()) {
                LOG(WARNING) << "Stack already shutdown";
                return;
              }
              BleAdvertisingManager::Get()->Unregister(advertiser_id);
            },
            advertiser_id));
  }

  void GetOwnAddress(uint8_t advertiser_id, GetAddressCallback cb) override {
    if (!BleAdvertisingManager::IsInitialized()) return;
    do_in_main_thread(FROM_HERE,
                      Bind(&BleAdvertisingManager::GetOwnAddress,
                           BleAdvertisingManager::Get(), advertiser_id,
                           jni_thread_wrapper(FROM_HERE, cb)));
  }

  void SetParameters(uint8_t advertiser_id, AdvertiseParameters params,
                     ParametersCallback cb) override {
    VLOG(1) << __func__;

    if (!BleAdvertisingManager::IsInitialized()) return;
    tBTM_BLE_ADV_PARAMS* p_params = new tBTM_BLE_ADV_PARAMS;
    parseParams(p_params, params);

    do_in_main_thread(FROM_HERE, Bind(&BleAdvertisingManager::SetParameters,
                                      BleAdvertisingManager::Get(),
                                      advertiser_id, base::Owned(p_params),
                                      jni_thread_wrapper(FROM_HERE, cb)));
  }

  void SetData(int advertiser_id, bool set_scan_rsp, vector<uint8_t> data,
               StatusCallback cb) override {
    if (!BleAdvertisingManager::IsInitialized()) return;
    do_in_main_thread(
        FROM_HERE,
        Bind(&BleAdvertisingManager::SetData, BleAdvertisingManager::Get(),
             advertiser_id, set_scan_rsp, std::move(data),
             jni_thread_wrapper(FROM_HERE, cb)));
  }

  void Enable(uint8_t advertiser_id, bool enable, StatusCallback cb,
              uint16_t duration, uint8_t maxExtAdvEvents,
              StatusCallback timeout_cb) override {
    VLOG(1) << __func__ << " advertiser_id: " << +advertiser_id
            << " ,enable: " << enable;

    if (!BleAdvertisingManager::IsInitialized()) return;
    do_in_main_thread(
        FROM_HERE,
        Bind(&BleAdvertisingManager::Enable, BleAdvertisingManager::Get(),
             advertiser_id, enable, jni_thread_wrapper(FROM_HERE, cb), duration,
             maxExtAdvEvents, jni_thread_wrapper(FROM_HERE, timeout_cb)));
  }

  void StartAdvertising(uint8_t advertiser_id, StatusCallback cb,
                        AdvertiseParameters params,
                        std::vector<uint8_t> advertise_data,
                        std::vector<uint8_t> scan_response_data, int timeout_s,
                        MultiAdvCb timeout_cb) override {
    VLOG(1) << __func__;

    if (!BleAdvertisingManager::IsInitialized()) return;
    tBTM_BLE_ADV_PARAMS* p_params = new tBTM_BLE_ADV_PARAMS;
    parseParams(p_params, params);

    do_in_main_thread(
        FROM_HERE,
        Bind(&BleAdvertisingManager::StartAdvertising,
             BleAdvertisingManager::Get(), advertiser_id,
             jni_thread_wrapper(FROM_HERE, cb), base::Owned(p_params),
             std::move(advertise_data), std::move(scan_response_data),
             timeout_s * 100, jni_thread_wrapper(FROM_HERE, timeout_cb)));
  }

  void StartAdvertisingSet(uint8_t client_id, int reg_id,
                           IdTxPowerStatusCallback cb,
                           AdvertiseParameters params,
                           std::vector<uint8_t> advertise_data,
                           std::vector<uint8_t> scan_response_data,
                           PeriodicAdvertisingParameters periodic_params,
                           std::vector<uint8_t> periodic_data,
                           uint16_t duration, uint8_t maxExtAdvEvents,
                           IdStatusCallback timeout_cb) override {
    VLOG(1) << __func__;

    if (!BleAdvertisingManager::IsInitialized()) return;
    tBTM_BLE_ADV_PARAMS* p_params = new tBTM_BLE_ADV_PARAMS;
    parseParams(p_params, params);

    tBLE_PERIODIC_ADV_PARAMS* p_periodic_params = new tBLE_PERIODIC_ADV_PARAMS;
    parsePeriodicParams(p_periodic_params, periodic_params);

    do_in_main_thread(
        FROM_HERE,
        Bind(&BleAdvertisingManager::StartAdvertisingSet,
             BleAdvertisingManager::Get(), jni_thread_wrapper(FROM_HERE, cb),
             base::Owned(p_params), std::move(advertise_data),
             std::move(scan_response_data), base::Owned(p_periodic_params),
             std::move(periodic_data), duration, maxExtAdvEvents,
             jni_thread_wrapper(FROM_HERE, timeout_cb)));

    return;
  }

  void SetPeriodicAdvertisingParameters(
      int advertiser_id, PeriodicAdvertisingParameters periodic_params,
      StatusCallback cb) override {
    VLOG(1) << __func__ << " advertiser_id: " << +advertiser_id;

    if (!BleAdvertisingManager::IsInitialized()) return;
    tBLE_PERIODIC_ADV_PARAMS* p_periodic_params = new tBLE_PERIODIC_ADV_PARAMS;
    parsePeriodicParams(p_periodic_params, periodic_params);

    do_in_main_thread(
        FROM_HERE,
        Bind(&BleAdvertisingManager::SetPeriodicAdvertisingParameters,
             BleAdvertisingManager::Get(), advertiser_id,
             base::Owned(p_periodic_params),
             jni_thread_wrapper(FROM_HERE, cb)));
  }

  void SetPeriodicAdvertisingData(int advertiser_id, std::vector<uint8_t> data,
                                  StatusCallback cb) override {
    VLOG(1) << __func__ << " advertiser_id: " << +advertiser_id;

    if (!BleAdvertisingManager::IsInitialized()) return;
    do_in_main_thread(FROM_HERE,
                      Bind(&BleAdvertisingManager::SetPeriodicAdvertisingData,
                           BleAdvertisingManager::Get(), advertiser_id,
                           std::move(data), jni_thread_wrapper(FROM_HERE, cb)));
  }

  void SetPeriodicAdvertisingEnable(int advertiser_id, bool enable,
                                    bool include_adi,
                                    StatusCallback cb) override {
    VLOG(1) << __func__ << " advertiser_id: " << +advertiser_id
            << " ,enable: " << enable;

    if (!BleAdvertisingManager::IsInitialized()) return;
    do_in_main_thread(FROM_HERE,
                      Bind(&BleAdvertisingManager::SetPeriodicAdvertisingEnable,
                           BleAdvertisingManager::Get(), advertiser_id, enable,
                           include_adi, jni_thread_wrapper(FROM_HERE, cb)));
  }

  void RegisterCallbacks(AdvertisingCallbacks* callbacks) {
    // For GD only
  }
};

}  // namespace

BleAdvertiserInterface* get_ble_advertiser_instance() {
  LOG(INFO) << __func__ << " use gd le advertiser";
+0 −2
Original line number Diff line number Diff line
@@ -368,8 +368,6 @@ static void event_shut_down_stack(ProfileStopCallback stopProfiles) {

  module_shut_down(get_local_module(RUST_MODULE));

  do_in_main_thread(FROM_HERE, base::BindOnce(&btm_ble_multi_adv_cleanup));

  do_in_main_thread(FROM_HERE, base::BindOnce(&btm_ble_scanner_cleanup));

  btif_dm_on_disable();
+0 −43
Original line number Diff line number Diff line
@@ -220,7 +220,6 @@ cc_library_static {
        "btm/btm_ble_bgconn.cc",
        "btm/btm_ble_cont_energy.cc",
        "btm/btm_ble_gap.cc",
        "btm/btm_ble_multi_adv.cc",
        "btm/btm_ble_privacy.cc",
        "btm/btm_ble_scanner.cc",
        "btm/btm_client_interface.cc",
@@ -826,47 +825,6 @@ cc_test {
    ],
}

// Bluetooth stack multi-advertising unit tests for target
cc_test {
    name: "net_test_stack_multi_adv",
    defaults: [
        "bluetooth_gtest_x86_asan_workaround",
        "fluoride_defaults",
        "mts_defaults",
    ],
    test_suites: ["device-tests"],
    local_include_dirs: [
        "btm",
        "include",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/gd",
        "packages/modules/Bluetooth/system/internal_include",
        "packages/modules/Bluetooth/system/internal_include",
    ],
    srcs: [
        ":TestMockDevice",
        "btm/btm_ble_multi_adv.cc",
        "test/ble_advertiser_test.cc",
    ],
    shared_libs: [
        "libbinder_ndk",
        "libcrypto",
        "libcutils",
    ],
    static_libs: [
        "android.system.suspend.control-V1-ndk",
        "libbluetooth-types",
        "libchrome",
        "libgmock",
        "liblog",
    ],
    sanitize: {
        cfi: false,
    },
}

// Bluetooth stack advertise data parsing unit tests for target
cc_test {
    name: "net_test_stack_ad_parser",
@@ -1445,7 +1403,6 @@ cc_test {
        "btm/btm_ble_bgconn.cc",
        "btm/btm_ble_cont_energy.cc",
        "btm/btm_ble_gap.cc",
        "btm/btm_ble_multi_adv.cc",
        "btm/btm_ble_privacy.cc",
        "btm/btm_ble_scanner.cc",
        "btm/btm_client_interface.cc",
+0 −30
Original line number Diff line number Diff line
@@ -114,7 +114,6 @@ source_set("stack") {
    "btm/btm_ble_bgconn.cc",
    "btm/btm_ble_cont_energy.cc",
    "btm/btm_ble_gap.cc",
    "btm/btm_ble_multi_adv.cc",
    "btm/btm_ble_privacy.cc",
    "btm/btm_ble_scanner.cc",
    "btm/btm_client_interface.cc",
@@ -383,33 +382,4 @@ if (defined(use.android) && use.android) {
      "//bt/system:target_defaults",
    ]
  }

  executable("net_test_stack_multi_adv") {
    sources = [
      "btm/btm_ble_multi_adv.cc",
      "test/ble_advertiser_test.cc",
    ]

    include_dirs = [
      "include",
      "//bt/system/",
      "//bt/system/internal_include",
      "//bt/system/stack/btm",
    ]

    libs = [
      "dl",
      "pthread",
      "resolv",
      "rt",
      "z",
    ]

    deps = [ "//bt/system/types" ]

    configs += [
      "//bt/system:external_gmock_main",
      "//bt/system:target_defaults",
    ]
  }
}
Loading