Commit 46010f2e authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS PhoneHub] Add is_out_of_band_connection DiscoveryOptions field

This field will be used by Phone Hub to start discovering a remote
device for an "out-of-band" connection using a pre-synced Bluetooth
address. This CL also makes the fast_advertisement_service_uuid field
optional for out-of-band connections.

Bug: 1106937
Change-Id: I35845fbf6a4626bfd18fd1e9451f4a18fdaabf14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2493427
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#824971}
parent 7ee639e9
......@@ -147,7 +147,8 @@ void NearbyConnectionsManagerImpl::StartDiscovery(
kServiceId,
DiscoveryOptions::New(
kStrategy, std::move(allowed_mediums),
device::BluetoothUUID(kFastAdvertisementServiceUuid)),
device::BluetoothUUID(kFastAdvertisementServiceUuid),
/*is_out_of_band_connection=*/false),
endpoint_discovery_listener_.BindNewPipeAndPassRemote(),
std::move(callback));
}
......
......@@ -297,11 +297,18 @@ void NearbyConnections::StartDiscovery(
mojom::DiscoveryOptionsPtr options,
mojo::PendingRemote<mojom::EndpointDiscoveryListener> listener,
StartDiscoveryCallback callback) {
// Left as empty string if no value has been passed in |options|.
std::string fast_advertisement_service_uuid;
if (options->fast_advertisement_service_uuid) {
fast_advertisement_service_uuid =
options->fast_advertisement_service_uuid->canonical_value();
}
ConnectionOptions connection_options{
.strategy = StrategyFromMojom(options->strategy),
.allowed = MediumSelectorFromMojom(options->allowed_mediums.get()),
.fast_advertisement_service_uuid =
options->fast_advertisement_service_uuid.canonical_value()};
.is_out_of_band_connection = options->is_out_of_band_connection,
.fast_advertisement_service_uuid = fast_advertisement_service_uuid};
mojo::SharedRemote<mojom::EndpointDiscoveryListener> remote(
std::move(listener));
DiscoveryListener discovery_listener{
......
......@@ -200,13 +200,13 @@ class NearbyConnectionsTest : public testing::Test {
void OnDisconnect() { disconnect_run_loop_.Quit(); }
ClientProxy* StartDiscovery(
FakeEndpointDiscoveryListener& fake_discovery_listener) {
FakeEndpointDiscoveryListener& fake_discovery_listener,
bool is_out_of_band_connection = false) {
ClientProxy* client_proxy;
EXPECT_CALL(*service_controller_ptr_, StartDiscovery)
.WillOnce([&client_proxy](ClientProxy* client,
const std::string& service_id,
const ConnectionOptions& options,
const DiscoveryListener& listener) {
.WillOnce([&](ClientProxy* client, const std::string& service_id,
const ConnectionOptions& options,
const DiscoveryListener& listener) {
client_proxy = client;
EXPECT_EQ(kServiceId, service_id);
EXPECT_EQ(Strategy::kP2pPointToPoint, options.strategy);
......@@ -214,8 +214,13 @@ class NearbyConnectionsTest : public testing::Test {
EXPECT_FALSE(options.allowed.ble);
EXPECT_FALSE(options.allowed.web_rtc);
EXPECT_TRUE(options.allowed.wifi_lan);
EXPECT_EQ(kFastAdvertisementServiceUuid,
options.fast_advertisement_service_uuid);
if (is_out_of_band_connection) {
EXPECT_TRUE(options.is_out_of_band_connection);
} else {
EXPECT_FALSE(options.is_out_of_band_connection);
EXPECT_EQ(kFastAdvertisementServiceUuid,
options.fast_advertisement_service_uuid);
}
client->StartedDiscovery(service_id, options.strategy, listener,
/*mediums=*/{});
return Status{Status::kAlreadyDiscovering};
......@@ -229,7 +234,8 @@ class NearbyConnectionsTest : public testing::Test {
/*ble=*/false,
/*web_rtc=*/false,
/*wifi_lan=*/true),
device::BluetoothUUID(kFastAdvertisementServiceUuid)),
device::BluetoothUUID(kFastAdvertisementServiceUuid),
is_out_of_band_connection),
fake_discovery_listener.receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kAlreadyDiscovering, status);
......@@ -455,6 +461,15 @@ TEST_F(NearbyConnectionsTest, StopDiscovery) {
EXPECT_CALL(*service_controller_ptr_, StopDiscovery(testing::_)).Times(1);
}
TEST_F(NearbyConnectionsTest, InjectEndpoint) {
FakeEndpointDiscoveryListener fake_discovery_listener;
StartDiscovery(fake_discovery_listener,
/*is_out_of_band_connection=*/true);
// TODO(khorimoto): Finish this test when InjectBluetoothEndpoint() Mojo API
// is added.
}
TEST_F(NearbyConnectionsTest, RequestConnectionInitiated) {
FakeEndpointDiscoveryListener fake_discovery_listener;
EndpointData endpoint_data = CreateEndpointData(1);
......
......@@ -153,7 +153,11 @@ struct DiscoveryOptions {
// of allowed and supported mediums will be used to scan.
MediumSelection allowed_mediums;
// The fast advertisement service id to scan for in BLE.
bluetooth.mojom.UUID fast_advertisement_service_uuid;
bluetooth.mojom.UUID? fast_advertisement_service_uuid;
// Whether this connection request skips over the normal discovery flow to
// inject discovery information synced outside the Nearby Connections library.
// Intended to be used in conjunction with InjectEndpoint().
bool is_out_of_band_connection = false;
};
// Options for a call to NearbyConnections::RequestConnection().
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment