internal clean

PiperOrigin-RevId: 604358478
This commit is contained in:
Hai Shang
2024-02-05 10:23:25 -08:00
committed by Copybara-Service
parent 0efbd2a29d
commit 9896e327c0
3 changed files with 0 additions and 95 deletions
-36
View File
@@ -130,42 +130,6 @@ bool BleV2Medium::StopScanning() {
return impl_->StopScanning();
}
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession>
BleV2Medium::StartScanningTmp(
const Uuid& service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
api::ble_v2::BleMedium::ScanningCallback callback) {
MutexLock lock(&mutex_);
if (impl_->StartScanning(
service_uuid, tx_power_level,
api::ble_v2::BleMedium::ScanCallback{
.advertisement_found_cb =
[this,
found_callback = std::move(callback.advertisement_found_cb)](
api::ble_v2::BlePeripheral& peripheral,
BleAdvertisementData advertisement_data) mutable {
MutexLock lock(&mutex_);
if (!peripherals_.contains(&peripheral)) {
NEARBY_LOGS(INFO)
<< "Peripheral impl=" << &peripheral
<< " does not exist; add it to the map.";
peripherals_.insert(&peripheral);
}
found_callback(peripheral, advertisement_data);
},
})) {
callback.start_scanning_result(absl::OkStatus());
} else {
callback.start_scanning_result(absl::InternalError("Failed to start scan"));
return nullptr;
}
return std::make_unique<api::ble_v2::BleMedium::ScanningSession>(
api::ble_v2::BleMedium::ScanningSession{.stop_scanning = [this]() {
return impl_->StopScanning()
? absl::OkStatus()
: absl::InternalError("Failed to stop advertising");
}});
}
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession>
BleV2Medium::StartScanning(const Uuid& service_uuid,
api::ble_v2::TxPowerLevel tx_power_level,
-9
View File
@@ -398,8 +398,6 @@ class BleV2Medium final {
// Returns true once the BLE scan has been initiated.
// This interface will be deprecated soon.
// TODO(b/271305977) remove this function.
// Use 'unique_ptr<ScanningSession> StartScanningTmp' instead.
bool StartScanning(const Uuid& service_uuid,
api::ble_v2::TxPowerLevel tx_power_level,
ScanCallback callback);
@@ -411,13 +409,6 @@ class BleV2Medium final {
const Uuid& service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
api::ble_v2::BleMedium::ScanningCallback callback);
// Temp interface for windows client to use before windows has native impl
// for 'unique_ptr<AdvertisingSession> StartScanning'.
// TODO(b/271305977) remove this function.
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> StartScanningTmp(
const Uuid& service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
api::ble_v2::BleMedium::ScanningCallback callback);
// Starts Gatt Server for waiting to client connection.
std::unique_ptr<GattServer> StartGattServer(
ServerGattConnectionCallback callback);
-50
View File
@@ -434,56 +434,6 @@ TEST_F(BleV2MediumTest, CanStartAsyncScanningAndAdvertising) {
env_.Stop();
}
TEST_F(BleV2MediumTest, CanStartAsyncScanningAndAdvertisingWithTmpImpl) {
env_.Start();
BluetoothAdapter adapter_a;
BluetoothAdapter adapter_b;
BleV2Medium ble_a(adapter_a);
BleV2Medium ble_b(adapter_b);
Uuid service_uuid(1234, 5678);
ByteArray advertisement_bytes{std::string(kAdvertisementString)};
ByteArray advertisement_header_bytes{std::string(kAdvertisementHeaderString)};
CountDownLatch found_latch(1);
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> scanning_session =
ble_a.StartScanningTmp(
service_uuid, kTxPowerLevel,
api::ble_v2::BleMedium::ScanningCallback{
.advertisement_found_cb =
[&](api::ble_v2::BlePeripheral& peripheral,
BleAdvertisementData advertisement_data) -> void {
found_latch.CountDown();
},
});
// Succeed to start regular advertisement.
BleAdvertisementData advertising_data;
advertising_data.is_extended_advertisement = false;
advertising_data.service_data = {{service_uuid, advertisement_header_bytes}};
std::unique_ptr<api::ble_v2::BleMedium::AdvertisingSession> adv_session =
ble_b.StartAdvertisingTmp(
advertising_data,
{.tx_power_level = kTxPowerLevel, .is_connectable = true},
{.start_advertising_result = [](absl::Status) {}});
EXPECT_NE(adv_session, nullptr);
EXPECT_TRUE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
EXPECT_TRUE(
env_.GetBleV2MediumStatus(*ble_b.GetImpl()).value().is_advertising);
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
EXPECT_OK(scanning_session->stop_scanning());
EXPECT_OK(adv_session->stop_advertising());
EXPECT_FALSE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
EXPECT_FALSE(
env_.GetBleV2MediumStatus(*ble_b.GetImpl()).value().is_advertising);
env_.UnregisterBleV2Medium(*ble_a.GetImpl());
env_.UnregisterBleV2Medium(*ble_b.GetImpl());
EXPECT_EQ(env_.GetBleV2MediumStatus(*ble_a.GetImpl()), absl::nullopt);
EXPECT_EQ(env_.GetBleV2MediumStatus(*ble_b.GetImpl()), absl::nullopt);
env_.Stop();
}
TEST_F(BleV2MediumTest, CanStartGattServer) {
env_.Start();
BluetoothAdapter adapter;