mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Add observer for pairing events.
Defines an observer for BT classic medium. The observer is notified when a device is paired or unpaired. PiperOrigin-RevId: 521917539
This commit is contained in:
committed by
Copybara-Service
parent
1d2b0272d3
commit
665b0b0e86
@@ -111,6 +111,29 @@ class BluetoothClassicMedium {
|
||||
DefaultCallback<BluetoothDevice&>();
|
||||
};
|
||||
|
||||
class Observer {
|
||||
public:
|
||||
virtual ~Observer() = default;
|
||||
|
||||
// Called when a new `device` is added to the adapter.
|
||||
virtual void DeviceAdded(BluetoothDevice& device) {}
|
||||
|
||||
// Called when `device` is removed from the adapter.
|
||||
virtual void DeviceRemoved(BluetoothDevice& device) {}
|
||||
|
||||
// Called when the address of `device` changed due to pairing.
|
||||
virtual void DeviceAddressChanged(BluetoothDevice& device,
|
||||
absl::string_view old_address) {}
|
||||
|
||||
// Called when the paired property of `device` changed.
|
||||
virtual void DevicePairedChanged(BluetoothDevice& device,
|
||||
bool new_paired_status) {}
|
||||
|
||||
// Called when `device` has connected or disconnected.
|
||||
virtual void DeviceConnectedStateChanged(BluetoothDevice& device,
|
||||
bool connected) {}
|
||||
};
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#startDiscovery()
|
||||
//
|
||||
// Returns true once the process of discovery has been initiated.
|
||||
@@ -152,6 +175,9 @@ class BluetoothClassicMedium {
|
||||
const std::string& service_name, const std::string& service_uuid) = 0;
|
||||
|
||||
virtual BluetoothDevice* GetRemoteDevice(const std::string& mac_address) = 0;
|
||||
|
||||
virtual void AddObserver(Observer* observer) = 0;
|
||||
virtual void RemoveObserver(Observer* observer) = 0;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
||||
@@ -277,5 +277,14 @@ api::BluetoothDevice* BluetoothClassicMedium::GetRemoteDevice(
|
||||
return env.FindBluetoothDevice(mac_address);
|
||||
}
|
||||
|
||||
void BluetoothClassicMedium::AddObserver(
|
||||
api::BluetoothClassicMedium::Observer* observer) {
|
||||
// TODO(b/269521993): Implement observer callbacks.
|
||||
}
|
||||
void BluetoothClassicMedium::RemoveObserver(
|
||||
api::BluetoothClassicMedium::Observer* observer) {
|
||||
// TODO(b/269521993): Implement observer callbacks.
|
||||
}
|
||||
|
||||
} // namespace g3
|
||||
} // namespace nearby
|
||||
|
||||
@@ -236,6 +236,9 @@ class BluetoothClassicMedium : public api::BluetoothClassicMedium {
|
||||
api::BluetoothDevice* GetRemoteDevice(
|
||||
const std::string& mac_address) override;
|
||||
|
||||
void AddObserver(Observer* observer) override;
|
||||
void RemoveObserver(Observer* observer) override;
|
||||
|
||||
private:
|
||||
absl::Mutex mutex_;
|
||||
BluetoothAdapter* adapter_; // Our device adapter; read-only.
|
||||
|
||||
@@ -148,6 +148,15 @@ class BluetoothClassicMedium : public api::BluetoothClassicMedium {
|
||||
api::BluetoothDevice* GetRemoteDevice(const std::string& mac_address) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
void AddObserver(Observer* observer) override {
|
||||
// TODO(b/269521993): Implement.
|
||||
}
|
||||
|
||||
// Removes an observer. It's OK to remove an unregistered observer.
|
||||
void RemoveObserver(Observer* observer) override {
|
||||
// TODO(b/269521993): Implement.
|
||||
}
|
||||
|
||||
private:
|
||||
bool StartScanning() ABSL_SHARED_LOCKS_REQUIRED(mutex_);
|
||||
bool StopScanning() ABSL_SHARED_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
Reference in New Issue
Block a user