Add InitialPair plugin

Creates plugins/ directory which will store internal plugins used for admin
tasks and testing. In this CL
* FakeFastPairPlugin for tests
* InitalPairPlugin - simple plugin that triggers Initial Pair flow

PiperOrigin-RevId: 536775192
This commit is contained in:
Janusz Sobczak
2023-05-31 11:36:00 -07:00
committed by Copybara-Service
parent a5060a3c18
commit ddbb711b7b
11 changed files with 242 additions and 17 deletions
+4 -6
View File
@@ -113,9 +113,9 @@ cc_test(
deps = [
":fast_pair_events",
":fast_pair_service",
":test_support",
"//fastpair/internal",
"//fastpair/message_stream:fake_provider",
"//fastpair/plugins:fake_fast_pair_plugin",
"//fastpair/server_access:test_support",
"//internal/platform:logging",
"//internal/platform:test_util",
@@ -128,17 +128,15 @@ cc_test(
cc_library(
name = "test_support",
testonly = True,
srcs = ["fake_fast_pair_plugin.cc"],
hdrs = [
"fake_fast_pair_plugin.h",
"mock_fast_pair_seeker.h",
],
visibility = [
"//fastpair:__subpackages__",
],
deps = [
":fast_pair_events",
":fast_pair_plugin",
":fast_pair_seeker",
"//fastpair/common",
"@com_google_absl//absl/status",
"@com_google_googletest//:gtest_for_library_testonly",
],
)
+3 -3
View File
@@ -48,7 +48,7 @@ class FastPairSeeker {
//
// Returns an error if pairing flow could not be started. Otherwise, the
// pairing result will be returned via the `callback`.
virtual absl::Status StartInitialPairing(FastPairDevice& device,
virtual absl::Status StartInitialPairing(const FastPairDevice& device,
const InitialPairingParam& params,
PairingCallback callback) = 0;
@@ -60,7 +60,7 @@ class FastPairSeeker {
// Returns an error if pairing flow could not be started. Otherwise, the
// pairing result will be returned via the `callback`.
virtual absl::Status StartSubsequentPairing(
FastPairDevice& device, const SubsequentPairingParam& params,
const FastPairDevice& device, const SubsequentPairingParam& params,
PairingCallback callback) = 0;
// Starts asynchronous retroactive pairing flow. This pairing flow is used
@@ -71,7 +71,7 @@ class FastPairSeeker {
// Returns an error if pairing flow could not be started. Otherwise, the
// pairing result will be returned via the `callback`.
virtual absl::Status StartRetroactivePairing(
FastPairDevice& device, const RetroactivePairingParam& param,
const FastPairDevice& device, const RetroactivePairingParam& param,
PairingCallback callback) = 0;
};
} // namespace fastpair
+1 -1
View File
@@ -20,10 +20,10 @@
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "fastpair/fake_fast_pair_plugin.h"
#include "fastpair/fast_pair_events.h"
#include "fastpair/internal/fast_pair_seeker_impl.h"
#include "fastpair/message_stream/fake_provider.h"
#include "fastpair/plugins/fake_fast_pair_plugin.h"
#include "fastpair/server_access/fake_fast_pair_repository.h"
#include "internal/platform/logging.h"
#include "internal/platform/medium_environment.h"
+3 -3
View File
@@ -26,19 +26,19 @@ namespace nearby {
namespace fastpair {
absl::Status FastPairSeekerImpl::StartInitialPairing(
FastPairDevice& device, const InitialPairingParam& params,
const FastPairDevice& device, const InitialPairingParam& params,
PairingCallback callback) {
return absl::UnimplementedError("StartInitialPairing");
}
absl::Status FastPairSeekerImpl::StartSubsequentPairing(
FastPairDevice& device, const SubsequentPairingParam& params,
const FastPairDevice& device, const SubsequentPairingParam& params,
PairingCallback callback) {
return absl::UnimplementedError("StartSubsequentPairing");
}
absl::Status FastPairSeekerImpl::StartRetroactivePairing(
FastPairDevice& device, const RetroactivePairingParam& param,
const FastPairDevice& device, const RetroactivePairingParam& param,
PairingCallback callback) {
return absl::UnimplementedError("StartRetroactivePairing");
}
+3 -3
View File
@@ -59,15 +59,15 @@ class FastPairSeekerImpl : public FastPairSeekerExt,
devices_(devices) {}
// From FastPairSeeker.
absl::Status StartInitialPairing(FastPairDevice& device,
absl::Status StartInitialPairing(const FastPairDevice& device,
const InitialPairingParam& params,
PairingCallback callback) override;
absl::Status StartSubsequentPairing(FastPairDevice& device,
absl::Status StartSubsequentPairing(const FastPairDevice& device,
const SubsequentPairingParam& params,
PairingCallback callback) override;
absl::Status StartRetroactivePairing(FastPairDevice& device,
absl::Status StartRetroactivePairing(const FastPairDevice& device,
const RetroactivePairingParam& param,
PairingCallback callback) override;
+46
View File
@@ -0,0 +1,46 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_MOCK_FAST_PAIR_SEEKER_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_MOCK_FAST_PAIR_SEEKER_H_
#include "gmock/gmock.h"
#include "absl/status/status.h"
#include "fastpair/fast_pair_seeker.h"
namespace nearby {
namespace fastpair {
class MockFastPairSeeker : public FastPairSeeker {
public:
MOCK_METHOD(absl::Status, StartInitialPairing,
(const FastPairDevice& device, const InitialPairingParam& params,
PairingCallback callback),
(override));
MOCK_METHOD(absl::Status, StartSubsequentPairing,
(const FastPairDevice& device,
const SubsequentPairingParam& params, PairingCallback callback),
(override));
MOCK_METHOD(absl::Status, StartRetroactivePairing,
(const FastPairDevice& device,
const RetroactivePairingParam& param, PairingCallback callback),
(override));
};
} // namespace fastpair
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_FASTPAIR_MOCK_FAST_PAIR_SEEKER_H_
+69
View File
@@ -0,0 +1,69 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
package_group(
name = "nearby_fastpair",
packages = [
"//fastpair/...",
],
)
cc_library(
name = "fake_initial_pair_plugin",
hdrs = ["fake_initial_pair_plugin.h"],
compatible_with = ["//buildenv/target:non_prod"],
visibility = ["//:__subpackages__"],
deps = [
"//fastpair:fast_pair_events",
"//fastpair:fast_pair_plugin",
"//fastpair:fast_pair_seeker",
"//fastpair/common",
"//internal/platform:types",
],
)
cc_test(
name = "fake_initial_pair_plugin_test",
size = "small",
srcs = [
"fake_initial_pair_plugin_test.cc",
],
deps = [
":fake_initial_pair_plugin",
"//fastpair:test_support",
"//fastpair/common",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/status",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "fake_fast_pair_plugin",
testonly = True,
srcs = ["fake_fast_pair_plugin.cc"],
hdrs = [
"fake_fast_pair_plugin.h",
],
visibility = [
"//fastpair:__subpackages__",
],
deps = [
"//fastpair:fast_pair_events",
"//fastpair:fast_pair_plugin",
"//fastpair:fast_pair_seeker",
"//fastpair/common",
],
)
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "fastpair/fake_fast_pair_plugin.h"
#include "fastpair/plugins/fake_fast_pair_plugin.h"
namespace nearby {
namespace fastpair {
@@ -0,0 +1,61 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_PLUGINS_INITIAL_PAIR_PLUGIN_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_PLUGINS_INITIAL_PAIR_PLUGIN_H_
#include <memory>
#include "fastpair/common/fast_pair_device.h"
#include "fastpair/fast_pair_events.h"
#include "fastpair/fast_pair_plugin.h"
#include "fastpair/fast_pair_seeker.h"
#include "internal/platform/logging.h"
namespace nearby {
namespace fastpair {
// Simple plugin that starts pairing when it sees a discoverable advertisement.
class FakeInitialPairPlugin : public FastPairPlugin {
public:
class Provider : public FastPairPluginProvider {
public:
std::unique_ptr<FastPairPlugin> GetPlugin(
FastPairSeeker* seeker, const FastPairDevice* device) override {
return std::make_unique<FakeInitialPairPlugin>(seeker, device);
}
};
FakeInitialPairPlugin(FastPairSeeker* seeker, const FastPairDevice* device)
: seeker_(seeker), device_(device) {}
void OnInitialDiscoveryEvent(const InitialDiscoveryEvent& event) override {
absl::Status status = seeker_->StartInitialPairing(
*device_, InitialPairingParam{},
{.on_pairing_result = [](const FastPairDevice& device,
absl::Status status) {
NEARBY_LOGS(INFO) << "Pairing result: " << status;
}});
NEARBY_LOGS(INFO) << "StartInitialPairing: " << status;
}
private:
FastPairSeeker* seeker_;
const FastPairDevice* device_;
};
} // namespace fastpair
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_FASTPAIR_PLUGINS_INITIAL_PAIR_PLUGIN_H_
@@ -0,0 +1,51 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "fastpair/plugins/fake_initial_pair_plugin.h"
#include <memory>
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "absl/status/status.h"
#include "fastpair/common/protocol.h"
#include "fastpair/mock_fast_pair_seeker.h"
namespace nearby {
namespace fastpair {
namespace {
using ::testing::Return;
} // namespace
TEST(FakeInitialPairPluginTest, InitialPair) {
constexpr absl::string_view kModelId = "123456";
constexpr absl::string_view kBleAddress = "F1:F2:F3:F4:F5:F6";
MockFastPairSeeker seeker;
FastPairDevice device(kModelId, kBleAddress,
Protocol::kFastPairInitialPairing);
EXPECT_CALL(seeker, StartInitialPairing)
.Times(1)
.WillOnce(Return(absl::OkStatus()));
FakeInitialPairPlugin::Provider provider;
std::unique_ptr<FastPairPlugin> plugin = provider.GetPlugin(&seeker, &device);
plugin->OnInitialDiscoveryEvent(InitialDiscoveryEvent{});
plugin.reset();
}
} // namespace fastpair
} // namespace nearby