Expose LE advertiser address for easier PTS tests (4/6)
This patchset adds a hidden method getOwnAddress, that lets app with
BLUETOOTH_PRIVILEGED permission to lear their own addreess. This is done
exclusively for PTS tests.
Bug: 35147497
Test: manual
Change-Id: I5ad554d872f2b772f2bf91642a9648c4018d935c
diff --git a/btif/src/btif_ble_advertiser.cc b/btif/src/btif_ble_advertiser.cc
index d26948f..a37b095 100644
--- a/btif/src/btif_ble_advertiser.cc
+++ b/btif/src/btif_ble_advertiser.cc
@@ -107,6 +107,13 @@
base::Unretained(BleAdvertisingManager::Get()), advertiser_id));
}
+ void GetOwnAddress(uint8_t advertiser_id, GetAddressCallback cb) override {
+ do_in_bta_thread(FROM_HERE,
+ Bind(&BleAdvertisingManager::GetOwnAddress,
+ base::Unretained(BleAdvertisingManager::Get()),
+ advertiser_id, jni_thread_wrapper(FROM_HERE, cb)));
+ }
+
void SetParameters(uint8_t advertiser_id, AdvertiseParameters params,
ParametersCallback cb) override {
VLOG(1) << __func__;
diff --git a/service/test/low_energy_advertiser_unittest.cc b/service/test/low_energy_advertiser_unittest.cc
index a61cdf3..03188d7 100644
--- a/service/test/low_energy_advertiser_unittest.cc
+++ b/service/test/low_energy_advertiser_unittest.cc
@@ -47,6 +47,7 @@
MOCK_METHOD1(RegisterAdvertiser, void(IdStatusCallback));
MOCK_METHOD1(Unregister, void(uint8_t));
+ MOCK_METHOD2(GetOwnAddress, void(uint8_t, GetAddressCallback));
MOCK_METHOD3(SetParameters,
void(uint8_t, AdvertiseParameters, ParametersCallback));
MOCK_METHOD4(SetData, void(int, bool, std::vector<uint8_t>, StatusCallback));
diff --git a/stack/btm/btm_ble_multi_adv.cc b/stack/btm/btm_ble_multi_adv.cc
index 8398b1a..aeb5a1e 100644
--- a/stack/btm/btm_ble_multi_adv.cc
+++ b/stack/btm/btm_ble_multi_adv.cc
@@ -160,6 +160,12 @@
~BleAdvertisingManagerImpl() { adv_inst.clear(); }
+ void GetOwnAddress(uint8_t inst_id, GetAddressCallback cb) override {
+ bt_bdaddr_t addr;
+ memcpy(addr.address, adv_inst[inst_id].own_address, BD_ADDR_LEN);
+ cb.Run(adv_inst[inst_id].own_address_type, addr);
+ }
+
void ReadInstanceCountCb(uint8_t instance_count) {
this->inst_count = instance_count;
adv_inst.reserve(inst_count);
diff --git a/stack/include/ble_advertiser.h b/stack/include/ble_advertiser.h
index 5fe30d2..d51161c 100644
--- a/stack/include/ble_advertiser.h
+++ b/stack/include/ble_advertiser.h
@@ -150,6 +150,10 @@
virtual void OnAdvertisingSetTerminated(
uint8_t status, uint8_t advertising_handle, uint16_t connection_handle,
uint8_t num_completed_extended_adv_events) = 0;
+
+ using GetAddressCallback =
+ base::Callback<void(uint8_t /* address_type*/, bt_bdaddr_t /*address*/)>;
+ virtual void GetOwnAddress(uint8_t inst_id, GetAddressCallback cb) = 0;
};
#endif // BLE_ADVERTISER_H