Bluetooth 5 AdvertisingSet implementation (4/4)
Test: manual
Bug: 30622771
Change-Id: Ie1c1588383a83296cabd29a0481f7d80a1168263
diff --git a/btif/src/btif_ble_advertiser.cc b/btif/src/btif_ble_advertiser.cc
index 1533bad..395bc1d 100644
--- a/btif/src/btif_ble_advertiser.cc
+++ b/btif/src/btif_ble_advertiser.cc
@@ -59,6 +59,29 @@
return OwnedArrayWrapper<T>(o);
}
+void parseParams(tBTM_BLE_ADV_PARAMS* p_params,
+ const AdvertiseParameters& params) {
+ 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 = params.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;
+}
+
+void parsePeriodicParams(tBLE_PERIODIC_ADV_PARAMS* p_periodic_params,
+ PeriodicAdvertisingParameters periodic_params) {
+ p_periodic_params->enable = periodic_params.enable;
+ 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(){};
@@ -84,36 +107,18 @@
base::Unretained(BleAdvertisingManager::Get()), advertiser_id));
}
- void SetParametersCb(StatusCallback cb, uint8_t status, int8_t tx_power) {
- LOG(INFO) << __func__ << " status: " << +status;
- do_in_jni_thread(Bind(cb, status));
- }
+ void SetParameters(uint8_t advertiser_id, AdvertiseParameters params,
+ ParametersCallback cb) override {
+ VLOG(1) << __func__;
- void SetParameters(uint8_t advertiser_id,
- uint16_t advertising_event_properties,
- uint32_t min_interval, uint32_t max_interval, int chnl_map,
- int tx_power, uint8_t primary_advertising_phy,
- uint8_t secondary_advertising_phy,
- uint8_t scan_request_notification_enable,
- StatusCallback cb) {
- tBTM_BLE_ADV_PARAMS* params = new tBTM_BLE_ADV_PARAMS;
+ tBTM_BLE_ADV_PARAMS* p_params = new tBTM_BLE_ADV_PARAMS;
+ parseParams(p_params, params);
- params->advertising_event_properties = advertising_event_properties;
- params->adv_int_min = min_interval;
- params->adv_int_max = max_interval;
- params->channel_map = chnl_map;
- params->adv_filter_policy = 0;
- params->tx_power = tx_power;
- params->primary_advertising_phy = primary_advertising_phy;
- params->secondary_advertising_phy = secondary_advertising_phy;
- params->scan_request_notification_enable = scan_request_notification_enable;
-
- do_in_bta_thread(FROM_HERE,
- Bind(&BleAdvertisingManager::SetParameters,
- base::Unretained(BleAdvertisingManager::Get()),
- advertiser_id, base::Owned(params),
- Bind(&BleAdvertiserInterfaceImpl::SetParametersCb,
- base::Unretained(this), cb)));
+ do_in_bta_thread(
+ FROM_HERE,
+ Bind(&BleAdvertisingManager::SetParameters,
+ base::Unretained(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,
@@ -146,17 +151,7 @@
VLOG(1) << __func__;
tBTM_BLE_ADV_PARAMS* p_params = new tBTM_BLE_ADV_PARAMS;
- 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 = params.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;
+ parseParams(p_params, params);
do_in_bta_thread(
FROM_HERE,
@@ -167,33 +162,20 @@
timeout_s, jni_thread_wrapper(FROM_HERE, timeout_cb)));
}
- void StartAdvertisingSet(IdStatusCallback cb, AdvertiseParameters params,
+ void StartAdvertisingSet(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, int timeout_s,
- IdStatusCallback timeout_cb) {
+ IdStatusCallback timeout_cb) override {
VLOG(1) << __func__;
tBTM_BLE_ADV_PARAMS* p_params = new tBTM_BLE_ADV_PARAMS;
- 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 = params.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;
+ parseParams(p_params, params);
tBLE_PERIODIC_ADV_PARAMS* p_periodic_params = new tBLE_PERIODIC_ADV_PARAMS;
- p_periodic_params->enable = periodic_params.enable;
- 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;
+ parsePeriodicParams(p_periodic_params, periodic_params);
do_in_bta_thread(
FROM_HERE,
@@ -203,7 +185,46 @@
std::move(advertise_data), std::move(scan_response_data),
base::Owned(p_periodic_params), std::move(periodic_data),
timeout_s, jni_thread_wrapper(FROM_HERE, timeout_cb)));
- };
+ }
+
+ void SetPeriodicAdvertisingParameters(
+ int advertiser_id, PeriodicAdvertisingParameters periodic_params,
+ StatusCallback cb) override {
+ VLOG(1) << __func__ << " advertiser_id: " << +advertiser_id;
+
+ tBLE_PERIODIC_ADV_PARAMS* p_periodic_params = new tBLE_PERIODIC_ADV_PARAMS;
+ parsePeriodicParams(p_periodic_params, periodic_params);
+
+ do_in_bta_thread(
+ FROM_HERE,
+ Bind(&BleAdvertisingManager::SetPeriodicAdvertisingParameters,
+ base::Unretained(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;
+
+ do_in_bta_thread(
+ FROM_HERE,
+ Bind(&BleAdvertisingManager::SetPeriodicAdvertisingData,
+ base::Unretained(BleAdvertisingManager::Get()), advertiser_id,
+ std::move(data), jni_thread_wrapper(FROM_HERE, cb)));
+ }
+
+ void SetPeriodicAdvertisingEnable(int advertiser_id, bool enable,
+ StatusCallback cb) override {
+ VLOG(1) << __func__ << " advertiser_id: " << +advertiser_id
+ << " ,enable: " << enable;
+
+ do_in_bta_thread(
+ FROM_HERE,
+ Bind(&BleAdvertisingManager::SetPeriodicAdvertisingEnable,
+ base::Unretained(BleAdvertisingManager::Get()), advertiser_id,
+ enable, jni_thread_wrapper(FROM_HERE, cb)));
+ }
};
BleAdvertiserInterface* btLeAdvertiserInstance = nullptr;
diff --git a/service/test/low_energy_advertiser_unittest.cc b/service/test/low_energy_advertiser_unittest.cc
index eb2211c..d7b0632 100644
--- a/service/test/low_energy_advertiser_unittest.cc
+++ b/service/test/low_energy_advertiser_unittest.cc
@@ -47,31 +47,27 @@
MOCK_METHOD1(RegisterAdvertiser, void(IdStatusCallback));
MOCK_METHOD1(Unregister, void(uint8_t));
- MOCK_METHOD10(SetParameters,
- void(uint8_t advertiser_id,
- uint16_t advertising_event_properties,
- uint32_t min_interval, uint32_t max_interval, int chnl_map,
- int tx_power, uint8_t primary_advertising_phy,
- uint8_t secondary_advertising_phy,
- uint8_t scan_request_notification_enable,
- StatusCallback cb));
- MOCK_METHOD4(SetData, void(int advertiser_id, bool set_scan_rsp,
- std::vector<uint8_t> data, StatusCallback cb));
+ MOCK_METHOD3(SetParameters,
+ void(uint8_t, AdvertiseParameters, ParametersCallback));
+ MOCK_METHOD4(SetData, void(int, bool, std::vector<uint8_t>, StatusCallback));
MOCK_METHOD5(Enable,
- void(uint8_t advertiser_id, bool enable, StatusCallback cb,
- int timeout_s, StatusCallback timeout_cb));
+ void(uint8_t, bool, StatusCallback, int, StatusCallback));
MOCK_METHOD7(StartAdvertising,
void(uint8_t advertiser_id, StatusCallback cb,
AdvertiseParameters, std::vector<uint8_t>,
std::vector<uint8_t>, int, StatusCallback));
-
MOCK_METHOD8(StartAdvertisingSet,
- void(IdStatusCallback cb, AdvertiseParameters params,
+ void(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, int timeout_s,
IdStatusCallback timeout_cb));
+ MOCK_METHOD3(SetPeriodicAdvertisingParameters,
+ void(int, PeriodicAdvertisingParameters, StatusCallback));
+ MOCK_METHOD3(SetPeriodicAdvertisingData,
+ void(int, std::vector<uint8_t>, StatusCallback));
+ MOCK_METHOD3(SetPeriodicAdvertisingEnable, void(int, bool, StatusCallback));
private:
DISALLOW_COPY_AND_ASSIGN(MockAdvertiserHandler);
diff --git a/stack/btm/btm_ble_multi_adv.cc b/stack/btm/btm_ble_multi_adv.cc
index b4ad65f..f659025 100644
--- a/stack/btm/btm_ble_multi_adv.cc
+++ b/stack/btm/btm_ble_multi_adv.cc
@@ -34,6 +34,8 @@
using base::Bind;
using RegisterCb =
base::Callback<void(uint8_t /* inst_id */, uint8_t /* status */)>;
+using IdTxPowerStatusCb = base::Callback<void(
+ uint8_t /* inst_id */, int8_t /* tx_power */, uint8_t /* status */)>;
extern void btm_gen_resolvable_private_addr(
base::Callback<void(uint8_t[8])> cb);
extern fixed_queue_t* btu_general_alarm_queue;
@@ -113,7 +115,7 @@
struct CreatorParams {
uint8_t inst_id;
BleAdvertisingManagerImpl* self;
- RegisterCb cb;
+ IdTxPowerStatusCb cb;
tBTM_BLE_ADV_PARAMS params;
std::vector<uint8_t> advertise_data;
std::vector<uint8_t> scan_response_data;
@@ -314,7 +316,7 @@
// clang-format on
}
- void StartAdvertisingSet(RegisterCb cb, tBTM_BLE_ADV_PARAMS* params,
+ void StartAdvertisingSet(IdTxPowerStatusCb cb, tBTM_BLE_ADV_PARAMS* params,
std::vector<uint8_t> advertise_data,
std::vector<uint8_t> scan_response_data,
tBLE_PERIODIC_ADV_PARAMS* periodic_params,
@@ -341,7 +343,7 @@
[](c_type c, uint8_t advertiser_id, uint8_t status) {
if (status != 0) {
LOG(ERROR) << "registering advertiser failed, status: " << +status;
- c->cb.Run(0, status);
+ c->cb.Run(0, 0, status);
return;
}
@@ -352,7 +354,7 @@
if (status != 0) {
c->self->Unregister(c->inst_id);
LOG(ERROR) << "setting parameters failed, status: " << +status;
- c->cb.Run(0, status);
+ c->cb.Run(0, 0, status);
return;
}
@@ -364,7 +366,7 @@
if (status != 0) {
c->self->Unregister(c->inst_id);
LOG(ERROR) << "setting random address failed, status: " << +status;
- c->cb.Run(0, status);
+ c->cb.Run(0, 0, status);
return;
}
@@ -373,7 +375,7 @@
if (status != 0) {
c->self->Unregister(c->inst_id);
LOG(ERROR) << "setting advertise data failed, status: " << +status;
- c->cb.Run(0, status);
+ c->cb.Run(0, 0, status);
return;
}
@@ -382,7 +384,7 @@
if (status != 0) {
c->self->Unregister(c->inst_id);
LOG(ERROR) << "setting scan response data failed, status: " << +status;
- c->cb.Run(0, status);
+ c->cb.Run(0, 0, status);
return;
}
@@ -408,7 +410,7 @@
if (status != 0) {
c->self->Unregister(c->inst_id);
LOG(ERROR) << "setting periodic parameters failed, status: " << +status;
- c->cb.Run(0, status);
+ c->cb.Run(0, 0, status);
return;
}
@@ -417,7 +419,7 @@
if (status != 0) {
c->self->Unregister(c->inst_id);
LOG(ERROR) << "setting periodic parameters failed, status: " << +status;
- c->cb.Run(0, status);
+ c->cb.Run(0, 0, status);
return;
}
@@ -426,7 +428,7 @@
if (status != 0) {
c->self->Unregister(c->inst_id);
LOG(ERROR) << "enabling periodic advertising failed, status: " << +status;
- c->cb.Run(0, status);
+ c->cb.Run(0, 0, status);
return;
}
@@ -448,10 +450,11 @@
if (status != 0) {
c->self->Unregister(c->inst_id);
LOG(ERROR) << "enabling advertiser failed, status: " << +status;
- c->cb.Run(0, status);
+ c->cb.Run(0, 0, status);
return;
}
- c->cb.Run(c->inst_id, status);
+ int8_t tx_power = c->self->adv_inst[c->inst_id].tx_power;
+ c->cb.Run(c->inst_id, tx_power, status);
},
base::Passed(&c));
@@ -461,6 +464,7 @@
void EnableWithTimerCb(uint8_t inst_id, MultiAdvCb enable_cb, int timeout_s,
MultiAdvCb timeout_cb, uint8_t status) {
+ VLOG(1) << __func__ << " inst_id: " << +inst_id;
AdvertisingInstance* p_inst = &adv_inst[inst_id];
// Run the regular enable callback
@@ -488,7 +492,7 @@
}
AdvertisingInstance* p_inst = &adv_inst[inst_id];
- VLOG(1) << __func__ << "enable: " << enable;
+ VLOG(1) << __func__ << " enable: " << enable << ", timeout: " << +timeout_s;
if (!p_inst->in_use) {
LOG(ERROR) << "Invalid or no active instance";
cb.Run(BTM_BLE_MULTI_ADV_FAILURE);
diff --git a/stack/include/ble_advertiser.h b/stack/include/ble_advertiser.h
index 7546c53..30fe6e6 100644
--- a/stack/include/ble_advertiser.h
+++ b/stack/include/ble_advertiser.h
@@ -95,7 +95,9 @@
* enabled.
*/
virtual void StartAdvertisingSet(
- base::Callback<void(uint8_t /* inst_id */, uint8_t /* status */)> cb,
+ base::Callback<void(uint8_t /* inst_id */, int8_t /* tx_power */,
+ uint8_t /* status */)>
+ cb,
tBTM_BLE_ADV_PARAMS* params, std::vector<uint8_t> advertise_data,
std::vector<uint8_t> scan_response_data,
tBLE_PERIODIC_ADV_PARAMS* periodic_params,