Skip to content

Commit

Permalink
[Chromecast][BLE] Add function IsConnectedLeDevice
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
tiansong0101 authored and Commit Bot committed Feb 26, 2019
1 parent e1cdd90 commit 6f76911
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions chromecast/device/bluetooth/le/gatt_client_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
3 changes: 3 additions & 0 deletions chromecast/device/bluetooth/le/gatt_client_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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>>)>>
Expand All @@ -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();
}

Expand Down

0 comments on commit 6f76911

Please sign in to comment.