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:
aaronyujiaze
2022-05-24 15:05:45 -07:00
committed by Copybara-Service
parent 28acece858
commit cb8fef7875
3 changed files with 6 additions and 4 deletions
+3 -1
View File
@@ -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) {