mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Add FastPairService adapter.
Add an adapter and windows plugin for scalable seeker, PiperOrigin-RevId: 545920541
This commit is contained in:
committed by
Copybara-Service
parent
08d157399c
commit
d516e52204
@@ -33,6 +33,23 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "windows_admin_plugin",
|
||||
srcs = ["windows_admin_plugin.cc"],
|
||||
hdrs = ["windows_admin_plugin.h"],
|
||||
compatible_with = ["//buildenv/target:non_prod"],
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//fastpair:fast_pair_events",
|
||||
"//fastpair:fast_pair_plugin",
|
||||
"//fastpair:fast_pair_seeker",
|
||||
"//fastpair:fast_pair_service",
|
||||
"//fastpair/common",
|
||||
"//fastpair/ui:fast_pair_ui",
|
||||
"//internal/platform:types",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "fake_initial_pair_plugin_test",
|
||||
size = "small",
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// 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/windows_admin_plugin.h"
|
||||
|
||||
#include "fastpair/internal/fast_pair_seeker_impl.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
|
||||
void WindowsAdminPlugin::PluginState::DiscoveryClicked(DiscoveryAction action) {
|
||||
NEARBY_LOGS(INFO) << __func__;
|
||||
if (device == nullptr || fast_pair_service == nullptr) return;
|
||||
absl::Status status = fast_pair_service->GetSeeker()->StartInitialPairing(
|
||||
*device, InitialPairingParam{},
|
||||
{.on_pairing_result = [](const FastPairDevice& device,
|
||||
absl::Status status) {
|
||||
NEARBY_LOGS(INFO) << "Pairing result: " << status;
|
||||
}});
|
||||
NEARBY_LOGS(INFO) << "StartInitialPairing: " << status;
|
||||
}
|
||||
|
||||
void WindowsAdminPlugin::PluginState::SetIsScreenLocked(bool is_locked) {
|
||||
NEARBY_LOGS(INFO) << __func__;
|
||||
if (device == nullptr || fast_pair_service == nullptr) return;
|
||||
FastPairSeekerExt* seeker =
|
||||
static_cast<FastPairSeekerExt*>(fast_pair_service->GetSeeker());
|
||||
seeker->SetIsScreenLocked(is_locked);
|
||||
}
|
||||
|
||||
void WindowsAdminPlugin::OnInitialDiscoveryEvent(
|
||||
const InitialDiscoveryEvent& event) {
|
||||
NEARBY_LOGS(INFO) << "Received on initial discovery event";
|
||||
auto metadata = device_->GetMetadata();
|
||||
if (!metadata) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Ignoring initial discovery event because metadata is missing";
|
||||
return;
|
||||
}
|
||||
state_->device = device_;
|
||||
for (auto* observer : state_->observers.GetObservers()) {
|
||||
observer->OnUpdateDevice(*metadata);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowsAdminPlugin::OnPairEvent(const PairEvent& event) {
|
||||
NEARBY_LOGS(INFO) << "Received on pair event";
|
||||
absl::Status status = seeker_->StartRetroactivePairing(
|
||||
*device_, RetroactivePairingParam{},
|
||||
{.on_pairing_result = [](const FastPairDevice& device,
|
||||
absl::Status status) {
|
||||
NEARBY_LOGS(INFO) << "Pairing result: " << status;
|
||||
// TODO(jsobczak): Ask for user constent and save the Account Key to
|
||||
// user's account.
|
||||
}});
|
||||
NEARBY_LOGS(INFO) << "StartRetroactivePairing: " << status;
|
||||
}
|
||||
|
||||
} // namespace fastpair
|
||||
} // namespace nearby
|
||||
@@ -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.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_PLUGINS_WINDOWS_ADMIN_PLUGIN_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_PLUGINS_WINDOWS_ADMIN_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 "fastpair/fast_pair_service.h"
|
||||
#include "fastpair/ui/actions.h"
|
||||
#include "fastpair/ui/fast_pair/fast_pair_notification_controller.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
|
||||
class WindowsAdminPlugin : public FastPairPlugin {
|
||||
public:
|
||||
struct PluginState {
|
||||
void DiscoveryClicked(DiscoveryAction action);
|
||||
void SetIsScreenLocked(bool is_locked);
|
||||
ObserverList<FastPairNotificationController::Observer> observers;
|
||||
const FastPairDevice* device = nullptr;
|
||||
std::unique_ptr<FastPairService> fast_pair_service;
|
||||
};
|
||||
class Provider : public FastPairPluginProvider {
|
||||
public:
|
||||
explicit Provider(PluginState* state) : state_(state) {}
|
||||
std::unique_ptr<FastPairPlugin> GetPlugin(
|
||||
FastPairSeeker* seeker, const FastPairDevice* device) override {
|
||||
return std::make_unique<WindowsAdminPlugin>(seeker, device, state_);
|
||||
}
|
||||
|
||||
private:
|
||||
PluginState* state_;
|
||||
};
|
||||
|
||||
WindowsAdminPlugin(FastPairSeeker* seeker, const FastPairDevice* device,
|
||||
PluginState* state)
|
||||
: seeker_(seeker), device_(device), state_(state) {}
|
||||
|
||||
void OnInitialDiscoveryEvent(const InitialDiscoveryEvent& event) override;
|
||||
void OnPairEvent(const PairEvent& event) override;
|
||||
|
||||
private:
|
||||
FastPairSeeker* seeker_;
|
||||
const FastPairDevice* device_;
|
||||
PluginState* state_;
|
||||
};
|
||||
|
||||
} // namespace fastpair
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_PLUGINS_WINDOWS_ADMIN_PLUGIN_H_
|
||||
Reference in New Issue
Block a user