mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Pause Bluetooth classic discovery
PiperOrigin-RevId: 647333108
This commit is contained in:
committed by
Copybara-Service
parent
f63912cc28
commit
32cee3439b
@@ -61,6 +61,7 @@ cc_library(
|
||||
"//internal/platform/implementation:comm",
|
||||
"//proto/mediums:web_rtc_signaling_frames_cc_proto",
|
||||
# TODO: Support WebRTC
|
||||
"@com_google_absl//absl/base:core_headers",
|
||||
"@com_google_absl//absl/container:btree",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
|
||||
@@ -20,11 +20,15 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/container/btree_map.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "connections/implementation/mediums/ble_v2/advertisement_read_result.h"
|
||||
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
|
||||
#include "connections/implementation/mediums/ble_v2/discovered_peripheral_callback.h"
|
||||
#include "connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.h"
|
||||
#include "connections/implementation/mediums/bluetooth_radio.h"
|
||||
#include "connections/power_level.h"
|
||||
@@ -32,9 +36,12 @@
|
||||
#include "internal/platform/bluetooth_adapter.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancelable_alarm.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/multi_thread_executor.h"
|
||||
#include "internal/platform/mutex.h"
|
||||
#include "internal/platform/mutex_lock.h"
|
||||
#include "internal/platform/runnable.h"
|
||||
#include "internal/platform/scheduled_executor.h"
|
||||
#include "internal/platform/single_thread_executor.h"
|
||||
|
||||
@@ -139,6 +146,12 @@ class BleV2 final {
|
||||
return medium_.IsValid();
|
||||
}
|
||||
|
||||
// Returns true if the BLE device support extended advertisement.
|
||||
bool IsExtendedAdvertisementsAvailable() ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
MutexLock lock(&mutex_);
|
||||
return medium_.IsExtendedAdvertisementsAvailable();
|
||||
};
|
||||
|
||||
private:
|
||||
struct AdvertisingInfo {
|
||||
mediums::BleAdvertisement medium_advertisement;
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "connections/implementation/mediums/bluetooth_radio.h"
|
||||
#include "internal/platform/bluetooth_adapter.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/mutex_lock.h"
|
||||
#include "internal/platform/uuid.h"
|
||||
@@ -208,7 +211,7 @@ bool BluetoothClassic::StartDiscovery(DiscoveredDeviceCallback callback) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsDiscovering()) {
|
||||
if (IsDiscoveringLocked()) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Refusing to start discovery of BT devices because another "
|
||||
"discovery is already in-progress.";
|
||||
@@ -229,7 +232,7 @@ bool BluetoothClassic::StartDiscovery(DiscoveredDeviceCallback callback) {
|
||||
bool BluetoothClassic::StopDiscovery() {
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
if (!IsDiscovering()) {
|
||||
if (!IsDiscoveringLocked()) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Can't stop discovery of BT devices because it never started.";
|
||||
return false;
|
||||
@@ -244,7 +247,7 @@ bool BluetoothClassic::StopDiscovery() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BluetoothClassic::IsDiscovering() const { return scan_info_.valid; }
|
||||
bool BluetoothClassic::IsDiscoveringLocked() const { return scan_info_.valid; }
|
||||
|
||||
bool BluetoothClassic::StartAcceptingConnections(
|
||||
const std::string& service_id, AcceptedConnectionCallback callback) {
|
||||
@@ -445,6 +448,12 @@ BluetoothDevice BluetoothClassic::GetRemoteDevice(
|
||||
return medium_->GetRemoteDevice(mac_address);
|
||||
}
|
||||
|
||||
bool BluetoothClassic::IsDiscovering() const {
|
||||
MutexLock lock(&mutex_);
|
||||
return IsDiscoveringLocked();
|
||||
;
|
||||
}
|
||||
|
||||
std::string BluetoothClassic::GetMacAddress() const {
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
|
||||
@@ -15,18 +15,16 @@
|
||||
#ifndef CORE_INTERNAL_MEDIUMS_BLUETOOTH_CLASSIC_H_
|
||||
#define CORE_INTERNAL_MEDIUMS_BLUETOOTH_CLASSIC_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "connections/implementation/mediums/bluetooth_radio.h"
|
||||
#include "connections/listeners.h"
|
||||
#include "internal/platform/bluetooth_adapter.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/multi_thread_executor.h"
|
||||
#include "internal/platform/mutex.h"
|
||||
@@ -121,6 +119,8 @@ class BluetoothClassic {
|
||||
BluetoothDevice GetRemoteDevice(const std::string& mac_address)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
bool IsDiscovering() const ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
protected:
|
||||
// Use for unit tests only to inject a BluetoothClassicMedium.
|
||||
BluetoothClassic(BluetoothRadio& radio,
|
||||
@@ -171,7 +171,7 @@ class BluetoothClassic {
|
||||
bool RestoreDeviceName() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
// Returns true if device is currently in discovery mode.
|
||||
bool IsDiscovering() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
bool IsDiscoveringLocked() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
// Establishes connection to BT service that was might be started on another
|
||||
// device with StartAcceptingConnections() using the same service_id.
|
||||
|
||||
Reference in New Issue
Block a user