[Chromecast][BLE] Add function IsConnectedLeDevice
Bug: internal b/125609259 Test: cast_bluetooth_unittests, manual Change-Id: I9756bb852fb568ba6725fd0d7f9dd716cf066453 Reviewed-on: https://chromium-review.googlesource.com/c/1487886 Commit-Queue: Yuchen Liu <yucliu@chromium.org> Reviewed-by: Yuchen Liu <yucliu@chromium.org> Reviewed-by: Bailey Forrest <bcf@chromium.org> Auto-Submit: Tiansong Cui <tiansong@google.com> Cr-Commit-Position: refs/heads/master@{#635379}
This commit is contained in:
chromecast/device/bluetooth/le
@ -158,6 +158,12 @@ void GattClientManagerImpl::EnqueueReadRemoteRssiRequest(
|
||||
}
|
||||
}
|
||||
|
||||
bool GattClientManagerImpl::IsConnectedLeDevice(
|
||||
const bluetooth_v2_shlib::Addr& addr) {
|
||||
DCHECK(io_task_runner_->BelongsToCurrentThread());
|
||||
return connected_devices_.find(addr) != connected_devices_.end();
|
||||
}
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner>
|
||||
GattClientManagerImpl::task_runner() {
|
||||
return io_task_runner_;
|
||||
|
@ -62,6 +62,9 @@ class GattClientManagerImpl
|
||||
// serially.
|
||||
void EnqueueReadRemoteRssiRequest(const bluetooth_v2_shlib::Addr& addr);
|
||||
|
||||
// True if it is a connected BLE device. Must be called on IO task runner.
|
||||
bool IsConnectedLeDevice(const bluetooth_v2_shlib::Addr& addr);
|
||||
|
||||
// TODO(bcf): Should be private and passed into objects which need it (e.g.
|
||||
// RemoteDevice, RemoteCharacteristic).
|
||||
bluetooth_v2_shlib::GattClient* gatt_client() const { return gatt_client_; }
|
||||
|
@ -250,6 +250,7 @@ TEST_F(GattClientManagerTest, RemoteDeviceConnect) {
|
||||
|
||||
scoped_refptr<RemoteDevice> device = GetDevice(kTestAddr1);
|
||||
EXPECT_FALSE(device->IsConnected());
|
||||
EXPECT_FALSE(gatt_client_manager_->IsConnectedLeDevice(kTestAddr1));
|
||||
EXPECT_EQ(kTestAddr1, device->addr());
|
||||
|
||||
// These should fail if we're not connected.
|
||||
@ -280,6 +281,7 @@ TEST_F(GattClientManagerTest, RemoteDeviceConnect) {
|
||||
delegate->OnGetServices(kTestAddr1, {});
|
||||
|
||||
EXPECT_TRUE(device->IsConnected());
|
||||
EXPECT_TRUE(gatt_client_manager_->IsConnectedLeDevice(kTestAddr1));
|
||||
|
||||
base::MockCallback<
|
||||
base::OnceCallback<void(std::vector<scoped_refptr<RemoteDevice>>)>>
|
||||
@ -298,6 +300,8 @@ TEST_F(GattClientManagerTest, RemoteDeviceConnect) {
|
||||
delegate->OnConnectChanged(kTestAddr1, true /* status */,
|
||||
false /* connected */);
|
||||
EXPECT_FALSE(device->IsConnected());
|
||||
EXPECT_FALSE(gatt_client_manager_->IsConnectedLeDevice(kTestAddr1));
|
||||
|
||||
fake_task_runner_->RunUntilIdle();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user