mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
internal bug fix
PiperOrigin-RevId: 704819636
This commit is contained in:
committed by
Copybara-Service
parent
2352d73b41
commit
8979083e31
@@ -490,9 +490,14 @@ api::BluetoothDevice* BluetoothClassicMedium::GetRemoteDevice(
|
||||
<< " is not in list. create it";
|
||||
auto bluetooth_device = std::make_unique<BluetoothDevice>(mac_address);
|
||||
|
||||
mac_address_to_bluetooth_device_map_[mac_address] =
|
||||
std::move(bluetooth_device);
|
||||
return mac_address_to_bluetooth_device_map_[mac_address].get();
|
||||
if (IsWatcherStarted()) {
|
||||
mac_address_to_bluetooth_device_map_[mac_address] =
|
||||
std::move(bluetooth_device);
|
||||
return mac_address_to_bluetooth_device_map_[mac_address].get();
|
||||
} else {
|
||||
cached_bluetooth_devices_map_[mac_address] = std::move(bluetooth_device);
|
||||
return cached_bluetooth_devices_map_[mac_address].get();
|
||||
}
|
||||
}
|
||||
|
||||
LOG(INFO) << __func__ << ": Bluetooth device " << mac_address
|
||||
@@ -511,6 +516,15 @@ bool BluetoothClassicMedium::StartScanning() {
|
||||
|
||||
mac_address_to_bluetooth_device_map_.clear();
|
||||
removed_bluetooth_devices_map_.clear();
|
||||
if (!cached_bluetooth_devices_map_.empty()) {
|
||||
for (auto& [mac_address, bluetooth_device] :
|
||||
cached_bluetooth_devices_map_) {
|
||||
mac_address_to_bluetooth_device_map_[mac_address] =
|
||||
std::move(bluetooth_device);
|
||||
}
|
||||
|
||||
cached_bluetooth_devices_map_.clear();
|
||||
}
|
||||
|
||||
// The Start method can only be called when the DeviceWatcher is in the
|
||||
// Created, Stopped or Aborted state.
|
||||
|
||||
@@ -159,6 +159,10 @@ class BluetoothClassicMedium : public api::BluetoothClassicMedium {
|
||||
absl::flat_hash_map<std::string, std::unique_ptr<BluetoothDevice>>
|
||||
removed_bluetooth_devices_map_;
|
||||
|
||||
// The caller may call to create Bluetooth device when scanning is off.
|
||||
absl::flat_hash_map<std::string, std::unique_ptr<BluetoothDevice>>
|
||||
cached_bluetooth_devices_map_;
|
||||
|
||||
BluetoothAdapter& bluetooth_adapter_;
|
||||
|
||||
BluetoothAdapter::ScanMode scan_mode_ = BluetoothAdapter::ScanMode::kUnknown;
|
||||
|
||||
Reference in New Issue
Block a user