mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Add fix to check the availability of BluetoothAdapter
This change makes sure BluetoothClassic and BLE medium can only be added to the CONNECTION_REQUEST frame if BluetoothAdapter is valid and enabled. PiperOrigin-RevId: 450777716
This commit is contained in:
committed by
Copybara-Service
parent
28acece858
commit
cb8fef7875
@@ -46,7 +46,9 @@ bool Ble::IsAvailable() const {
|
||||
return IsAvailableLocked();
|
||||
}
|
||||
|
||||
bool Ble::IsAvailableLocked() const { return medium_.IsValid(); }
|
||||
bool Ble::IsAvailableLocked() const {
|
||||
return medium_.IsValid() && adapter_.IsValid() && adapter_.IsEnabled();
|
||||
}
|
||||
|
||||
bool Ble::StartAdvertising(const std::string& service_id,
|
||||
const ByteArray& advertisement_bytes,
|
||||
|
||||
@@ -181,10 +181,10 @@ TEST_F(BleTest, CanConstructValidObject) {
|
||||
|
||||
EXPECT_TRUE(ble_a.IsMediumValid());
|
||||
EXPECT_TRUE(ble_a.IsAdapterValid());
|
||||
EXPECT_TRUE(ble_a.IsAvailable());
|
||||
EXPECT_FALSE(ble_a.IsAvailable());
|
||||
EXPECT_TRUE(ble_b.IsMediumValid());
|
||||
EXPECT_TRUE(ble_b.IsAdapterValid());
|
||||
EXPECT_TRUE(ble_b.IsAvailable());
|
||||
EXPECT_FALSE(ble_b.IsAvailable());
|
||||
EXPECT_NE(&radio_a.GetBluetoothAdapter(), &radio_b.GetBluetoothAdapter());
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ bool BluetoothClassic::IsAvailable() const {
|
||||
}
|
||||
|
||||
bool BluetoothClassic::IsAvailableLocked() const {
|
||||
return medium_.IsValid() && adapter_.IsValid();
|
||||
return medium_.IsValid() && adapter_.IsValid() && adapter_.IsEnabled();
|
||||
}
|
||||
|
||||
bool BluetoothClassic::TurnOnDiscoverability(const std::string& device_name) {
|
||||
|
||||
Reference in New Issue
Block a user